-
Notifications
You must be signed in to change notification settings - Fork 1
/
display.ino
110 lines (83 loc) · 2.56 KB
/
display.ino
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
void display_setup() {
// Initializes the SSD1306 display
display.init();
display.flipScreenVertically();
display.setFont(Roboto_48);
display.setTextAlignment(TEXT_ALIGN_CENTER);
}
void display_nothing(){
// Empty screen
display.clear();
display.display();
}
void display_weight() {
// Display weight in the middle of the screen
static float last_weight;
if(weight != last_weight){
last_weight = weight;
display.clear();
display.drawString(DISPLAY_WIDTH / 2, 0, get_weight_string());
display.display();
}
}
void display_uploading(){
// Display the uploading image
display.clear();
display.drawXbm(0,0, IMAGES_WIDTH, IMAGES_HEIGHT, uploading_image);
display.display();
}
void display_upload_success(){
// Alternate between the uploaded successfully image and the uploaded weight
const int blinking_delay = 500;
for(int i=0; i<10; i++){
display.clear();
display.drawXbm(0,0, IMAGES_WIDTH, IMAGES_HEIGHT, uploaded_image);
display.display();
delay(blinking_delay);
display.clear();
display.drawString(DISPLAY_WIDTH / 2, 0, get_weight_string());
display.display();
delay(blinking_delay);
}
}
void display_upload_fail(){
// Blink the upload failed image
const int blinking_delay = 500;
for(int i=0; i<10; i++){
display.clear();
display.drawXbm(0,0, IMAGES_WIDTH, IMAGES_HEIGHT, upload_fail);
display.display();
delay(blinking_delay);
display.clear();
display.display();
delay(blinking_delay);
}
}
void display_connecting(){
// Display the connecting animation
long now = millis();
static long last_change;
const long change_period = 200;
static int frame = 0;
if(now-last_change > change_period){
last_change = now;
frame++;
if(frame > 3){
frame = 0;
}
}
display.clear();
if(frame == 0) display.drawXbm(0,0, IMAGES_WIDTH, IMAGES_HEIGHT, connecting_bar_1_2_3_off);
else if(frame == 1) display.drawXbm(0,0, IMAGES_WIDTH, IMAGES_HEIGHT, connecting_bar_2_3_off);
else if(frame == 2) display.drawXbm(0,0, IMAGES_WIDTH, IMAGES_HEIGHT, connecting_bar_3_off);
else if(frame == 3) display.drawXbm(0,0, IMAGES_WIDTH, IMAGES_HEIGHT, connecting_full);
display.display();
}
void display_connected(){
// Display the connected image for 2 seconds and clear diplay
display.clear();
display.drawXbm(0,0, IMAGES_WIDTH, IMAGES_HEIGHT, wifi_ok);
display.display();
delay(2000);
display_nothing();
}