colorcoding

This commit is contained in:
legop3
2026-03-23 03:39:36 -04:00
parent ad1b6b48f8
commit 20227cd0f8
27 changed files with 291 additions and 143 deletions
+1
View File
@@ -3,6 +3,7 @@ package roverd
type helloMessage struct {
Type string `json:"type"`
Name string `json:"name"`
Color string `json:"color,omitempty"`
Battery BatteryConfig `json:"battery"`
MaxWheelSpeed int `json:"maxWheelSpeed"`
Media MediaConfig `json:"media"`
+21
View File
@@ -5,6 +5,8 @@ import (
"fmt"
"net/url"
"os"
"regexp"
"strings"
"time"
"gopkg.in/yaml.v3"
@@ -123,6 +125,7 @@ type AutoSideBrushConfig struct {
type Config struct {
Name string `yaml:"name"`
Color string `yaml:"color" json:"color,omitempty"`
ServerURL string `yaml:"serverUrl"`
Serial SerialConfig `yaml:"serial"`
BRC BRCConfig `yaml:"brc"`
@@ -207,6 +210,11 @@ func LoadConfig(path string) (*Config, error) {
if cfg.Name == "" {
return nil, errors.New("missing name")
}
normalizedColor, err := normalizeHexColor(cfg.Color)
if err != nil {
return nil, err
}
cfg.Color = normalizedColor
if cfg.ServerURL == "" {
return nil, errors.New("missing serverUrl")
}
@@ -410,3 +418,16 @@ func deriveSRTURL(serverURL, streamName string, port int, mode string) (string,
escaped := url.PathEscape(streamName)
return fmt.Sprintf("srt://%s:%d?streamid=#!::r=%s,m=%s&latency=10&mode=caller&transtype=live&pkt_size=1316", host, port, escaped, mode), nil
}
var hexColorRe = regexp.MustCompile(`^#[0-9A-Fa-f]{6}$`)
func normalizeHexColor(raw string) (string, error) {
trimmed := strings.TrimSpace(raw)
if trimmed == "" {
return "", nil
}
if !hexColorRe.MatchString(trimmed) {
return "", fmt.Errorf("color must be #RRGGBB, got %q", raw)
}
return strings.ToUpper(trimmed), nil
}
+1
View File
@@ -1,5 +1,6 @@
# Sample configuration for roverd
name: roomba-alpha
color: "#4DB6AC"
serverUrl: ws://control-server.local:8080/rover
serial:
device: /dev/ttyAMA0
+1
View File
@@ -113,6 +113,7 @@ func (c *WSClient) sendHello(ctx context.Context, conn *websocket.Conn) error {
msg := helloMessage{
Type: "hello",
Name: c.cfg.Name,
Color: c.cfg.Color,
Battery: c.cfg.Battery,
MaxWheelSpeed: c.cfg.MaxWheelMMs,
Media: c.cfg.Media,