1
1
#include "actions.h"
2
2
#include "screens.h"
3
+ #include "ui.h"
4
+ #include <stdio.h>
3
5
4
6
int handle_gesture_screen_switch (lv_event_t * e , lv_dir_t direction , int screenId ) {
5
7
lv_event_code_t event_code = lv_event_get_code (e );
@@ -31,6 +33,14 @@ void action_switch_to_about(lv_event_t *e) {
31
33
loadScreen (SCREEN_ID_ABOUT_SCREEN );
32
34
}
33
35
36
+ void action_switch_to_reset_config (lv_event_t * e ) {
37
+ loadScreen (SCREEN_ID_RESET_CONFIG_SCREEN );
38
+ }
39
+
40
+ void action_switch_to_reboot (lv_event_t * e ) {
41
+ loadScreen (SCREEN_ID_REBOOT_SCREEN );
42
+ }
43
+
34
44
void action_menu_screen_gesture (lv_event_t * e ) {
35
45
handle_gesture_screen_switch (e , LV_DIR_RIGHT , SCREEN_ID_HOME_SCREEN );
36
46
}
@@ -51,27 +61,56 @@ void action_about_screen_gesture(lv_event_t * e) {
51
61
handle_gesture_screen_switch (e , LV_DIR_RIGHT , SCREEN_ID_MENU_SCREEN );
52
62
}
53
63
54
- static const int RESET_LONG_PRESS_DURATION = 1000 * 20 ; // 20 seconds
64
+ // user_data doesn't seem to be working, so we use a global variable here
65
+ static uint32_t t_reset_config ;
66
+ static uint32_t t_reboot ;
67
+ const int RESET_CONFIG_HOLD_TIME = 10 ;
68
+ const int REBOOT_HOLD_TIME = 5 ;
55
69
56
70
void action_reset_config (lv_event_t * e ) {
57
71
lv_event_code_t event_code = lv_event_get_code (e );
58
72
lv_obj_t * obj = lv_event_get_target (e );
59
73
60
74
if (event_code == LV_EVENT_PRESSED ) {
61
- // Button pressed - start timing
62
- uint32_t reset_press_start_time = lv_tick_get ();
63
- lv_obj_set_user_data (obj , (uint32_t ) reset_press_start_time );
75
+ t_reset_config = lv_tick_get ();
64
76
}
65
77
else if (event_code == LV_EVENT_PRESSING ) {
66
- uint32_t reset_press_start_time = (uint32_t ) lv_obj_get_user_data (obj );
67
- if (reset_press_start_time == 0 ) {
68
- return ;
78
+ int remaining_time = RESET_CONFIG_HOLD_TIME * 1000 - lv_tick_elaps (t_reset_config );
79
+ if (remaining_time <= 0 ) {
80
+ lv_obj_add_flag (objects .reset_config_button , LV_OBJ_FLAG_HIDDEN );
81
+ lv_obj_clear_flag (objects .reset_config_spinner , LV_OBJ_FLAG_HIDDEN );
82
+ ui_call_rpc_handler ("resetConfig" , NULL );
83
+ } else {
84
+ char buf [100 ];
85
+ int remaining_time_seconds = remaining_time / 1000 ;
86
+ if (remaining_time_seconds <= 1 ) {
87
+ remaining_time_seconds = 1 ;
88
+ }
89
+ sprintf (buf , "Press and hold for %d seconds" , remaining_time_seconds );
90
+ lv_label_set_text (objects .reset_config_label , buf );
69
91
}
92
+ }
93
+ }
70
94
71
- uint32_t current_time = lv_tick_get ();
72
- if (current_time - reset_press_start_time >= RESET_LONG_PRESS_DURATION ) {
73
- lv_obj_add_flag (objects .reset_config_button , LV_OBJ_FLAG_HIDDEN );
74
- lv_obj_clear_flag (objects .reset_config_spinner , LV_OBJ_FLAG_HIDDEN );
95
+ void action_reboot (lv_event_t * e ) {
96
+ lv_event_code_t event_code = lv_event_get_code (e );
97
+ lv_obj_t * obj = lv_event_get_target (e );
98
+
99
+ if (event_code == LV_EVENT_PRESSED ) {
100
+ t_reboot = lv_tick_get ();
101
+ }
102
+ else if (event_code == LV_EVENT_PRESSING ) {
103
+ int remaining_time = REBOOT_HOLD_TIME * 1000 - lv_tick_elaps (t_reboot );
104
+ if (remaining_time <= 0 ) {
105
+ ui_call_rpc_handler ("reboot" , NULL );
106
+ } else {
107
+ char buf [100 ];
108
+ int remaining_time_seconds = remaining_time / 1000 ;
109
+ if (remaining_time_seconds <= 1 ) {
110
+ remaining_time_seconds = 1 ;
111
+ }
112
+ sprintf (buf , "Press and hold for %d seconds" , remaining_time_seconds );
113
+ lv_label_set_text (objects .reboot_label , buf );
75
114
}
76
115
}
77
116
}
0 commit comments