ui: implement a screen timeout after a period of user inactivity
passed 60 sec of no touch screen activity, daemon turns off backlight and gui places a black "topdrop", opposite of backdrop. simply touching the screen reactivates it immediately. there seem to be no way to turn screen power off, so backlight plus black topdrop is the next best. there's no user settings to change 60 sec timeout at the moment because it is unclear whether it's worth adding UI elements. can always do so later. the implementation also provides means to reactivate the screen in an event of an alert from the daemon in the future. closes #3pull/20/head v0.1.0
parent
021c810dc7
commit
fd49235f9e
@ -0,0 +1,43 @@
|
|||||||
|
///! display and touch screen helper functions.
|
||||||
|
const std = @import("std");
|
||||||
|
const Thread = std.Thread;
|
||||||
|
|
||||||
|
const lvgl = @import("lvgl.zig");
|
||||||
|
const drv = @import("drv.zig");
|
||||||
|
const ui = @import("ui.zig");
|
||||||
|
|
||||||
|
const logger = std.log.scoped(.screen);
|
||||||
|
|
||||||
|
/// cover the whole screen in black (top layer) and block until either
|
||||||
|
/// a touch screen activity or wake event is triggered.
|
||||||
|
/// sleep removes all input devices at enter and reinstates them at exit so that
|
||||||
|
/// a touch event triggers no accidental action.
|
||||||
|
pub fn sleep(wake: *const Thread.ResetEvent) void {
|
||||||
|
drv.deinitInput();
|
||||||
|
ui.topdrop(.show);
|
||||||
|
defer {
|
||||||
|
drv.initInput() catch |err| logger.err("drv.initInput: {any}", .{err});
|
||||||
|
ui.topdrop(.remove);
|
||||||
|
}
|
||||||
|
|
||||||
|
const watcher = drv.InputWatcher() catch |err| {
|
||||||
|
logger.err("drv.InputWatcher: {any}", .{err});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
defer watcher.close();
|
||||||
|
while (!wake.isSet()) {
|
||||||
|
if (watcher.consume()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std.atomic.spinLoopHint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// turn on or off display backlight.
|
||||||
|
pub fn backlight(onoff: enum { on, off }) !void {
|
||||||
|
const blpath = "/sys/class/backlight/rpi_backlight/bl_power";
|
||||||
|
const f = try std.fs.openFileAbsolute(blpath, .{ .mode = .write_only });
|
||||||
|
defer f.close();
|
||||||
|
const v = if (onoff == .on) "0" else "1";
|
||||||
|
_ = try f.write(v);
|
||||||
|
}
|
Reference in New Issue