Stay in idle mode until first temperature reading has occurred
This commit is contained in:
parent
7f4718fabc
commit
5e1db5e14a
1 changed files with 18 additions and 3 deletions
|
@ -38,9 +38,10 @@ type ChamberController struct {
|
||||||
isPaused bool
|
isPaused bool
|
||||||
|
|
||||||
// Current temperature readings.
|
// Current temperature readings.
|
||||||
ambientTemperature float64
|
ambientTemperature float64
|
||||||
chamberTemperature float64
|
chamberTemperature float64
|
||||||
wortTemperature float64
|
wortTemperature float64
|
||||||
|
lastTemperatureUpdate time.Time
|
||||||
|
|
||||||
chTemp chan temperature.TemperatureReading
|
chTemp chan temperature.TemperatureReading
|
||||||
chPause chan bool
|
chPause chan bool
|
||||||
|
@ -78,6 +79,7 @@ func (p *ChamberController) Run(ctx context.Context, wg *sync.WaitGroup) {
|
||||||
p.ambientTemperature = t.Ambient
|
p.ambientTemperature = t.Ambient
|
||||||
p.chamberTemperature = t.Chamber
|
p.chamberTemperature = t.Chamber
|
||||||
p.wortTemperature = t.Wort
|
p.wortTemperature = t.Wort
|
||||||
|
p.lastTemperatureUpdate = time.Now()
|
||||||
|
|
||||||
case pause := <-p.chPause:
|
case pause := <-p.chPause:
|
||||||
p.setPause(pause)
|
p.setPause(pause)
|
||||||
|
@ -143,6 +145,11 @@ 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
|
||||||
|
|
||||||
|
// Stay in idle mode until first temperature update is received
|
||||||
|
if p.lastTemperatureUpdate.IsZero() {
|
||||||
|
return ChamberStateIdle
|
||||||
|
}
|
||||||
|
|
||||||
runtimeSecs := time.Since(p.lastChamberStateChange).Seconds()
|
runtimeSecs := time.Since(p.lastChamberStateChange).Seconds()
|
||||||
|
|
||||||
if p.chamberState == ChamberStateCooling {
|
if p.chamberState == ChamberStateCooling {
|
||||||
|
@ -198,5 +205,13 @@ func (p *ChamberController) computeChamberState() ChamberState {
|
||||||
return ChamberStateIdle
|
return ChamberStateIdle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Force idle mode when temperature updates are missing
|
||||||
|
if time.Since(p.lastTemperatureUpdate) > 1*time.Minute {
|
||||||
|
err := fmt.Errorf("no temperature update on controller for 1 minute - setting IDLE mode")
|
||||||
|
p.hub.CaptureException(err)
|
||||||
|
log.Print(err)
|
||||||
|
next = ChamberStateIdle
|
||||||
|
}
|
||||||
|
|
||||||
return next
|
return next
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue