package fb import ( "bufio" "fmt" "image" "image/color" "io" "os" "path/filepath" ) /* old version that worked some time for some reason func Resolution() (w int, h int) { resFile, err := os.Open("/sys/class/graphics/fb0/virtual_size") if err != nil { panic(err) } r := bufio.NewReader(resFile) s, err := r.ReadString('\n') if err != nil { panic(err) } fmt.Sscanf(s, "%d,%d", &w, &h) return } */ func Resolution() (w int, h int) { matches, err := filepath.Glob("sys/class/drm/*/modes") if err != nil { panic(err) } for _, match := range matches { f, err := os.Open(match) if err != nil { panic(err) } r := bufio.NewReader(f) s, err := r.ReadString('\n') if err != nil { switch err { case io.EOF: continue default: panic(err) } } fmt.Sscanf(s, "%dx%d", &w, &h) } return } var devfb *os.File var width, height = Resolution() func init() { var err error devfb, err = os.OpenFile("/dev/fb0", os.O_WRONLY, os.ModePerm) if err != nil { panic(err) } } func Bytes(c color.Color) []byte { r, g, b, a := c.RGBA() return []byte{byte(b), byte(g), byte(r), byte(a)} } func Draw(img image.Image) error { buf := bufio.NewWriterSize(devfb, 1<<16) for h := 0; h < height; h++ { for w := 0; w < width; w++ { _, err := buf.Write(Bytes(img.At(w, h))) if err != nil { return err } } } err := buf.Flush() if err != nil { return err } _, err = devfb.Seek(0, 0) if err != nil { return err } return nil }