package device import ( "errors" "fmt" "github.com/spf13/viper" ) // Returns the correct manager for sensor/controller type Device interface { Start() error Exit() error IsActive() int SetDeviceManager(*DeviceManager) } func New(bus, addr int, config *viper.Viper) (Device, error) { // returns correct device manager by ID var err error var defaultName string var m Device switch addr { case 97: // DO defaultName = "DO Sensor" m = NewDOManager() case 99: // pH defaultName = "pH Sensor" m = NewPHManager() case 102: // RTD defaultName = "RTD Sensor" m = NewRTDManager() case 256: // PWM defaultName = "PWM Controller" m = NewPWMManager() default: err = errors.New(fmt.Sprintf("Error: device id %d unrecognized!", addr)) } // setting device manager dm := NewDeviceManager(bus, addr, config, defaultName) m.SetDeviceManager(dm) // setting up gRPC server functionality return m, err }