-
Notifications
You must be signed in to change notification settings - Fork 2
/
xbot_display_show.cpp
144 lines (134 loc) · 3.55 KB
/
xbot_display_show.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "xbot_display_show.h"
xbot_display_show::xbot_display_show()
{
}
xbot_display_show::~xbot_display_show()
{
}
void xbot_display_show::init()
{
actual_mode_ = 0;
modeCount_ = 3;
// (width, height, wire, resetPin)
disp = new Adafruit_SSD1306(128, 64, &Wire, -1);
disp->begin(SSD1306_SWITCHCAPVCC, 0x3C);
disp->clearDisplay();
disp->setCursor(30,30);
disp->setTextColor(WHITE);
disp->setTextSize(2);
disp->print("boot");
disp->display();
delay(250);
disp->print(".");
disp->display();
delay(250);
disp->print(".");
disp->display();
delay(250);
disp->print(".");
disp->display();
delay(250);
}
void xbot_display_show::update(xbot_display_data* data)
{
disp->clearDisplay();
switch(actual_mode_)
{
// Home
case 0:
disp->fillRect(0,0,128,16,WHITE);
disp->setTextColor(BLACK);
//label
disp->setCursor(53,2);
disp->setTextSize(1);
disp->print("Home");
//battery
disp->setTextSize(2);
disp->setCursor(80,1);
disp->print(data->battery_percent_);
disp->print("%");
//throttle
disp->setTextSize(1);
disp->setCursor(3,1);
disp->print("T: ");
disp->print(data->throttle_);
disp->print("%");
//break
disp->setTextSize(1);
disp->setCursor(3,9);
disp->print("B: ");
disp->print(data->break_);
disp->print("%");
disp->setTextColor(WHITE);
//light
if(!data->light_)
disp->drawCircle(122,20,4,WHITE);
if(data->light_)
disp->fillCircle(122,20,4,WHITE);
//eco
if(!data->eco_)
disp->drawCircle(4,20,4,WHITE);
if(data->eco_)
disp->fillCircle(4,20,4,WHITE);
//unlockedSpeed
if(!data->unlockedSpeed_)
disp->drawCircle(59,20,4,WHITE);
if(data->unlockedSpeed_)
disp->fillCircle(59,20,4,WHITE);
//speed
disp->setTextSize(5);
if(data->speed_ > 9.999)
{
disp->setCursor(5,25);
disp->print(data->speed_,1);
}
else if(data->speed_ > 99.999)
{
disp->setCursor(20,25);
disp->print(data->speed_,0);
}
else
{
disp->setCursor(20,25);
disp->print(data->speed_,1);
}
break;
// throttle break graph
case 1:
disp->fillRect(0,0,128,16,WHITE);
disp->setTextColor(BLACK);
//label
disp->setCursor(42,2);
disp->setTextSize(1);
disp->print("Throttle");
disp->setTextColor(WHITE);
disp->setCursor(10,20);
disp->print("Throttle");
disp->fillRect(10,30,data->throttle_,5,WHITE);
disp->setCursor(10,45);
disp->print("Break");
disp->fillRect(10,55,data->break_,5,WHITE);
break;
// off
case 2:
break;
default:
disp->setTextColor(WHITE);
disp->setTextSize(2);
disp->setCursor(10,20);
disp->print("Error!");
break;
}
disp->display();
}
void xbot_display_show::changeMode()
{
if(actual_mode_ + 1 >= modeCount_)
{
actual_mode_ = 0;
}
else
{
actual_mode_ = actual_mode_ + 1;
}
}