text
stringlengths
0
1.47k
func ioctl(fd uintptr, req uintptr, arg unsafe.Pointer) error {
if _, _, e := syscall.Syscall(syscall.SYS_IOCTL, fd, req, uintptr(arg)); e != 0 {
return e
}
return nil
}
// background is the color behind everything: the mark's own dark brown, or whatever -fill asked for.
func background(fill string) color.RGBA {
bg := color.RGBA{0x1c, 0x15, 0x11, 0xff}
if fill != "" {
if c, err := strconv.ParseUint(fill, 16, 32); err == nil {
bg = color.RGBA{uint8(c >> 16), uint8(c >> 8), uint8(c), 0xff}
}
}
return bg
}
// compose draws the landscape image, and says where the clock goes so the repaint can clear only
// that much. Kept apart from the framebuffer so -png can render exactly what the panel would show
// on a machine with no panel: wording that nobody can see before it is on a device is wording that
// gets shipped wrong.
func compose(w, h int, bg color.RGBA, fill, title, lines string) (*image.RGBA, image.Rectangle, int, int) {
img := image.NewRGBA(image.Rect(0, 0, w, h))
draw.Draw(img, img.Bounds(), image.NewUniform(bg), image.Point{}, draw.Src)
amber := color.RGBA{0xe9, 0xa2, 0x3b, 0xff}
paper := color.RGBA{0xe8, 0xdc, 0xc8, 0xff}
clockAt := image.Rect(40, 250, w-40, 360)
clockY, clockScale := 300, 6
switch {
case fill != "":
// Nothing but the color: the caller wants the panel proved, not described.
case title != "":
// Something to say, which on this device means the rescue environment saying so. The test
// image is not drawn: color bars beside an explanation read as a fault in the explanation.
scale, margin, chars := fits(w)
step := 13*scale + 5 // a line, plus enough that the rows do not touch
top := 40 + 13*(scale+3) + scale // under the heading, which is drawn three sizes larger
frame(img, img.Bounds().Inset(8), 4, amber)
text(img, title, margin, 40, scale+3, amber)
for i, l := range strings.Split(lines, "|") {
if l = strings.TrimSpace(l); l != "" {
if len(l) > chars {
l = l[:chars]
}
text(img, l, margin, top+i*step, scale, paper)
}
}
// Bottom left, clear of the lines and clear of the bottom edge, and still ticking: a clock
// that moves is how somebody in front of the device tells this screen from a frozen one.
clockAt = image.Rect(margin, h-90, margin+260, h-18)
clockY, clockScale = h-70, scale+1
text(img, time.Now().Format("15:04:05"), margin, clockY, clockScale, paper)
default:
// Color bars along the bottom, an amber frame, and text.
bars := []color.RGBA{{0xff, 0, 0, 0xff}, {0, 0xff, 0, 0xff}, {0, 0, 0xff, 0xff}, {0xff, 0xff, 0xff, 0xff}, {0xe9, 0xa2, 0x3b, 0xff}}
bw := w / len(bars)
for i, c := range bars {
draw.Draw(img, image.Rect(i*bw, h-60, (i+1)*bw, h), image.NewUniform(c), image.Point{}, draw.Src)
}
frame(img, img.Bounds().Inset(8), 4, amber)
text(img, "TECHO5", 40, 120, 8, amber)
text(img, fmt.Sprintf("framebuffer %dx%d", w, h), 40, 220, 3, paper)
text(img, time.Now().Format("15:04:05"), 40, 300, 6, paper)
}
return img, clockAt, clockY, clockScale
}
func main() {
info := flag.Bool("info", false, "print framebuffer geometry and exit")
png := flag.String("png", "", "write what the panel would show to this file and exit (no device needed)")
pw := flag.Int("png-w", 960, "canvas width for -png (960 Show 5, 480 Spot, 1280 Show 8)")
ph := flag.Int("png-h", 480, "canvas height for -png")
fill := flag.String("fill", "", "fill with this rrggbb color only")
hold := flag.Duration("hold", 0, "keep repainting for this long (0 = paint once and exit)")
title := flag.String("title", "", "a heading to draw instead of the test image")
lines := flag.String("lines", "", "lines under the heading, separated by | (needs -title)")
mapSize := flag.Int("map", 0, "try this mmap size first, in bytes")
dump := flag.String("dump", "", "write the page the panel is showing to this PNG and exit")
decodeDir := flag.String("decode", "", "time decoding every .jpg in this directory and putting it on the panel")
decodeN := flag.Int("decode-n", 10, "how many times -decode times each frame")
watch := flag.Bool("watch", false, "report how often the panel's page changes (reads only)")
watchFor := flag.Duration("watch-for", 30*time.Second, "how long -watch runs (0 = until interrupted)")
watchEach := flag.Bool("watch-each", false, "print every frame -watch sees")
bench := flag.Int("bench", 0, "pan the panel this many times, as fast as the driver takes it")
benchFor := flag.Duration("bench-for", 0, "stop -bench after this long (0 = by count alone)")
benchInterval := flag.Duration("bench-interval", 0, "pace -bench to this interval (0 = as fast as possible)")
benchEach := flag.Bool("bench-each", false, "print every -bench frame")
fill2 := flag.String("fill2", "ffffff", "the other color -bench alternates with")
flag.Parse()
// -watch reads and changes nothing, so it runs while the daemon is still working: what the
// daemon presents while it is working is the question, and a frozen daemon answers another one.
if *watch {
wf, err := os.Open(fbDev)