Add convenience functions for the muxPi 45/138545/5
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Wed, 12 Jul 2017 09:53:55 +0000 (11:53 +0200)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Tue, 26 Sep 2017 14:35:23 +0000 (16:35 +0200)
The stm package is intended to be used with MuxPi.
It is common to implement functions as package's public that call
methods on structure with default values set. It is safe to call
these methods accross packages and goroutines as long as developer
is aware that Open with corresponding Close should be called once.

Change-Id: Ic5c2fb35b2ec7f41eaedc24a7d78edf09745c1b8

stm/stm.go

index f60a550..ee1dd97 100644 (file)
@@ -65,6 +65,12 @@ type STM struct {
        mux    *sync.Mutex
 }
 
+var muxPi *STM
+
+func init() {
+       muxPi = NewSTM("/dev/ttyS2", 115200)
+}
+
 // NewSTM prepares STM structure with serial configuration.
 func NewSTM(ttyPath string, baudrate int) *STM {
        return &STM{
@@ -190,3 +196,43 @@ func (stm *STM) DUT() error {
 func (stm *STM) TS() error {
        return stm.executeCommand("ts")
 }
+
+// Open is a convenience function for default MuxPi settings.
+func Open() error {
+       return muxPi.Open()
+}
+
+// Close is a convenience function for default MuxPi settings.
+func Close() error {
+       return muxPi.Close()
+}
+
+// PowerTick is a convenience function for default MuxPi settings.
+func PowerTick(d time.Duration) error {
+       return muxPi.PowerTick(d)
+}
+
+// SetLED is a convenience function for default MuxPi settings.
+func SetLED(led LED, r, g, b uint8) error {
+       return muxPi.SetLED(led, r, g, b)
+}
+
+// ClearDisplay is a convenience function for default MuxPi settings.
+func ClearDisplay() error {
+       return muxPi.ClearDisplay()
+}
+
+// PrintText is a convenience function for default MuxPi settings.
+func PrintText(x, y uint, color Color, text string) error {
+       return muxPi.PrintText(x, y, color, text)
+}
+
+// DUT is a convenience function for default MuxPi settings.
+func DUT() error {
+       return muxPi.DUT()
+}
+
+// TS is a convenience function for default MuxPi settings.
+func TS() error {
+       return muxPi.TS()
+}