Skip to content

Commit

Permalink
Add HDMI and SetDyper to Interface
Browse files Browse the repository at this point in the history
Change-Id: I357fdd3d48dde5d5e6fd0c1e1dbee2a3a58e641b
  • Loading branch information
amistewicz committed Jul 17, 2018
1 parent cd20a0d commit 7aba001
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 0 deletions.
53 changes: 53 additions & 0 deletions sw/nanopi/cmd/stm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,56 @@ func (l *leds) run(dev stm.Interface) {
l.setLED(dev, l.led2, stm.LED2)
}
}

func getBoolState(name, state string) (bool, error) {
switch state {
case "on":
return true, nil
case "off":
return false, nil
}
return false, fmt.Errorf("unexpected value provided to %s: %s", name, state)
}

type switches struct {
dyper1State string
dyper2State string
hdmiState string
}

func (s *switches) setFlags() {
flag.StringVar(&s.dyper1State, "dyper1", "", "switch dyper1 to the given state (on|off)")
flag.StringVar(&s.dyper2State, "dyper2", "", "switch dyper2 to the given state (on|off)")
flag.StringVar(&s.hdmiState, "hdmi", "", "switch HDMI HOTPLUG pin (on|off)")
}

func (s *switches) setDyper(dev stm.Interface, dyper stm.Dyper, state string) {
if state == "" {
return
}
b, err := getBoolState("dyper", state)
if err != nil {
log.Println(err)
return
}
dev.SetDyper(dyper, b)
}

func (s *switches) setHDMI(dev stm.Interface, state string) {
if state == "" {
return
}
b, err := getBoolState("hdmi", state)
if err != nil {
log.Println(err)
return
}
dev.HDMI(b)
}

