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