forked from CentralIllinoisRoboticsClub/wheele_gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen_shutdown.cpp
69 lines (56 loc) · 1.96 KB
/
screen_shutdown.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "screen.h"
#define COUNTDOWN_TIMER_RESET 5
#define COUNTDOWN_TIMER_DELAY_MS 1000
static Box back_button(10,5,30,20,SCREEN_COLOR_RED);
static Box confirm_button(190,85,100,40,SCREEN_COLOR_BLACK);
static Box cancel_button(190,135,100,40,SCREEN_COLOR_BLACK);
static Box countdown_box(25,75,125,125,SCREEN_COLOR_BLACK,true,10);
static int countdown_timer = COUNTDOWN_TIMER_RESET;
static unsigned long update_time;
void draw_shutdown_screen(Adafruit_ILI9341& screen){
screen.fillScreen(ILI9341_DARKGREY);
screen.setCursor(80,10);
screen.setTextSize(2);
screen.setTextColor(SCREEN_TITLE_COLOR);
screen.print(F("WheelE Shutdown"));
screen.fillRect(0,SCREEN_TITLE_BAR_Y,320,SCREEN_TITLE_BAR_HEIGHT,SCREEN_TITLE_BAR_COLOR);
// buttons
back_button.draw(screen);
confirm_button.set_label(String("Confirm"),SCREEN_COLOR_WHITE);
confirm_button.draw(screen);
cancel_button.set_label(String("Cancel"),SCREEN_COLOR_WHITE);
cancel_button.draw(screen);
// countdown timer
if(countdown_timer != 0){
countdown_box.set_label(String(countdown_timer),SCREEN_COLOR_RED);
countdown_box.draw(screen);
update_time = millis();
}
}
int touch_shutdown_screen(Adafruit_ILI9341& screen, TSPoint& p)
{
int new_screen = SHUTDOWN_SCREEN; // default no change
if(back_button.touched(p) || cancel_button.touched(p)){
countdown_timer = COUNTDOWN_TIMER_RESET;
new_screen = HOME_SCREEN;
}
if(confirm_button.touched(p)){
countdown_timer = 0;
}
return new_screen;
}
void update_shutdown_screen(Adafruit_ILI9341& screen){
unsigned long current_time = millis();
if((current_time - update_time) > COUNTDOWN_TIMER_DELAY_MS){
if(countdown_timer > 1){
countdown_timer--;
countdown_box.set_label(String(countdown_timer),SCREEN_COLOR_RED);
countdown_box.draw(screen);
update_time = millis();
}
else{
countdown_box.set_label(String("SHUTDOWN!"),SCREEN_COLOR_RED);
countdown_box.draw(screen);
}
}
}