func (s *switches) run(dev stm.Interface) {
s.setDyper(dev, stm.DYPER1, s.dyper1State)
s.setDyper(dev, stm.DYPER2, s.dyper2State)

s.setHDMI(dev, s.hdmiState)
}
1 change: 1 addition & 0 deletions sw/nanopi/cmd/stm/stm.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func main() {
new(current),
new(display),
new(leds),
new(switches),
}
for _, cmd := range allCommands {
cmd.setFlags()
Expand Down
47 changes: 47 additions & 0 deletions sw/nanopi/stm/rpc_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,37 @@ func (s *InterfaceService) GetCurrentRecord(request *InterfaceGetCurrentRecordRe
return
}

// InterfaceHDMIRequest is a helper structure for HDMI method.
type InterfaceHDMIRequest struct {
On bool
}

// InterfaceHDMIResponse is a helper structure for HDMI method.
type InterfaceHDMIResponse struct {
}

// HDMI is RPC implementation of HDMI calling it.
func (s *InterfaceService) HDMI(request *InterfaceHDMIRequest, response *InterfaceHDMIResponse) (err error) {
err = s.impl.HDMI(request.On)
return
}

// InterfaceSetDyperRequest is a helper structure for SetDyper method.
type InterfaceSetDyperRequest struct {
Dyper Dyper
On bool
}

// InterfaceSetDyperResponse is a helper structure for SetDyper method.
type InterfaceSetDyperResponse struct {
}

// SetDyper is RPC implementation of SetDyper calling it.
func (s *InterfaceService) SetDyper(request *InterfaceSetDyperRequest, response *InterfaceSetDyperResponse) (err error) {
err = s.impl.SetDyper(request.Dyper, request.On)
return
}

// InterfaceSetLEDRequest is a helper structure for SetLED method.
type InterfaceSetLEDRequest struct {
Led LED
Expand Down Expand Up @@ -249,6 +280,22 @@ func (_c *InterfaceClient) GetCurrentRecord() (samples []int, err error) {
return _response.Samples, err
}

// HDMI is part of implementation of Interface calling corresponding method on RPC server.
func (_c *InterfaceClient) HDMI(on bool) (err error) {
_request := &InterfaceHDMIRequest{on}
_response := &InterfaceHDMIResponse{}
err = _c.client.Call("Interface.HDMI", _request, _response)
return err
}

// SetDyper is part of implementation of Interface calling corresponding method on RPC server.
func (_c *InterfaceClient) SetDyper(dyper Dyper, on bool) (err error) {
_request := &InterfaceSetDyperRequest{dyper, on}
_response := &InterfaceSetDyperResponse{}
err = _c.client.Call("Interface.SetDyper", _request, _response)
return err
}

// SetLED is part of implementation of Interface calling corresponding method on RPC server.
func (_c *InterfaceClient) SetLED(led LED, r, g, b uint8) (err error) {
_request := &InterfaceSetLEDRequest{led, r, g, b}
Expand Down
47 changes: 47 additions & 0 deletions sw/nanopi/stm/rpc_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,37 @@ func (s *UserInterfaceService) GetCurrentRecord(request *UserInterfaceGetCurrent
return
}

// UserInterfaceHDMIRequest is a helper structure for HDMI method.
type UserInterfaceHDMIRequest struct {
On bool
}

// UserInterfaceHDMIResponse is a helper structure for HDMI method.
type UserInterfaceHDMIResponse struct {
}

// HDMI is RPC implementation of HDMI calling it.
func (s *UserInterfaceService) HDMI(request *UserInterfaceHDMIRequest, response *UserInterfaceHDMIResponse) (err error) {
err = s.impl.HDMI(request.On)
return
}

// UserInterfaceSetDyperRequest is a helper structure for SetDyper method.
type UserInterfaceSetDyperRequest struct {
Dyper Dyper
On bool
}

// UserInterfaceSetDyperResponse is a helper structure for SetDyper method.
type UserInterfaceSetDyperResponse struct {
}

// SetDyper is RPC implementation of SetDyper calling it.
func (s *UserInterfaceService) SetDyper(request *UserInterfaceSetDyperRequest, response *UserInterfaceSetDyperResponse) (err error) {
err = s.impl.SetDyper(request.Dyper, request.On)
return
}

// UserInterfaceClient is generated client for UserInterface interface.
type UserInterfaceClient struct {
client *rpc.Client
Expand Down Expand Up @@ -201,3 +232,19 @@ func (_c *UserInterfaceClient) GetCurrentRecord() (samples []int, err error) {
err = _c.client.Call("Interface.GetCurrentRecord", _request, _response)
return _response.Samples, err
}

// HDMI is part of implementation of UserInterface calling corresponding method on RPC server.
func (_c *UserInterfaceClient) HDMI(on bool) (err error) {
_request := &UserInterfaceHDMIRequest{on}
_response := &UserInterfaceHDMIResponse{}
err = _c.client.Call("Interface.HDMI", _request, _response)
return err
}

// SetDyper is part of implementation of UserInterface calling corresponding method on RPC server.
func (_c *UserInterfaceClient) SetDyper(dyper Dyper, on bool) (err error) {
_request := &UserInterfaceSetDyperRequest{dyper, on}
_response := &UserInterfaceSetDyperResponse{}
err = _c.client.Call("Interface.SetDyper", _request, _response)
return err
}
33 changes: 33 additions & 0 deletions sw/nanopi/stm/stm.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ const (
LED2 LED = "2"
)

// Dyper represents all DYPERs available via STM.
type Dyper string

const (
// DYPER1 is Dyper controlling the left column of pins.
DYPER1 Dyper = "dyper 1"
// DYPER2 is Dyper controlling the right column of pins.
DYPER2 Dyper = "dyper 2"
)

// STM provides methods to execute commands via serial interface.
//
// It is safe for concurrent use.
Expand All @@ -88,6 +98,8 @@ type UserInterface interface {
StartCurrentRecord(samples int, interval time.Duration) (err error)
StopCurrentRecord() (err error)
GetCurrentRecord() (samples []int, err error)
HDMI(on bool) (err error)
SetDyper(dyper Dyper, on bool) (err error)
}

// AdminInterface contains methods of STM that are intended to
Expand Down Expand Up @@ -377,3 +389,24 @@ func (stm *STM) GetCurrentRecord() (samples []int, err error) {
}
return stm.sample, nil
}

func appendSwitch(org string, on bool) string {
if on {
return org + " on"
}
return org + " off"
}

// HDMI sets (or unsets) HDMI HOTPLUG pin.
func (stm *STM) HDMI(on bool) (err error) {
return stm.executeCommand(appendSwitch("hdmi", on))
}

// SetDyper switches dyper, specified by 1st argument, on or off depending on 2nd argument.
func (stm *STM) SetDyper(dyper Dyper, on bool) (err error) {
switch dyper {
case DYPER1, DYPER2:
return stm.executeCommand(appendSwitch(string(dyper), on))
}
return fmt.Errorf("invalid dyper value: %v", dyper)
}

0 comments on commit 7aba001

Please sign in to comment.