fix: add, rename and remove sensor
changes: - Implement function to add, rename and remove sensors
This commit is contained in:
48
pkg/cli/cli.go
Normal file
48
pkg/cli/cli.go
Normal file
@ -0,0 +1,48 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/volker-raschek/flucky/pkg/config"
|
||||
)
|
||||
|
||||
// PrintSensors displays a list with all configured sensors
|
||||
func PrintSensors(cnf *config.Config, w io.Writer) error {
|
||||
|
||||
// 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")
|
||||
|
||||
for _, sensor := range cnf.Sensors {
|
||||
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)
|
||||
}
|
||||
|
||||
tw.Flush()
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user