2020-05-17 11:00:51 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"text/tabwriter"
|
|
|
|
|
2020-06-10 19:13:05 +00:00
|
|
|
"git.cryptic.systems/volker.raschek/flucky/pkg/types"
|
2020-05-17 11:00:51 +00:00
|
|
|
)
|
|
|
|
|
2020-09-21 17:36:42 +00:00
|
|
|
func PrintMeasuredValues(measuredValues []*types.MeasuredValue, w io.Writer) error {
|
|
|
|
// declar tabwriter
|
|
|
|
tw := tabwriter.NewWriter(w, 0, 0, 3, ' ', 0)
|
|
|
|
|
|
|
|
fmt.Fprint(tw, "timestamp\ttype\tvalue\n")
|
|
|
|
|
|
|
|
for i := range measuredValues {
|
|
|
|
fmt.Fprintf(tw, "%v\t%v\t%v\n", measuredValues[i].Date.String(), measuredValues[i].ValueType, measuredValues[i].Value)
|
|
|
|
}
|
|
|
|
|
|
|
|
err := tw.Flush()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-17 11:00:51 +00:00
|
|
|
// PrintSensors displays a list with all configured sensors
|
2020-05-21 15:40:24 +00:00
|
|
|
func PrintSensors(sensors []*types.Sensor, w io.Writer) error {
|
2020-05-17 11:00:51 +00:00
|
|
|
// declar tabwriter
|
|
|
|
tw := tabwriter.NewWriter(w, 0, 0, 3, ' ', 0)
|
|
|
|
|
|
|
|
fmt.Fprint(tw, "name\tlocation\ttype\twire-id\ti2c-bus\ti2c-address\tgpio\ttick-duration\tenabled\n")
|
|
|
|
|
2020-05-21 15:40:24 +00:00
|
|
|
for _, sensor := range sensors {
|
2020-05-17 11:00:51 +00:00
|
|
|
fmt.Fprintf(tw, "%v\t%v\t%v\t", sensor.Name, sensor.Location, sensor.Model)
|
|
|
|
|
|
|
|
if sensor.WireID != nil {
|
|
|
|
fmt.Fprintf(tw, "%v\t", *sensor.WireID)
|
|
|
|
} else {
|
|
|
|
fmt.Fprintf(tw, "\t")
|
|
|
|
}
|
|
|
|
|
|
|
|
if sensor.I2CBus != nil {
|
|
|
|
fmt.Fprintf(tw, "%v\t", *sensor.I2CBus)
|
|
|
|
} else {
|
|
|
|
fmt.Fprintf(tw, "\t")
|
|
|
|
}
|
|
|
|
|
|
|
|
if sensor.I2CAddress != nil {
|
|
|
|
fmt.Fprintf(tw, "%#v\t", *sensor.I2CAddress)
|
|
|
|
} else {
|
|
|
|
fmt.Fprintf(tw, "\t")
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(tw, "%v\t", sensor.GPIONumber)
|
|
|
|
|
|
|
|
fmt.Fprintf(tw, "%v\t%v\n", sensor.TickDuration, sensor.Enabled)
|
|
|
|
}
|
|
|
|
|
2020-09-21 17:36:42 +00:00
|
|
|
err := tw.Flush()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-17 11:00:51 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|