-
Notifications
You must be signed in to change notification settings - Fork 25
/
davega_simple_screen.cpp
58 lines (51 loc) · 2.02 KB
/
davega_simple_screen.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
/*
Copyright 2019 Jan Pomikalek <[email protected]>
This file is part of the DAVEga firmware.
DAVEga firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAVEga firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DAVEga firmware. If not, see <https://www.gnu.org/licenses/>.
*/
#include "davega_simple_screen.h"
#include "davega_util.h"
#include <TFT_22_ILI9225.h>
uint16_t primary_item_color(t_screen_item screen_item, t_davega_data* data, t_davega_screen_config* config) {
uint16_t color = COLOR_WHITE;
if (screen_item == SCR_BATTERY_CURRENT || screen_item == SCR_MOTOR_CURRENT) {
float value = screen_item == SCR_BATTERY_CURRENT ? data->battery_amps : data->motor_amps;
if (value < 0)
color = COLOR_RED;
if (value >= 100)
color = COLOR_YELLOW;
if (value >= 200)
color = COLOR_BLUEVIOLET;
}
else {
// speed
if (data->speed_kph > SS_RED_SPEED_KPH)
color = COLOR_RED;
else if (data->speed_kph > SS_YELLOW_SPEED_KPH)
color = COLOR_YELLOW;
}
return color;
}
uint8_t primary_item_value(t_screen_item screen_item, t_davega_data* data, t_davega_screen_config* config) {
float value;
switch (screen_item) {
case SCR_BATTERY_CURRENT:
value = data->battery_amps;
break;
case SCR_MOTOR_CURRENT:
value = data->motor_amps;
break;
default:
value = convert_speed(data->speed_kph, config->imperial_units);
}
return abs(round(value)) % 100;
}