2018-11-20 21:55:06 +00:00
|
|
|
package sensor
|
|
|
|
|
2019-02-24 21:46:36 +00:00
|
|
|
import (
|
2020-05-03 12:04:08 +00:00
|
|
|
"errors"
|
|
|
|
"sync"
|
|
|
|
|
2020-01-19 12:30:47 +00:00
|
|
|
"github.com/volker-raschek/flucky/pkg/types"
|
2019-02-24 21:46:36 +00:00
|
|
|
)
|
|
|
|
|
2020-05-03 12:04:08 +00:00
|
|
|
var (
|
|
|
|
ErrSensorModelNotMatched = errors.New("Sensor model not matched")
|
|
|
|
)
|
2019-06-27 07:31:40 +00:00
|
|
|
|
2020-05-03 12:04:08 +00:00
|
|
|
// New returns a new sensor
|
|
|
|
func New(sensor *types.Sensor) (Sensor, error) {
|
|
|
|
switch sensor.Model {
|
|
|
|
case "BME280":
|
|
|
|
return &BME280{
|
|
|
|
Sensor: sensor,
|
|
|
|
mutex: new(sync.Mutex),
|
|
|
|
}, nil
|
|
|
|
case "DHT11":
|
|
|
|
return &DHT11{
|
|
|
|
Sensor: sensor,
|
|
|
|
mutex: new(sync.Mutex),
|
|
|
|
}, nil
|
|
|
|
case "DHT22":
|
|
|
|
return &DHT22{
|
|
|
|
Sensor: sensor,
|
|
|
|
mutex: new(sync.Mutex),
|
|
|
|
}, nil
|
|
|
|
case "DS18B20":
|
|
|
|
return &DS18B20{
|
|
|
|
Sensor: sensor,
|
|
|
|
mutex: new(sync.Mutex),
|
|
|
|
}, nil
|
|
|
|
default:
|
|
|
|
return nil, ErrSensorModelNotMatched
|
2019-02-24 21:46:36 +00:00
|
|
|
}
|
2019-06-13 19:25:32 +00:00
|
|
|
}
|