api
Package api provides the public client interface for the z13ctl daemon. It contains the shared protocol types and socket client functions used by CLI commands, GUI frontends, and any other tool that communicates with the z13ctl daemon over its Unix socket.
Index
- func SendApply(device, color, color2, mode, speed string, brightness int) (bool, error)
- func SendBatteryLimitGet() (handled bool, limit int, err error)
- func SendBatteryLimitSet(limit int) (bool, error)
- func SendBootSoundGet() (handled bool, value int, err error)
- func SendBootSoundSet(value int) (bool, error)
- func SendBrightness(device string, level int) (bool, error)
- func SendFanCurveGet() (handled bool, value string, err error)
- func SendFanCurveReset() (bool, error)
- func SendFanCurveSet(curve string) (bool, error)
- func SendOff(device string) (bool, error)
- func SendPanelOverdriveGet() (handled bool, value int, err error)
- func SendPanelOverdriveSet(value int) (bool, error)
- func SendProfileGet() (handled bool, profile string, err error)
- func SendProfileSet(profile string) (bool, error)
- func SendTdpGet() (handled bool, value string, err error)
- func SendTdpReset() (bool, error)
- func SendTdpSet(watts string, pl1, pl2, pl3 string, force bool) (bool, error)
- func SendUndervoltGet() (handled bool, value string, err error)
- func SendUndervoltReset() (bool, error)
- func SendUndervoltSet(cpu string) (bool, error)
- func SocketPath() string
- func Subscribe(events []string) (\<-chan string, func(), error)
- type FanCurvePoint
- type FanCurveState
- type LightingState
- type State
- func SendGetState() (bool, *State, error)
- type TDPState
- type UndervoltState
func SendApply
SendApply sends an apply command to the daemon. color and color2 must be "RRGGBB" hex strings. device may be "keyboard", "lightbar", a /dev/hidrawN path, or "" to target all devices. Returns (true, nil) on success, (false, nil) if the daemon is not running (caller should fall back to direct HID access).
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Apply a static red color at full brightness to all devices.
handled, err := api.SendApply("", "FF0000", "000000", "static", "normal", 3)
if !handled {
fmt.Println("daemon not running, falling back to direct HID access")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("applied")
}
func SendBatteryLimitGet
SendBatteryLimitGet queries the daemon for the current battery charge limit by reading sysfs (not cached daemon state). Intended for GUI/plugin callers. Returns (false, 0, nil) if the daemon is not running.
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Read the current battery charge limit.
handled, limit, err := api.SendBatteryLimitGet()
if !handled {
fmt.Println("daemon not running")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("battery limit:", limit)
}
func SendBatteryLimitSet
SendBatteryLimitSet sends a battery limit set command to the daemon.
Example
func SendBootSoundGet
SendBootSoundGet queries the daemon for the current boot sound setting by reading sysfs. Returns (false, 0, nil) if the daemon is not running.
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Read the current boot sound setting.
handled, value, err := api.SendBootSoundGet()
if !handled {
fmt.Println("daemon not running")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("boot sound:", value)
}
func SendBootSoundSet
SendBootSoundSet sends a boot sound set command to the daemon.
Example
func SendBrightness
SendBrightness sends a brightness-only command to the daemon. device may be "keyboard", "lightbar", a /dev/hidrawN path, or "" to target all devices.
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Set brightness to medium on the keyboard only.
handled, err := api.SendBrightness("keyboard", 2)
if !handled {
fmt.Println("daemon not running, falling back to direct HID access")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("brightness set")
}
func SendFanCurveGet
SendFanCurveGet queries the daemon for the current fan curve data. Returns JSON value string with both fans' curve and mode.
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Read the current fan curve for both fans via the daemon.
handled, value, err := api.SendFanCurveGet()
if !handled {
fmt.Println("daemon not running")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("fan curve:", value)
}
func SendFanCurveReset
SendFanCurveReset resets both fans to firmware auto mode.
Example
func SendFanCurveSet
SendFanCurveSet sends a fan curve set command to the daemon. The curve is applied to both fans simultaneously.
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Set a custom 8-point fan curve (applied to both fans).
handled, err := api.SendFanCurveSet("48:2,53:22,57:30,60:43,63:56,65:68,70:89,76:102")
if !handled {
fmt.Println("daemon not running")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("fan curve set")
}
func SendOff
SendOff sends an off command to the daemon. device may be "keyboard", "lightbar", a /dev/hidrawN path, or "" to target all devices.
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Turn off lighting on all devices.
handled, err := api.SendOff("")
if !handled {
fmt.Println("daemon not running, falling back to direct HID access")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("lights off")
}
func SendPanelOverdriveGet
SendPanelOverdriveGet queries the daemon for the current panel overdrive setting by reading sysfs. Returns (false, 0, nil) if the daemon is not running.
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Read the current panel overdrive setting.
handled, value, err := api.SendPanelOverdriveGet()
if !handled {
fmt.Println("daemon not running")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("panel overdrive:", value)
}
func SendPanelOverdriveSet
SendPanelOverdriveSet sends a panel overdrive set command to the daemon.
Example
func SendProfileGet
SendProfileGet queries the daemon for the current performance profile by reading sysfs (not cached daemon state). Intended for GUI/plugin callers. Returns (false, "", nil) if the daemon is not running.
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Read the current performance profile from sysfs via the daemon.
handled, profile, err := api.SendProfileGet()
if !handled {
fmt.Println("daemon not running")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("profile:", profile)
}
func SendProfileSet
SendProfileSet sends a profile set command to the daemon.
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Switch to the performance power profile.
handled, err := api.SendProfileSet("performance")
if !handled {
fmt.Println("daemon not running")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("profile set")
}
func SendTdpGet
SendTdpGet queries the daemon for current TDP/PPT values. Returns JSON value string.
Example
func SendTdpReset
SendTdpReset sends a TDP reset command to the daemon.
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Reset to balanced profile (firmware manages PPT and fan curves).
handled, err := api.SendTdpReset()
if !handled {
fmt.Println("daemon not running")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("tdp reset")
}
func SendTdpSet
SendTdpSet sends a TDP set command to the daemon.
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Set TDP to 50W (all PPT values equal).
handled, err := api.SendTdpSet("50", "", "", "", false)
if !handled {
fmt.Println("daemon not running")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("tdp set")
}
func SendUndervoltGet
SendUndervoltGet queries the daemon for the current Curve Optimizer offsets. Returns JSON value string. Returns (false, "", nil) if the daemon is not running.
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Read current Curve Optimizer offsets from daemon state.
handled, value, err := api.SendUndervoltGet()
if !handled {
fmt.Println("daemon not running")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("undervolt:", value)
}
func SendUndervoltReset
SendUndervoltReset resets Curve Optimizer to stock (0).
Example
func SendUndervoltSet
SendUndervoltSet sends a Curve Optimizer set command to the daemon. cpu is a string representation of the CO offset (e.g. "-20").
Example
func SocketPath
SocketPath returns the runtime path for the daemon's Unix socket.
func Subscribe
Subscribe opens a long-lived subscription to the daemon and returns a channel that receives event name strings (e.g. "gui-toggle") as they are streamed. The returned cancel func closes the underlying connection and stops the goroutine; the channel is closed when the connection drops or cancel is called. Returns (nil, nil, nil) if the daemon is not running.
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Subscribe to Armoury Crate button press events.
ch, cancel, err := api.Subscribe([]string{"gui-toggle"})
if ch == nil {
fmt.Println("daemon not running")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
defer cancel()
for event := range ch {
fmt.Println("received event:", event)
}
}
type FanCurvePoint
FanCurvePoint represents one point on an 8-point fan curve.
type FanCurvePoint struct {
Temp int `json:"temp"` // degrees Celsius
PWM int `json:"pwm"` // 0–255 duty cycle
}
type FanCurveState
FanCurveState captures the fan curve and mode applied to both fans.
type FanCurveState struct {
Mode int `json:"mode"` // pwm_enable: 0=full-speed, 1=custom, 2=auto
Points []FanCurvePoint `json:"points"` // 8 points
}
type LightingState
LightingState captures all parameters needed to reproduce one lighting zone.
type LightingState struct {
Enabled bool `json:"enabled"`
Mode string `json:"mode"`
Color string `json:"color"` // "RRGGBB" hex
Color2 string `json:"color2"` // "RRGGBB" hex
Speed string `json:"speed"`
Brightness int `json:"brightness"` // 0–3
}
type State
State holds the last-applied settings for all controllable subsystems. It is returned by SendGetState and broadcast as part of daemon responses.
type State struct {
Lighting LightingState `json:"lighting"`
Devices map[string]LightingState `json:"devices,omitempty"` // per-device overrides keyed by name
Profile string `json:"profile,omitempty"`
Battery int `json:"battery_limit,omitempty"`
BootSound int `json:"boot_sound,omitempty"`
PanelOverdrive int `json:"panel_overdrive,omitempty"`
FanCurve *FanCurveState `json:"fan_curve,omitempty"`
TDP *TDPState `json:"tdp,omitempty"`
Undervolt *UndervoltState `json:"undervolt,omitempty"`
UndervoltAvailable bool `json:"undervolt_available"` // true if ryzen_smu is loaded
Temperature int `json:"temperature,omitempty"` // APU temp, degrees Celsius
FanRPM int `json:"fan_rpm,omitempty"` // fan1 speed in RPM
}
func SendGetState
SendGetState fetches the daemon's full cached state for GUI initialization. Returns (false, nil, nil) if the daemon is not running.
Example
package main
import (
"fmt"
"github.com/dahui/z13ctl/api"
)
func main() {
// Fetch the daemon's full cached state for GUI initialization.
handled, state, err := api.SendGetState()
if !handled {
fmt.Println("daemon not running")
return
}
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println("mode:", state.Lighting.Mode)
}
type TDPState
TDPState captures all PPT (Package Power Tracking) values in watts.
type TDPState struct {
PL1SPL int `json:"pl1_spl"` // Sustained Power Limit
PL2SPPT int `json:"pl2_sppt"` // Short Boost
FPPT int `json:"fppt"` // Fast Boost
APUSPPT int `json:"apu_sppt"` // APU Short PPT
PlatformSPPT int `json:"platform_sppt"` // Platform Short PPT
}
type UndervoltState
UndervoltState captures the AMD Curve Optimizer offset applied to the CPU. Values are non-positive integers (0 = stock, negative = undervolt). Active indicates whether the offset is currently applied to hardware.
type UndervoltState struct {
CPUCO int `json:"cpu_co"` // all-core CPU Curve Optimizer offset
Active bool `json:"active"` // true when CO is applied to hardware
}
Generated by gomarkdoc