From 03fae13a609c0d9f653406a134032fc1f0c9db46 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 30 Dec 2016 13:22:26 +0100 Subject: Split prettyprinting --- types.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 types.go (limited to 'types.go') diff --git a/types.go b/types.go new file mode 100644 index 0000000..121deba --- /dev/null +++ b/types.go @@ -0,0 +1,59 @@ +package anki + +import ( + "fmt" + "time" +) + +//go:generate stringer -type=ID +type ID uint8 + +//go:generate stringer -type=Direction +type Direction uint8 + +type MicroSec uint32 + +func (v MicroSec) String() string { + return fmt.Sprintf("%v", time.Duration(v)*time.Microsecond) +} + +type MilliVolt uint16 + +func (v MilliVolt) String() string { + return fmt.Sprintf("%6.4fV", float64(v)/1000.0) +} + +type Bool uint8 + +func (v Bool) String() string { + return fmt.Sprintf("%t", v != 0) +} + +type MMperSecSQ uint16 + +func (v MMperSecSQ) String() string { + return fmt.Sprintf("%5.3fm/s²", float64(v)/1000.0) +} + +type MMperSec uint16 + +func (v MMperSec) String() string { + return fmt.Sprintf("%5.3fm/s", float64(v)/1000.0) +} + +type Offset float32 + +func (c Offset) String() string { + return fmt.Sprintf("%4.1fmm", c) +} + +type Flags uint8 + +func (f Flags) String() string { + return fmt.Sprintf("{Bits: %d InvColor: %t RevParse: %t RevDrive: %t}", + f&ParseflagsMaskNumBits, + f&ParseflagsMaskInvertedColor != 0, + f&ParseflagsMaskReverseParsing != 0, + f&ParseflagsMaskReverseDriving != 0, + ) +} -- cgit v1.2.3