display-epaper/main.go

59 lines
1.3 KiB
Go
Raw Normal View History

2024-09-14 21:34:02 +02:00
package main
import (
2024-09-15 10:46:07 +02:00
"context"
2024-09-15 12:00:36 +02:00
"github.com/Crocmagnon/display-epaper/fete"
2024-09-15 10:46:07 +02:00
"github.com/Crocmagnon/display-epaper/transports"
2024-09-15 23:25:17 +02:00
"github.com/Crocmagnon/display-epaper/weather"
2024-09-14 21:34:02 +02:00
"github.com/golang/freetype/truetype"
"github.com/llgcode/draw2d"
_ "golang.org/x/image/bmp"
"golang.org/x/image/font/gofont/goregular"
"log"
2024-09-15 10:46:07 +02:00
"os"
"time"
2024-09-14 21:34:02 +02:00
)
const fontName = "default"
func main() {
log.Println("starting...")
2024-09-15 10:46:07 +02:00
ctx := context.Background()
2024-09-14 21:34:02 +02:00
font, err := truetype.Parse(goregular.TTF)
if err != nil {
log.Fatalf("loading font: %v\n", err)
}
fontCache := MyFontCache{}
fontCache.Store(draw2d.FontData{Name: fontName}, font)
draw2d.SetFontCache(fontCache)
2024-09-15 14:19:01 +02:00
transportsClient := transports.New(nil, transports.Config{})
2024-09-15 10:46:07 +02:00
2024-09-15 12:00:36 +02:00
feteClient := fete.New(nil, fete.Config{
APIKey: os.Getenv("FETE_API_KEY"),
CacheLocation: os.Getenv("FETE_CACHE_LOCATION"),
})
2024-09-15 23:25:17 +02:00
weatherClient := weather.New(nil, weather.Config{
2024-09-16 00:28:43 +02:00
APIKey: os.Getenv("WEATHER_API_KEY"),
CacheLocation: os.Getenv("WEATHER_CACHE_LOCATION"),
2024-09-15 23:25:17 +02:00
})
2024-09-16 18:09:00 +02:00
const minSleep = 1 * time.Second
sleep, err := time.ParseDuration(os.Getenv("SLEEP_DURATION"))
if err != nil || sleep < minSleep {
sleep = minSleep
}
log.Printf("sleep duration: %v\n", sleep)
if err := run(ctx, sleep, transportsClient, feteClient, weatherClient); err != nil {
2024-09-15 09:01:13 +02:00
log.Fatal("error: ", err)
2024-09-14 21:34:02 +02:00
}
log.Println("done")
}