package device import ( "FRMS/internal/pkg/manager" "errors" "fmt" "github.com/spf13/viper" ) // Returns the correct manager for sensor/controller type Device interface { Start() error Stop() error IsActive() manager.Status 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, err = NewDOManager() case 99: // pH defaultName = "pH Sensor" m, err = NewPHManager() case 102: // RTD defaultName = "RTD Sensor" m, err = NewRTDManager() case 256: // PWM defaultName = "PWM Controller" m, err = NewPWMManager() default: err = errors.New(fmt.Sprintf("Error: device id %d unrecognized!", addr)) } if err != nil { return m, err } dm, err := NewDeviceManager(bus, addr, config, defaultName) if err != nil { return m, err } m.SetDeviceManager(dm) return m, err }