Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var LCDCommands = []term.Command{ {Name: "on", Desc: "Turn on the backlight.", Exec: func(r term.RunArgs) error { if err := r.Parse(); err != nil { return err } dev := r.Get("lcd").(*lcd.HD44780) return dev.SetBacklight(true) }}, {Name: "off", Desc: "Turn off the backlight.", Exec: func(r term.RunArgs) error { if err := r.Parse(); err != nil { return err } dev := r.Get("lcd").(*lcd.HD44780) return dev.SetBacklight(false) }}, {Name: "cls", Desc: "Clear the screen.", Exec: func(r term.RunArgs) error { if err := r.Parse(); err != nil { return err } dev := r.Get("lcd").(*lcd.HD44780) return dev.Clear() }}, {Name: "type", Desc: "Type a string on the screen.", Exec: func(r term.RunArgs) error { if err := r.Parse(); err != nil { return err } dev := r.Get("lcd").(*lcd.HD44780) for { c := <-r.Input() if c == 0 { continue } if c == term.Interrupt { return nil } dev.WriteByte(byte(c)) } }}, {Name: "stress", Desc: "Stream data to the display.", Exec: func(r term.RunArgs) error { randData := r.Bool(term.Flag{Name: "rand", Short: 'r', Desc: "Randomize the data."}) if err := r.Parse(); err != nil { return err } dev := r.Get("lcd").(*lcd.HD44780) d := byte('a') for r.WaitForInterrupt() { if *randData { dev.WriteByte(byte(rand.Intn('~'-' ')) + ' ') } else { dev.WriteByte(d) d++ if d > 'z' { d = 'a' } } } return nil }}, {Name: "w", Desc: "Write to the screen.", Exec: func(r term.RunArgs) error { x := r.Int(term.Flag{Short: 'x', Def: "0", Desc: "Cursor start X.", Req: true}) y := r.Int(term.Flag{Short: 'y', Def: "0", Desc: "Cursor start Y.", Req: true}) if err := r.Parse(); err != nil { return err } dev := r.Get("lcd").(*lcd.HD44780) err := dev.SetCursorXY(*x, *y) if err != nil { return err } _, err = io.WriteString(dev, r.Arg(0)) return err }}, }
LCDCommands are commands for interacting with an HD44780 display.
The device must be available at the 'lcd' key.
View Source
var MemCommands = []term.Command{ {Name: "r", Desc: "Read device data.", Exec: func(r term.RunArgs) error { start := r.Int(term.Flag{Short: 's', Def: "0", Desc: "Position to start from.", Req: true}) count := r.Int(term.Flag{Short: 'n', Def: "0", Desc: "Number of bytes to read, if zero read to end."}) if err := r.Parse(); err != nil { return err } mem := r.Get("mem").(memDevice) _, err := mem.Seek(int64(*start), 0) if err != nil { return err } wc := hex.Dumper(r) if *count == 0 { io.Copy(wc, mem) } else { io.CopyN(wc, mem, int64(*count)) } return wc.Close() }}, {Name: "w", Desc: "Write device data.", Exec: func(r term.RunArgs) error { r.SetHelpParameters("[data]") start := r.Int(term.Flag{Short: 's', Def: "0", Desc: "Position to start from.", Req: true}) binData := r.Bytes(term.Flag{Name: "data", Short: 'b', Desc: "Write bytes (comma separated) before arg data."}) if err := r.Parse(); err != nil { return err } mem := r.Get("mem").(memDevice) data := append(*binData, []byte(r.Arg(0))...) _, err := mem.WriteAt(data, int64(*start)) if err != nil { return err } return nil }}, {Name: "crc", Desc: "Calculate CRC value of bytes.", Exec: func(r term.RunArgs) error { if err := r.Parse(); err != nil { return err } crc := crc32.ChecksumIEEE([]byte(r.Arg(0))) data := make([]byte, 4) binary.LittleEndian.PutUint32(data, crc) r.Printf("CRC: 0x%02x 0x%02x 0x%02x 0x%02x\n", data[0], data[1], data[2], data[3]) return nil }}, {Name: "format", Desc: "Clear all data.", Exec: func(r term.RunArgs) error { start := r.Int(term.Flag{Short: 'p', Def: "0", Desc: "Position to start from.", Req: true}) count := r.Int(term.Flag{Short: 'n', Def: "0", Desc: "Number of bytes to wipe, if zero clear to end."}) value := r.Byte(term.Flag{Short: 'v', Def: "0xff", Desc: "Value to write."}) rnd := r.Bool(term.Flag{Name: "random", Desc: "Fill with random data."}) seq := r.Bool(term.Flag{Name: "sequential", Desc: "Fill with sequential data."}) if err := r.Parse(); err != nil { return err } mem := r.Get("mem").(memDevice) if *count == 0 { *count = size(mem) - *start } if *count <= 0 { return nil } data := make([]byte, *count) for i := range data { switch { case *seq: data[i] = byte(i) case *rnd: data[i] = byte(rand.Intn(256)) default: data[i] = *value } } _, err := mem.WriteAt(data, int64(*start)) if err != nil { return err } return nil }}, }
View Source
var RTCCommands = []term.Command{ {Name: "date", Desc: "Read current date.", Exec: func(ra term.RunArgs) error { if err := ra.Parse(); err != nil { return err } rtc := ra.Get("rtc").(*rtc.DS3231) n, err := rtc.Now() if err != nil { return err } ra.Println(n.Format(time.RFC3339)) return nil }}, {Name: "set", Desc: "Set current date.", Exec: func(ra term.RunArgs) error { use12 := ra.Bool(term.Flag{Name: "12", Desc: "Use 12-hour clock."}) timeStr := ra.String(term.Flag{Name: "time", Short: 't', Desc: "Time to set (instead of system clock) in ISO format."}) if err := ra.Parse(); err != nil { return err } rtc := ra.Get("rtc").(*rtc.DS3231) if *timeStr == "" { return rtc.SetTime(time.Now(), *use12) } t, err := time.Parse(time.RFC3339, *timeStr) if err != nil { return err } return rtc.SetTime(t, *use12) }}, }
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.