diff --git a/config.toml b/config.toml index be5e762..5a7dfde 100644 --- a/config.toml +++ b/config.toml @@ -3,13 +3,19 @@ port = 9090 # web port debug = true # enable to use simulated PCB for development +# all DB settings are individual to each DB [DB] type = "sqlite3" path = "test.db" freq = 60 +# Configure channel 1 +# type = 'U' => UV, else use other letters for resp type +# filter.samples => sample buffer size +# filter.type => filtering function to use [0-3; 0 default] + [Channel_1] -type = 'U' +type = 'U' filter.samples = 100 filter.type = 1 diff --git a/config/config.go b/config/config.go index 559969c..a835c49 100644 --- a/config/config.go +++ b/config/config.go @@ -76,6 +76,7 @@ func Load() (config.Config, error) { v.SetDefault(head+".unit", "UV") // filter settings v.SetDefault(head+".filter.samples", 50) + v.SetDefault(head+".filter.type", 0) } for i := 1; i < 8; i++ { diff --git a/core/th7/service.go b/core/th7/service.go index caa3bce..e136eaf 100644 --- a/core/th7/service.go +++ b/core/th7/service.go @@ -50,11 +50,9 @@ func startCacheService(t *TH7Adapter) { time.Sleep(DurWaitBetweenChannel) } - // do alpha~beta on each channel, - // putting the value in - // TODO: in config have different types. + // apply filter to each set of samples. First run will be noisy. for i := range samples { - data[i].Value = filter.AlphaBetaFilter(samples[i], data[i].Value) + data[i].Value = filter.FilterByType(t.cfg.Channels[i].Filter.Type, samples[i], data[i].Value) } // read pcb temp and apply CJC diff --git a/filter/filter.go b/filter/filter.go index 6abf08a..82dd548 100644 --- a/filter/filter.go +++ b/filter/filter.go @@ -1,6 +1,21 @@ package filter -func AlphaBetaFilter(arr []float64, init float64) float64 { +func FilterByType(t int, arr []float64, init float64) float64 { + switch t { + case 0: + return AlphaBeta(arr, init) + case 1: + return Lag_1(arr, init) + case 2: + return Lag_2(arr, init) + case 3: + return Lag_3(arr, init) + } + + return AlphaBeta(arr, init) +} + +func AlphaBeta(arr []float64, init float64) float64 { value := init for i := range arr {