mirror of
https://github.com/Crocmagnon/display-epaper.git
synced 2024-12-22 20:11:46 +01:00
use opensans font + display current weather icon
This commit is contained in:
parent
0378809eac
commit
a59b175666
6 changed files with 30 additions and 13 deletions
12
fonts/fonts.go
Normal file
12
fonts/fonts.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package fonts
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed ttf/OpenSans-Bold.ttf
|
||||
var Bold []byte
|
||||
|
||||
//go:embed ttf/OpenSans-Regular.ttf
|
||||
var Regular []byte
|
||||
|
||||
//go:embed ttf/OpenSans-Italic.ttf
|
||||
var Italic []byte
|
BIN
fonts/ttf/OpenSans-Bold.ttf
Normal file
BIN
fonts/ttf/OpenSans-Bold.ttf
Normal file
Binary file not shown.
BIN
fonts/ttf/OpenSans-Italic.ttf
Normal file
BIN
fonts/ttf/OpenSans-Italic.ttf
Normal file
Binary file not shown.
BIN
fonts/ttf/OpenSans-Regular.ttf
Normal file
BIN
fonts/ttf/OpenSans-Regular.ttf
Normal file
Binary file not shown.
18
img.go
18
img.go
|
@ -136,7 +136,7 @@ func getImg(ctx context.Context, nowFunc func() time.Time, transportsClient *tra
|
|||
msg = quotes.GetQuote(nowFunc())
|
||||
}
|
||||
|
||||
drawTCL(gc, bus, 55)
|
||||
drawTCL(gc, bus, 45)
|
||||
drawTCL(gc, tram, 205)
|
||||
drawVelov(gc, velovRoc, 365)
|
||||
drawDate(gc, nowFunc())
|
||||
|
@ -148,7 +148,7 @@ func getImg(ctx context.Context, nowFunc func() time.Time, transportsClient *tra
|
|||
}
|
||||
|
||||
func drawMsg(gc *draw2dimg.GraphicContext, quote string) {
|
||||
text(gc, quote, 15, leftX, 450, fontRegular)
|
||||
text(gc, quote, 15, leftX, 450, fontItalic)
|
||||
|
||||
}
|
||||
|
||||
|
@ -166,16 +166,20 @@ func drawWeather(ctx context.Context, gc *draw2dimg.GraphicContext, wthr *weathe
|
|||
|
||||
daily := wthr.Daily[0]
|
||||
dailyWeather := daily.Weather[0]
|
||||
err := drawWeatherIcon(gc, dailyWeather)
|
||||
err := drawWeatherIcon(gc, wthr.Current.Weather[0])
|
||||
if err != nil {
|
||||
slog.ErrorContext(ctx, "Failed to draw weather icon", "err", err)
|
||||
}
|
||||
|
||||
text(gc, formatTemp(wthr.Current.Temp), 23, leftX, 120, fontRegular)
|
||||
text(gc, formatTemp(wthr.Current.Temp), 23, leftX, 125, fontRegular)
|
||||
|
||||
text(gc, "max "+formatTemp(daily.Temp.Max), 18, 120, 45, fontRegular)
|
||||
text(gc, fmt.Sprintf("pluie %v%%", int(math.Round(daily.Pop*100))), 18, 120, 80, fontRegular)
|
||||
text(gc, dailyWeather.Description, 18, 120, 115, fontRegular)
|
||||
const xAlign = 120
|
||||
const fontSize = 18
|
||||
|
||||
text(gc, "journée", fontSize, xAlign, 35, fontBold)
|
||||
text(gc, "max "+formatTemp(daily.Temp.Max), fontSize, xAlign, 65, fontRegular)
|
||||
text(gc, fmt.Sprintf("pluie %v%%", int(math.Round(daily.Pop*100))), fontSize, xAlign, 95, fontRegular)
|
||||
text(gc, dailyWeather.Description, fontSize, xAlign, 125, fontRegular)
|
||||
}
|
||||
|
||||
func drawWeatherIcon(gc *draw2dimg.GraphicContext, dailyWeather weather.Weather) error {
|
||||
|
|
13
main.go
13
main.go
|
@ -3,22 +3,22 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"github.com/Crocmagnon/display-epaper/fete"
|
||||
"github.com/Crocmagnon/display-epaper/fonts"
|
||||
"github.com/Crocmagnon/display-epaper/home_assistant"
|
||||
"github.com/Crocmagnon/display-epaper/transports"
|
||||
"github.com/Crocmagnon/display-epaper/weather"
|
||||
"github.com/golang/freetype/truetype"
|
||||
"github.com/llgcode/draw2d"
|
||||
_ "golang.org/x/image/bmp"
|
||||
"golang.org/x/image/font/gofont/gobold"
|
||||
"golang.org/x/image/font/gofont/goregular"
|
||||
"log/slog"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
fontRegular = "goregular"
|
||||
fontBold = "gobold"
|
||||
fontRegular = "regular"
|
||||
fontBold = "bold"
|
||||
fontItalic = "italic"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -27,8 +27,9 @@ func main() {
|
|||
slog.InfoContext(ctx, "starting...")
|
||||
fontCache := MyFontCache{}
|
||||
|
||||
loadFont(ctx, fontCache, goregular.TTF, fontRegular)
|
||||
loadFont(ctx, fontCache, gobold.TTF, fontBold)
|
||||
loadFont(ctx, fontCache, fonts.Regular, fontRegular)
|
||||
loadFont(ctx, fontCache, fonts.Bold, fontBold)
|
||||
loadFont(ctx, fontCache, fonts.Italic, fontItalic)
|
||||
|
||||
draw2d.SetFontCache(fontCache)
|
||||
|
||||
|
|
Loading…
Reference in a new issue