This commit is contained in:
William Clark 2023-11-21 14:57:53 +00:00
parent a58f3e8b5f
commit e2d57edf45
5 changed files with 10 additions and 14 deletions

View File

@ -98,9 +98,9 @@ func Load() (config.Config, error) {
return cfg, err
}
c.Thermo = tc
c.Filter.SampleSize = v.GetInt(head+".filter.samples")
c.Filter.SampleSize = v.GetInt(head + ".filter.samples")
cfg.Channels = append(cfg.Channels, c)
}

View File

@ -15,8 +15,6 @@ const (
DurWaitRestart = 1000 * time.Millisecond
)
// Continuously sample each configured channel, apply filter, and save result
// in a mutex controlled shared data object, that can be accessed at any time
// by a web-request or similar.
@ -36,13 +34,13 @@ func startCacheService(t *TH7Adapter) {
for t.run {
timer_start := time.Now()
for channel := range t.cfg.Channels {
channel_id := t.cfg.Channels[channel].Id
channel_gain := t.cfg.Channels[channel].Gain
for i:=0; i<t.cfg.Channels[channel].Filter.SampleSize; i++ {
for i := 0; i < t.cfg.Channels[channel].Filter.SampleSize; i++ {
// update vref table
t.pcbPort.UpdateTable()
measurement := t.pcbPort.ReadChannel(channel_id, channel_gain)

View File

@ -5,7 +5,7 @@ import (
)
type Filter struct {
SampleSize int `json:"sample_size"`
SampleSize int `json:"sample_size"`
}
type Channel struct {
@ -13,7 +13,7 @@ type Channel struct {
Thermo thermocouple.Type `json:"thermocouple"`
Gain float64 `json:"gain"`
Offset float64 `json:"offset"`
Filter Filter `json:"filter"`
Filter Filter `json:"filter"`
}
type TH7 struct {

View File

@ -1,9 +1,8 @@
package core
type Channel struct {
Id int `json:"id"`
Value float64 `json:"value"`
Id int `json:"id"`
Value float64 `json:"value"`
}
type Ratio struct {

View File

@ -1,6 +1,5 @@
package filter
func AlphaBetaFilter(arr []float64, init float64) float64 {
value := init
@ -9,4 +8,4 @@ func AlphaBetaFilter(arr []float64, init float64) float64 {
value += (gain*arr[i] - value)
}
return value
}
}