7 Commits

Author SHA1 Message Date
14b5f6988d Use both buttons to toggle driver & testing view 2022-03-13 20:01:46 +01:00
3cf68cd3cb Add more values 2022-03-13 19:57:34 +01:00
894ced16ef Redraw screen after alarms/changing encoders 2022-03-13 19:54:54 +01:00
5eecc507a0 Use debouncer for button states 2022-03-13 19:52:11 +01:00
373266f6be [WIP] Major rewrite of display code
Currently, the displayed values are hardcoded
2022-03-13 18:18:11 +01:00
f62f264b29 Implement some EDIPTFT commands 2022-03-13 18:17:41 +01:00
0eeafa9393 Debounce the rest of the buttons 2022-03-13 18:15:41 +01:00
6 changed files with 500 additions and 359 deletions

View File

@ -8,31 +8,15 @@ EDIPTFT tft(true,false);
String bezeichnungen[]={"T_mot","T_oil","P_oil","% fa","U_batt","P_wat","T_air", 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"}; "P_b_front","P_b_rear","Error Type","Speed_fl","Speed_fr","Speed"};
//"Drehzahl","P_fuel","Index" //"Drehzahl","P_fuel","Index"
int vergleichsindex;
int sizeaalt;
int sizeaneu;
int sizebalt;
int sizebneu;
int sizecalt;
int sizecneu;
int sizedalt;
int sizedneu;
int sizeealt;
int sizeeneu;
uint8_t clearcounter = 56;
uint8_t trcalt = Stw_data.trc;
uint8_t modealt = Stw_data.mode;
uint8_t trccounter;// = Stw_data.trc;
uint8_t modecounter;// = Stw_data.mode;
bool trctimer;
bool modetimer;
int led_s[] = {led1,led2,led3,led4,led5,led6,led7,led8,led9,led10,led11,led12,led13,led14,led15,led16}; int led_s[] = {led1,led2,led3,led4,led5,led6,led7,led8,led9,led10,led11,led12,led13,led14,led15,led16};
unsigned long poiltimer;
unsigned long tmottimer; DataBox gear_box(121, 0, 199, 94, 160, 0, EA_SWISS30B, 4, 4, 'C');
unsigned long toiltimer; DataBox left_box(0, 0, 119, 94, 110, 12, EA_FONT7X12, 3, 8, 'R');
bool poilbool = true; DataBox right_box(201, 0, 320, 94, 310, 12, EA_FONT7X12, 3, 8, 'R');
bool tmotbool = true; TireTempBox fl_box(80, 130, 156, 176, 118, 124, EA_FONT7X12, 3, 5, 'C');
bool toilbool = true; 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() { void init_display() {
pinMode(writeprotect, OUTPUT); pinMode(writeprotect, OUTPUT);
@ -41,336 +25,227 @@ void init_display() {
pinMode(disp_cs, OUTPUT); pinMode(disp_cs, OUTPUT);
pinMode(MOSI, OUTPUT); pinMode(MOSI, OUTPUT);
pinMode(MISO, OUTPUT); pinMode(MISO, OUTPUT);
//pinMode(CLK, INPUT);
digitalWrite(disp_cs, HIGH); digitalWrite(disp_cs, HIGH);
digitalWrite(MOSI, HIGH); digitalWrite(MOSI, HIGH);
digitalWrite(MISO, HIGH); digitalWrite(MISO, HIGH);
digitalWrite(reset, LOW); digitalWrite(reset, LOW);
//edip.smallProtoSelect(7);
//edip.setNewColor(EA_GREY, 0xe3, 0xe3,0xe3); // redefine r-g-b-values of EA_GREY
//edip.drawImage(0,50,FASTTUBE_LOGO_PNG);
digitalWrite(reset,HIGH); digitalWrite(reset,HIGH);
tft.begin(115200); // start display communication tft.begin(115200); // start display communication
/*int h = 20;
char charh[2];
String strh = String(h);
strh.toCharArray(charh,2);
tft.DisplayLight(charh);*/
tft.cursorOn(false); tft.cursorOn(false);
tft.terminalOn(false); tft.terminalOn(false);
tft.setDisplayColor(EA_WHITE,EA_BLACK); tft.setDisplayColor(EA_WHITE,EA_BLACK);
tft.setTextColor(EA_WHITE,EA_BLACK); tft.setTextColor(EA_WHITE,EA_TRANSPARENT);
//tft.setTextFont('4');
tft.setTextSize(5,8); tft.setTextSize(5,8);
tft.clear(); tft.clear();
//tft.displayLight('30');
tft.drawText(0, 14, 'C', "FaSTTUBe"); //draw some text gear_box.update_label(get_label(VAL_GEAR));
//tft.loadImage(0,0,1); left_box.update_label(get_label(VAL_FIRST_LEFT_BOX));
//delay(2000); right_box.update_label(get_label(VAL_RPM));
} }
double get_value(int a){ String get_value(Value val) {
double value; switch (val) {
if (a == 0){ case VAL_GEAR:
value = Vehicle_data.gear; if (Vehicle_data.gear == 0) {
//}else if (a == 11){ return "N";
// value = Stw_data.i; }
//}else if (a == 1){ return String(Vehicle_data.gear);
// value = Vehicle_data.revol/2; case VAL_RPM:
}else if (a == 1){ return String(Vehicle_data.revol);
value = Vehicle_data.t_mot-40; case VAL_TT_FL:
}else if (a == 5){ return "00";
value = 0.0706949*Vehicle_data.u_batt; case VAL_TT_FR:
}else if (a == 7){ return "01";
value = Vehicle_data.t_air-40; case VAL_TT_RL:
}else if(a == 10){ return "10";
value = Stw_data.error_type; case VAL_TT_RR:
}else if (a == 2){ return "11";
value = Vehicle_data.t_oil-40; case VAL_LAPTIME:
}else if (a == 6){ return "93.13";
value = 0.0514*Vehicle_data.p_wat; case VAL_UBATT:
//}else if (a == 7){ return String(0.0706949 * Vehicle_data.u_batt, 2);
// value = 0.0514*Vehicle_data.p_fuel; case VAL_TMOT:
}else if (a == 3){ return String(Vehicle_data.t_mot - 40);
value = 0.0514*Vehicle_data.p_oil; case VAL_TAIR:
}else if (a == 8){ return String(Vehicle_data.t_air - 40);
value = Vehicle_data.p_brake_front; case VAL_TOIL:
}else if (a == 9){ return String(Vehicle_data.t_oil - 40);
value = Vehicle_data.p_brake_rear; case VAL_ERR_TYPE:
}else if(a == 4){ return String(Stw_data.error_type);
value = 200*Vehicle_data.p_brake_front/(Vehicle_data.p_brake_rear+(2*Vehicle_data.p_brake_front)); case VAL_PWAT:
}else if (a == 11){ return String(0.0514*Vehicle_data.p_wat, 2);
value = Vehicle_data.speed_fl; case VAL_POIL:
}else if (a == 12){ return String(0.0514*Vehicle_data.p_oil, 2);
value = Vehicle_data.speed_fr; case VAL_PBF:
}else if(a == 13){ return String(Vehicle_data.p_brake_front);
value = Vehicle_data.speed; 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 "???";
} }
return value; }
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(){ void update_display(){
if(((millis()-poiltimer)>=20000) and poilbool){ static DisplayPage page = PAGE_DRIVER;
poilbool = false; static uint32_t last_cleared;
alarm("P_oil"); static bool cleared = true;
}
if(((millis()-tmottimer)>=20000) and tmotbool){
tmotbool = false;
alarm("T_mot");
}
if(((millis()-toiltimer)>=10000) and toilbool){
toilbool = false;
alarm("T_oil");
}
if((0.0514*Vehicle_data.p_oil)>=0,1 or Vehicle_data.speed == 0){
poiltimer = millis();
}
if(((Vehicle_data.t_mot - 40) <= 0x69) or ((Vehicle_data.t_mot - 40)==0xC8)){
tmottimer = millis();
}
if((Vehicle_data.t_oil - 40) <= 0x96){
toiltimer = millis();
}
if(Stw_data.buttonState1 & Stw_data.buttonState4){
alarm("");
}
if(!tft.disconnected){
tft.cursorOn(false);
if(trcalt!=Stw_data.trc or trctimer == true or Stw_data.buttonStateEnc1 == HIGH){
display_trc();
}else if(modealt!=Stw_data.mode or modetimer == true or Stw_data.buttonStateEnc2 == HIGH){
display_mode();
}else{
if(clearcounter>=56){
tft.clear();
clearcounter = 0;
}
clearcounter+=1;
if(Stw_data.buttonState4){
if(Stw_data.displayindex>=sizeof(bezeichnungen)/sizeof(String)-3){
Stw_data.displayindex = 0;
delay(250);
}else{
Stw_data.displayindex+=1;
delay(250);
}
}
if(Stw_data.buttonState1){
if(Stw_data.displayindex<=0){
Stw_data.displayindex = sizeof(bezeichnungen)/sizeof(String)-3;
delay(250);
}else{
Stw_data.displayindex-=1;
delay(250);
}
}
if(vergleichsindex!=Stw_data.displayindex){
tft.clear();
vergleichsindex=Stw_data.displayindex;
}
int a = sizeof(bezeichnungen[Stw_data.displayindex]);
int g = sizeof(bezeichnungen[Stw_data.displayindex+1]);
int h = sizeof(bezeichnungen[Stw_data.displayindex+2]);
char d[a];
char e[g];
char f[h];
bezeichnungen[Stw_data.displayindex].toCharArray(d,a);
bezeichnungen[Stw_data.displayindex+1].toCharArray(e,g);
bezeichnungen[Stw_data.displayindex+2].toCharArray(f,h);
char b[2];
char c[5];
char i[5];
char j[5];
char k[5];
char m[5];
String str=String(int(get_value(0)));
if(str.equals(String(0))){
str = "N";
}
String str1;
String str2;
String str3;
if(Stw_data.displayindex+1==0 or Stw_data.displayindex+1==2 or Stw_data.displayindex+1==1 or Stw_data.displayindex+1==10 or Stw_data.displayindex+1==7 or Stw_data.displayindex+1==11 or Stw_data.displayindex+1==12 or Stw_data.displayindex+1==13){
str1=String(int(get_value(Stw_data.displayindex+1)));
}else{
str1=String(get_value(Stw_data.displayindex+1));
}
if(Stw_data.displayindex+1 == 10){
if(str1.equals(String(1))){
str1 = "PC";
}else if(str1.equals(String(2))){
str1 = "BSE";
}else if(str1.equals(String(3))){
str1 = "APS";
}else if(str1.equals(String(4))){
str1 = "ETB";
}else if(str1.equals(String(0))){
str1 = "None";
}
}
if(Stw_data.displayindex+2==0 or Stw_data.displayindex+2==2 or Stw_data.displayindex+2==1 or Stw_data.displayindex+2==10 or Stw_data.displayindex+2==7 or Stw_data.displayindex+2==11 or Stw_data.displayindex+2==12 or Stw_data.displayindex+2==13){
str2=String(int(get_value(Stw_data.displayindex+2)));
}else{
str2=String(get_value(Stw_data.displayindex+2));
}
if(Stw_data.displayindex+2 == 10){
if(str2.equals(String(1))){
str2 = "PC";
}else if(str2.equals(String(2))){
str2 = "BSE";
}else if(str2.equals(String(3))){
str2 = "APS";
}else if(str2.equals(String(4))){
str2 = "ETB";
}else if(str2.equals(String(0))){
str2 = "None";
}
}
if(Stw_data.displayindex+3==0 or Stw_data.displayindex+3==2 or Stw_data.displayindex+3==1 or Stw_data.displayindex+3==10 or Stw_data.displayindex+3==7 or Stw_data.displayindex+3==11 or Stw_data.displayindex+3==12 or Stw_data.displayindex+3==13){
str3=String(int(get_value(Stw_data.displayindex+3)));
}else{
str3=String(get_value(Stw_data.displayindex+3));
}
if(Stw_data.displayindex+3 == 10){
if(str3.equals(String(1))){
str3 = "PC";
}else if(str3.equals(String(2))){
str3 = "BSE";
}else if(str3.equals(String(3))){
str3 = "APS";
}else if(str3.equals(String(4))){
str3 = "ETB";
}else if(str3.equals(String(0))){
str3 = "None";
}
}
String str5=String(Vehicle_data.revol/2);
String str4=String(0.0514*Vehicle_data.p_fuel);
str.toCharArray(b,2);
str1.toCharArray(c,5);
str2.toCharArray(i,5);
str3.toCharArray(j,5);
str4.toCharArray(k,5);
str5.toCharArray(m,5);
sizeaneu = strlen(c);
sizebneu = strlen(i);
sizecneu = strlen(j);
sizedneu = strlen(k);
sizeeneu = strlen(m);
if(sizeaalt!=sizeaneu){
tft.clear();
sizeaalt=sizeaneu;
}
if(sizebalt!=sizebneu){
tft.clear();
sizebalt=sizebneu;
}
if(sizecalt!=sizecneu){
tft.clear();
sizecalt=sizecneu;
}
if(sizedalt!=sizedneu){
tft.clear();
sizedalt=sizedneu;
}
if(sizeealt!=sizeeneu){
tft.clear();
sizeealt=sizeeneu;
}
tft.setTextSize(6,8);
tft.drawText(132, 0, 'L', b);
tft.setTextSize(2,7);
tft.drawText(10, 20, 'L', k);
tft.drawText(240, 20, 'L', m);
tft.drawText(10,130, 'L', c);
tft.drawText(120, 130, 'L', i);
tft.drawText(240,130, 'L', j);
tft.setTextSize(1,1);
tft.drawText(136,116, 'L', "Gang");
tft.drawText(10,116, 'L', "P_fuel");
tft.drawText(240,116, 'L', "Drehzahl");
tft.drawText(10,226, 'L', d);
tft.drawText(120,226, 'L', e);
tft.drawText(240,226, 'L', f);
/*if (cleaner){
tft.setTextSize(5,8);
tft.drawText(0, 14, 'C', "FaSTTUBe"); // draw some text
tft.setTextSize(4,4);
tft.drawText(24, 120, 'C', "insert coin"); // draw some text
tft.drawText(0, 180, 'C', "to continue");
cleaner = false;
}else{
tft.setTextSize(5,8);
tft.drawText(0, 14, 'C', "FaSTTUBe"); // draw some text
tft.setTextSize(4,4);
tft.drawText(24, 120, 'C', " "); // draw some text
tft.drawText(0, 180, 'C', " ");
cleaner = true;
}
delay(80);*/
}
}
}
void display_trc(){ if (check_alarms()) {
if(trcalt!=Stw_data.trc or Stw_data.buttonStateEnc1 == HIGH){ cleared = true;
tft.clear(); return;
tft.setTextSize(7,8); }
tft.setDisplayColor(EA_WHITE,EA_RED); if (tft.disconnected) {
tft.setTextColor(EA_WHITE,EA_RED); return;
char trcanzeige[7];
String str = String("ARB:");
if(Stw_data.trc==11){
str+="ED";
}else{
str+=String(Stw_data.trc);
}
str.toCharArray(trcanzeige,7);
tft.drawText(0,0,'L'," ");
tft.drawText(0,60,'L'," ");
tft.drawText(0,120,'L'," ");
tft.drawText(0,180,'L'," ");
tft.drawText(15,68,'L',trcanzeige);
trccounter = 0;
trcalt = Stw_data.trc;
trctimer = true;
}else if(trccounter >= 255){
tft.setDisplayColor(EA_WHITE,EA_BLACK);
tft.setTextColor(EA_WHITE,EA_BLACK);
tft.clear();
trctimer = false;
}else{
trccounter+=1;
delay(5);
} }
}
void display_mode(){ if (check_enc_displays()) {
if(modealt!=Stw_data.mode or Stw_data.buttonStateEnc2 == HIGH){ 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(); tft.clear();
tft.setTextSize(6,8); last_cleared = now;
tft.setDisplayColor(EA_WHITE,EA_RED); cleared = true;
tft.setTextColor(EA_WHITE,EA_RED); }
char modeanzeige[7];
String str = String("MODE:"); if (now - last_cleared >= DISP_CLEAR_INTERVAL) {
str+=String(Stw_data.mode);
str.toCharArray(modeanzeige,7);
tft.drawText(0,0,'L'," ");
tft.drawText(0,60,'L'," ");
tft.drawText(0,120,'L'," ");
tft.drawText(0,180,'L'," ");
tft.drawText(15,68,'L',modeanzeige);
modecounter = 0;
modealt = Stw_data.mode;
modetimer = true;
}else if(modecounter >= 255){
tft.setDisplayColor(EA_WHITE,EA_BLACK);
tft.setTextColor(EA_WHITE,EA_BLACK);
tft.clear(); tft.clear();
modetimer = false; last_cleared = now;
}else{ cleared = true;
modecounter+=1; }
delay(5);
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();
}
} }
} }
@ -400,7 +275,138 @@ void alarm(String textstr){
delay(100); delay(100);
if(Stw_data.buttonState1 & Stw_data.buttonState4){ if(Stw_data.buttonState1 & Stw_data.buttonState4){
x=0; x=0;
tft.setTextColor(EA_WHITE,EA_BLACK); 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() {
}
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() {}

View File

@ -3,26 +3,94 @@
#include "FT_2018_STW_CAN.h" #include "FT_2018_STW_CAN.h"
#include "FT18_STW_INIT.h" #include "FT18_STW_INIT.h"
#ifndef FT18_STW_DISPLAY_h #ifndef FT18_STW_DISPLAY_h
#define FT18_STW_DISPLAY_h #define FT18_STW_DISPLAY_h
#define EA_BLACK 1
#define EA_RED 3
#define EA_GREY 10
#define EA_WHITE 8
#define MOSI 75 #define MOSI 75
#define MISO 74 #define MISO 74
#define CLK 76 #define CLK 76
#define disp_cs 42 #define disp_cs 42
#define reset 43 #define reset 43
#define writeprotect 52 #define writeprotect 52
void init_display(void); #define POIL_ALARM_THRESH ((uint32_t) (0.1 / 0.0514))
void update_display(void); #define POIL_ALARM_TIME 20000 // ms
double get_value(int a); #define TMOT_ALARM_THRESH (40 + 105)
void display_trc(void); #define TMOT_SAFE_VALUE (40 + 200)
void display_mode(void); #define TMOT_ALARM_TIME 20000 // ms
void alarm(String text); #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 #endif

View File

@ -51,13 +51,22 @@ void read_buttons(){
Stw_data.Stw_shift_down = debouncer[4].rose(); Stw_data.Stw_shift_down = debouncer[4].rose();
Stw_data.Stw_shift_up = debouncer[5].rose(); Stw_data.Stw_shift_up = debouncer[5].rose();
// These are also used for GUI, so if we set them only at rising edge, they Stw_data.buttonState1 = debouncer[0].isPressed();
// might never be high when checked in the GUI. Stw_data.buttonState4 = debouncer[3].isPressed();
// TODO: Rewrite so we can use debounced values here as well Stw_data.buttonStateEnc1 = debouncer[6].isPressed();
Stw_data.buttonState1 = digitalRead(button1); Stw_data.buttonStateEnc2 = debouncer[7].isPressed();
Stw_data.buttonState4 = digitalRead(button4); if (debouncer[0].rose()) {
Stw_data.buttonStateEnc1 = digitalRead(enc1PinS); Stw_data.button1_rises++;
Stw_data.buttonStateEnc2 = digitalRead(enc2PinS); }
if (debouncer[3].rose()) {
Stw_data.button4_rises++;
}
if (debouncer[6].rose()) {
Stw_data.enc1_rises++;
}
if (debouncer[7].rose()) {
Stw_data.enc2_rises++;
}
} }
void read_rotary(){ void read_rotary(){

View File

@ -69,6 +69,10 @@ typedef struct
uint8_t trc; uint8_t trc;
uint8_t mode; uint8_t mode;
uint8_t button1_rises;
uint8_t button4_rises;
uint8_t enc1_rises;
uint8_t enc2_rises;
} stw_data_type; } stw_data_type;
typedef struct typedef struct

View File

@ -471,6 +471,22 @@ void EDIPTFT::drawText(uint16_t x1, uint16_t y1, char justification, const char*
} }
void EDIPTFT::drawTextInRect(int x1, int y1, int x2, int y2, uint8_t align, const char* text) {
int len_text = strlen(text);
int len = 3 + 8 + 1 + len_text + 1;
char data[len] = {
27, 'Z', 'B', lowByte(x1), highByte(x1), lowByte(y1), highByte(y1),
lowByte(x2), highByte(x2), lowByte(y2), highByte(y2), align
};
for (int i = 0; i < len_text; i++) {
data[3 + 8 + 1 + i] = text[i];
}
data[len - 1] = 0;
sendData(data, len);
}
void EDIPTFT::drawLine(int x1, int y1, int x2, int y2) { void EDIPTFT::drawLine(int x1, int y1, int x2, int y2) {
char command [] = { char command [] = {
27,'G','D', 27,'G','D',
@ -514,6 +530,25 @@ void EDIPTFT::drawRectf(int x1, int y1, int x2, int y2, char color) {
} }
void EDIPTFT::clearRect(int x1, int y1, int x2, int y2) {
Serial.print("Clearing ");
Serial.print(x1); Serial.print(", ");
Serial.print(y1); Serial.print(", ");
Serial.print(x2); Serial.print(", ");
Serial.println(y2);
char command [] = {
27, 'R', 'L',
#if COORD_SIZE == 1
x1, y1, x2, y2
#else
lowByte(x1),highByte(x1),lowByte(y1),highByte(y1),
lowByte(x2),highByte(x2),lowByte(y2),highByte(y2),
#endif
};
sendData(command, sizeof(command));
}
void EDIPTFT::defineTouchKey(int x1, int y1, int x2, int y2, char down, char up, void EDIPTFT::defineTouchKey(int x1, int y1, int x2, int y2, char down, char up,
const char* text) { //text nicht const 17 const char* text) { //text nicht const 17
byte len = strlen(text); byte len = strlen(text);

View File

@ -37,6 +37,7 @@
#define COORD_SIZE DEVICE //Byte count for coordinates #define COORD_SIZE DEVICE //Byte count for coordinates
#define SERIAL_DEV Serial3 #define SERIAL_DEV Serial3
#define EA_TRANSPARENT 0
#define EA_BLACK 1 #define EA_BLACK 1
#define EA_BLUE 2 #define EA_BLUE 2
#define EA_RED 3 #define EA_RED 3
@ -252,6 +253,21 @@ class EDIPTFT {
*/ */
void drawText(uint16_t x1, uint16_t y1, char justification, const char* text); void drawText(uint16_t x1, uint16_t y1, char justification, const char* text);
/*! \brief Draw text on display in an area
*
* Draw a *text* on screen. Several lines are separated by the character `|`
* ($7C).
* * place text between `~`: characters flash on/off
* * place text between `@`: characters flash inversely
* * use `\\` as to escape special characters
*
* \param align set alignment in the rectangle. 1 = top left, 2 = top
* center, 3 = top right, 4 = center left, 5 = center, 6 = center right, 7 =
* bottom left, 8 = bottom center, 9 = bottom right.
* \param text text to draw on display
*/
void drawTextInRect(int x1, int y1, int x2, int y2, uint8_t align, const char* text);
// Rectangle and Line // Rectangle and Line
void setLineColor(char fg, char bg); void setLineColor(char fg, char bg);
@ -276,6 +292,9 @@ class EDIPTFT {
void drawRectf(int x1, int y1, int x2, int y2, char color); void drawRectf(int x1, int y1, int x2, int y2, char color);
/*! \brief Clear rectangular area */
void clearRect(int x1, int y1, int x2, int y2);
// Touch keys // Touch keys
/*! \brief Define touch key /*! \brief Define touch key