You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
938 B
Go

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
}