Compare commits

..

No commits in common. "20fab2ade06680f7e6154ed31cef7d84a30482bb" and "e9793181321fc7006da8681bbfd57d69002da375" have entirely different histories.

7 changed files with 43 additions and 76 deletions

View file

@ -22,29 +22,21 @@ func main() {
// Load the config file // Load the config file
pfConfig, _ := config.LoadConfig() pfConfig, _ := config.LoadConfig()
log.Print("========================================") // For some reason the map isn't populated 'right away' and/or doesn't always come in via koanf
pfConfig.Print() // Work around by re-loading the config as necessary to get valid values
log.Print("========================================") for pfConfig.Float64Map(config.CONFIG_KEY_FAN_SPEEDS)[config.CONFIG_MAP_KEY_FAN_SPEED_100] == 0 {
log.Print(pfConfig.Keys()) pfConfig, _ = config.LoadConfig()
log.Print("========================================") }
// Get the various fan related config options as local variables // Get the various fan related config options as local variables
speedMap := pfConfig.Float64Map(config.CONFIG_KEY_FAN_SPEEDS) speedMap := pfConfig.Float64Map(config.CONFIG_KEY_FAN_SPEEDS)
POLL_INTERVAL := pfConfig.String(config.CONFIG_KEY_FAN_POLL_INTERVAL) POLL_INTERVAL := pfConfig.String(config.CONFIG_KEY_FAN_POLL_INTERVAL)
SPEED_FULL_TEMP := pfConfig.Float64(config.CONFIG_KEY_FAN_SPEEDS + "." + config.CONFIG_MAP_KEY_FAN_SPEED_100) SPEED_FULL_TEMP := speedMap[config.CONFIG_MAP_KEY_FAN_SPEED_100]
SPEED_SEVENTY_FIVE_PERCENT_TEMP := pfConfig.Float64(config.CONFIG_KEY_FAN_SPEEDS + "." + config.CONFIG_MAP_KEY_FAN_SPEED_75) SPEED_SEVENTY_FIVE_PERCENT_TEMP := speedMap[config.CONFIG_MAP_KEY_FAN_SPEED_75]
SPEED_FIFTY_PERCENT_TEMP := pfConfig.Float64(config.CONFIG_KEY_FAN_SPEEDS + "." + config.CONFIG_MAP_KEY_FAN_SPEED_50) SPEED_FIFTY_PERCENT_TEMP := speedMap[config.CONFIG_MAP_KEY_FAN_SPEED_50]
SPEED_TWENTY_FIVE_PERCENT_TEMP := pfConfig.Float64(config.CONFIG_KEY_FAN_SPEEDS + "." + config.CONFIG_MAP_KEY_FAN_SPEED_25) SPEED_TWENTY_FIVE_PERCENT_TEMP := speedMap[config.CONFIG_MAP_KEY_FAN_SPEED_25]
SPEED_MINIMUM := pfConfig.Int(config.CONFIG_KEY_FAN_MIN_SPEED) SPEED_MINIMUM := pfConfig.Int(config.CONFIG_KEY_FAN_MIN_SPEED)
log.Print(speedMap)
log.Print(POLL_INTERVAL)
log.Print(SPEED_FULL_TEMP)
log.Print(SPEED_SEVENTY_FIVE_PERCENT_TEMP)
log.Print(SPEED_FIFTY_PERCENT_TEMP)
log.Print(SPEED_TWENTY_FIVE_PERCENT_TEMP)
log.Print(SPEED_MINIMUM)
// Setup fan and bail if we can't see it // Setup fan and bail if we can't see it
fan, err := argonFan.New(ADDRESS, BUS) fan, err := argonFan.New(ADDRESS, BUS)
if err != nil { if err != nil {
@ -79,52 +71,42 @@ func main() {
if cpuTemp >= SPEED_FULL_TEMP || gpuTemp >= SPEED_FULL_TEMP { if cpuTemp >= SPEED_FULL_TEMP || gpuTemp >= SPEED_FULL_TEMP {
if SPEED_MINIMUM > 100 { if SPEED_MINIMUM > 100 {
log.Print("MIN speed in 100")
fan.SetSpeed(SPEED_MINIMUM) fan.SetSpeed(SPEED_MINIMUM)
} else { } else {
log.Print("Speed 100%")
fan.SetSpeed(100) fan.SetSpeed(100)
} }
continue continue
} }
if cpuTemp >= SPEED_SEVENTY_FIVE_PERCENT_TEMP || gpuTemp >= SPEED_SEVENTY_FIVE_PERCENT_TEMP { if cpuTemp >= SPEED_SEVENTY_FIVE_PERCENT_TEMP || gpuTemp >= SPEED_SEVENTY_FIVE_PERCENT_TEMP {
if SPEED_MINIMUM > 75 { if SPEED_MINIMUM > 75 {
log.Print("MIN speed in 75")
fan.SetSpeed(SPEED_MINIMUM) fan.SetSpeed(SPEED_MINIMUM)
} else { } else {
log.Print("Speed 75%")
fan.SetSpeed(75) fan.SetSpeed(75)
} }
continue continue
} }
if cpuTemp >= SPEED_FIFTY_PERCENT_TEMP || gpuTemp >= SPEED_FIFTY_PERCENT_TEMP { if cpuTemp >= SPEED_FIFTY_PERCENT_TEMP || gpuTemp >= SPEED_FIFTY_PERCENT_TEMP {
if SPEED_MINIMUM > 50 { if SPEED_MINIMUM > 50 {
log.Print("MIN speed in 50")
fan.SetSpeed(SPEED_MINIMUM) fan.SetSpeed(SPEED_MINIMUM)
} else { } else {
log.Print("Speed 50%")
fan.SetSpeed(50) fan.SetSpeed(50)
} }
continue continue
} }
if cpuTemp >= SPEED_TWENTY_FIVE_PERCENT_TEMP || gpuTemp >= SPEED_TWENTY_FIVE_PERCENT_TEMP { if cpuTemp >= SPEED_TWENTY_FIVE_PERCENT_TEMP || gpuTemp >= SPEED_TWENTY_FIVE_PERCENT_TEMP {
if SPEED_MINIMUM > 25 { if SPEED_MINIMUM > 25 {
log.Print("MIN speed in 25")
fan.SetSpeed(SPEED_MINIMUM) fan.SetSpeed(SPEED_MINIMUM)
} else { } else {
log.Print("Speed 25%")
fan.SetSpeed(25) fan.SetSpeed(25)
} }
continue continue
} }
if cpuTemp < SPEED_TWENTY_FIVE_PERCENT_TEMP || gpuTemp < SPEED_TWENTY_FIVE_PERCENT_TEMP { if cpuTemp < SPEED_TWENTY_FIVE_PERCENT_TEMP || gpuTemp < SPEED_TWENTY_FIVE_PERCENT_TEMP {
log.Print("MIN SPEED")
fan.SetSpeed(SPEED_MINIMUM) fan.SetSpeed(SPEED_MINIMUM)
continue continue
} }
// We should never get here but... // We should never get here but...
// Maxing fan to be on the safe side // Maxing fan to be on the safe side
log.Print("This should never happen")
fan.SetSpeed(100) fan.SetSpeed(100)
} }
} }

