select filter in config file
This commit is contained in:
parent
0ffeb62954
commit
321f2e0e53
@ -3,11 +3,17 @@
|
||||
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'
|
||||
filter.samples = 100
|
||||
|
@ -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++ {
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user