Add a TON of error handling that was previously skipped (intentionally but really needs to be there) ; added basic filesystem walk of albums dir to facilitate config of which albums are used for the slideshow
This commit is contained in:
parent
e3008a6d43
commit
37bbc4658d
41
cmd/ui/ui.go
41
cmd/ui/ui.go
|
@ -6,7 +6,9 @@ import (
|
|||
"log"
|
||||
"math"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -22,6 +24,8 @@ const (
|
|||
CMD_FINDMNT = "/usr/bin/findmnt"
|
||||
CMD_VCGENCMD = "/opt/vc/bin/vcgencmd"
|
||||
FILE_CPU_TEMP = "/sys/class/thermal/thermal_zone0/temp"
|
||||
ALBUM_ROOT_DIR = "/tank/pictures"
|
||||
SYNCTHING_FOLDER_SKIP = ".stfolder"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -42,29 +46,56 @@ func main() {
|
|||
// Network interfaces for status panel
|
||||
ifaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
log.Printf("Error getting netork interfaces : %s", err)
|
||||
log.Fatalf("Error getting netork interfaces : %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Disk use
|
||||
findmntOut, _ := exec.Command(CMD_FINDMNT, "-n", "-l",
|
||||
findmntOut, err := exec.Command(CMD_FINDMNT, "-n", "-l",
|
||||
"-o", "TARGET,USE%",
|
||||
"-t", "ext4,exfat,vfat,btrfs,zfs,xfs").Output()
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting disk use : %s", err)
|
||||
}
|
||||
filesystems := strings.Split(strings.Trim(string(findmntOut), "\n"), "\n")
|
||||
|
||||
// GPU Temp
|
||||
vcgencmdOut, _ := exec.Command(CMD_VCGENCMD, "measure_temp").Output()
|
||||
vcgencmdOut, err := exec.Command(CMD_VCGENCMD, "measure_temp").Output()
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting GPU temp : %s", err)
|
||||
}
|
||||
gpuTemp := strings.Split(strings.Trim(string(vcgencmdOut), "\n"), "=")[1]
|
||||
|
||||
// CPU Temp
|
||||
cpuTempFileContents, err := ioutil.ReadFile(FILE_CPU_TEMP)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading file %s : %s", FILE_CPU_TEMP, err)
|
||||
log.Fatalf("Error getting CPU temp : %s", err)
|
||||
}
|
||||
cpuTempStr := strings.Trim(string(cpuTempFileContents), "\n")
|
||||
cpuTempInt, _ := strconv.Atoi(cpuTempStr)
|
||||
cpuTempInt, err := strconv.Atoi(cpuTempStr)
|
||||
if err != nil {
|
||||
log.Fatalf("Error processing CPU temp : %S", err)
|
||||
}
|
||||
cpuTemp := fmt.Sprintf("%.2f'C", float64(cpuTempInt)/1000.0)
|
||||
|
||||
// Get list of all folders that can be used as albums
|
||||
var albums []string
|
||||
err = filepath.Walk(ALBUM_ROOT_DIR, func(path string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if fi.IsDir() {
|
||||
if strings.Contains(path, SYNCTHING_FOLDER_SKIP) {
|
||||
return nil
|
||||
}
|
||||
albums = append(albums, path)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting list of albums : %s", err)
|
||||
}
|
||||
|
||||
// Run config UI when slideshow stops
|
||||
app := tview.NewApplication()
|
||||
|
||||
|
|
Loading…
Reference in a new issue