diff --git a/README.md b/README.md index 5283b4a..967556f 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,57 @@ Features not yet implemented but planned: ![Alt](/.gitea/webview0.png "Web view demo") +## Configuring the TH7 + +This program is controlled with a config file `config.toml` in which the user can configure each thermocouple channel independently, enable a web view, configure database logging, etc. +The TH7 software uses sane default values where possible. + +```properties +# EXAMPLE TH7 CONFIG +[TH7] +# port used by the web view +port = 9090 +# enable the blinking lights on the Raspberry Pi Hat +LED = true +# if true, the software will use a simulated TH7 +debug = false + +# Configure channel 1 +[Channel_1] +# set type to K-type thermocouple +type = 'K' +# gain is used during signal conversion +gain = 106.8 +# offset is added to the final converted value (in °C) +offset = -5.6 +# samples for the filter function +filter.samples = 50 +# integer representing the filter function type +filter.type = 0 + +# Filter functions: +# 0: simple alpha-beta filter (default) +# 1: lag filter: old * 0.90 + new * 0.10 +# 2: lag filter: old * 0.95 + new * 0.05 +# 3: lag filter: old * 0.99 + new * 0.01 + +# Configure channel 2 to read μV +# this example uses default values for gain, offset and filter. +[Channel_2] +# set thermocouple type to 'U' to just read μV +type = 'U' + +# Database +# Each database type (so far only SQLite3) requires its own set of values +# Below is an example for SQLite3 +[DB] +type = "sqlite3" +# where to save the database file +path = "/home/pi/th7.db" +# logging frequency. specified in seconds. +freq = 60 +``` + ## Building on a Raspberry Pi This code builds without fuss on Raspberry Pi 4 with go version go1.19.3 linux/arm diff --git a/config.toml b/config.toml index f757ed4..a4bd0aa 100644 --- a/config.toml +++ b/config.toml @@ -2,6 +2,7 @@ [TH7] port = 9090 # web port debug = true # enable to use simulated PCB for development +nolog = true # all DB settings are individual to each DB [DB] diff --git a/config/config.go b/config/config.go index a835c49..27a4c92 100644 --- a/config/config.go +++ b/config/config.go @@ -51,12 +51,7 @@ func Load() (config.Config, error) { return cfg, err } - v.SetDefault("TH7.port", 8080) - v.SetDefault("TH7.cache", true) - v.SetDefault("TH7.LED", true) - v.SetDefault("TH7.debug", false) - v.SetDefault("TH7.nolog", false) - v.SetDefault("DB.freq", 60) + SetDefaultConfig(v) cfg.Board.Port = v.GetInt("TH7.port") cfg.Board.Cache = v.GetBool("TH7.cache") @@ -67,18 +62,6 @@ func Load() (config.Config, error) { cfg.Channels = make([]config.Channel, 0) - // set defaults for channels - for i := 1; i < 8; i++ { - var head = fmt.Sprintf("Channel_%d", i) - v.SetDefault(head+".type", "NOTSET") - v.SetDefault(head+".gain", 106.8) - v.SetDefault(head+".offset", 0.0) - 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++ { var c config.Channel var tc thermocouple.Type @@ -94,11 +77,11 @@ func Load() (config.Config, error) { tc, err := getThermocoupleType(v.GetString(head + ".type")) if err != nil { - fmt.Printf("%s.type=%s\n", head, v.GetString(head+".type")) + fmt.Printf("%s.type=%s\n", head, v.GetString(head+ ".type")) return cfg, err } - c.Thermo = tc + c.Thermo = tc c.Filter.SampleSize = v.GetInt(head + ".filter.samples") c.Filter.Type = v.GetInt(head + ".filter.type") diff --git a/config/defaults.go b/config/defaults.go new file mode 100644 index 0000000..664d382 --- /dev/null +++ b/config/defaults.go @@ -0,0 +1,28 @@ +package config + +import ( + "fmt" + + "github.com/spf13/viper" +) + +func SetDefaultConfig(v *viper.Viper) { + v.SetDefault("TH7.port", 8080) + v.SetDefault("TH7.cache", true) + v.SetDefault("TH7.LED", true) + v.SetDefault("TH7.debug", false) + v.SetDefault("TH7.nolog", false) + v.SetDefault("DB.freq", 600) + + // set defaults for channels + for i := 1; i < 8; i++ { + var head = fmt.Sprintf("Channel_%d", i) + v.SetDefault(head+".type", "NOTSET") + v.SetDefault(head+".gain", 106.8) + v.SetDefault(head+".offset", 0.0) + v.SetDefault(head+".unit", "U") + // filter settings + v.SetDefault(head+".filter.samples", 50) + v.SetDefault(head+".filter.type", 0) + } +}