fermentord/pkg/temperature/sensor.go

36 lines
592 B
Go
Raw Normal View History

2022-03-15 20:07:53 +00:00
package temperature
import "log"
type Sensor struct {
Name string
Path string
Filter EWMAFilter
accErrors int
}
func NewSensor(name, path string, weight float64) Sensor {
return Sensor{
Name: name,
Path: path,
Filter: NewEWMAFilter(weight),
}
}
func (p *Sensor) Update(value int64) float64 {
p.accErrors = 0
degrees := float64(value) / 1000
return p.Filter.Update(degrees)
}
func (p *Sensor) Fail() error {
p.accErrors++
if p.accErrors > 60 {
log.Fatalf("Thermal sensor read of %v failed 60 times in a row -- terminating", p.Name)
}
return nil
}