"io"
"strings"
"sync"
+ "time"
"github.com/tarm/serial"
)
retryLimit = 8
)
+// Color denotes a string representation of a color accepted by STM.
+//
+// MuxPi has only two colors available: orange (foreground), black (background).
+type Color string
+
+const (
+ // Foreground is displayed as orange, usually (255, 128, 0) in RGB notation.
+ Foreground Color = "on"
+ // Background is black, no pixels are lighted.
+ Background = "off"
+)
+
+// LED represents all LEDs available via STM.
+type LED string
+
+const (
+ // LED1 is an RGB LED located in the bottom-left corner of MuxPi.
+ LED1 LED = "1"
+ // LED2 is an RGB LED located on the right of the OLED display.
+ LED2 = "2"
+)
+
// STM provides methods to execute commands via serial interface.
//
// It is safe for concurrent use.
}
return fmt.Errorf("retry limit exceeded")
}
+
+// PowerTick cuts power off DUT, waits specified time and switches power back on.
+func (stm *STM) PowerTick(d time.Duration) error {
+ return stm.executeCommand(fmt.Sprintf("power tick %d", int(d/time.Millisecond)))
+}
+
+// SetLED sets color of an RGB LED.
+func (stm *STM) SetLED(led LED, r, g, b uint8) error {
+ return stm.executeCommand(fmt.Sprintf("led %s %d %d %d", led, r, g, b))
+}
+
+// ClearDisplay clears the OLED display.
+func (stm *STM) ClearDisplay() error {
+ return stm.executeCommand("clr")
+}
+
+// PrintText prints text at x,y position (from top-left corner) in color.
+func (stm *STM) PrintText(x, y uint, color Color, text string) error {
+ return stm.executeCommand(fmt.Sprintf("text %d %d %s %s", x, y, color, text))
+}
+
+// DUT instructs STM to connect microSD card and power to a DUT (Device Under Test).
+func (stm *STM) DUT() error {
+ return stm.executeCommand("dut")
+}
+
+// TS instructs STM to connect microSD card to TS (test server)
+// and disconnect power source from a DUT.
+func (stm *STM) TS() error {
+ return stm.executeCommand("ts")
+}