config

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config handles platform-specific configuration for sensorpanel.

Configuration is stored in platform-specific locations:

  • Linux: $XDG_CONFIG_HOME/sensorpanel/config.json (default: ~/.config/sensorpanel/)
  • macOS: ~/Library/Application Support/sensorpanel/config.json
  • Windows: %APPDATA%\sensorpanel\config.json

The config file stores:

  • Selected USB device (VID, PID, Serial)
  • Display settings (brightness, etc.)

Package config provides USB device discovery for sensorpanel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigPath

func ConfigPath() (string, error)

ConfigPath returns the full path to the config file.

func GetProfileID

func GetProfileID() (string, error)

GetProfileID returns the currently configured device profile ID.

func GetTheme

func GetTheme() (string, error)

GetTheme returns the currently configured theme name.

func Save

func Save(cfg *Config) error

Save writes the config to the XDG config file.

func SetDevice

func SetDevice(vid, pid uint16, serial string) error

SetDevice updates the selected device and saves the config.

func SetProfileID

func SetProfileID(profileID string) error

SetProfileID updates the device profile ID and saves the config.

func SetTheme

func SetTheme(themeName string) error

SetTheme updates the active theme and saves the config.

Types

type Config

type Config struct {
	// Selected USB display device
	Device USBDevice `json:"device"`

	// Device profile ID (e.g., "qtkeji", "generic")
	// If empty, profile is auto-detected from VID/PID
	ProfileID string `json:"profile_id,omitempty"`

	// Display settings
	Brightness int `json:"brightness,omitempty"` // 0-7, default 7

	// Theme settings
	Theme string `json:"theme,omitempty"` // Active theme name (empty = use built-in renderer)

	// Sensor settings
	UpdateInterval float64                `json:"update_interval,omitempty"` // seconds
	SensorOptions  map[string]interface{} `json:"sensor_options,omitempty"`  // Provider-specific options (e.g., "disk.mounts": ["/", "/home"])
}

Config represents the application configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a config with sensible defaults. Note: Device is not set - user must select a device first.

func Load

func Load() (*Config, error)

Load reads the config from the XDG config file. Returns default config if file doesn't exist.

type DiscoveredDevice

type DiscoveredDevice struct {
	VendorID     uint16
	ProductID    uint16
	Manufacturer string
	Product      string
	Serial       string
	Speed        string
	BusAddr      string // Bus:Address for identification
	IsProbable   bool   // Likely to be a display panel based on heuristics
}

DiscoveredDevice represents a USB device found during scanning.

func AutoDetectOrPrompt

func AutoDetectOrPrompt() (*DiscoveredDevice, bool, error)

AutoDetectOrPrompt tries to find a display device automatically. Returns the device to use, whether user interaction was needed, and any error.

func DiscoverDevices

func DiscoverDevices(knownOnly bool) ([]DiscoveredDevice, error)

DiscoverDevices scans USB bus for potential display devices. If knownOnly is true, only returns devices matching KnownDisplayVendors. Otherwise, uses heuristics to find probable display devices.

func FindConfiguredDevice

func FindConfiguredDevice() (*DiscoveredDevice, error)

FindConfiguredDevice attempts to find and validate the configured device. Returns the discovered device info if found, or an error if not found.

func (DiscoveredDevice) String

func (d DiscoveredDevice) String() string

String returns a human-readable description.

func (DiscoveredDevice) ToUSBDevice

func (d DiscoveredDevice) ToUSBDevice() USBDevice

ToUSBDevice converts to a USBDevice for config storage.

type USBDevice

type USBDevice struct {
	VendorID  uint16 `json:"vendor_id"`
	ProductID uint16 `json:"product_id"`
	Serial    string `json:"serial,omitempty"` // Optional: disambiguate multiple identical devices
}

USBDevice represents a USB device identifier.

func GetDevice

func GetDevice() (USBDevice, error)

GetDevice returns the currently configured device.

func (USBDevice) IsZero

func (d USBDevice) IsZero() bool

IsZero returns true if the device is not configured.

func (USBDevice) String

func (d USBDevice) String() string

String returns a human-readable representation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL