Basic config file load
This commit is contained in:
parent
0834f3779f
commit
8737f2fe1a
|
@ -1,3 +1,28 @@
|
||||||
# gui
|
# gui
|
||||||
|
|
||||||
This is the main source code for the custom UI used by PiFrame. This is responsible for things like restart, WiFi config, ensuring the slide show is running and more.
|
This is the main source code for the custom UI used by PiFrame. This is responsible for things like restart, WiFi config, ensuring the slide show is running and more.
|
||||||
|
|
||||||
|
## Config
|
||||||
|
|
||||||
|
The GUI will work off a config similar to the following. Use the ```generate config``` option to generate a default configuration in ```/etc/default/pf.toml```
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
[slideshow]
|
||||||
|
duration = "300s"
|
||||||
|
|
||||||
|
[hdmi]
|
||||||
|
# These are SYSTEMD.TIME formatted times
|
||||||
|
# You probably want to just adjust the actual times here
|
||||||
|
# See https://www.freedesktop.org/software/systemd/man/systemd.time.html
|
||||||
|
off = "*-*-* 00:00:00"
|
||||||
|
on = "*-*-* 06:00:00"
|
||||||
|
|
||||||
|
[albums]
|
||||||
|
root = "/tank/pictures"
|
||||||
|
selected = [
|
||||||
|
"/",
|
||||||
|
"/KemoNine"
|
||||||
|
]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
|
@ -1,10 +1,63 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.kemonine.info/PiFrame/ui"
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/knadh/koanf"
|
||||||
|
"github.com/knadh/koanf/parsers/toml"
|
||||||
|
"github.com/knadh/koanf/providers/confmap"
|
||||||
|
"github.com/knadh/koanf/providers/file"
|
||||||
|
//"git.kemonine.info/PiFrame/ui"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
CONFIG_FILE_PATH = "/etc/default/pf.toml"
|
||||||
|
CONFIG_KEY_SLIDESHOW_DURATION = "slideshow.duration"
|
||||||
|
CONFIG_KEY_HDMI_OFF = "hdmi.off"
|
||||||
|
CONFIG_KEY_HDMI_ON = "hdmi.on"
|
||||||
|
CONFIG_KEY_ALBUMS_ROOT = "albums.root"
|
||||||
|
CONFIG_KEY_ALBUMS_SELECTED = "albums.selected"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DEFAULT_SLIDESHOW_DURATION = "300s"
|
||||||
|
DEFAULT_HDMI_OFF = "*-*-* 00:00:00"
|
||||||
|
DEFAULT_HDMI_ON = "*-*-* 06:00:00"
|
||||||
|
DEFAULT_ALBUMS_ROOT = "/tank/pictures"
|
||||||
|
DEFAULT_ALBUM_SELECTED = "/"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ui.Slideshow()
|
// Main config variable
|
||||||
ui.ConfigGui()
|
var pfConfig = koanf.New(".")
|
||||||
|
|
||||||
|
// Setup some defaults
|
||||||
|
pfConfig.Load(confmap.Provider(map[string]interface{}{
|
||||||
|
CONFIG_KEY_SLIDESHOW_DURATION: DEFAULT_SLIDESHOW_DURATION,
|
||||||
|
CONFIG_KEY_HDMI_OFF: DEFAULT_HDMI_OFF,
|
||||||
|
CONFIG_KEY_HDMI_ON: DEFAULT_HDMI_ON,
|
||||||
|
CONFIG_KEY_ALBUMS_ROOT: DEFAULT_ALBUMS_ROOT,
|
||||||
|
CONFIG_KEY_ALBUMS_SELECTED: []string{DEFAULT_ALBUM_SELECTED},
|
||||||
|
}, "."), nil)
|
||||||
|
|
||||||
|
_, err := os.Stat(CONFIG_FILE_PATH)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
log.Printf("%s does not exist, USING DEFAULTS", CONFIG_FILE_PATH)
|
||||||
|
} else {
|
||||||
|
if errConfigFile := pfConfig.Load(file.Provider(CONFIG_FILE_PATH), toml.Parser()); errConfigFile != nil {
|
||||||
|
log.Fatalf("Error loading config: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// slideshowDuration := pfConfig.Duration(CONFIG_KEY_SLIDESHOW_DURATION)
|
||||||
|
// hdmiOff := pfConfig.String(CONFIG_KEY_HDMI_OFF)
|
||||||
|
// hdmiOn := pfConfig.String(CONFIG_KEY_HDMI_ON)
|
||||||
|
// albumsRoot := pfConfig.String(CONFIG_KEY_ALBUMS_ROOT)
|
||||||
|
// albumsSelected := pfConfig.Strings(CONFIG_KEY_ALBUMS_SELECTED)
|
||||||
|
|
||||||
|
//ui.Slideshow()
|
||||||
|
//ui.ConfigGui()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue