From: Aleksander Mistewicz Date: Tue, 11 Jul 2017 17:00:10 +0000 (+0200) Subject: Add most functions provided by STM X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a33d26fca09c18aed5d4932d6bab4e5259454527;p=tools%2Fmuxpi.git Add most functions provided by STM Following commands are implemented: power - PowerTick led - LED1 and LED2 clr - ClearDisplay text - PrintText dut - DUT ts - TS Link to documentation of all functions: https://wiki.tizen.org/MuxPi#Features_accessible_thorugh_Cortex-M0 Change-Id: I4dac5c828d8062761a2014ef679192125f0a9154 --- diff --git a/stm/stm.go b/stm/stm.go index 16622c5..f60a550 100644 --- a/stm/stm.go +++ b/stm/stm.go @@ -23,6 +23,7 @@ import ( "io" "strings" "sync" + "time" "github.com/tarm/serial" ) @@ -32,6 +33,28 @@ const ( 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. @@ -136,3 +159,34 @@ func (stm *STM) noEcho() (err error) { } 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") +}