summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-04-03 15:15:00 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-04-03 15:15:00 (GMT)
commit52b261e874e27172c0d0afb9a66a3e8946c0b32a (patch)
tree3c74f7858da2a0442b47165ee16c39231cc9f1c0 /src
parentcdf69dcc35af329584e9678a6f36f811311a82f2 (diff)
telnet interface now renders switch state
Diffstat (limited to 'src')
-rw-r--r--src/rhctl/audio_switch.go12
-rw-r--r--src/rhctl/telnet.go31
2 files changed, 32 insertions, 11 deletions
diff --git a/src/rhctl/audio_switch.go b/src/rhctl/audio_switch.go
index f3821d8..3bb4abb 100644
--- a/src/rhctl/audio_switch.go
+++ b/src/rhctl/audio_switch.go
@@ -80,13 +80,13 @@ type SwitchUpdate struct {
}
type SwitchState struct {
- audio [SwitchOutputNumMax]struct {
- inputs [SwitchInputNumMax]bool
- silence bool
+ Audio [SwitchOutputNumMax]struct {
+ Inputs [SwitchInputNumMax]bool
+ Silence bool
}
- gpi [SwitchGPINumMax]bool
- relay [SwitchRelayNumMax]bool
- oc [SwitchOCNumMax]bool
+ GPI [SwitchGPINumMax]bool
+ Relay [SwitchRelayNumMax]bool
+ OC [SwitchOCNumMax]bool
}
type AudioSwitch struct {
diff --git a/src/rhctl/telnet.go b/src/rhctl/telnet.go
index a6a53fe..4735956 100644
--- a/src/rhctl/telnet.go
+++ b/src/rhctl/telnet.go
@@ -23,6 +23,7 @@ package main
import (
"sort"
+ "strings"
"github.com/spreadspace/telgo"
)
@@ -31,6 +32,18 @@ type TelnetInterface struct {
server *telgo.Server
}
+func genStateString(values []bool) string {
+ var states []string
+ for _, val := range values {
+ if val {
+ states = append(states, "1")
+ } else {
+ states = append(states, "0")
+ }
+ }
+ return strings.Join(states, ",")
+}
+
func telnetCmdState(c *telgo.Client, args []string, ctrl *SwitchControl) bool {
resp := make(chan interface{})
ctrl.Commands <- &Command{Type: CmdState, Response: resp}
@@ -44,11 +57,19 @@ func telnetCmdState(c *telgo.Client, args []string, ctrl *SwitchControl) bool {
c.Sayln("Mood: %v", s.Mood)
c.Sayln("Switch:")
- c.Sayln(" audio:") //
- c.Sayln(" output 1: ? (silence!!)?") //
- c.Sayln(" output 2: ? (silence!!)?") // TODO: fill this with actual data
- c.Sayln(" relays: ?") //
- c.Sayln(" oc: ?") //
+ c.Sayln(" audio:")
+ for num, out := range s.Switch.Audio {
+ c.Say(" out %d: ", num+1)
+
+ if out.Silence {
+ c.Sayln("%s (silence!!!)", genStateString(out.Inputs[:]))
+ } else {
+ c.Sayln("%s", genStateString(out.Inputs[:]))
+ }
+ }
+ c.Sayln(" gpi: %s", genStateString(s.Switch.GPI[:]))
+ c.Sayln(" relay: %s", genStateString(s.Switch.Relay[:]))
+ c.Sayln(" oc: %s", genStateString(s.Switch.OC[:]))
c.Sayln("Server:")
var names []string