package config import ( "fmt" "periph.io/x/conn/v3/gpio" "periph.io/x/conn/v3/gpio/gpioreg" ) /* // Load the configuration file. func Load(name string) (*Configuration, error) { var ( cfg Configuration md, err = toml.DecodeFile(name, &cfg) ) if err != nil { return nil, err } if u := md.Undecoded(); len(u) > 0 { return nil, fmt.Errorf("bragi: unknown configuration keys: %v", u) } return &cfg, nil } */ // Structure holds the configuration settings for the application. type Structure struct { Audio *Audio `hcl:"audio,block"` Player *Player `hcl:"player,block"` Page []*Page `hcl:"page,block"` Display []*Display `hcl:"display,block"` Input []*Input `hcl:"input,block"` Visual []*Visual `hcl:"visual,block"` } // Audio stream configuration. type Audio struct { Type string `hcl:"type"` Host *string `hcl:"host"` Path *string `hcl:"path"` } // Player configuration for the music player. type Player struct { Type string `hcl:"type"` Host *string `hcl:"host"` Password *string `hcl:"password"` } // Page configuration. type Page struct { Name string `hcl:"name,label"` Visual []string `hcl:"visual"` Action *PageAction `hcl:"action,block"` } type PageAction struct { RotaryCW *string `hcl:"rotary_cw"` RotaryCCW *string `hcl:"rotary_ccw"` RotaryClick *string `hcl:"rotary_click"` RotaryHold *string `hcl:"rotary_hold"` } // Display configuration for the display(s). type Display struct { Name string `hcl:"name,label"` // Type of display. Type string `hcl:"type"` // Size of the display in pixels. Size string `hcl:"size"` // Bus is the I²C or SPI bus name. Bus string `hcl:"bus,optional"` // Address is the I²C address. Address string `hcl:"addr,optional"` // Frequency is the I²C or SPI bus frequency. Freq string `hcl:"frequency,optional"` // Reset is the reset pin. Reset string `hcl:"reset,optional"` // DC is the data/command pin. DC string `hcl:"dc,optional"` // CS is the chip select pin. CS string `hcl:"cs,optional"` // BL is the backlight pin. BL string `hcl:"bl,optional"` // Host name. Host string `hcl:"host,optional"` // Port name or number. Port string `hcl:"port,optional"` // Rotate the screen. Rotate string `hcl:"rotate,optional"` } // Input configuration for the input devices. type Input struct { Name string `hcl:"name,label"` Type string `hcl:"type"` } // InputRotary configuration for a rotary encoder. type InputRotary struct { // Name of the rotary encoder. Name string `hcl:"name,label"` // ID is the device identifier, if left empty the device is the first rotary found. ID *string `hcl:"id,omitempty"` // CCW is the counter-clockwise action. CCW string `hcl:"ccw"` // CW is the clockwise action. CW string `hcl:"cw"` // Click is the switch action. Click string `hcl:"click"` } // Visual configuration. type Visual struct { Name string `hcl:"name,label"` Type string `hcl:"type"` Config map[string]string `hcl:"config,optional"` } // BusType is the bus type (i2c or spi). type BusType string func (t *BusType) UnmarshalText(text []byte) error { switch string(text) { case "i2c", "spi": *t = BusType(string(text)) return nil default: return fmt.Errorf("bragi: invalid bus type %q", text) } } // PinOut is the GPIO output pin. type PinOut struct { Pin gpio.PinOut } func (c *PinOut) UnmarshalText(text []byte) error { if c.Pin = gpioreg.ByName(string(text)); c.Pin == nil { return fmt.Errorf("bragi: invalid GPIO pin %q", text) } return nil }