View file

@ -12,7 +12,7 @@ The GUI uses a config similar to the following. To generate a default config, la
# Slideshow intervals # Slideshow intervals
slideshow.slideinterval = "300s" slideshow.slideinterval = "300s"
slideshow.restartinterval = "168h" slideshow.restartinterval = "7d"
# These are SYSTEMD.TIME formatted times # These are SYSTEMD.TIME formatted times
# You probably want to just adjust the actual times here # You probably want to just adjust the actual times here

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"time"
"github.com/knadh/koanf/providers/confmap" "github.com/knadh/koanf/providers/confmap"
"github.com/knadh/koanf/providers/posflag" "github.com/knadh/koanf/providers/posflag"
@ -14,7 +15,6 @@ import (
) )
func main() { func main() {
log.Print("Starting up")
// Command line flag handler // Command line flag handler
f := flag.NewFlagSet("piframe", flag.ContinueOnError) f := flag.NewFlagSet("piframe", flag.ContinueOnError)
f.Usage = func() { f.Usage = func() {
@ -22,7 +22,6 @@ func main() {
os.Exit(0) os.Exit(0)
} }
// Command line flags // Command line flags
log.Print("Setting up CLI flags")
f.Bool(config.CLI_FLAG_CONFIG_ONLY, false, "Only show the config UI, NOT the slideshow") f.Bool(config.CLI_FLAG_CONFIG_ONLY, false, "Only show the config UI, NOT the slideshow")
cliFlag := f.Lookup(config.CLI_FLAG_CONFIG_ONLY) cliFlag := f.Lookup(config.CLI_FLAG_CONFIG_ONLY)
if cliFlag != nil { if cliFlag != nil {
@ -31,25 +30,30 @@ func main() {
// Process command line flags into handler // Process command line flags into handler
f.Parse(os.Args[1:]) f.Parse(os.Args[1:])
log.Print("Loading config")
// Load the config file // Load the config file
pfConfig, _ := config.LoadConfig() pfConfig, configFileProvider := config.LoadConfig()
log.Printf("%v", pfConfig)
pfConfig.Print() // For some reason the restart interval comes through the config as 0s
// Similar to the fan daemon, keep reloading config until we get a valid value
restartDuration := pfConfig.Duration(config.CONFIG_KEY_SLIDESHOW_RESTART_INTERVAL)
for restartDuration.Milliseconds() < 1 {
pfConfig, configFileProvider = config.LoadConfig()
restartDuration = pfConfig.Duration(config.CONFIG_KEY_SLIDESHOW_RESTART_INTERVAL)
}
// Watch for config changes and re-load config if needed // Watch for config changes and re-load config if needed
// configFileProvider.Watch(func(event interface{}, err error) { configFileProvider.Watch(func(event interface{}, err error) {
// if err != nil { if err != nil {
// log.Printf("Error setting up watch of config : %s", err) log.Printf("Error setting up watch of config : %s", err)
// return return
// } }
// // Give the config UI a chance to save and exit clean // Give the config UI a chance to save and exit clean
// time.Sleep(time.Minute) time.Sleep(time.Minute)
// // Bail on slideshow if there is a config change so it restarts with updated config // Bail on slideshow if there is a config change so it restarts with updated config
// log.Fatalf("Config file changed! Exiting!") log.Fatalf("Config file changed! Exiting!")
// }) })
// Process command line flags // Process command line flags
if err := pfConfig.Load(posflag.Provider(f, ".", pfConfig), nil); err != nil { if err := pfConfig.Load(posflag.Provider(f, ".", pfConfig), nil); err != nil {

View file

@ -2,6 +2,7 @@ package config
import ( import (
"log" "log"
"os"
"github.com/knadh/koanf" "github.com/knadh/koanf"
"github.com/knadh/koanf/parsers/toml" "github.com/knadh/koanf/parsers/toml"
@ -24,20 +25,18 @@ func LoadConfig() (*koanf.Koanf, *kfile.File) {
CONFIG_KEY_FAN_POLL_INTERVAL: DEFAULT_FAN_POLL_INTERVAL, CONFIG_KEY_FAN_POLL_INTERVAL: DEFAULT_FAN_POLL_INTERVAL,
CONFIG_KEY_FAN_SPEEDS: DEFAULT_FAN_SPEEDS, CONFIG_KEY_FAN_SPEEDS: DEFAULT_FAN_SPEEDS,
CONFIG_KEY_FAN_MIN_SPEED: DEFAULT_FAN_MIN_SPEED, CONFIG_KEY_FAN_MIN_SPEED: DEFAULT_FAN_MIN_SPEED,
}, ""), nil) }, "."), nil)
// Bring in /etc/defaults/pf.toml if it exists // Bring in /etc/defaults/pf.toml if it exists
configFileProvider := kfile.Provider(CONFIG_FILE_PATH) configFileProvider := kfile.Provider(CONFIG_FILE_PATH)
log.Print("========================================") _, err := os.Stat(CONFIG_FILE_PATH)
if err := pfConfig.Load(configFileProvider, toml.Parser()); err != nil { if os.IsNotExist(err) {
//log.Printf("%s does not exist, USING DEFAULTS", CONFIG_FILE_PATH)
} else {
if errConfigFile := pfConfig.Load(configFileProvider, toml.Parser()); errConfigFile != nil {
log.Fatalf("Error loading config : %s", err) log.Fatalf("Error loading config : %s", err)
} }
log.Print("========================================") }
log.Print("========================================")
log.Print("Loaded Config")
pfConfig.Print()
log.Print("========================================")
return pfConfig, configFileProvider return pfConfig, configFileProvider
} }

View file

@ -24,7 +24,7 @@ const (
const ( const (
DEFAULT_SLIDESHOW_INTERVAL = "300s" DEFAULT_SLIDESHOW_INTERVAL = "300s"
DEFAULT_SLIDESHOW_RESTART_INTERVAL = "168h" DEFAULT_SLIDESHOW_RESTART_INTERVAL = "7d"
DEFAULT_HDMI_OFF = "*-*-* 00:00:00" DEFAULT_HDMI_OFF = "*-*-* 00:00:00"
DEFAULT_HDMI_ON = "*-*-* 06:00:00" DEFAULT_HDMI_ON = "*-*-* 06:00:00"
DEFAULT_ALBUMS_ROOT = "/tank/pictures" DEFAULT_ALBUMS_ROOT = "/tank/pictures"

View file

@ -272,7 +272,7 @@ func ConfigGui(pfconfig *koanf.Koanf) {
main.SetTitle("Configure Intervals") main.SetTitle("Configure Intervals")
main.Clear() main.Clear()
main.AddItem(intervalsForm, 0, 1, true) main.AddItem(intervalsForm, 0, 1, true)
main.AddItem(tview.NewTextView().SetText("Intervals are a number + letter\n\nUse\ns for seconds\nm for minutes\nh for hours"), 0, 1, false) main.AddItem(tview.NewTextView().SetText("Intervals are a number + letter\n\nUse\ns for seconds\nm for minutes\nh for hours\nd for days\nw for weeks"), 0, 1, false)
app.SetFocus(intervalsForm) app.SetFocus(intervalsForm)
} }
if title == "HDMI On/Off" { if title == "HDMI On/Off" {

View file

@ -25,7 +25,6 @@ var fim *exec.Cmd = nil
var stdin io.WriteCloser = nil var stdin io.WriteCloser = nil
func setupFim(PATH_TEMP_FOR_SLIDESHOW string) { func setupFim(PATH_TEMP_FOR_SLIDESHOW string) {
log.Print("Setting up new fim process")
// Prep slideshow command and arguments // Prep slideshow command and arguments
// NOTE: The random flag is seeded with time() ; this is bad as we will be restarting the slideshow at about the same time per the configurd schedule // NOTE: The random flag is seeded with time() ; this is bad as we will be restarting the slideshow at about the same time per the configurd schedule
// We use the non-seeded form to ensure that it's a little more random (or at least hope it's a little more random) // We use the non-seeded form to ensure that it's a little more random (or at least hope it's a little more random)
@ -57,7 +56,6 @@ func Slideshow(pfconfig *koanf.Koanf) {
// /run is a tmpfs so this won't wear on the sd card storage // /run is a tmpfs so this won't wear on the sd card storage
// Create temp folder // Create temp folder
log.Print("Creating temp folder for album selections")
_, err := os.Stat(PATH_TEMP_FOR_SLIDESHOW) _, err := os.Stat(PATH_TEMP_FOR_SLIDESHOW)
if os.IsNotExist(err) { if os.IsNotExist(err) {
errDir := os.MkdirAll(PATH_TEMP_FOR_SLIDESHOW, 0755) errDir := os.MkdirAll(PATH_TEMP_FOR_SLIDESHOW, 0755)
@ -67,7 +65,6 @@ func Slideshow(pfconfig *koanf.Koanf) {
} }
// Cleanup temp folder if it already existed // Cleanup temp folder if it already existed
log.Print("Cleaning up temp folder if it exists")
dirRead, err := os.Open(PATH_TEMP_FOR_SLIDESHOW) dirRead, err := os.Open(PATH_TEMP_FOR_SLIDESHOW)
if err != nil { if err != nil {
log.Fatalf("Error setting up slideshow : %s", err) log.Fatalf("Error setting up slideshow : %s", err)
@ -93,7 +90,6 @@ func Slideshow(pfconfig *koanf.Koanf) {
// Setup symlinks to selected albums to be used with slideshow // Setup symlinks to selected albums to be used with slideshow
// Add albums full paths to command line args for fim // Add albums full paths to command line args for fim
log.Print("Setting up symlinks to selected albums")
albumRootPath := pfconfig.String(config.CONFIG_KEY_ALBUMS_ROOT) albumRootPath := pfconfig.String(config.CONFIG_KEY_ALBUMS_ROOT)
for _, album := range pfconfig.Strings(config.CONFIG_KEY_ALBUMS_SELECTED) { for _, album := range pfconfig.Strings(config.CONFIG_KEY_ALBUMS_SELECTED) {
source := albumRootPath + album source := albumRootPath + album
@ -131,13 +127,7 @@ func Slideshow(pfconfig *koanf.Koanf) {
setupFim(PATH_TEMP_FOR_SLIDESHOW) setupFim(PATH_TEMP_FOR_SLIDESHOW)
// Advance slideshow every interval as defined in const() // Advance slideshow every interval as defined in const()
log.Print("Setting up slideshow advance slide ticker") ticker := time.NewTicker(pfconfig.Duration(config.CONFIG_KEY_SLIDESHOW_INTERVAL))
slideshowAdvanceDurationString := pfconfig.String(config.CONFIG_KEY_SLIDESHOW_INTERVAL)
slideshowAdvanceDuration, err := time.ParseDuration(slideshowAdvanceDurationString)
if err != nil {
log.Fatalf("Error parsing slide duration : %s", err)
}
ticker := time.NewTicker(slideshowAdvanceDuration)
stop_ticker := make(chan struct{}) stop_ticker := make(chan struct{})
go func() { go func() {
for { for {
@ -172,7 +162,6 @@ func Slideshow(pfconfig *koanf.Koanf) {
STOP_SLIDESHOW := false STOP_SLIDESHOW := false
// Goroutine for tracking which keys are pressed and controlling fim if appropriate // Goroutine for tracking which keys are pressed and controlling fim if appropriate
log.Print("Setting up keyboard listener")
keyboardCtx, keyboardCancel := context.WithCancel(context.Background()) keyboardCtx, keyboardCancel := context.WithCancel(context.Background())
go func(keyboardCtx context.Context) { go func(keyboardCtx context.Context) {
for { for {
@ -222,13 +211,7 @@ func Slideshow(pfconfig *koanf.Koanf) {
}(keyboardCtx) }(keyboardCtx)
// Restart fim after configured timeout ; This is setup as a ticker due to KemoNine not getting CommandWithContext stuff to work properly (lots of pointer related crashes and the like) // Restart fim after configured timeout ; This is setup as a ticker due to KemoNine not getting CommandWithContext stuff to work properly (lots of pointer related crashes and the like)
log.Print("Setting up fim restart ticker") fimTicker := time.NewTicker(pfconfig.Duration(config.CONFIG_KEY_SLIDESHOW_RESTART_INTERVAL))
fimRestartDurationString := pfconfig.String(config.CONFIG_KEY_SLIDESHOW_RESTART_INTERVAL)
fimRestartDuration, err := time.ParseDuration(fimRestartDurationString)
if err != nil {
log.Fatalf("Error parsing restart duration : %S", err)
}
fimTicker := time.NewTicker(fimRestartDuration)
stop_fim_ticker := make(chan struct{}) stop_fim_ticker := make(chan struct{})
go func() { go func() {
for { for {
@ -251,7 +234,6 @@ func Slideshow(pfconfig *koanf.Koanf) {
// Run fim // Run fim
for !STOP_SLIDESHOW { for !STOP_SLIDESHOW {
log.Print("Top of fim slideshow loop")
if err := fim.Run(); err != nil { if err := fim.Run(); err != nil {
// Unwrap the error a bit so we can find out if a signal killed fim or something else // Unwrap the error a bit so we can find out if a signal killed fim or something else
// An exit code of -1 means the program didn't exit in time or was terminated by a signal (per the docs) // An exit code of -1 means the program didn't exit in time or was terminated by a signal (per the docs)