first draft cjc

This commit is contained in:
William Clark 2022-12-05 12:40:07 +00:00
parent 8036c9840b
commit 70cde17508
2 changed files with 52 additions and 0 deletions

View File

@ -2,6 +2,8 @@ package th7
import (
"fmt"
"log"
"th7/thermocouple"
"time"
)
@ -69,6 +71,31 @@ func startCacheService(t *TH7Adapter) {
}
// read pcb temp and apply CJC
// the board temperature wont noticeably change for the ~300 ms of sampling
// so only reading pcb temp and applying cjc after this duration
// probably wont affect the readings.
pcb_temperature := t.pcbPort.ReadPCBTemp()
for k := range t.cfg.Channels {
tc := t.cfg.Channels[k].Thermo
if thermocouple.WithinTemperatureRange(tc, pcb_temperature) {
// if we can apply CJC with this configuration ...
cjc_uv, err := thermocouple.UV(tc, pcb_temperature)
if err != nil {
log.Println("Error doing CJC", err)
continue
}
data[k].Value -= cjc_uv
data[k].Unit = t.cfg.Channels[k].Unit
} else {
// CJC can not be applied
// board temp out of range for specified thermocouple type
// perhaps just subtract board temperature? dont know
fmt.Println("No valid CJC", t.cfg.Channels[k])
}
}
t.mu.Lock()
t.data = data

View File

@ -4,6 +4,31 @@ import (
"th7/data/thermocouple"
)
func WithinTemperatureRange(thermo thermocouple.Type, c float64) bool {
switch thermo {
case thermocouple.B:
return c >= B_MIN_C && c <= B_MAX_C
case thermocouple.E:
return c >= E_MIN_C && c <= E_MAX_C
case thermocouple.J:
return c >= J_MIN_C && c <= J_MAX_C
case thermocouple.K:
return c >= K_MIN_C && c <= K_MAX_C
case thermocouple.N:
return c >= N_MIN_C && c <= N_MAX_C
case thermocouple.R:
return c >= R_MIN_C && c <= R_MAX_C
case thermocouple.S:
return c >= S_MIN_C && c <= S_MAX_C
case thermocouple.T:
return c >= T_MIN_C && c <= T_MAX_C
}
// None type
return false
}
func C(thermo thermocouple.Type, uv float64) (float64, error) {
switch thermo {