Format everything
The next commit will add this to a `.git-blame-ignore-revs` file which
you can use to ignore this commit when running git blame. Simply run
git blame --ignore-revs-file .git-blame-ignore-revs [...]
Or configure git to persistently ignore the commit:
git config blame.ignoreRevsFile .git-blame-ignore-revs
This commit is contained in:
@ -1,412 +1,441 @@
|
||||
#include "Arduino.h"
|
||||
#include "EDIPTFT.h"
|
||||
#include "FT_2018_STW_CAN.h"
|
||||
#include "FT18_STW_INIT.h"
|
||||
#include "FT18_STW_DISPLAY.h"
|
||||
|
||||
EDIPTFT tft(true,false);
|
||||
String bezeichnungen[]={"T_mot","T_oil","P_oil","% fa","U_batt","P_wat","T_air",
|
||||
"P_b_front","P_b_rear","Error Type","Speed_fl","Speed_fr","Speed"};
|
||||
//"Drehzahl","P_fuel","Index"
|
||||
int led_s[] = {led1,led2,led3,led4,led5,led6,led7,led8,led9,led10,led11,led12,led13,led14,led15,led16};
|
||||
|
||||
DataBox gear_box(121, 0, 199, 94, 160, 0, EA_SWISS30B, 4, 4, 'C');
|
||||
DataBox left_box(0, 0, 119, 94, 110, 12, EA_FONT7X12, 3, 8, 'R');
|
||||
DataBox right_box(201, 0, 320, 94, 310, 12, EA_FONT7X12, 3, 8, 'R');
|
||||
TireTempBox fl_box(80, 130, 156, 176, 118, 124, EA_FONT7X12, 3, 5, 'C');
|
||||
TireTempBox fr_box(164, 130, 240, 176, 202, 124, EA_FONT7X12, 3, 5, 'C');
|
||||
TireTempBox rl_box(80, 184, 156, 230, 118, 178, EA_FONT7X12, 3, 5, 'C');
|
||||
TireTempBox rr_box(164, 184, 240, 230, 202, 178, EA_FONT7X12, 3, 5, 'C');
|
||||
|
||||
void init_display() {
|
||||
pinMode(writeprotect, OUTPUT);
|
||||
digitalWrite(writeprotect, HIGH);
|
||||
pinMode(reset, OUTPUT);
|
||||
pinMode(disp_cs, OUTPUT);
|
||||
pinMode(MOSI, OUTPUT);
|
||||
pinMode(MISO, OUTPUT);
|
||||
digitalWrite(disp_cs, HIGH);
|
||||
digitalWrite(MOSI, HIGH);
|
||||
digitalWrite(MISO, HIGH);
|
||||
digitalWrite(reset, LOW);
|
||||
digitalWrite(reset,HIGH);
|
||||
tft.begin(115200); // start display communication
|
||||
tft.cursorOn(false);
|
||||
tft.terminalOn(false);
|
||||
tft.setDisplayColor(EA_WHITE,EA_BLACK);
|
||||
tft.setTextColor(EA_WHITE,EA_TRANSPARENT);
|
||||
tft.setTextSize(5,8);
|
||||
tft.clear();
|
||||
|
||||
gear_box.update_label(get_label(VAL_GEAR));
|
||||
left_box.update_label(get_label(VAL_FIRST_LEFT_BOX));
|
||||
right_box.update_label(get_label(VAL_RPM));
|
||||
}
|
||||
|
||||
String get_value(Value val) {
|
||||
switch (val) {
|
||||
case VAL_GEAR:
|
||||
if (Vehicle_data.gear == 0) {
|
||||
return "N";
|
||||
}
|
||||
return String(Vehicle_data.gear);
|
||||
case VAL_RPM:
|
||||
return String(Vehicle_data.revol);
|
||||
case VAL_TT_FL:
|
||||
return "00";
|
||||
case VAL_TT_FR:
|
||||
return "01";
|
||||
case VAL_TT_RL:
|
||||
return "10";
|
||||
case VAL_TT_RR:
|
||||
return "11";
|
||||
case VAL_LAPTIME:
|
||||
return "93.13";
|
||||
case VAL_UBATT:
|
||||
return String(0.0706949 * Vehicle_data.u_batt, 2);
|
||||
case VAL_TMOT:
|
||||
return String(Vehicle_data.t_mot - 40);
|
||||
case VAL_TAIR:
|
||||
return String(Vehicle_data.t_air - 40);
|
||||
case VAL_TOIL:
|
||||
return String(Vehicle_data.t_oil - 40);
|
||||
case VAL_ERR_TYPE:
|
||||
return String(Stw_data.error_type);
|
||||
case VAL_PWAT:
|
||||
return String(0.0514*Vehicle_data.p_wat, 2);
|
||||
case VAL_POIL:
|
||||
return String(0.0514*Vehicle_data.p_oil, 2);
|
||||
case VAL_PBF:
|
||||
return String(Vehicle_data.p_brake_front);
|
||||
case VAL_PBR:
|
||||
return String(Vehicle_data.p_brake_rear);
|
||||
case VAL_SPEED_FL:
|
||||
return String(Vehicle_data.speed_fl);
|
||||
case VAL_SPEED_FR:
|
||||
return String(Vehicle_data.speed_fr);
|
||||
case VAL_SPEED:
|
||||
return String(Vehicle_data.speed);
|
||||
default:
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
|
||||
String get_label(Value val) {
|
||||
switch (val) {
|
||||
case VAL_GEAR:
|
||||
return "GEAR";
|
||||
case VAL_RPM:
|
||||
return "RPM";
|
||||
case VAL_TT_FL:
|
||||
return "TEMP FL";
|
||||
case VAL_TT_FR:
|
||||
return "TEMP FR";
|
||||
case VAL_TT_RL:
|
||||
return "TEMP RL";
|
||||
case VAL_TT_RR:
|
||||
return "TEMP RR";
|
||||
case VAL_LAPTIME:
|
||||
return "LAPTIME";
|
||||
case VAL_UBATT:
|
||||
return "BATT VOLTAGE";
|
||||
case VAL_TMOT:
|
||||
return "TEMP ENG";
|
||||
case VAL_TAIR:
|
||||
return "TEMP AIR";
|
||||
case VAL_TOIL:
|
||||
return "TEMP OIL";
|
||||
case VAL_ERR_TYPE:
|
||||
return "ERROR TYPE";
|
||||
case VAL_PWAT:
|
||||
return "PRESS WAT";
|
||||
case VAL_POIL:
|
||||
return "PRESS OIL";
|
||||
case VAL_PBF:
|
||||
return "PRESS BRAKE F";
|
||||
case VAL_PBR:
|
||||
return "PRESS BRAKE R";
|
||||
case VAL_SPEED_FL:
|
||||
return "SPEED FL";
|
||||
case VAL_SPEED_FR:
|
||||
return "SPEED FR";
|
||||
case VAL_SPEED:
|
||||
return "SPEED";
|
||||
default:
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
|
||||
bool check_alarms() {
|
||||
static uint32_t poil_last_valid, tmot_last_valid, toil_last_valid;
|
||||
uint32_t now = millis();
|
||||
if (Vehicle_data.p_oil >= POIL_ALARM_THRESH || Vehicle_data.speed == 0) {
|
||||
poil_last_valid = now;
|
||||
}
|
||||
if (Vehicle_data.t_mot <= TMOT_ALARM_THRESH || Vehicle_data.t_mot == TMOT_SAFE_VALUE) {
|
||||
tmot_last_valid = now;
|
||||
}
|
||||
if (Vehicle_data.t_oil <= TOIL_ALARM_THRESH) {
|
||||
toil_last_valid = now;
|
||||
}
|
||||
bool poil_alarm = now - poil_last_valid >= POIL_ALARM_TIME;
|
||||
bool tmot_alarm = now - tmot_last_valid >= TMOT_ALARM_TIME;
|
||||
bool toil_alarm = now - toil_last_valid >= TOIL_ALARM_TIME;
|
||||
bool alarm_active = poil_alarm || tmot_alarm || toil_alarm;
|
||||
|
||||
if (alarm_active) {
|
||||
String alarm_text = "";
|
||||
if (poil_alarm) alarm_text += "PO";
|
||||
if (tmot_alarm) alarm_text += "TM";
|
||||
if (toil_alarm) alarm_text += "TO";
|
||||
alarm(alarm_text);
|
||||
}
|
||||
|
||||
return alarm_active;
|
||||
}
|
||||
|
||||
bool check_enc_displays() {
|
||||
static uint8_t trc_old, mode_old;
|
||||
static bool display_trc, display_mode;
|
||||
static uint32_t display_trc_begin, display_mode_begin;
|
||||
|
||||
return check_display(trc_old, Stw_data.trc, display_trc, display_trc_begin, "ARB") ||
|
||||
check_display(mode_old, Stw_data.mode, display_mode, display_mode_begin, "MODE");
|
||||
}
|
||||
|
||||
bool check_display(uint8_t& val_old, uint8_t val_new, bool& active, uint32_t& begin, const String& title) {
|
||||
if (val_old != val_new) {
|
||||
active = true;
|
||||
begin = millis();
|
||||
val_old = val_new;
|
||||
tft.clear();
|
||||
tft.fillDisplayColor(EA_RED);
|
||||
tft.setTextColor(EA_WHITE, EA_RED);
|
||||
tft.setTextSize(7,8);
|
||||
String text = title + ":" + val_new;
|
||||
char text_arr[16];
|
||||
text.toCharArray(text_arr, 16);
|
||||
tft.drawText(15, 68, 'C', text_arr);
|
||||
} else if (active && millis() - begin > ENC_DISPLAY_TIME) {
|
||||
tft.setTextColor(EA_WHITE, EA_TRANSPARENT);
|
||||
tft.clear();
|
||||
active = false;
|
||||
}
|
||||
|
||||
return active;
|
||||
}
|
||||
|
||||
void update_display(){
|
||||
static DisplayPage page = PAGE_DRIVER;
|
||||
static uint32_t last_cleared;
|
||||
static bool cleared = true;
|
||||
|
||||
if (check_alarms()) {
|
||||
cleared = true;
|
||||
return;
|
||||
}
|
||||
if (tft.disconnected) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (check_enc_displays()) {
|
||||
cleared = true;
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t now = millis();
|
||||
// Both buttons have to be pressed at the same time, but we also use the
|
||||
// debounced rises to ensure we don't keep toggling between the pages
|
||||
if (Stw_data.buttonState1 && Stw_data.buttonState4 &&
|
||||
(Stw_data.button1_rises > 0|| Stw_data.button4_rises > 0)){
|
||||
Stw_data.button1_rises = 0;
|
||||
Stw_data.button4_rises = 0;
|
||||
page = (DisplayPage) ((page + 1) % DISPLAY_PAGES);
|
||||
tft.clear();
|
||||
last_cleared = now;
|
||||
cleared = true;
|
||||
}
|
||||
|
||||
if (now - last_cleared >= DISP_CLEAR_INTERVAL) {
|
||||
tft.clear();
|
||||
last_cleared = now;
|
||||
cleared = true;
|
||||
}
|
||||
|
||||
if (page == PAGE_DRIVER) {
|
||||
if (cleared) {
|
||||
redraw_page_driver();
|
||||
cleared = false;
|
||||
} else {
|
||||
update_page_driver();
|
||||
}
|
||||
} else {
|
||||
if (cleared) {
|
||||
redraw_page_testing();
|
||||
cleared = false;
|
||||
} else {
|
||||
update_page_testing();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void alarm(String textstr){
|
||||
uint8_t x = 1;;
|
||||
char text[7];
|
||||
textstr.toCharArray(text,7);
|
||||
tft.setTextSize(8,8);
|
||||
while(x==1){
|
||||
if(!tft.disconnected){
|
||||
tft.setTextColor(EA_BLACK,EA_RED);
|
||||
tft.fillDisplayColor(EA_RED);
|
||||
tft.drawText(5,68,'L',text);
|
||||
}
|
||||
for (int j = 0; j < 16; j++){
|
||||
digitalWrite(led_s[j], HIGH);
|
||||
}
|
||||
delay(100);
|
||||
if(!tft.disconnected){
|
||||
tft.setTextColor(EA_BLACK,EA_WHITE);
|
||||
tft.fillDisplayColor(EA_WHITE);
|
||||
tft.drawText(5,68,'L',text);
|
||||
}
|
||||
for (int j = 0; j < 16; j++){
|
||||
digitalWrite(led_s[j], LOW);
|
||||
}
|
||||
delay(100);
|
||||
if(Stw_data.buttonState1 & Stw_data.buttonState4){
|
||||
x=0;
|
||||
tft.setTextColor(EA_WHITE,EA_TRANSPARENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void redraw_page_driver() {
|
||||
// Boxes
|
||||
tft.drawLine(0, 110, 320, 110);
|
||||
tft.drawLine(120, 0, 120, 110);
|
||||
tft.drawLine(200, 0, 200, 110);
|
||||
|
||||
// Tire temperature cross
|
||||
tft.drawLine(80, 180, 240, 180);
|
||||
tft.drawLine(160, 130, 160, 230);
|
||||
|
||||
// Boxes
|
||||
gear_box.redraw();
|
||||
left_box.redraw();
|
||||
right_box.redraw();
|
||||
fl_box.redraw();
|
||||
fr_box.redraw();
|
||||
rl_box.redraw();
|
||||
rr_box.redraw();
|
||||
}
|
||||
|
||||
void update_page_driver() {
|
||||
static Value left_box_value = VAL_FIRST_LEFT_BOX;
|
||||
if (Stw_data.button4_rises > 0) {
|
||||
Stw_data.button4_rises--;
|
||||
if (left_box_value == VAL_LAST) {
|
||||
left_box_value = VAL_FIRST_LEFT_BOX;
|
||||
} else {
|
||||
left_box_value = (Value) (left_box_value + 1);
|
||||
}
|
||||
left_box.update_label(get_label(left_box_value));
|
||||
if (Stw_data.button1_rises > 0) {
|
||||
Stw_data.button1_rises--;
|
||||
if (left_box_value == VAL_FIRST_LEFT_BOX) {
|
||||
left_box_value = VAL_LAST;
|
||||
} else {
|
||||
left_box_value = (Value) (left_box_value - 1);
|
||||
}
|
||||
left_box.update_label(get_label(left_box_value));
|
||||
}
|
||||
|
||||
gear_box.update_value(get_value(VAL_GEAR));
|
||||
left_box.update_value(get_value(left_box_value));
|
||||
right_box.update_value(get_value(VAL_RPM));
|
||||
fl_box.update_value(2);
|
||||
fr_box.update_value(55);
|
||||
rl_box.update_value(65);
|
||||
rr_box.update_value(90);
|
||||
}
|
||||
|
||||
void redraw_page_testing() {
|
||||
#include "FT18_STW_DISPLAY.h"
|
||||
#include "Arduino.h"
|
||||
#include "EDIPTFT.h"
|
||||
#include "FT18_STW_INIT.h"
|
||||
#include "FT_2018_STW_CAN.h"
|
||||
|
||||
EDIPTFT tft(true, false);
|
||||
String bezeichnungen[] = {"T_mot", "T_oil", "P_oil", "% fa",
|
||||
"U_batt", "P_wat", "T_air", "P_b_front",
|
||||
"P_b_rear", "Error Type", "Speed_fl", "Speed_fr",
|
||||
"Speed"};
|
||||
//"Drehzahl","P_fuel","Index"
|
||||
int led_s[] = {led1, led2, led3, led4, led5, led6, led7, led8,
|
||||
led9, led10, led11, led12, led13, led14, led15, led16};
|
||||
|
||||
DataBox gear_box(121, 0, 199, 94, 160, 0, EA_SWISS30B, 4, 4, 'C');
|
||||
DataBox left_box(0, 0, 119, 94, 110, 12, EA_FONT7X12, 3, 8, 'R');
|
||||
DataBox right_box(201, 0, 320, 94, 310, 12, EA_FONT7X12, 3, 8, 'R');
|
||||
TireTempBox fl_box(80, 130, 156, 176, 118, 124, EA_FONT7X12, 3, 5, 'C');
|
||||
TireTempBox fr_box(164, 130, 240, 176, 202, 124, EA_FONT7X12, 3, 5, 'C');
|
||||
TireTempBox rl_box(80, 184, 156, 230, 118, 178, EA_FONT7X12, 3, 5, 'C');
|
||||
TireTempBox rr_box(164, 184, 240, 230, 202, 178, EA_FONT7X12, 3, 5, 'C');
|
||||
|
||||
void init_display() {
|
||||
pinMode(writeprotect, OUTPUT);
|
||||
digitalWrite(writeprotect, HIGH);
|
||||
pinMode(reset, OUTPUT);
|
||||
pinMode(disp_cs, OUTPUT);
|
||||
pinMode(MOSI, OUTPUT);
|
||||
pinMode(MISO, OUTPUT);
|
||||
digitalWrite(disp_cs, HIGH);
|
||||
digitalWrite(MOSI, HIGH);
|
||||
digitalWrite(MISO, HIGH);
|
||||
digitalWrite(reset, LOW);
|
||||
digitalWrite(reset, HIGH);
|
||||
tft.begin(115200); // start display communication
|
||||
tft.cursorOn(false);
|
||||
tft.terminalOn(false);
|
||||
tft.setDisplayColor(EA_WHITE, EA_BLACK);
|
||||
tft.setTextColor(EA_WHITE, EA_TRANSPARENT);
|
||||
tft.setTextSize(5, 8);
|
||||
tft.clear();
|
||||
|
||||
gear_box.update_label(get_label(VAL_GEAR));
|
||||
left_box.update_label(get_label(VAL_FIRST_LEFT_BOX));
|
||||
right_box.update_label(get_label(VAL_RPM));
|
||||
}
|
||||
|
||||
String get_value(Value val) {
|
||||
switch (val) {
|
||||
case VAL_GEAR:
|
||||
if (Vehicle_data.gear == 0) {
|
||||
return "N";
|
||||
}
|
||||
return String(Vehicle_data.gear);
|
||||
case VAL_RPM:
|
||||
return String(Vehicle_data.revol);
|
||||
case VAL_TT_FL:
|
||||
return "00";
|
||||
case VAL_TT_FR:
|
||||
return "01";
|
||||
case VAL_TT_RL:
|
||||
return "10";
|
||||
case VAL_TT_RR:
|
||||
return "11";
|
||||
case VAL_LAPTIME:
|
||||
return "93.13";
|
||||
case VAL_UBATT:
|
||||
return String(0.0706949 * Vehicle_data.u_batt, 2);
|
||||
case VAL_TMOT:
|
||||
return String(Vehicle_data.t_mot - 40);
|
||||
case VAL_TAIR:
|
||||
return String(Vehicle_data.t_air - 40);
|
||||
case VAL_TOIL:
|
||||
return String(Vehicle_data.t_oil - 40);
|
||||
case VAL_ERR_TYPE:
|
||||
return String(Stw_data.error_type);
|
||||
case VAL_PWAT:
|
||||
return String(0.0514 * Vehicle_data.p_wat, 2);
|
||||
case VAL_POIL:
|
||||
return String(0.0514 * Vehicle_data.p_oil, 2);
|
||||
case VAL_PBF:
|
||||
return String(Vehicle_data.p_brake_front);
|
||||
case VAL_PBR:
|
||||
return String(Vehicle_data.p_brake_rear);
|
||||
case VAL_SPEED_FL:
|
||||
return String(Vehicle_data.speed_fl);
|
||||
case VAL_SPEED_FR:
|
||||
return String(Vehicle_data.speed_fr);
|
||||
case VAL_SPEED:
|
||||
return String(Vehicle_data.speed);
|
||||
default:
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
|
||||
String get_label(Value val) {
|
||||
switch (val) {
|
||||
case VAL_GEAR:
|
||||
return "GEAR";
|
||||
case VAL_RPM:
|
||||
return "RPM";
|
||||
case VAL_TT_FL:
|
||||
return "TEMP FL";
|
||||
case VAL_TT_FR:
|
||||
return "TEMP FR";
|
||||
case VAL_TT_RL:
|
||||
return "TEMP RL";
|
||||
case VAL_TT_RR:
|
||||
return "TEMP RR";
|
||||
case VAL_LAPTIME:
|
||||
return "LAPTIME";
|
||||
case VAL_UBATT:
|
||||
return "BATT VOLTAGE";
|
||||
case VAL_TMOT:
|
||||
return "TEMP ENG";
|
||||
case VAL_TAIR:
|
||||
return "TEMP AIR";
|
||||
case VAL_TOIL:
|
||||
return "TEMP OIL";
|
||||
case VAL_ERR_TYPE:
|
||||
return "ERROR TYPE";
|
||||
case VAL_PWAT:
|
||||
return "PRESS WAT";
|
||||
case VAL_POIL:
|
||||
return "PRESS OIL";
|
||||
case VAL_PBF:
|
||||
return "PRESS BRAKE F";
|
||||
case VAL_PBR:
|
||||
return "PRESS BRAKE R";
|
||||
case VAL_SPEED_FL:
|
||||
return "SPEED FL";
|
||||
case VAL_SPEED_FR:
|
||||
return "SPEED FR";
|
||||
case VAL_SPEED:
|
||||
return "SPEED";
|
||||
default:
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
|
||||
bool check_alarms() {
|
||||
static uint32_t poil_last_valid, tmot_last_valid, toil_last_valid;
|
||||
uint32_t now = millis();
|
||||
if (Vehicle_data.p_oil >= POIL_ALARM_THRESH || Vehicle_data.speed == 0) {
|
||||
poil_last_valid = now;
|
||||
}
|
||||
if (Vehicle_data.t_mot <= TMOT_ALARM_THRESH ||
|
||||
Vehicle_data.t_mot == TMOT_SAFE_VALUE) {
|
||||
tmot_last_valid = now;
|
||||
}
|
||||
if (Vehicle_data.t_oil <= TOIL_ALARM_THRESH) {
|
||||
toil_last_valid = now;
|
||||
}
|
||||
bool poil_alarm = now - poil_last_valid >= POIL_ALARM_TIME;
|
||||
bool tmot_alarm = now - tmot_last_valid >= TMOT_ALARM_TIME;
|
||||
bool toil_alarm = now - toil_last_valid >= TOIL_ALARM_TIME;
|
||||
bool alarm_active = poil_alarm || tmot_alarm || toil_alarm;
|
||||
|
||||
if (alarm_active) {
|
||||
String alarm_text = "";
|
||||
if (poil_alarm)
|
||||
alarm_text += "PO";
|
||||
if (tmot_alarm)
|
||||
alarm_text += "TM";
|
||||
if (toil_alarm)
|
||||
alarm_text += "TO";
|
||||
alarm(alarm_text);
|
||||
}
|
||||
|
||||
return alarm_active;
|
||||
}
|
||||
|
||||
bool check_enc_displays() {
|
||||
static uint8_t trc_old, mode_old;
|
||||
static bool display_trc, display_mode;
|
||||
static uint32_t display_trc_begin, display_mode_begin;
|
||||
|
||||
return check_display(trc_old, Stw_data.trc, display_trc, display_trc_begin,
|
||||
"ARB") ||
|
||||
check_display(mode_old, Stw_data.mode, display_mode,
|
||||
display_mode_begin, "MODE");
|
||||
}
|
||||
|
||||
bool check_display(uint8_t& val_old, uint8_t val_new, bool& active,
|
||||
uint32_t& begin, const String& title) {
|
||||
if (val_old != val_new) {
|
||||
active = true;
|
||||
begin = millis();
|
||||
val_old = val_new;
|
||||
tft.clear();
|
||||
tft.fillDisplayColor(EA_RED);
|
||||
tft.setTextColor(EA_WHITE, EA_RED);
|
||||
tft.setTextSize(7, 8);
|
||||
String text = title + ":" + val_new;
|
||||
char text_arr[16];
|
||||
text.toCharArray(text_arr, 16);
|
||||
tft.drawText(15, 68, 'C', text_arr);
|
||||
} else if (active && millis() - begin > ENC_DISPLAY_TIME) {
|
||||
tft.setTextColor(EA_WHITE, EA_TRANSPARENT);
|
||||
tft.clear();
|
||||
active = false;
|
||||
}
|
||||
|
||||
return active;
|
||||
}
|
||||
|
||||
void update_display() {
|
||||
static DisplayPage page = PAGE_DRIVER;
|
||||
static uint32_t last_cleared;
|
||||
static bool cleared = true;
|
||||
|
||||
if (check_alarms()) {
|
||||
cleared = true;
|
||||
return;
|
||||
}
|
||||
if (tft.disconnected) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (check_enc_displays()) {
|
||||
cleared = true;
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t now = millis();
|
||||
// Both buttons have to be pressed at the same time, but we also use the
|
||||
// debounced rises to ensure we don't keep toggling between the pages
|
||||
if (Stw_data.buttonState1 && Stw_data.buttonState4 &&
|
||||
(Stw_data.button1_rises > 0 || Stw_data.button4_rises > 0)) {
|
||||
Stw_data.button1_rises = 0;
|
||||
Stw_data.button4_rises = 0;
|
||||
page = (DisplayPage)((page + 1) % DISPLAY_PAGES);
|
||||
tft.clear();
|
||||
last_cleared = now;
|
||||
cleared = true;
|
||||
}
|
||||
|
||||
if (now - last_cleared >= DISP_CLEAR_INTERVAL) {
|
||||
tft.clear();
|
||||
last_cleared = now;
|
||||
cleared = true;
|
||||
}
|
||||
|
||||
if (page == PAGE_DRIVER) {
|
||||
if (cleared) {
|
||||
redraw_page_driver();
|
||||
cleared = false;
|
||||
} else {
|
||||
update_page_driver();
|
||||
}
|
||||
} else {
|
||||
if (cleared) {
|
||||
redraw_page_testing();
|
||||
cleared = false;
|
||||
} else {
|
||||
update_page_testing();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void alarm(String textstr) {
|
||||
uint8_t x = 1;
|
||||
;
|
||||
char text[7];
|
||||
textstr.toCharArray(text, 7);
|
||||
tft.setTextSize(8, 8);
|
||||
while (x == 1) {
|
||||
if (!tft.disconnected) {
|
||||
tft.setTextColor(EA_BLACK, EA_RED);
|
||||
tft.fillDisplayColor(EA_RED);
|
||||
tft.drawText(5, 68, 'L', text);
|
||||
}
|
||||
for (int j = 0; j < 16; j++) {
|
||||
digitalWrite(led_s[j], HIGH);
|
||||
}
|
||||
delay(100);
|
||||
if (!tft.disconnected) {
|
||||
tft.setTextColor(EA_BLACK, EA_WHITE);
|
||||
tft.fillDisplayColor(EA_WHITE);
|
||||
tft.drawText(5, 68, 'L', text);
|
||||
}
|
||||
for (int j = 0; j < 16; j++) {
|
||||
digitalWrite(led_s[j], LOW);
|
||||
}
|
||||
delay(100);
|
||||
if (Stw_data.buttonState1 & Stw_data.buttonState4) {
|
||||
x = 0;
|
||||
tft.setTextColor(EA_WHITE, EA_TRANSPARENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void redraw_page_driver() {
|
||||
// Boxes
|
||||
tft.drawLine(0, 110, 320, 110);
|
||||
tft.drawLine(120, 0, 120, 110);
|
||||
tft.drawLine(200, 0, 200, 110);
|
||||
|
||||
// Tire temperature cross
|
||||
tft.drawLine(80, 180, 240, 180);
|
||||
tft.drawLine(160, 130, 160, 230);
|
||||
|
||||
// Boxes
|
||||
gear_box.redraw();
|
||||
left_box.redraw();
|
||||
right_box.redraw();
|
||||
fl_box.redraw();
|
||||
fr_box.redraw();
|
||||
rl_box.redraw();
|
||||
rr_box.redraw();
|
||||
}
|
||||
|
||||
void update_page_driver() {
|
||||
static Value left_box_value = VAL_FIRST_LEFT_BOX;
|
||||
if (Stw_data.button4_rises > 0) {
|
||||
Stw_data.button4_rises--;
|
||||
if (left_box_value == VAL_LAST) {
|
||||
left_box_value = VAL_FIRST_LEFT_BOX;
|
||||
} else {
|
||||
left_box_value = (Value)(left_box_value + 1);
|
||||
}
|
||||
left_box.update_label(get_label(left_box_value));
|
||||
}
|
||||
if (Stw_data.button1_rises > 0) {
|
||||
Stw_data.button1_rises--;
|
||||
if (left_box_value == VAL_FIRST_LEFT_BOX) {
|
||||
left_box_value = VAL_LAST;
|
||||
} else {
|
||||
left_box_value = (Value)(left_box_value - 1);
|
||||
}
|
||||
left_box.update_label(get_label(left_box_value));
|
||||
}
|
||||
|
||||
gear_box.update_value(get_value(VAL_GEAR));
|
||||
left_box.update_value(get_value(left_box_value));
|
||||
right_box.update_value(get_value(VAL_RPM));
|
||||
fl_box.update_value(2);
|
||||
fr_box.update_value(55);
|
||||
rl_box.update_value(65);
|
||||
rr_box.update_value(90);
|
||||
}
|
||||
|
||||
void redraw_page_testing() {
|
||||
tft.setTextFont(EA_FONT7X12);
|
||||
tft.setTextSize(2, 2);
|
||||
for (int i = 0; i <= min(VAL_LAST, 9); i++) {
|
||||
String text = get_label((Value)i) + ":";
|
||||
int x = (i < 10) ? 10 : 170;
|
||||
tft.drawText(x, (i % 10) * 24, 'L', text.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void update_page_testing() {
|
||||
// tft.setTextFont(EA_FONT7X12);
|
||||
// tft.setTextSize(2, 2);
|
||||
// for (int i = 0; i < min(VALUES, 20); i++) {
|
||||
// String text = get_value((Value) i);
|
||||
// int x = (i < 10) ? 10 : 170;
|
||||
// tft.drawText(10, (i % 10) * 24, 'L', text.c_str());
|
||||
// }
|
||||
}
|
||||
|
||||
DataBox::DataBox(int x1, int y1, int x2, int y2, int text_x, int text_y,
|
||||
int font, int size_x, int size_y, uint8_t justification)
|
||||
: x1{x1}, y1{y1}, x2{x2}, y2{y2}, text_x{text_x}, text_y{text_y},
|
||||
font{font}, size_x{size_x}, size_y{size_y},
|
||||
justification{justification}, value{""}, label{""} {}
|
||||
|
||||
void DataBox::update_value(String val_new) {
|
||||
if (!val_new.equals(value)) {
|
||||
value = val_new;
|
||||
redraw_value();
|
||||
}
|
||||
}
|
||||
|
||||
void DataBox::update_label(String label_new) {
|
||||
if (!label_new.equals(label)) {
|
||||
label = label_new;
|
||||
redraw_label();
|
||||
}
|
||||
}
|
||||
|
||||
void DataBox::redraw() {
|
||||
redraw_value();
|
||||
redraw_label();
|
||||
}
|
||||
|
||||
void DataBox::redraw_value() {
|
||||
tft.setTextFont(font);
|
||||
tft.setTextSize(size_x, size_y);
|
||||
Serial.println("Redrawing value:");
|
||||
tft.clearRect(x1, y1, x2, y2);
|
||||
tft.drawText(text_x, text_y, justification, value.c_str());
|
||||
}
|
||||
|
||||
void DataBox::redraw_label() {
|
||||
tft.setTextFont(EA_FONT7X12);
|
||||
tft.setTextSize(1, 1);
|
||||
Serial.println("Redrawing label:");
|
||||
tft.clearRect(x1, y2 + 1, x2, y2 + 13);
|
||||
tft.drawText((x1 + x2) / 2, y2 + 1, 'C', label.c_str());
|
||||
}
|
||||
|
||||
TireTempBox::TireTempBox(int x1, int y1, int x2, int y2, int text_x, int text_y,
|
||||
int font, int size_x, int size_y,
|
||||
uint8_t justification)
|
||||
: DataBox{x1, y1, x2, y2, text_x,
|
||||
text_y, font, size_x, size_y, justification},
|
||||
num_value{-1} {}
|
||||
|
||||
void TireTempBox::update_value(int val_new) {
|
||||
if (val_new != num_value) {
|
||||
num_value = val_new;
|
||||
if (val_new < TT_THRESH1) {
|
||||
color = TT_COL0;
|
||||
} else if (val_new < TT_THRESH2) {
|
||||
color = TT_COL1;
|
||||
} else if (val_new < TT_THRESH3) {
|
||||
color = TT_COL2;
|
||||
} else {
|
||||
color = TT_COL3;
|
||||
}
|
||||
String val_str = String(val_new);
|
||||
if (val_str.length() == 1) {
|
||||
val_str = " " + val_str;
|
||||
} else if (val_str.length() == 2) {
|
||||
val_str = " " + val_str;
|
||||
}
|
||||
DataBox::update_value(val_str);
|
||||
}
|
||||
}
|
||||
|
||||
void TireTempBox::redraw_value() {
|
||||
tft.setTextFont(font);
|
||||
tft.setTextSize(size_x, size_y);
|
||||
tft.drawRectf(x1, y1, x2, y2, color);
|
||||
tft.drawText(text_x, text_y, justification, value.c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void update_page_testing() {}
|
||||
|
||||
DataBox::DataBox(int x1, int y1, int x2, int y2, int text_x, int text_y, int font,
|
||||
int size_x, int size_y, uint8_t justification)
|
||||
: x1{x1}, y1{y1}, x2{x2}, y2{y2}, text_x{text_x}, text_y{text_y},
|
||||
font{font}, size_x{size_x}, size_y{size_y},
|
||||
justification{justification}, value{""}, label{""} {}
|
||||
|
||||
void DataBox::update_value(String val_new) {
|
||||
if (!val_new.equals(value)) {
|
||||
value = val_new;
|
||||
redraw_value();
|
||||
}
|
||||
}
|
||||
|
||||
void DataBox::update_label(String label_new) {
|
||||
if (!label_new.equals(label)) {
|
||||
label = label_new;
|
||||
redraw_label();
|
||||
}
|
||||
}
|
||||
|
||||
void DataBox::redraw() {
|
||||
redraw_value();
|
||||
redraw_label();
|
||||
}
|
||||
|
||||
void DataBox::redraw_value() {
|
||||
tft.setTextFont(font);
|
||||
tft.setTextSize(size_x, size_y);
|
||||
Serial.println("Redrawing value:");
|
||||
tft.clearRect(x1, y1, x2, y2);
|
||||
tft.drawText(text_x, text_y, justification, value.c_str());
|
||||
}
|
||||
|
||||
void DataBox::redraw_label() {
|
||||
tft.setTextFont(EA_FONT7X12);
|
||||
tft.setTextSize(1, 1);
|
||||
Serial.println("Redrawing label:");
|
||||
tft.clearRect(x1, y2 + 1, x2, y2 + 13);
|
||||
tft.drawText((x1 + x2) / 2, y2 + 1, 'C', label.c_str());
|
||||
}
|
||||
|
||||
TireTempBox::TireTempBox(int x1, int y1, int x2, int y2, int text_x, int text_y,
|
||||
int font, int size_x, int size_y, uint8_t justification)
|
||||
: DataBox{x1, y1, x2, y2, text_x, text_y, font, size_x, size_y, justification}, num_value{-1} {}
|
||||
|
||||
void TireTempBox::update_value(int val_new) {
|
||||
if (val_new != num_value) {
|
||||
num_value = val_new;
|
||||
if (val_new < TT_THRESH1) {
|
||||
color = TT_COL0;
|
||||
} else if (val_new < TT_THRESH2) {
|
||||
color = TT_COL1;
|
||||
} else if (val_new < TT_THRESH3) {
|
||||
color = TT_COL2;
|
||||
} else {
|
||||
color = TT_COL3;
|
||||
}
|
||||
String val_str = String(val_new);
|
||||
if (val_str.length() == 1) {
|
||||
val_str = " " + val_str;
|
||||
} else if (val_str.length() == 2) {
|
||||
val_str = " " + val_str;
|
||||
}
|
||||
DataBox::update_value(val_str);
|
||||
}
|
||||
}
|
||||
|
||||
void TireTempBox::redraw_value() {
|
||||
tft.setTextFont(font);
|
||||
tft.setTextSize(size_x, size_y);
|
||||
tft.drawRectf(x1, y1, x2, y2, color);
|
||||
tft.drawText(text_x, text_y, justification, value.c_str());
|
||||
}
|
||||
|
||||
void TireTempBox::redraw_label() {}
|
||||
@ -1,96 +1,113 @@
|
||||
#include "Arduino.h"
|
||||
#include "EDIPTFT.h"
|
||||
#include "FT_2018_STW_CAN.h"
|
||||
#include "FT18_STW_INIT.h"
|
||||
#ifndef FT18_STW_DISPLAY_h
|
||||
#define FT18_STW_DISPLAY_h
|
||||
|
||||
#define MOSI 75
|
||||
#define MISO 74
|
||||
#define CLK 76
|
||||
#define disp_cs 42
|
||||
#define reset 43
|
||||
#define writeprotect 52
|
||||
|
||||
|
||||
#define POIL_ALARM_THRESH ((uint32_t) (0.1 / 0.0514))
|
||||
#define POIL_ALARM_TIME 20000 // ms
|
||||
#define TMOT_ALARM_THRESH (40 + 105)
|
||||
#define TMOT_SAFE_VALUE (40 + 200)
|
||||
#define TMOT_ALARM_TIME 20000 // ms
|
||||
#define TOIL_ALARM_THRESH (40 + 150)
|
||||
#define TOIL_ALARM_TIME 10000 // ms
|
||||
#define ENC_DISPLAY_TIME 1000 // ms
|
||||
|
||||
enum DisplayPage {PAGE_DRIVER, PAGE_TESTING};
|
||||
#define DISPLAY_PAGES 2
|
||||
|
||||
enum Value {
|
||||
VAL_GEAR, VAL_RPM, VAL_TT_FL, VAL_TT_FR, VAL_TT_RL, VAL_TT_RR, VAL_LAPTIME,
|
||||
VAL_UBATT, VAL_TMOT, VAL_TAIR, VAL_TOIL, VAL_ERR_TYPE, VAL_PWAT, VAL_POIL,
|
||||
VAL_PBF, VAL_PBR, VAL_SPEED_FL, VAL_SPEED_FR, VAL_SPEED,
|
||||
VAL_FIRST_LEFT_BOX = VAL_LAPTIME, VAL_LAST = VAL_SPEED
|
||||
};
|
||||
String get_value(Value val);
|
||||
String get_label(Value val);
|
||||
|
||||
#define DISP_CLEAR_INTERVAL 5000 // ms
|
||||
|
||||
void init_display(void);
|
||||
void update_display(void);
|
||||
void display_trc(void);
|
||||
void display_mode(void);
|
||||
void alarm(String text);
|
||||
|
||||
bool check_alarms();
|
||||
bool check_enc_displays();
|
||||
bool check_display(uint8_t& val_old, uint8_t val_new, bool& active, uint32_t& begin, const String& title);
|
||||
|
||||
void redraw_page_driver();
|
||||
void update_page_driver();
|
||||
void redraw_page_testing();
|
||||
void update_page_testing();
|
||||
|
||||
class DataBox {
|
||||
public:
|
||||
DataBox(int x1, int y1, int x2, int y2, int text_x, int text_y, int font,
|
||||
int size_x, int size_y, uint8_t justification);
|
||||
|
||||
void update_value(String val_new);
|
||||
void update_label(String label_new);
|
||||
|
||||
void redraw();
|
||||
virtual void redraw_value();
|
||||
virtual void redraw_label();
|
||||
|
||||
protected:
|
||||
int x1, y1, x2, y2, text_x, text_y, font, size_x, size_y;
|
||||
uint8_t justification;
|
||||
String value;
|
||||
String label;
|
||||
};
|
||||
|
||||
#define TT_COL0 EA_LIGHTBLUE
|
||||
#define TT_COL1 EA_GREEN
|
||||
#define TT_COL2 EA_ORANGE
|
||||
#define TT_COL3 EA_RED
|
||||
#define TT_THRESH1 50
|
||||
#define TT_THRESH2 60
|
||||
#define TT_THRESH3 70
|
||||
|
||||
class TireTempBox : public DataBox {
|
||||
public:
|
||||
TireTempBox(int x1, int y1, int x2, int y2, int text_x, int text_y,
|
||||
int font, int size_x, int size_y, uint8_t justification);
|
||||
|
||||
void update_value(int val_new);
|
||||
|
||||
void redraw_value() override;
|
||||
void redraw_label() override;
|
||||
|
||||
private:
|
||||
int color;
|
||||
int num_value;
|
||||
};
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "EDIPTFT.h"
|
||||
#include "FT18_STW_INIT.h"
|
||||
#include "FT_2018_STW_CAN.h"
|
||||
#ifndef FT18_STW_DISPLAY_h
|
||||
#define FT18_STW_DISPLAY_h
|
||||
|
||||
#define MOSI 75
|
||||
#define MISO 74
|
||||
#define CLK 76
|
||||
#define disp_cs 42
|
||||
#define reset 43
|
||||
#define writeprotect 52
|
||||
|
||||
#define POIL_ALARM_THRESH ((uint32_t)(0.1 / 0.0514))
|
||||
#define POIL_ALARM_TIME 20000 // ms
|
||||
#define TMOT_ALARM_THRESH (40 + 105)
|
||||
#define TMOT_SAFE_VALUE (40 + 200)
|
||||
#define TMOT_ALARM_TIME 20000 // ms
|
||||
#define TOIL_ALARM_THRESH (40 + 150)
|
||||
#define TOIL_ALARM_TIME 10000 // ms
|
||||
#define ENC_DISPLAY_TIME 1000 // ms
|
||||
|
||||
enum DisplayPage { PAGE_DRIVER, PAGE_TESTING };
|
||||
#define DISPLAY_PAGES 2
|
||||
|
||||
enum Value {
|
||||
VAL_GEAR,
|
||||
VAL_RPM,
|
||||
VAL_TT_FL,
|
||||
VAL_TT_FR,
|
||||
VAL_TT_RL,
|
||||
VAL_TT_RR,
|
||||
VAL_LAPTIME,
|
||||
VAL_UBATT,
|
||||
VAL_TMOT,
|
||||
VAL_TAIR,
|
||||
VAL_TOIL,
|
||||
VAL_ERR_TYPE,
|
||||
VAL_PWAT,
|
||||
VAL_POIL,
|
||||
VAL_PBF,
|
||||
VAL_PBR,
|
||||
VAL_SPEED_FL,
|
||||
VAL_SPEED_FR,
|
||||
VAL_SPEED,
|
||||
VAL_FIRST_LEFT_BOX = VAL_LAPTIME,
|
||||
VAL_LAST = VAL_SPEED
|
||||
};
|
||||
String get_value(Value val);
|
||||
String get_label(Value val);
|
||||
|
||||
#define DISP_CLEAR_INTERVAL 5000 // ms
|
||||
|
||||
void init_display(void);
|
||||
void update_display(void);
|
||||
void display_trc(void);
|
||||
void display_mode(void);
|
||||
void alarm(String text);
|
||||
|
||||
bool check_alarms();
|
||||
bool check_enc_displays();
|
||||
bool check_display(uint8_t& val_old, uint8_t val_new, bool& active,
|
||||
uint32_t& begin, const String& title);
|
||||
|
||||
void redraw_page_driver();
|
||||
void update_page_driver();
|
||||
void redraw_page_testing();
|
||||
void update_page_testing();
|
||||
|
||||
class DataBox {
|
||||
public:
|
||||
DataBox(int x1, int y1, int x2, int y2, int text_x, int text_y, int font,
|
||||
int size_x, int size_y, uint8_t justification);
|
||||
|
||||
void update_value(String val_new);
|
||||
void update_label(String label_new);
|
||||
|
||||
void redraw();
|
||||
virtual void redraw_value();
|
||||
virtual void redraw_label();
|
||||
|
||||
protected:
|
||||
int x1, y1, x2, y2, text_x, text_y, font, size_x, size_y;
|
||||
uint8_t justification;
|
||||
String value;
|
||||
String label;
|
||||
};
|
||||
|
||||
#define TT_COL0 EA_LIGHTBLUE
|
||||
#define TT_COL1 EA_GREEN
|
||||
#define TT_COL2 EA_ORANGE
|
||||
#define TT_COL3 EA_RED
|
||||
#define TT_THRESH1 50
|
||||
#define TT_THRESH2 60
|
||||
#define TT_THRESH3 70
|
||||
|
||||
class TireTempBox : public DataBox {
|
||||
public:
|
||||
TireTempBox(int x1, int y1, int x2, int y2, int text_x, int text_y, int font,
|
||||
int size_x, int size_y, uint8_t justification);
|
||||
|
||||
void update_value(int val_new);
|
||||
|
||||
void redraw_value() override;
|
||||
void redraw_label() override;
|
||||
|
||||
private:
|
||||
int color;
|
||||
int num_value;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user