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