This commit is contained in:
William Clark 2022-12-05 13:12:17 +00:00
parent cf07519baa
commit 376727840c
2 changed files with 40 additions and 28 deletions

View File

@ -1,21 +1,13 @@
[TH7]
port = 8080
logfreq = 60
debug = true
[DB]
type = "sqlite3"
path = "test.db"
[Channel_1]
type = 'k'
[Channel_2]
type = 'K'
unit = 'C'
gain = 106.8
offset = 2.4
[Channel_5]
type = 'N'
unit = 'F'
[Channel_6]
type = 'S'

View File

@ -3,6 +3,8 @@ package th7
import (
"fmt"
"log"
temp_data "th7/data/temperature"
"th7/temperature"
"th7/thermocouple"
"time"
)
@ -79,30 +81,48 @@ func startCacheService(t *TH7Adapter) {
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 ...
if thermocouple.WithinTemperatureRange(tc, pcb_temperature) {
cjc_uv, err := thermocouple.UV(tc, pcb_temperature)
if err != nil {
log.Println("Error doing CJC", err)
} else {
cjc_uv = 0.0
}
data[k].Value -= cjc_uv
data[k].Unit = t.cfg.Channels[k].Unit
data[k].Id = t.cfg.Channels[k].Id
new_value_c, err := thermocouple.C(tc, data[k].Value)
if err != nil {
log.Println("Error converting UV to C", t.cfg.Channels[k], data[k].Value)
}
//TODO: different temp units
data[k].Value = new_value_c
}
} 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 for Channel", t.cfg.Channels[k].Id)
//fmt.Println("No valid CJC for Channel", t.cfg.Channels[k].Id)
// if the temperature unit is "None", it is probably for UV only.
// so do not convert it to a value using t/c polys
if data[k].Unit != temp_data.None {
new_value_c, err := thermocouple.C(tc, data[k].Value)
if err != nil {
log.Println("Error converting UV to C", t.cfg.Channels[k].Id, data[k].Value)
new_value_c = data[k].Value
}
data[k].Value = new_value_c
// It is celsius by default
switch data[k].Unit {
case temp_data.F:
data[k].Value = temperature.F(temp_data.C, data[k].Value)
case temp_data.K:
data[k].Value = temperature.K(temp_data.C, data[k].Value)
}
}
}