Allow shutting down the device on inactivity
This can be enabled by setting the `general.timeout` configuration. Timeout must be specified in seconds, and the max ceiling is 3600 (one hour). Specifying 0 (default) will disable this feature. Signed-off-by: Eugenio Paolantonio (g7) <me@medesimo.eu>
This commit is contained in:
parent
4117778324
commit
0afd4a22e9
4 changed files with 29 additions and 3 deletions
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
- feat: Add config option to customise bullet character (#17)
|
||||
- fix: Use actual screen DPI value to compute sizes and spaces
|
||||
- feat: Allow shutting down the device on inactivity
|
||||
|
||||
## 0.2.0 (2022-05-27)
|
||||
|
||||
|
|
|
|||
8
config.c
8
config.c
|
|
@ -22,7 +22,10 @@
|
|||
|
||||
#include "log.h"
|
||||
|
||||
#include "lvgl/lvgl.h"
|
||||
|
||||
#include <ini.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "squeek2lvgl/sq2lv.h"
|
||||
|
||||
|
|
@ -74,6 +77,7 @@ static bool parse_bool(const char *value, bool *result);
|
|||
static void init_opts(ul_config_opts *opts) {
|
||||
opts->general.animations = false;
|
||||
opts->general.backend = ul_backends_backends[0] == NULL ? UL_BACKENDS_BACKEND_NONE : 0;
|
||||
opts->general.timeout = 0;
|
||||
opts->keyboard.autohide = true;
|
||||
opts->keyboard.layout_id = SQ2LV_LAYOUT_US;
|
||||
opts->keyboard.popovers = false;
|
||||
|
|
@ -103,6 +107,10 @@ static int parsing_handler(void* user_data, const char* section, const char* key
|
|||
opts->general.backend = id;
|
||||
return 1;
|
||||
}
|
||||
} else if (strcmp(key, "timeout") == 0) {
|
||||
/* Use a max ceiling of 60 minutes (3600 secs) */
|
||||
opts->general.timeout = (uint16_t)LV_MIN(strtoul(value, (char **)NULL, 10), 3600);
|
||||
return 1;
|
||||
}
|
||||
} else if (strcmp(section, "keyboard") == 0) {
|
||||
if (strcmp(key, "autohide") == 0) {
|
||||
|
|
|
|||
3
config.h
3
config.h
|
|
@ -28,6 +28,7 @@
|
|||
#include "sq2lv_layouts.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* General options
|
||||
|
|
@ -37,6 +38,8 @@ typedef struct {
|
|||
ul_backends_backend_id_t backend;
|
||||
/* If true, use animations */
|
||||
bool animations;
|
||||
/* Timeout (in seconds) - once elapsed, the device will shutdown. 0 (default) to disable */
|
||||
uint16_t timeout;
|
||||
} ul_config_opts_general;
|
||||
|
||||
/**
|
||||
|
|
|
|||
20
main.c
20
main.c
|
|
@ -182,6 +182,11 @@ static void textarea_ready_cb(lv_event_t *event);
|
|||
*/
|
||||
static void print_password_and_exit(lv_obj_t *textarea);
|
||||
|
||||
/**
|
||||
* Shuts down the device.
|
||||
*/
|
||||
static void shutdown(void);
|
||||
|
||||
/**
|
||||
* Handle termination signals sent to the process.
|
||||
*
|
||||
|
|
@ -278,8 +283,7 @@ static void shutdown_btn_clicked_cb(lv_event_t *event) {
|
|||
static void shutdown_mbox_value_changed_cb(lv_event_t *event) {
|
||||
lv_obj_t *mbox = lv_event_get_current_target(event);
|
||||
if (lv_msgbox_get_active_btn(mbox) == 0) {
|
||||
sync();
|
||||
reboot(RB_POWER_OFF);
|
||||
shutdown();
|
||||
}
|
||||
lv_msgbox_close(mbox);
|
||||
}
|
||||
|
|
@ -313,6 +317,11 @@ static void print_password_and_exit(lv_obj_t *textarea) {
|
|||
sigaction_handler(SIGTERM);
|
||||
}
|
||||
|
||||
static void shutdown(void) {
|
||||
sync();
|
||||
reboot(RB_POWER_OFF);
|
||||
}
|
||||
|
||||
static void sigaction_handler(int signum) {
|
||||
LV_UNUSED(signum);
|
||||
ul_terminal_reset_current_terminal();
|
||||
|
|
@ -558,8 +567,13 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
/* Run lvgl in "tickless" mode */
|
||||
uint32_t timeout = conf_opts.general.timeout * 1000; /* ms */
|
||||
while(1) {
|
||||
lv_task_handler();
|
||||
if (!timeout || lv_disp_get_inactive_time(NULL) < timeout) {
|
||||
lv_task_handler();
|
||||
} else if (timeout) {
|
||||
shutdown();
|
||||
}
|
||||
usleep(5000);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue