6 Commits

Author SHA1 Message Date
1a72d6aa0f Attempt to resurrect the display after disconnect 2022-03-17 00:11:01 +01:00
1fdadd8b85 Reduce flicker 2022-03-17 00:10:41 +01:00
130a0dde2f Lower UBAT LED threshold 2022-03-17 00:09:54 +01:00
6609947618 Fix RPM CAN bytes 2022-03-17 00:09:36 +01:00
c8e94175d1 Read tire temps from CAN 2022-03-17 00:09:13 +01:00
197b805f35 Display fuel pressure 2022-03-16 16:13:50 +01:00
5 changed files with 88 additions and 34 deletions

View File

@ -22,9 +22,9 @@ String bezeichnungen[] = {"T_mot", "T_oil", "P_oil", "% fa",
int led_s[] = {led1, led2, led3, led4, led5, led6, led7, led8, int led_s[] = {led1, led2, led3, led4, led5, led6, led7, led8,
led9, led10, led11, led12, led13, led14, led15, led16}; led9, led10, led11, led12, led13, led14, led15, led16};
DataBox gear_box(121, 0, 199, 94, 160, 0, EA_SWISS30B, 4, 4, 'C'); DataBox gear_box(121, 0, 199, 94, 160, 0, EA_SWISS30B, 4, 4, 'C', true);
DataBox left_box(0, 0, 119, 94, 110, 12, EA_FONT7X12, 3, 8, 'R'); DataBox left_box(0, 25, 119, 94, 110, 25, EA_FONT6X8, 3, 8, 'R', false);
DataBox right_box(201, 0, 320, 94, 310, 12, EA_FONT7X12, 3, 8, 'R'); DataBox right_box(201, 25, 320, 94, 310, 25, EA_FONT6X8, 3, 8, 'R', false);
TireTempBox fl_box(80, 130, 156, 176, 118, 124, EA_FONT7X12, 3, 5, 'C'); 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 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 rl_box(80, 184, 156, 230, 118, 178, EA_FONT7X12, 3, 5, 'C');
@ -67,16 +67,26 @@ String get_value(Value val) {
case VAL_RPM: case VAL_RPM:
return String(Vehicle_data.revol / 2); return String(Vehicle_data.revol / 2);
case VAL_TT_FL: case VAL_TT_FL:
return "00"; return String(Vehicle_data.t_tfl * 0.423529 + 8, 0);
case VAL_TT_FR: case VAL_TT_FR:
return "01"; return String(Vehicle_data.t_tfr * 0.423529 + 0, 0);
case VAL_TT_RL: case VAL_TT_RL:
return "10"; return String(Vehicle_data.t_trl * 0.423529 + 11, 0);
case VAL_TT_RR: case VAL_TT_RR:
return "11"; return String(Vehicle_data.t_trr * 0.423529 + 4, 0);
case VAL_LAPTIME: case VAL_LAPTIME: {
return String( double time =
Vehicle_data.lap_time_sec + Vehicle_data.lap_time_msec / 1000.0, 2); Vehicle_data.lap_time_sec + Vehicle_data.lap_time_msec / 1000.0;
if (time < 100) {
return String(time, 2);
} else if (time < 1000) {
return String(time, 1);
} else if (time < 10000) {
return String(time, 0);
} else {
return "2SLOW";
}
}
case VAL_UBATT: case VAL_UBATT:
return String(0.0706949 * Vehicle_data.u_batt, 2); return String(0.0706949 * Vehicle_data.u_batt, 2);
case VAL_TMOT: case VAL_TMOT:
@ -87,6 +97,8 @@ String get_value(Value val) {
return String(Vehicle_data.t_oil - 40); return String(Vehicle_data.t_oil - 40);
case VAL_ERR_TYPE: case VAL_ERR_TYPE:
return String(Stw_data.error_type); return String(Stw_data.error_type);
case VAL_PFUEL:
return String(0.0514 * Vehicle_data.p_fuel, 2);
case VAL_PWAT: case VAL_PWAT:
return String(0.0514 * Vehicle_data.p_wat, 2); return String(0.0514 * Vehicle_data.p_wat, 2);
case VAL_POIL: case VAL_POIL:
@ -132,6 +144,8 @@ String get_label(Value val) {
return "TEMP OIL"; return "TEMP OIL";
case VAL_ERR_TYPE: case VAL_ERR_TYPE:
return "ERROR TYPE"; return "ERROR TYPE";
case VAL_PFUEL:
return "PRESS FUEL";
case VAL_PWAT: case VAL_PWAT:
return "PRESS WAT"; return "PRESS WAT";
case VAL_POIL: case VAL_POIL:
@ -227,8 +241,18 @@ void update_display() {
return; return;
} }
if (tft.disconnected) { if (tft.disconnected) {
uint32_t now = millis();
if (now - last_cleared < 1000) {
return; return;
} }
digitalWrite(reset, LOW);
delay(100);
digitalWrite(reset, HIGH);
tft.disconnected = false;
tft.clear();
cleared = true;
last_cleared = now;
}
if (check_enc_displays()) { if (check_enc_displays()) {
cleared = true; cleared = true;
@ -244,7 +268,6 @@ void update_display() {
Stw_data.button4_rises = 0; Stw_data.button4_rises = 0;
view = (DisplayView)((view + 1) % (VIEW_LAST + 1)); view = (DisplayView)((view + 1) % (VIEW_LAST + 1));
tft.clear(); tft.clear();
last_cleared = now;
cleared = true; cleared = true;
} }
@ -340,13 +363,22 @@ void update_view_driver() {
left_box.update_label(get_label(left_box_value)); left_box.update_label(get_label(left_box_value));
} }
// These can change rapidly, which would lead to a lot of flickering if
// rendered in the clear-redraw method. So instead, they're simply overwritten
// with a black background.
tft.setTextColor(EA_WHITE, EA_BLACK);
left_box.update_value(pad_left(get_value(left_box_value), 5));
right_box.update_value(pad_left(get_value(VAL_RPM), 5));
// These don't change as rapidly, and would overwrite adjacent elements
// (lines/labels) if rendered with a background because of the empty pixels
// above/below the characters. So they're rendered using the clear-redraw
// method.0
tft.setTextColor(EA_WHITE, EA_TRANSPARENT);
gear_box.update_value(get_value(VAL_GEAR)); gear_box.update_value(get_value(VAL_GEAR));
left_box.update_value(get_value(left_box_value)); fl_box.update_value(get_value(VAL_TT_FL).toInt());
right_box.update_value(get_value(VAL_RPM)); fr_box.update_value(get_value(VAL_TT_FR).toInt());
fl_box.update_value(2); rl_box.update_value(get_value(VAL_TT_RL).toInt());
fr_box.update_value(55); rr_box.update_value(get_value(VAL_TT_RR).toInt());
rl_box.update_value(65);
rr_box.update_value(90);
} }
void redraw_view_testing() { void redraw_view_testing() {
@ -414,10 +446,11 @@ void update_value_testing(int i) {
} }
DataBox::DataBox(int x1, int y1, int x2, int y2, int text_x, int text_y, 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) int font, int size_x, int size_y, uint8_t justification,
bool do_clear)
: x1{x1}, y1{y1}, x2{x2}, y2{y2}, text_x{text_x}, text_y{text_y}, : 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}, font{font}, size_x{size_x}, size_y{size_y},
justification{justification}, value{""}, label{""} {} justification{justification}, do_clear{do_clear}, value{""}, label{""} {}
void DataBox::update_value(String val_new) { void DataBox::update_value(String val_new) {
if (!val_new.equals(value)) { if (!val_new.equals(value)) {
@ -442,7 +475,9 @@ void DataBox::redraw_value() {
tft.setTextFont(font); tft.setTextFont(font);
tft.setTextSize(size_x, size_y); tft.setTextSize(size_x, size_y);
Serial.println("Redrawing value:"); Serial.println("Redrawing value:");
if (do_clear) {
tft.clearRect(x1, y1, x2, y2); tft.clearRect(x1, y1, x2, y2);
}
tft.drawText(text_x, text_y, justification, value.c_str()); tft.drawText(text_x, text_y, justification, value.c_str());
} }
@ -458,7 +493,8 @@ TireTempBox::TireTempBox(int x1, int y1, int x2, int y2, int text_x, int text_y,
int font, int size_x, int size_y, int font, int size_x, int size_y,
uint8_t justification) uint8_t justification)
: DataBox{x1, y1, x2, y2, text_x, : DataBox{x1, y1, x2, y2, text_x,
text_y, font, size_x, size_y, justification}, text_y, font, size_x, size_y, justification,
false},
num_value{-1} {} num_value{-1} {}
void TireTempBox::update_value(int val_new) { void TireTempBox::update_value(int val_new) {

View File

@ -38,6 +38,7 @@ enum Value {
VAL_TAIR, VAL_TAIR,
VAL_TOIL, VAL_TOIL,
VAL_ERR_TYPE, VAL_ERR_TYPE,
VAL_PFUEL,
VAL_PWAT, VAL_PWAT,
VAL_POIL, VAL_POIL,
VAL_PBF, VAL_PBF,
@ -72,7 +73,7 @@ void update_value_testing(int i);
class DataBox { class DataBox {
public: public:
DataBox(int x1, int y1, int x2, int y2, int text_x, int text_y, int font, 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); int size_x, int size_y, uint8_t justification, bool do_clear);
void update_value(String val_new); void update_value(String val_new);
void update_label(String label_new); void update_label(String label_new);
@ -84,6 +85,7 @@ public:
protected: protected:
int x1, y1, x2, y2, text_x, text_y, font, size_x, size_y; int x1, y1, x2, y2, text_x, text_y, font, size_x, size_y;
uint8_t justification; uint8_t justification;
bool do_clear;
String value; String value;
String label; String label;
}; };

View File

@ -60,8 +60,8 @@ typedef struct {
// uint8_t i; //Index // uint8_t i; //Index
// linker Drehschalter // linker Drehschalter
uint8_t buttonStateEnc1; // button uint8_t buttonStateEnc1; // button
// uint8_t br; //test mode : // uint8_t br; //test
// mittlere Drehschalter position // mode : mittlere Drehschalter position
uint8_t buttonStateEnc2; // button uint8_t buttonStateEnc2; // button
uint8_t displayindex; // index für Displayanzeige uint8_t displayindex; // index für Displayanzeige
uint8_t error_type; // Extrainfos über Error-LED uint8_t error_type; // Extrainfos über Error-LED
@ -82,6 +82,10 @@ typedef struct {
uint8_t t_oil; // Öl-Motor-Temperatur uint8_t t_oil; // Öl-Motor-Temperatur
uint8_t t_mot; // Wasser-Motor-Temperatur uint8_t t_mot; // Wasser-Motor-Temperatur
uint8_t t_air; // LLK-Temperatur uint8_t t_air; // LLK-Temperatur
uint8_t t_tfl; // Tire temp front left
uint8_t t_tfr; // Tire temp front right
uint8_t t_trl; // Tire temp rear left
uint8_t t_trr; // Tire temp rear right
uint8_t u_batt; // Batteriespannung uint8_t u_batt; // Batteriespannung
uint8_t rev_lim; // Drehzahllimit Bit uint8_t rev_lim; // Drehzahllimit Bit
uint8_t p_wat; uint8_t p_wat;
@ -93,7 +97,7 @@ typedef struct {
uint8_t speed_fr; uint8_t speed_fr;
uint8_t speed; uint8_t speed;
uint8_t lap_time_sec; uint8_t lap_time_sec;
uint8_t lap_time_msec; uint16_t lap_time_msec;
} vehicle_data_type; } vehicle_data_type;
extern volatile stw_data_type Stw_data; extern volatile stw_data_type Stw_data;

View File

@ -19,11 +19,13 @@ void Init_Can_0() {
Can0.setNumTXBoxes(1); // reserves mailbox 0 for tx only 8 mailboxes are Can0.setNumTXBoxes(1); // reserves mailbox 0 for tx only 8 mailboxes are
// available (the other 7 mailboxes are for rx) // available (the other 7 mailboxes are for rx)
// We only have 7 mailboxes, but want to receive 8 messages. This trick should // We only have 7 mailboxes, but want to receive 9 messages. This trick should
// allow us to receive BCU_APS_BRAKE and BCU_ETC in the same mailbox. // allow us to receive BCU_APS_BRAKE, BCU_ETC and BCU_SHIFT_CTRL in the same
Can0.watchFor(CAN_ID_BCU_APS_BRAKE & CAN_ID_BCU_ETC, // mailbox. It will also let through 0x506, but that shouldn't be much of an
~(CAN_ID_BCU_APS_BRAKE ^ CAN_ID_BCU_ETC)); // issue.
Can0.watchFor(CAN_ID_BCU_SHIFT_CTRL); Can0.watchFor(CAN_ID_BCU_APS_BRAKE & CAN_ID_BCU_ETC & CAN_ID_BCU_SHIFT_CTRL,
0x7FC);
Can0.watchFor(CAN_ID_BCU_TIRES);
Can0.watchFor(CAN_ID_BCU_LAP_TIME); Can0.watchFor(CAN_ID_BCU_LAP_TIME);
Can0.watchFor(CAN_ID_MS4_IGN_REV_ATH); Can0.watchFor(CAN_ID_MS4_IGN_REV_ATH);
Can0.watchFor(CAN_ID_MS4_SPEED); Can0.watchFor(CAN_ID_MS4_SPEED);
@ -92,13 +94,22 @@ void Receive_Can_0(CAN_FRAME *temp_message) {
Vehicle_data.gear = (temp_message->data.byte[1]) >> 5; Vehicle_data.gear = (temp_message->data.byte[1]) >> 5;
break; break;
} }
case CAN_ID_BCU_TIRES: { // Tire temps
Vehicle_data.t_trl = temp_message->data.byte[1];
Vehicle_data.t_trr = temp_message->data.byte[4];
Vehicle_data.t_tfl = temp_message->data.byte[5];
Vehicle_data.t_tfr = temp_message->data.byte[6];
break;
}
case CAN_ID_BCU_LAP_TIME: { // lap time case CAN_ID_BCU_LAP_TIME: { // lap time
Vehicle_data.lap_time_sec = temp_message->data.byte[1]; Vehicle_data.lap_time_sec = temp_message->data.byte[1];
Vehicle_data.lap_time_msec = temp_message->data.byte[1]; Vehicle_data.lap_time_msec =
temp_message->data.byte[2] | ((temp_message->data.byte[3] & 0b11) << 8);
break;
} }
case CAN_ID_MS4_IGN_REV_ATH: { // rpm case CAN_ID_MS4_IGN_REV_ATH: { // rpm
Vehicle_data.revol = Vehicle_data.revol =
(temp_message->data.byte[5] | temp_message->data.byte[4] << 8); (temp_message->data.byte[4] | temp_message->data.byte[3] << 8);
break; break;
} }
case CAN_ID_MS4_SPEED: { // speed case CAN_ID_MS4_SPEED: { // speed
@ -144,7 +155,7 @@ void update_LED() {
((Vehicle_data.t_mot - 40) != 0xC8); // 105°C temp.water und !=200 ((Vehicle_data.t_mot - 40) != 0xC8); // 105°C temp.water und !=200
bool g_auto = Vehicle_data.g_auto; bool g_auto = Vehicle_data.g_auto;
bool u_batt = Vehicle_data.u_batt <= 0xB1; // 12.5V batt.spann. bool u_batt = Vehicle_data.u_batt <= 0xA9; // 11.95V batt.spann.
bool e_dros = Vehicle_data.e_thro; // error-bit bool e_dros = Vehicle_data.e_thro; // error-bit
bool rev_lim = Vehicle_data.rev_lim; bool rev_lim = Vehicle_data.rev_lim;

View File

@ -11,6 +11,7 @@ FT_2018_STW_CAN.h
#define CAN_ID_BCU_APS_BRAKE 0x500 #define CAN_ID_BCU_APS_BRAKE 0x500
#define CAN_ID_BCU_ETC 0x502 #define CAN_ID_BCU_ETC 0x502
#define CAN_ID_BCU_SHIFT_CTRL 0x504 #define CAN_ID_BCU_SHIFT_CTRL 0x504
#define CAN_ID_BCU_TIRES 0x562
#define CAN_ID_BCU_LAP_TIME 0x570 #define CAN_ID_BCU_LAP_TIME 0x570
#define CAN_ID_MS4_IGN_REV_ATH 0x773 #define CAN_ID_MS4_IGN_REV_ATH 0x773
#define CAN_ID_MS4_SPEED 0x775 #define CAN_ID_MS4_SPEED 0x775