package main import ( "encoding/hex" "fmt" "os" "git.zaphyra.eu/airpodsctl/types" ) func (state State) toggleFeatureCommand(feature string, value types.Bool) { if feature == "" { fmt.Fprint(os.Stderr, "[toggleFeatureCommand] Error: No feature supplied!\n\nUse `--help` for a list of available features.\n", feature) os.Exit(1) } if _, ok := AACPControlCommand[feature]; !ok { fmt.Fprintf(os.Stderr, "[toggleFeatureCommand] Error: Unknown feature: %s!\nUse `--help` for a list of available features.\n", feature) os.Exit(1) } device, err := state.Devices.Get(state.SelectedDevice) if err != nil { fmt.Fprintf(os.Stderr, "[toggleFeatureCommand] Error: Device '%s' is not connected!\n", state.SelectedDevice) os.Exit(1) } cmd := AACPControlCommandPacket cmd[6] = AACPControlCommand[feature] cmd[7] = AACPControlCommandBool[bool(value)] if err := state.SendRawCommand(device, hex.EncodeToString(cmd)); err != nil { fmt.Fprintln(os.Stderr, "[toggleFeatureCommand] Error:", err) os.Exit(1) } os.Exit(0) }