Checkpoint
This commit is contained in:
138 files changed
+1898
-57607
No files matched your search
+49
-110
@@ -1,74 +1,32 @@
|
||||
// Package config contains the configuration structure and parser.
|
||||
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"`
|
||||
// Config structure.
|
||||
type Config struct {
|
||||
Display Display `hcl:"display,block"`
|
||||
Input Input `hcl:"input,block"`
|
||||
Audio Audio `hcl:"audio,block"`
|
||||
Player Player `hcl:"player,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).
|
||||
// Display configuration for OLED and TFT screens.
|
||||
type Display struct {
|
||||
Name string `hcl:"name,label"`
|
||||
FPS int `hcl:"fps,optional"`
|
||||
Left DisplayConfig `hcl:"left,block"`
|
||||
Right DisplayConfig `hcl:"right,block"`
|
||||
Color DisplayConfig `hcl:"color,block"`
|
||||
}
|
||||
|
||||
// DisplayConfig is the configuration for one display.
|
||||
type DisplayConfig struct {
|
||||
Name string
|
||||
|
||||
// Type of display.
|
||||
Type string `hcl:"type"`
|
||||
|
||||
// Mode of operation; i2c or spi (defaults to i2c).
|
||||
Mode string `hcl:"mode,optional"`
|
||||
|
||||
// Size of the display in pixels.
|
||||
Size string `hcl:"size"`
|
||||
|
||||
@@ -101,60 +59,41 @@ type Display struct {
|
||||
|
||||
// Rotate the screen.
|
||||
Rotate string `hcl:"rotate,optional"`
|
||||
|
||||
// Flip the screen vertically (if supported by hardware).
|
||||
Flip bool `hcl:"flip,optional"`
|
||||
|
||||
// Mirror the screen horizontally (if supported by hardware).
|
||||
Mirror bool `hcl:"flip,optional"`
|
||||
}
|
||||
|
||||
// Input configuration for the input devices.
|
||||
// Input peripherals.
|
||||
type Input struct {
|
||||
Name string `hcl:"name,label"`
|
||||
Encoder Encoder `hcl:"encoder,block"`
|
||||
}
|
||||
|
||||
// Encoder is a rotary encoder.
|
||||
type Encoder struct {
|
||||
Type string `hcl:"type"`
|
||||
|
||||
CW string `hcl:"cw,optional"`
|
||||
CCW string `hcl:"ccw,optional"`
|
||||
Switch string `hcl:"sw,optional"`
|
||||
}
|
||||
|
||||
// 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"`
|
||||
// Audio source provides PCM samples.
|
||||
type Audio struct {
|
||||
Type string `hcl:"type"`
|
||||
Path string `hcl:"path,optional"`
|
||||
Host string `hcl:"host,optional"`
|
||||
Rate float64 `hcl:"rate,optional"`
|
||||
Channels int `hcl:"channels,optional"`
|
||||
Bits int `hcl:"bits,optional"`
|
||||
}
|
||||
|
||||
// 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
|
||||
// Player controls the audio.
|
||||
type Player struct {
|
||||
Type string `hcl:"type"`
|
||||
Host string `hcl:"host,optional"`
|
||||
Password string `hcl:"password,optional"`
|
||||
}
|
||||
Reference in new issue
Block a user