This commit is contained in:
parent
ce647f2898
commit
9e9992a0d9
4 changed files with 25 additions and 14 deletions
|
@ -87,8 +87,6 @@ func (p *ChamberController) Run(ctx context.Context, wg *sync.WaitGroup) {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
p.isPaused = false
|
p.isPaused = false
|
||||||
// TODO Check if the line below blocks on shutdown
|
|
||||||
//p.setChamberState(ChamberStateIdle)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -129,7 +127,7 @@ func (p *ChamberController) setChamberState(state ChamberState) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("State changed from %v to %v", p.chamberState, state)
|
//log.Printf("State changed from %v to %v", p.chamberState, state)
|
||||||
|
|
||||||
if p.chamberState == ChamberStateCooling || state == ChamberStateCooling {
|
if p.chamberState == ChamberStateCooling || state == ChamberStateCooling {
|
||||||
p.lastCoolerStateChange = time.Now()
|
p.lastCoolerStateChange = time.Now()
|
||||||
|
@ -141,8 +139,8 @@ func (p *ChamberController) setChamberState(state ChamberState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ChamberController) computeChamberState() ChamberState {
|
func (p *ChamberController) computeChamberState() ChamberState {
|
||||||
offset := p.pid.Compute(p.chamberTemperature, p.config.FermentationTemperature)
|
//offset := p.pid.Compute(p.chamberTemperature, p.config.FermentationTemperature)
|
||||||
chamberTargetTemp := p.config.FermentationTemperature + offset
|
//chamberTargetTemp := p.config.FermentationTemperature + offset
|
||||||
|
|
||||||
runtimeSecs := time.Since(p.lastChamberStateChange).Seconds()
|
runtimeSecs := time.Since(p.lastChamberStateChange).Seconds()
|
||||||
|
|
||||||
|
@ -169,10 +167,10 @@ func (p *ChamberController) computeChamberState() ChamberState {
|
||||||
}
|
}
|
||||||
|
|
||||||
var next ChamberState
|
var next ChamberState
|
||||||
heater := p.chamberTemperature < p.config.FermentationTemperature-p.config.DeltaTemperatureHeat &&
|
heater := p.chamberTemperature < p.config.FermentationTemperature-p.config.DeltaTemperatureHeat //&&
|
||||||
p.chamberTemperature < chamberTargetTemp-p.config.DeltaTemperatureHeat
|
//p.chamberTemperature < chamberTargetTemp-p.config.DeltaTemperatureHeat
|
||||||
cooler := p.chamberTemperature > p.config.FermentationTemperature+p.config.DeltaTemperatureCool &&
|
cooler := p.chamberTemperature > p.config.FermentationTemperature+p.config.DeltaTemperatureCool //&&
|
||||||
p.chamberTemperature > chamberTargetTemp+p.config.DeltaTemperatureCool
|
//p.chamberTemperature > chamberTargetTemp+p.config.DeltaTemperatureCool
|
||||||
|
|
||||||
if cooler && heater {
|
if cooler && heater {
|
||||||
// This should not happen!
|
// This should not happen!
|
||||||
|
|
|
@ -135,13 +135,15 @@ func readSensors(hub *sentry.Hub) {
|
||||||
Wort: NaN,
|
Wort: NaN,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasReadFailure := false
|
||||||
|
|
||||||
for _, sensor := range sensors {
|
for _, sensor := range sensors {
|
||||||
t, err := read(sensor.Path)
|
t, err := read(sensor.Path)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
hasReadFailure = true
|
||||||
sensor.Fail()
|
sensor.Fail()
|
||||||
hub.CaptureException(err)
|
hub.CaptureException(err)
|
||||||
log.Printf("Error reading temperature sensor %v: %v", sensor, err)
|
log.Printf("Error reading temperature sensor %v/%v: %v", sensor.Name, sensor.Path, err)
|
||||||
metrics.TemperatureSensorReadingStatus.WithLabelValues(sensor.Name, "failed").Inc()
|
metrics.TemperatureSensorReadingStatus.WithLabelValues(sensor.Name, "failed").Inc()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -167,9 +169,17 @@ func readSensors(hub *sentry.Hub) {
|
||||||
metrics.TemperatureSensorReadingStatus.WithLabelValues(sensor.Name, "ok").Inc()
|
metrics.TemperatureSensorReadingStatus.WithLabelValues(sensor.Name, "ok").Inc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Throw away reading if any sensor failed
|
||||||
|
if hasReadFailure {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case Reading <- r:
|
case Reading <- r:
|
||||||
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
log.Fatal("Temperature channel overflow!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
C = make(chan Tilt, 100)
|
C = make(chan Tilt, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PollSensors(ctx context.Context, wg *sync.WaitGroup, interval time.Duration, scanDuration time.Duration) {
|
func PollSensors(ctx context.Context, wg *sync.WaitGroup, interval time.Duration, scanDuration time.Duration) {
|
||||||
|
@ -22,8 +22,10 @@ func PollSensors(ctx context.Context, wg *sync.WaitGroup, interval time.Duration
|
||||||
log.Fatal("Unable to use interval < scanDuration")
|
log.Fatal("Unable to use interval < scanDuration")
|
||||||
}
|
}
|
||||||
|
|
||||||
ticker := time.NewTicker(interval)
|
// Perform initial scan when booting
|
||||||
|
scan(ctx, scanDuration)
|
||||||
|
|
||||||
|
ticker := time.NewTicker(interval)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
@ -45,7 +47,7 @@ func scan(ctx context.Context, timeout time.Duration) {
|
||||||
metricTemp.WithLabelValues(color).Set(t.Celsius())
|
metricTemp.WithLabelValues(color).Set(t.Celsius())
|
||||||
|
|
||||||
// Log tilt readings
|
// Log tilt readings
|
||||||
t.Print()
|
//t.Print()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case C <- t:
|
case C <- t:
|
||||||
|
|
|
@ -54,6 +54,7 @@ func (s *Scanner) Scan(ctx context.Context, timeout time.Duration) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ble.SetDefaultDevice(d)
|
ble.SetDefaultDevice(d)
|
||||||
|
defer ble.Stop()
|
||||||
|
|
||||||
ctx2 := ble.WithSigHandler(context.WithTimeout(ctx, timeout))
|
ctx2 := ble.WithSigHandler(context.WithTimeout(ctx, timeout))
|
||||||
err = ble.Scan(ctx2, false, s.advHandler, advFilter)
|
err = ble.Scan(ctx2, false, s.advHandler, advFilter)
|
||||||
|
|
Loading…
Reference in a new issue