Categorygithub.com/bfanger/clock
module
0.0.0-20241125061308-1c09cdca7836
Repository: https://github.com/bfanger/clock.git
Documentation: pkg.go.dev

# README

Clock

A "smart" clock written in Go which runs on a 4.0 inch screen connected to a Raspberry Pi

Time for feeding the fish and going to bed

Goal

  • Show time
  • Alarm (for School)
  • Show train delays

Setup

go install github.com/bokwoon95/wgo@latest
apt-get install libsdl2{,-mixer,-image,-ttf,-gfx}-dev
go get -v github.com/veandco/go-sdl2/{sdl,img,ttf}
go get -v github.com/bfanger/clock

MacOS dev setup

brew install pkg-config sdl2 sdl2_image sdl2_ttf

Architecture / Design

An abstraction on top of SDL to make an efficient event-based ui.

Lazy execution

Allow work is deferred until the results are needed. This allows freely changing individual properties of a layer without causing an updated texture for every change.

The actual work is performed when a Image(\*sdl.Renderer) via Compose(\*sdl.Renderer) is called. The resulting texture is cached, so drawing the next frame will be even faster.

Concepts

type Imager interface {
  Image(r *sdl.Renderer) (*Image, error)
}

An Imager can generate a image/texture based on it's properties. It doesn't have a position and can't be displayed on its own.

type Composer interface {
  Compose(*sdl.Renderer) error
}

To display something in the renderer you'll need a Composer. The Composer is responsible for rendering the texture(s) onto the screen

Engine

Composers are added to a Scene in the Engine and are rendered automatically. All UI operations should be wrapped in a engine.Go() closure which are batched and executed in the main/ui thread. A useful side-effect of calling engine.Go is that it will trigger a re-render.

Getting latest SDL on Raspberry OS

Download latest libsdl2 source (2.30.5 at the time of writing)

tar -xvf ./SDL2-2.30.5.tar.gz
cd SDL2-2.30.5
./configure
make
sudo chmod -R pi /usr/local
make install

Download SDL_image

sudo apt install libjpeg-dev libtiff-dev
tar -xvf ./SDL2_image-2.8.2.tar.gz
cd SDL2_image-2.8.2
./configure
make
make install

and SDL_ttf

tar -xvf ./SDL2_ttf-2.22.0.tar.gz
cd SDL2_ttf-2.22.0
./configure
make
make install

Remove the packaged version:

sudo apt-get remove libsdl2{,-mixer,-image,-ttf,-gfx}-dev
sudo apt-get remove libsdl2{,-mixer,-image,-ttf}-2.0

# Packages

No description provided by the author
No description provided by the author