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.

59 lines
1010 B
Go

package device
import (
"FRMS/internal/pkg/manager"
"errors"
"fmt"
2 years ago
"github.com/spf13/viper"
)
2 years ago
// Returns the correct manager for sensor/controller
type Device interface {
Start() error
Stop() error
IsActive() manager.Status
2 years ago
SetDeviceManager(*DeviceManager)
}
2 years ago
func New(bus, addr int, config *viper.Viper) (Device, error) {
// returns correct device manager by ID
var err error
2 years ago
var defaultName string
var m Device
switch addr {
case 97:
// DO
2 years ago
defaultName = "DO Sensor"
m, err = NewDOManager()
case 99:
// pH
2 years ago
defaultName = "pH Sensor"
m, err = NewPHManager()
case 102:
// RTD
2 years ago
defaultName = "RTD Sensor"
m, err = NewRTDManager()
case 256:
// PWM
2 years ago
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
}
2 years ago
m.SetDeviceManager(dm)
return m, err
}