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:
Jasper Blanckenburg 2022-03-13 20:30:14 +01:00
parent 14b5f6988d
commit 41d3bd907e
16 changed files with 2336 additions and 2319 deletions

8
.editorconfig Normal file
View File

@ -0,0 +1,8 @@
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
[*.{cpp,c,h,hpp}]
indent_style = space
indent_size = 4

View File

@ -13,9 +13,7 @@ struct FaultStatusRegisters {
uint32_t SHCSR; uint32_t SHCSR;
}; };
enum class FaultType { enum class FaultType { HardFault, MemManage, BusFault, UsageFault };
HardFault, MemManage, BusFault, UsageFault
};
struct FlashDump { struct FlashDump {
FaultType type; FaultType type;
@ -43,22 +41,23 @@ const FlashDump *flash_dump_get_fault(uint32_t n);
void uart_wait_for_txrdy(); void uart_wait_for_txrdy();
size_t uart_write(uint8_t c); size_t uart_write(uint8_t c);
size_t uart_print(const char* str); size_t uart_print(const char *str);
size_t uart_print_hex(uint32_t x); size_t uart_print_hex(uint32_t x);
void print_dumped_faults(bool in_irq=false); void print_dumped_faults(bool in_irq = false);
void print_stacked_registers(const uint32_t *stack, bool in_irq=false); void print_stacked_registers(const uint32_t *stack, bool in_irq = false);
void print_fault_registers(const FaultStatusRegisters *fsr, bool in_irq=false); void print_fault_registers(const FaultStatusRegisters *fsr,
bool in_irq = false);
FaultStatusRegisters get_current_fsr(); FaultStatusRegisters get_current_fsr();
const char* get_fault_type_name(FaultType type); const char *get_fault_type_name(FaultType type);
void fault_handler(uint32_t *stack_addr, FaultType fault_type, void fault_handler(uint32_t *stack_addr, FaultType fault_type, const int *leds,
const int *leds, unsigned n_leds); unsigned n_leds);
void inline busy_wait(size_t iterations) { void inline busy_wait(size_t iterations) {
for (size_t i = 0; i < iterations; i++) { for (size_t i = 0; i < iterations; i++) {
// Does nothing, but ensures the compiler doesn't optimize the loop away. // Does nothing, but ensures the compiler doesn't optimize the loop away.
__ASM ("" ::: "memory"); __ASM("" ::: "memory");
} }
} }

View File

@ -1,14 +1,17 @@
#include "FT18_STW_DISPLAY.h"
#include "Arduino.h" #include "Arduino.h"
#include "EDIPTFT.h" #include "EDIPTFT.h"
#include "FT_2018_STW_CAN.h"
#include "FT18_STW_INIT.h" #include "FT18_STW_INIT.h"
#include "FT18_STW_DISPLAY.h" #include "FT_2018_STW_CAN.h"
EDIPTFT tft(true,false); 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",
"P_b_front","P_b_rear","Error Type","Speed_fl","Speed_fr","Speed"}; "U_batt", "P_wat", "T_air", "P_b_front",
"P_b_rear", "Error Type", "Speed_fl", "Speed_fr",
"Speed"};
//"Drehzahl","P_fuel","Index" //"Drehzahl","P_fuel","Index"
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};
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');
DataBox left_box(0, 0, 119, 94, 110, 12, EA_FONT7X12, 3, 8, 'R'); DataBox left_box(0, 0, 119, 94, 110, 12, EA_FONT7X12, 3, 8, 'R');
@ -19,394 +22,420 @@ 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'); 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);
digitalWrite(writeprotect, HIGH); digitalWrite(writeprotect, HIGH);
pinMode(reset, OUTPUT); pinMode(reset, OUTPUT);
pinMode(disp_cs, OUTPUT); pinMode(disp_cs, OUTPUT);
pinMode(MOSI, OUTPUT); pinMode(MOSI, OUTPUT);
pinMode(MISO, OUTPUT); pinMode(MISO, OUTPUT);
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);
digitalWrite(reset,HIGH); digitalWrite(reset, HIGH);
tft.begin(115200); // start display communication tft.begin(115200); // start display communication
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_TRANSPARENT); tft.setTextColor(EA_WHITE, EA_TRANSPARENT);
tft.setTextSize(5,8); tft.setTextSize(5, 8);
tft.clear(); tft.clear();
gear_box.update_label(get_label(VAL_GEAR)); gear_box.update_label(get_label(VAL_GEAR));
left_box.update_label(get_label(VAL_FIRST_LEFT_BOX)); left_box.update_label(get_label(VAL_FIRST_LEFT_BOX));
right_box.update_label(get_label(VAL_RPM)); right_box.update_label(get_label(VAL_RPM));
} }
String get_value(Value val) { String get_value(Value val) {
switch (val) { switch (val) {
case VAL_GEAR: case VAL_GEAR:
if (Vehicle_data.gear == 0) { if (Vehicle_data.gear == 0) {
return "N"; return "N";
} }
return String(Vehicle_data.gear); return String(Vehicle_data.gear);
case VAL_RPM: case VAL_RPM:
return String(Vehicle_data.revol); return String(Vehicle_data.revol);
case VAL_TT_FL: case VAL_TT_FL:
return "00"; return "00";
case VAL_TT_FR: case VAL_TT_FR:
return "01"; return "01";
case VAL_TT_RL: case VAL_TT_RL:
return "10"; return "10";
case VAL_TT_RR: case VAL_TT_RR:
return "11"; return "11";
case VAL_LAPTIME: case VAL_LAPTIME:
return "93.13"; return "93.13";
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:
return String(Vehicle_data.t_mot - 40); return String(Vehicle_data.t_mot - 40);
case VAL_TAIR: case VAL_TAIR:
return String(Vehicle_data.t_air - 40); return String(Vehicle_data.t_air - 40);
case VAL_TOIL: case VAL_TOIL:
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_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:
return String(0.0514*Vehicle_data.p_oil, 2); return String(0.0514 * Vehicle_data.p_oil, 2);
case VAL_PBF: case VAL_PBF:
return String(Vehicle_data.p_brake_front); return String(Vehicle_data.p_brake_front);
case VAL_PBR: case VAL_PBR:
return String(Vehicle_data.p_brake_rear); return String(Vehicle_data.p_brake_rear);
case VAL_SPEED_FL: case VAL_SPEED_FL:
return String(Vehicle_data.speed_fl); return String(Vehicle_data.speed_fl);
case VAL_SPEED_FR: case VAL_SPEED_FR:
return String(Vehicle_data.speed_fr); return String(Vehicle_data.speed_fr);
case VAL_SPEED: case VAL_SPEED:
return String(Vehicle_data.speed); return String(Vehicle_data.speed);
default: default:
return "???"; return "???";
} }
} }
String get_label(Value val) { String get_label(Value val) {
switch (val) { switch (val) {
case VAL_GEAR: case VAL_GEAR:
return "GEAR"; return "GEAR";
case VAL_RPM: case VAL_RPM:
return "RPM"; return "RPM";
case VAL_TT_FL: case VAL_TT_FL:
return "TEMP FL"; return "TEMP FL";
case VAL_TT_FR: case VAL_TT_FR:
return "TEMP FR"; return "TEMP FR";
case VAL_TT_RL: case VAL_TT_RL:
return "TEMP RL"; return "TEMP RL";
case VAL_TT_RR: case VAL_TT_RR:
return "TEMP RR"; return "TEMP RR";
case VAL_LAPTIME: case VAL_LAPTIME:
return "LAPTIME"; return "LAPTIME";
case VAL_UBATT: case VAL_UBATT:
return "BATT VOLTAGE"; return "BATT VOLTAGE";
case VAL_TMOT: case VAL_TMOT:
return "TEMP ENG"; return "TEMP ENG";
case VAL_TAIR: case VAL_TAIR:
return "TEMP AIR"; return "TEMP AIR";
case VAL_TOIL: case VAL_TOIL:
return "TEMP OIL"; return "TEMP OIL";
case VAL_ERR_TYPE: case VAL_ERR_TYPE:
return "ERROR TYPE"; return "ERROR TYPE";
case VAL_PWAT: case VAL_PWAT:
return "PRESS WAT"; return "PRESS WAT";
case VAL_POIL: case VAL_POIL:
return "PRESS OIL"; return "PRESS OIL";
case VAL_PBF: case VAL_PBF:
return "PRESS BRAKE F"; return "PRESS BRAKE F";
case VAL_PBR: case VAL_PBR:
return "PRESS BRAKE R"; return "PRESS BRAKE R";
case VAL_SPEED_FL: case VAL_SPEED_FL:
return "SPEED FL"; return "SPEED FL";
case VAL_SPEED_FR: case VAL_SPEED_FR:
return "SPEED FR"; return "SPEED FR";
case VAL_SPEED: case VAL_SPEED:
return "SPEED"; return "SPEED";
default: default:
return "???"; return "???";
} }
} }
bool check_alarms() { bool check_alarms() {
static uint32_t poil_last_valid, tmot_last_valid, toil_last_valid; static uint32_t poil_last_valid, tmot_last_valid, toil_last_valid;
uint32_t now = millis(); uint32_t now = millis();
if (Vehicle_data.p_oil >= POIL_ALARM_THRESH || Vehicle_data.speed == 0) { if (Vehicle_data.p_oil >= POIL_ALARM_THRESH || Vehicle_data.speed == 0) {
poil_last_valid = now; poil_last_valid = now;
} }
if (Vehicle_data.t_mot <= TMOT_ALARM_THRESH || Vehicle_data.t_mot == TMOT_SAFE_VALUE) { if (Vehicle_data.t_mot <= TMOT_ALARM_THRESH ||
tmot_last_valid = now; Vehicle_data.t_mot == TMOT_SAFE_VALUE) {
} tmot_last_valid = now;
if (Vehicle_data.t_oil <= TOIL_ALARM_THRESH) { }
toil_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 poil_alarm = now - poil_last_valid >= POIL_ALARM_TIME;
bool toil_alarm = now - toil_last_valid >= TOIL_ALARM_TIME; bool tmot_alarm = now - tmot_last_valid >= TMOT_ALARM_TIME;
bool alarm_active = poil_alarm || tmot_alarm || toil_alarm; bool toil_alarm = now - toil_last_valid >= TOIL_ALARM_TIME;
bool alarm_active = poil_alarm || tmot_alarm || toil_alarm;
if (alarm_active) { if (alarm_active) {
String alarm_text = ""; String alarm_text = "";
if (poil_alarm) alarm_text += "PO"; if (poil_alarm)
if (tmot_alarm) alarm_text += "TM"; alarm_text += "PO";
if (toil_alarm) alarm_text += "TO"; if (tmot_alarm)
alarm(alarm_text); alarm_text += "TM";
} if (toil_alarm)
alarm_text += "TO";
alarm(alarm_text);
}
return alarm_active; return alarm_active;
} }
bool check_enc_displays() { bool check_enc_displays() {
static uint8_t trc_old, mode_old; static uint8_t trc_old, mode_old;
static bool display_trc, display_mode; static bool display_trc, display_mode;
static uint32_t display_trc_begin, display_mode_begin; static uint32_t display_trc_begin, display_mode_begin;
return check_display(trc_old, Stw_data.trc, display_trc, display_trc_begin, "ARB") || return check_display(trc_old, Stw_data.trc, display_trc, display_trc_begin,
check_display(mode_old, Stw_data.mode, display_mode, display_mode_begin, "MODE"); "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) { bool check_display(uint8_t& val_old, uint8_t val_new, bool& active,
if (val_old != val_new) { uint32_t& begin, const String& title) {
active = true; if (val_old != val_new) {
begin = millis(); active = true;
val_old = val_new; begin = millis();
tft.clear(); val_old = val_new;
tft.fillDisplayColor(EA_RED); tft.clear();
tft.setTextColor(EA_WHITE, EA_RED); tft.fillDisplayColor(EA_RED);
tft.setTextSize(7,8); tft.setTextColor(EA_WHITE, EA_RED);
String text = title + ":" + val_new; tft.setTextSize(7, 8);
char text_arr[16]; String text = title + ":" + val_new;
text.toCharArray(text_arr, 16); char text_arr[16];
tft.drawText(15, 68, 'C', text_arr); text.toCharArray(text_arr, 16);
} else if (active && millis() - begin > ENC_DISPLAY_TIME) { tft.drawText(15, 68, 'C', text_arr);
tft.setTextColor(EA_WHITE, EA_TRANSPARENT); } else if (active && millis() - begin > ENC_DISPLAY_TIME) {
tft.clear(); tft.setTextColor(EA_WHITE, EA_TRANSPARENT);
active = false; tft.clear();
} active = false;
}
return active; return active;
} }
void update_display(){ void update_display() {
static DisplayPage page = PAGE_DRIVER; static DisplayPage page = PAGE_DRIVER;
static uint32_t last_cleared; static uint32_t last_cleared;
static bool cleared = true; static bool cleared = true;
if (check_alarms()) { if (check_alarms()) {
cleared = true; cleared = true;
return; return;
} }
if (tft.disconnected) { if (tft.disconnected) {
return; return;
} }
if (check_enc_displays()) { if (check_enc_displays()) {
cleared = true; cleared = true;
return; return;
} }
uint32_t now = millis(); uint32_t now = millis();
// Both buttons have to be pressed at the same time, but we also use the // 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 // debounced rises to ensure we don't keep toggling between the pages
if (Stw_data.buttonState1 && Stw_data.buttonState4 && 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)) {
Stw_data.button1_rises = 0; Stw_data.button1_rises = 0;
Stw_data.button4_rises = 0; Stw_data.button4_rises = 0;
page = (DisplayPage) ((page + 1) % DISPLAY_PAGES); page = (DisplayPage)((page + 1) % DISPLAY_PAGES);
tft.clear(); tft.clear();
last_cleared = now; last_cleared = now;
cleared = true; cleared = true;
} }
if (now - last_cleared >= DISP_CLEAR_INTERVAL) { if (now - last_cleared >= DISP_CLEAR_INTERVAL) {
tft.clear(); tft.clear();
last_cleared = now; last_cleared = now;
cleared = true; cleared = true;
} }
if (page == PAGE_DRIVER) { if (page == PAGE_DRIVER) {
if (cleared) { if (cleared) {
redraw_page_driver(); redraw_page_driver();
cleared = false; cleared = false;
} else { } else {
update_page_driver(); update_page_driver();
} }
} else { } else {
if (cleared) { if (cleared) {
redraw_page_testing(); redraw_page_testing();
cleared = false; cleared = false;
} else { } else {
update_page_testing(); update_page_testing();
} }
} }
} }
void alarm(String textstr){ void alarm(String textstr) {
uint8_t x = 1;; uint8_t x = 1;
char text[7]; ;
textstr.toCharArray(text,7); char text[7];
tft.setTextSize(8,8); textstr.toCharArray(text, 7);
while(x==1){ tft.setTextSize(8, 8);
if(!tft.disconnected){ while (x == 1) {
tft.setTextColor(EA_BLACK,EA_RED); if (!tft.disconnected) {
tft.fillDisplayColor(EA_RED); tft.setTextColor(EA_BLACK, EA_RED);
tft.drawText(5,68,'L',text); tft.fillDisplayColor(EA_RED);
} tft.drawText(5, 68, 'L', text);
for (int j = 0; j < 16; j++){ }
digitalWrite(led_s[j], HIGH); for (int j = 0; j < 16; j++) {
} digitalWrite(led_s[j], HIGH);
delay(100); }
if(!tft.disconnected){ delay(100);
tft.setTextColor(EA_BLACK,EA_WHITE); if (!tft.disconnected) {
tft.fillDisplayColor(EA_WHITE); tft.setTextColor(EA_BLACK, EA_WHITE);
tft.drawText(5,68,'L',text); tft.fillDisplayColor(EA_WHITE);
} tft.drawText(5, 68, 'L', text);
for (int j = 0; j < 16; j++){ }
digitalWrite(led_s[j], LOW); for (int j = 0; j < 16; j++) {
} digitalWrite(led_s[j], LOW);
delay(100); }
if(Stw_data.buttonState1 & Stw_data.buttonState4){ delay(100);
x=0; if (Stw_data.buttonState1 & Stw_data.buttonState4) {
tft.setTextColor(EA_WHITE,EA_TRANSPARENT); x = 0;
} tft.setTextColor(EA_WHITE, EA_TRANSPARENT);
} }
}
} }
void redraw_page_driver() { void redraw_page_driver() {
// Boxes // Boxes
tft.drawLine(0, 110, 320, 110); tft.drawLine(0, 110, 320, 110);
tft.drawLine(120, 0, 120, 110); tft.drawLine(120, 0, 120, 110);
tft.drawLine(200, 0, 200, 110); tft.drawLine(200, 0, 200, 110);
// Tire temperature cross // Tire temperature cross
tft.drawLine(80, 180, 240, 180); tft.drawLine(80, 180, 240, 180);
tft.drawLine(160, 130, 160, 230); tft.drawLine(160, 130, 160, 230);
// Boxes // Boxes
gear_box.redraw(); gear_box.redraw();
left_box.redraw(); left_box.redraw();
right_box.redraw(); right_box.redraw();
fl_box.redraw(); fl_box.redraw();
fr_box.redraw(); fr_box.redraw();
rl_box.redraw(); rl_box.redraw();
rr_box.redraw(); rr_box.redraw();
} }
void update_page_driver() { void update_page_driver() {
static Value left_box_value = VAL_FIRST_LEFT_BOX; static Value left_box_value = VAL_FIRST_LEFT_BOX;
if (Stw_data.button4_rises > 0) { if (Stw_data.button4_rises > 0) {
Stw_data.button4_rises--; Stw_data.button4_rises--;
if (left_box_value == VAL_LAST) { if (left_box_value == VAL_LAST) {
left_box_value = VAL_FIRST_LEFT_BOX; left_box_value = VAL_FIRST_LEFT_BOX;
} else { } else {
left_box_value = (Value) (left_box_value + 1); left_box_value = (Value)(left_box_value + 1);
} }
left_box.update_label(get_label(left_box_value)); left_box.update_label(get_label(left_box_value));
if (Stw_data.button1_rises > 0) { }
Stw_data.button1_rises--; if (Stw_data.button1_rises > 0) {
if (left_box_value == VAL_FIRST_LEFT_BOX) { Stw_data.button1_rises--;
left_box_value = VAL_LAST; if (left_box_value == VAL_FIRST_LEFT_BOX) {
} else { left_box_value = VAL_LAST;
left_box_value = (Value) (left_box_value - 1); } else {
} left_box_value = (Value)(left_box_value - 1);
left_box.update_label(get_label(left_box_value)); }
} left_box.update_label(get_label(left_box_value));
}
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)); left_box.update_value(get_value(left_box_value));
right_box.update_value(get_value(VAL_RPM)); right_box.update_value(get_value(VAL_RPM));
fl_box.update_value(2); fl_box.update_value(2);
fr_box.update_value(55); fr_box.update_value(55);
rl_box.update_value(65); rl_box.update_value(65);
rr_box.update_value(90); rr_box.update_value(90);
} }
void redraw_page_testing() { 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() {} 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, DataBox::DataBox(int x1, int y1, int x2, int y2, int text_x, int text_y,
int size_x, int size_y, uint8_t justification) 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}, : 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}, 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)) {
value = val_new; value = val_new;
redraw_value(); redraw_value();
} }
} }
void DataBox::update_label(String label_new) { void DataBox::update_label(String label_new) {
if (!label_new.equals(label)) { if (!label_new.equals(label)) {
label = label_new; label = label_new;
redraw_label(); redraw_label();
} }
} }
void DataBox::redraw() { void DataBox::redraw() {
redraw_value(); redraw_value();
redraw_label(); redraw_label();
} }
void DataBox::redraw_value() { 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:");
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());
} }
void DataBox::redraw_label() { void DataBox::redraw_label() {
tft.setTextFont(EA_FONT7X12); tft.setTextFont(EA_FONT7X12);
tft.setTextSize(1, 1); tft.setTextSize(1, 1);
Serial.println("Redrawing label:"); Serial.println("Redrawing label:");
tft.clearRect(x1, y2 + 1, x2, y2 + 13); tft.clearRect(x1, y2 + 1, x2, y2 + 13);
tft.drawText((x1 + x2) / 2, y2 + 1, 'C', label.c_str()); 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, 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) int font, int size_x, int size_y,
: DataBox{x1, y1, x2, y2, text_x, text_y, font, size_x, size_y, justification}, num_value{-1} {} 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) { void TireTempBox::update_value(int val_new) {
if (val_new != num_value) { if (val_new != num_value) {
num_value = val_new; num_value = val_new;
if (val_new < TT_THRESH1) { if (val_new < TT_THRESH1) {
color = TT_COL0; color = TT_COL0;
} else if (val_new < TT_THRESH2) { } else if (val_new < TT_THRESH2) {
color = TT_COL1; color = TT_COL1;
} else if (val_new < TT_THRESH3) { } else if (val_new < TT_THRESH3) {
color = TT_COL2; color = TT_COL2;
} else { } else {
color = TT_COL3; color = TT_COL3;
} }
String val_str = String(val_new); String val_str = String(val_new);
if (val_str.length() == 1) { if (val_str.length() == 1) {
val_str = " " + val_str; val_str = " " + val_str;
} else if (val_str.length() == 2) { } else if (val_str.length() == 2) {
val_str = " " + val_str; val_str = " " + val_str;
} }
DataBox::update_value(val_str); DataBox::update_value(val_str);
} }
} }
void TireTempBox::redraw_value() { void TireTempBox::redraw_value() {
tft.setTextFont(font); tft.setTextFont(font);
tft.setTextSize(size_x, size_y); tft.setTextSize(size_x, size_y);
tft.drawRectf(x1, y1, x2, y2, color); tft.drawRectf(x1, y1, x2, y2, color);
tft.drawText(text_x, text_y, justification, value.c_str()); tft.drawText(text_x, text_y, justification, value.c_str());
} }
void TireTempBox::redraw_label() {} void TireTempBox::redraw_label() {}

View File

@ -1,19 +1,18 @@
#include "Arduino.h" #include "Arduino.h"
#include "EDIPTFT.h" #include "EDIPTFT.h"
#include "FT_2018_STW_CAN.h"
#include "FT18_STW_INIT.h" #include "FT18_STW_INIT.h"
#include "FT_2018_STW_CAN.h"
#ifndef FT18_STW_DISPLAY_h #ifndef FT18_STW_DISPLAY_h
#define FT18_STW_DISPLAY_h #define FT18_STW_DISPLAY_h
#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
#define POIL_ALARM_THRESH ((uint32_t)(0.1 / 0.0514))
#define POIL_ALARM_THRESH ((uint32_t) (0.1 / 0.0514))
#define POIL_ALARM_TIME 20000 // ms #define POIL_ALARM_TIME 20000 // ms
#define TMOT_ALARM_THRESH (40 + 105) #define TMOT_ALARM_THRESH (40 + 105)
#define TMOT_SAFE_VALUE (40 + 200) #define TMOT_SAFE_VALUE (40 + 200)
@ -22,14 +21,31 @@
#define TOIL_ALARM_TIME 10000 // ms #define TOIL_ALARM_TIME 10000 // ms
#define ENC_DISPLAY_TIME 1000 // ms #define ENC_DISPLAY_TIME 1000 // ms
enum DisplayPage {PAGE_DRIVER, PAGE_TESTING}; enum DisplayPage { PAGE_DRIVER, PAGE_TESTING };
#define DISPLAY_PAGES 2 #define DISPLAY_PAGES 2
enum Value { enum Value {
VAL_GEAR, VAL_RPM, VAL_TT_FL, VAL_TT_FR, VAL_TT_RL, VAL_TT_RR, VAL_LAPTIME, VAL_GEAR,
VAL_UBATT, VAL_TMOT, VAL_TAIR, VAL_TOIL, VAL_ERR_TYPE, VAL_PWAT, VAL_POIL, VAL_RPM,
VAL_PBF, VAL_PBR, VAL_SPEED_FL, VAL_SPEED_FR, VAL_SPEED, VAL_TT_FL,
VAL_FIRST_LEFT_BOX = VAL_LAPTIME, VAL_LAST = VAL_SPEED 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_value(Value val);
String get_label(Value val); String get_label(Value val);
@ -44,7 +60,8 @@ void alarm(String text);
bool check_alarms(); bool check_alarms();
bool check_enc_displays(); bool check_enc_displays();
bool check_display(uint8_t& val_old, uint8_t val_new, bool& active, uint32_t& begin, const String& title); bool check_display(uint8_t& val_old, uint8_t val_new, bool& active,
uint32_t& begin, const String& title);
void redraw_page_driver(); void redraw_page_driver();
void update_page_driver(); void update_page_driver();
@ -53,21 +70,21 @@ void update_page_testing();
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);
void update_value(String val_new); void update_value(String val_new);
void update_label(String label_new); void update_label(String label_new);
void redraw(); void redraw();
virtual void redraw_value(); virtual void redraw_value();
virtual void redraw_label(); virtual void redraw_label();
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;
String value; String value;
String label; String label;
}; };
#define TT_COL0 EA_LIGHTBLUE #define TT_COL0 EA_LIGHTBLUE
@ -80,17 +97,17 @@ protected:
class TireTempBox : public DataBox { class TireTempBox : public DataBox {
public: public:
TireTempBox(int x1, int y1, int x2, int y2, int text_x, int text_y, TireTempBox(int x1, int y1, int x2, int y2, int text_x, int text_y, int font,
int font, int size_x, int size_y, uint8_t justification); int size_x, int size_y, uint8_t justification);
void update_value(int val_new); void update_value(int val_new);
void redraw_value() override; void redraw_value() override;
void redraw_label() override; void redraw_label() override;
private: private:
int color; int color;
int num_value; int num_value;
}; };
#endif #endif

View File

@ -4,139 +4,141 @@
#include <Bounce2.h> #include <Bounce2.h>
#include <RotaryEncoder.h> #include <RotaryEncoder.h>
volatile stw_data_type Stw_data = {0}; //alles mit 0 initialisieren volatile stw_data_type Stw_data = {0}; // alles mit 0 initialisieren
volatile vehicle_data_type Vehicle_data = {0}; //alles mit 0 initialisieren volatile vehicle_data_type Vehicle_data = {0}; // alles mit 0 initialisieren
bool enc1PinALast,enc1PinANow,enc2PinALast,enc2PinANow; bool enc1PinALast, enc1PinANow, enc2PinALast, enc2PinANow;
int led[] = {led1,led2,led3,led4,led5,led6,led7,led8,led9,led10,led11,led12,led13,led14,led15,led16}; int led[] = {led1, led2, led3, led4, led5, led6, led7, led8,
led9, led10, led11, led12, led13, led14, led15, led16};
bool entprell; bool entprell;
int buttons[] = {button1,button2,button3,button4,button5,button6,enc1PinS,enc2PinS}; int buttons[] = {button1, button2, button3, button4,
constexpr size_t N_BUTTONS = sizeof(buttons)/sizeof(buttons[0]); button5, button6, enc1PinS, enc2PinS};
constexpr size_t N_BUTTONS = sizeof(buttons) / sizeof(buttons[0]);
Bounce2::Button debouncer[N_BUTTONS]; Bounce2::Button debouncer[N_BUTTONS];
double val = 0; double val = 0;
double val2 = 0; double val2 = 0;
RotaryEncoder encoder(enc1PinA,enc1PinB,1,1,50); RotaryEncoder encoder(enc1PinA, enc1PinB, 1, 1, 50);
RotaryEncoder encoder2(enc2PinA,enc2PinB,1,1,50); RotaryEncoder encoder2(enc2PinA, enc2PinB, 1, 1, 50);
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
// functions // functions
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
void set_pins(){ void set_pins() {
pinMode (l,OUTPUT); pinMode(l, OUTPUT);
for (int thisLed = 0; thisLed < sizeof(led)/sizeof(int); thisLed++) { for (int thisLed = 0; thisLed < sizeof(led) / sizeof(int); thisLed++) {
pinMode(led[thisLed], OUTPUT); pinMode(led[thisLed], OUTPUT);
} }
pinMode(enc1PinA, INPUT); pinMode(enc1PinA, INPUT);
pinMode(enc1PinB, INPUT); pinMode(enc1PinB, INPUT);
pinMode(enc2PinA, INPUT); pinMode(enc2PinA, INPUT);
pinMode(enc2PinB, INPUT); pinMode(enc2PinB, INPUT);
enc1PinALast=LOW; enc1PinALast = LOW;
enc1PinANow=LOW; enc1PinANow = LOW;
enc2PinALast=LOW; enc2PinALast = LOW;
enc2PinANow=LOW; enc2PinANow = LOW;
for(int i = 0; i < N_BUTTONS; i++){ for (int i = 0; i < N_BUTTONS; i++) {
debouncer[i].attach(buttons[i], INPUT); debouncer[i].attach(buttons[i], INPUT);
debouncer[i].interval(10); debouncer[i].interval(10);
} }
} }
void read_buttons(){ void read_buttons() {
for (int i = 0; i < N_BUTTONS; i++) { for (int i = 0; i < N_BUTTONS; i++) {
debouncer[i].update(); debouncer[i].update();
} }
// These are only used to send them out via CAN, so they only need to be // These are only used to send them out via CAN, so they only need to be
// high once. // high once.
Stw_data.Stw_neutral = debouncer[1].rose(); Stw_data.Stw_neutral = debouncer[1].rose();
Stw_data.Stw_auto_shift = debouncer[2].rose(); Stw_data.Stw_auto_shift = debouncer[2].rose();
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();
Stw_data.buttonState1 = debouncer[0].isPressed(); Stw_data.buttonState1 = debouncer[0].isPressed();
Stw_data.buttonState4 = debouncer[3].isPressed(); Stw_data.buttonState4 = debouncer[3].isPressed();
Stw_data.buttonStateEnc1 = debouncer[6].isPressed(); Stw_data.buttonStateEnc1 = debouncer[6].isPressed();
Stw_data.buttonStateEnc2 = debouncer[7].isPressed(); Stw_data.buttonStateEnc2 = debouncer[7].isPressed();
if (debouncer[0].rose()) { if (debouncer[0].rose()) {
Stw_data.button1_rises++; Stw_data.button1_rises++;
} }
if (debouncer[3].rose()) { if (debouncer[3].rose()) {
Stw_data.button4_rises++; Stw_data.button4_rises++;
} }
if (debouncer[6].rose()) { if (debouncer[6].rose()) {
Stw_data.enc1_rises++; Stw_data.enc1_rises++;
} }
if (debouncer[7].rose()) { if (debouncer[7].rose()) {
Stw_data.enc2_rises++; Stw_data.enc2_rises++;
} }
} }
void read_rotary(){ void read_rotary() {
int enc = encoder.readEncoder(); int enc = encoder.readEncoder();
int enc2 = encoder2.readEncoder(); int enc2 = encoder2.readEncoder();
if(enc != 0){ if (enc != 0) {
val = val +0.5*enc; val = val + 0.5 * enc;
if (val==1 or val ==-1){ if (val == 1 or val == -1) {
if(Stw_data.trc==0 and enc<0){ if (Stw_data.trc == 0 and enc < 0) {
Stw_data.trc = 11; Stw_data.trc = 11;
}else if(Stw_data.trc==11 and enc>0){ } else if (Stw_data.trc == 11 and enc > 0) {
Stw_data.trc=0; Stw_data.trc = 0;
}else{ } else {
Stw_data.trc = Stw_data.trc + enc; Stw_data.trc = Stw_data.trc + enc;
} }
val = 0; val = 0;
} }
} }
/*enc1PinANow = digitalRead(enc1PinA); /*enc1PinANow = digitalRead(enc1PinA);
enc2PinANow = digitalRead(enc2PinA); enc2PinANow = digitalRead(enc2PinA);
if ((enc1PinALast == LOW) && (enc1PinANow == HIGH)) { if ((enc1PinALast == LOW) && (enc1PinANow == HIGH)) {
if (digitalRead(enc1PinB) == HIGH) { if (digitalRead(enc1PinB) == HIGH) {
if(Stw_data.trc==0){ if(Stw_data.trc==0){
Stw_data.trc = 5; Stw_data.trc = 5;
}else{ }else{
Stw_data.trc--; Stw_data.trc--;
} }
}else { }else {
if(Stw_data.trc==5){ if(Stw_data.trc==5){
Stw_data.trc=0; Stw_data.trc=0;
}else{ }else{
Stw_data.trc++; Stw_data.trc++;
} }
} }
} }
enc1PinALast = enc1PinANow; enc1PinALast = enc1PinANow;
/*if (Stw_data.buttonStateEnc1 == HIGH){ /*if (Stw_data.buttonStateEnc1 == HIGH){
digitalWrite(led[Stw_data.i], HIGH); digitalWrite(led[Stw_data.i], HIGH);
}*/ }*/
if(enc2 != 0){ if (enc2 != 0) {
val2 = val2 +0.5*enc2; val2 = val2 + 0.5 * enc2;
if(val2==1 or val2==-1){ if (val2 == 1 or val2 == -1) {
if((Stw_data.mode==1 or Stw_data.mode==0) and enc2<0){ if ((Stw_data.mode == 1 or Stw_data.mode == 0) and enc2 < 0) {
Stw_data.mode = 5; Stw_data.mode = 5;
}else if(Stw_data.mode==5 and enc2>0){ } else if (Stw_data.mode == 5 and enc2 > 0) {
Stw_data.mode=1; Stw_data.mode = 1;
}else{ } else {
Stw_data.mode = Stw_data.mode + enc2; Stw_data.mode = Stw_data.mode + enc2;
} }
val2=0; val2 = 0;
} }
} }
/*if ((enc2PinALast == LOW) && (enc2PinANow == HIGH)) { /*if ((enc2PinALast == LOW) && (enc2PinANow == HIGH)) {
//if(enc2PinALast != enc2PinANow){ //if(enc2PinALast != enc2PinANow){
if (digitalRead(enc2PinB) == HIGH) { if (digitalRead(enc2PinB) == HIGH) {
if(Stw_data.i==0){ if(Stw_data.i==0){
Stw_data.i = sizeof(led)/sizeof(int)-1; Stw_data.i = sizeof(led)/sizeof(int)-1;
}else{ }else{
Stw_data.i--; Stw_data.i--;
} }
}else { }else {
if(Stw_data.i==sizeof(led)/sizeof(int)-1){ if(Stw_data.i==sizeof(led)/sizeof(int)-1){
Stw_data.i=0; Stw_data.i=0;
}else{ }else{
Stw_data.i++; Stw_data.i++;
} }
} }
} }
enc2PinALast = enc2PinANow;*/ enc2PinALast = enc2PinANow;*/
/*if (Stw_data.buttonStateEnc2 == HIGH){ /*if (Stw_data.buttonStateEnc2 == HIGH){
digitalWrite(led[Stw_data.i], HIGH); digitalWrite(led[Stw_data.i], HIGH);
}*/ }*/
} }

View File

@ -2,104 +2,100 @@
#ifndef FT18_STW_Init #ifndef FT18_STW_Init
#define FT18_STW_Init #define FT18_STW_Init
#define l 78 //test_led #define l 78 // test_led
#define led1 12//PD8 #define led1 12 // PD8
#define led2 11//PD7 #define led2 11 // PD7
#define led3 9//PC21 #define led3 9 // PC21
#define led4 8//PC22 #define led4 8 // PC22
#define led5 7//PC23 #define led5 7 // PC23
#define led6 6//PC24 #define led6 6 // PC24
#define led7 5//PC25 #define led7 5 // PC25
#define led8 4//PC26 und PA29 #define led8 4 // PC26 und PA29
#define led9 3//PC28 #define led9 3 // PC28
#define led10 2//PB25 #define led10 2 // PB25
#define led11 10//PC29 und PA28 #define led11 10 // PC29 und PA28
#define led12 22//PB26 #define led12 22 // PB26
#define led13 19//PA10 #define led13 19 // PA10
#define led14 13//PB27 #define led14 13 // PB27
#define led15 17//PA12 #define led15 17 // PA12
#define led16 18//PA11 #define led16 18 // PA11
#define button1 48//bl #define button1 48 // bl
#define button2 47//gl #define button2 47 // gl
#define button3 44//gr #define button3 44 // gr
#define button4 46//br #define button4 46 // br
#define button5 45//sl #define button5 45 // sl
#define button6 49//sr #define button6 49 // sr
#define enc1PinA 37 #define enc1PinA 37
#define enc1PinB 38 #define enc1PinB 38
#define enc1PinS 35 #define enc1PinS 35
#define enc2PinA 40 #define enc2PinA 40
#define enc2PinB 41 #define enc2PinB 41
#define enc2PinS 39 #define enc2PinS 39
// define Drehzahlgrenzen TODOOOO // define Drehzahlgrenzen TODOOOO
#define RPM_THRES_1 1000 #define RPM_THRES_1 1000
#define RPM_THRES_2 6000 #define RPM_THRES_2 6000
#define RPM_THRES_3 7000 #define RPM_THRES_3 7000
#define RPM_THRES_4 8000 #define RPM_THRES_4 8000
#define RPM_THRES_5 10000 #define RPM_THRES_5 10000
#define RPM_THRES_6 14000 #define RPM_THRES_6 14000
#define RPM_THRES_7 17000 #define RPM_THRES_7 17000
#define RPM_THRES_8 18000 #define RPM_THRES_8 18000
#define RPM_THRES_9 20000 #define RPM_THRES_9 20000
#define RPM_THRES_10 20000 #define RPM_THRES_10 20000
void set_pins(void); void set_pins(void);
void read_buttons(void); void read_buttons(void);
void read_rotary(void); // read rotary switches void read_rotary(void); // read rotary switches
typedef struct typedef struct {
{ uint8_t Stw_shift_up; // 1 Bit 0
uint8_t Stw_shift_up; // 1 Bit 0 uint8_t Stw_shift_down; // 1 Bit 1
uint8_t Stw_shift_down; // 1 Bit 1 uint8_t Stw_neutral; // 1 Bit 2
uint8_t Stw_neutral; // 1 Bit 2 uint8_t Stw_auto_shift; // 1 Bit 3
uint8_t Stw_auto_shift; // 1 Bit 3 uint8_t buttonState1; // 1 Bit 4
uint8_t buttonState1; // 1 Bit 4 uint8_t buttonState4; // 1 Bit 5
uint8_t buttonState4; // 1 Bit 5 // bool CAN_toggle;
//bool CAN_toggle; // bool CAN_check;
//bool CAN_check; // 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 : mittlere Drehschalter position // uint8_t br; //test mode : mittlere
uint8_t buttonStateEnc2; //button // Drehschalter position
uint8_t displayindex; //index für Displayanzeige uint8_t buttonStateEnc2; // button
uint8_t error_type; //Extrainfos über Error-LED uint8_t displayindex; // index für Displayanzeige
uint8_t trc; uint8_t error_type; // Extrainfos über Error-LED
uint8_t mode; uint8_t trc;
uint8_t mode;
uint8_t button1_rises; uint8_t button1_rises;
uint8_t button4_rises; uint8_t button4_rises;
uint8_t enc1_rises; uint8_t enc1_rises;
uint8_t enc2_rises; uint8_t enc2_rises;
} stw_data_type; } stw_data_type;
typedef struct typedef struct {
{ uint8_t e_thro; // E-Drossel
uint8_t e_thro; // E-Drossel uint8_t g_auto; // Auto-Shift
uint8_t g_auto; // Auto-Shift uint8_t gear; // Gang
uint8_t gear; // Gang uint16_t revol; // Drehzahl
uint16_t revol; // Drehzahl 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 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; uint8_t p_fuel;
uint8_t p_fuel; uint8_t p_oil;
uint8_t p_oil; uint8_t p_brake_front;
uint8_t p_brake_front; uint8_t p_brake_rear;
uint8_t p_brake_rear; uint8_t speed_fl;
uint8_t speed_fl; uint8_t speed_fr;
uint8_t speed_fr; uint8_t speed;
uint8_t speed;
} vehicle_data_type; } vehicle_data_type;
extern volatile stw_data_type Stw_data;
extern volatile vehicle_data_type Vehicle_data;
extern volatile stw_data_type Stw_data;
extern volatile vehicle_data_type Vehicle_data;
#endif #endif

View File

@ -1,8 +1,8 @@
#include "FT18e_STW_DISPLAY.h"
#include "Arduino.h" #include "Arduino.h"
#include "EDIPTFT.h" #include "EDIPTFT.h"
#include "FT_2018e_STW_CAN.h"
#include "FT18e_STW_INIT.h" #include "FT18e_STW_INIT.h"
#include "FT18e_STW_DISPLAY.h" #include "FT_2018e_STW_CAN.h"
EDIPTFT tft(true, false); EDIPTFT tft(true, false);
String bezeichnungen[] = {"Batterieleistung", "Moment", "Batterietemp"}; String bezeichnungen[] = {"Batterieleistung", "Moment", "Batterietemp"};
@ -22,11 +22,12 @@ int sizeealt;
int sizeeneu; int sizeeneu;
uint8_t clearcounter = 56; uint8_t clearcounter = 56;
uint8_t modealt = Stw_data.mode; uint8_t modealt = Stw_data.mode;
uint8_t trccounter; // = Stw_data.trc; uint8_t trccounter; // = Stw_data.trc;
uint8_t modecounter; // = Stw_data.mode; uint8_t modecounter; // = Stw_data.mode;
bool trctimer; bool trctimer;
bool modetimer; 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 poiltimer;
unsigned long tmottimer; unsigned long tmottimer;
unsigned long toiltimer; unsigned long toiltimer;
@ -34,138 +35,115 @@ bool poilbool = true;
bool tmotbool = true; bool tmotbool = true;
bool toilbool = true; bool toilbool = true;
void init_display() void init_display() {
{ pinMode(writeprotect, OUTPUT);
pinMode(writeprotect, OUTPUT); digitalWrite(writeprotect, HIGH);
digitalWrite(writeprotect, HIGH); pinMode(reset, OUTPUT);
pinMode(reset, OUTPUT); pinMode(disp_cs, OUTPUT);
pinMode(disp_cs, OUTPUT); pinMode(MOSI, OUTPUT);
pinMode(MOSI, OUTPUT); pinMode(MISO, OUTPUT);
pinMode(MISO, OUTPUT); // pinMode(CLK, INPUT);
//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.smallProtoSelect(7); // edip.setNewColor(EA_GREY, 0xe3, 0xe3,0xe3); // redefine r-g-b-values
//edip.setNewColor(EA_GREY, 0xe3, 0xe3,0xe3); // redefine r-g-b-values of EA_GREY // of EA_GREY edip.drawImage(0,50,FASTTUBE_LOGO_PNG);
//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;
/*int h = 20; char charh[2];
char charh[2]; String strh = String(h);
String strh = String(h); strh.toCharArray(charh,2);
strh.toCharArray(charh,2); tft.DisplayLight(charh);*/
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_BLACK); // tft.setTextFont('4');
//tft.setTextFont('4'); tft.setTextSize(5, 8);
tft.setTextSize(5, 8); tft.clear();
tft.clear(); // tft.displayLight('30');
//tft.displayLight('30'); tft.drawText(0, 14, 'C', "FaSTTUBe"); // draw some text
tft.drawText(0, 14, 'C', "FaSTTUBe"); //draw some text // tft.loadImage(0,0,1);
//tft.loadImage(0,0,1); // delay(2000);
//delay(2000);
} }
double get_value(int a) double get_value(int a) { return 0; }
{
return 0; void update_display() {
if (!tft.disconnected) {
tft.cursorOn(false);
if (modealt != Stw_data.mode || modetimer == true) {
display_mode();
} else {
if (clearcounter >= 56) {
tft.clear();
clearcounter = 0;
}
clearcounter += 1;
}
}
} }
void update_display() void display_mode() {
{ if (modealt != Stw_data.mode) {
if (!tft.disconnected) tft.clear();
{ tft.setTextSize(6, 8);
tft.cursorOn(false); tft.setDisplayColor(EA_WHITE, EA_RED);
if (modealt != Stw_data.mode || modetimer == true) tft.setTextColor(EA_WHITE, EA_RED);
{ char modeanzeige[7];
display_mode(); String str = String("MODE:");
} str += String(Stw_data.mode);
else str.toCharArray(modeanzeige, 7);
{ tft.drawText(0, 0, 'L', " ");
if (clearcounter >= 56) tft.drawText(0, 60, 'L', " ");
{ tft.drawText(0, 120, 'L', " ");
tft.clear(); tft.drawText(0, 180, 'L', " ");
clearcounter = 0; tft.drawText(15, 68, 'L', modeanzeige);
} modecounter = 0;
clearcounter += 1; modealt = Stw_data.mode;
} modetimer = true;
} } else if (modecounter >= 255) {
tft.setDisplayColor(EA_WHITE, EA_BLACK);
tft.setTextColor(EA_WHITE, EA_BLACK);
tft.clear();
modetimer = false;
} else {
modecounter += 1;
delay(5);
}
} }
void display_mode() void alarm(String textstr) {
{ uint8_t x = 1;
if (modealt != Stw_data.mode) ;
{ char text[7];
tft.clear(); textstr.toCharArray(text, 7);
tft.setTextSize(6, 8); tft.setTextSize(8, 8);
tft.setDisplayColor(EA_WHITE, EA_RED); while (x == 1) {
tft.setTextColor(EA_WHITE, EA_RED); if (!tft.disconnected) {
char modeanzeige[7]; tft.setTextColor(EA_BLACK, EA_RED);
String str = String("MODE:"); tft.fillDisplayColor(EA_RED);
str += String(Stw_data.mode); tft.drawText(5, 68, 'L', text);
str.toCharArray(modeanzeige, 7); }
tft.drawText(0, 0, 'L', " "); for (int j = 0; j < 16; j++) {
tft.drawText(0, 60, 'L', " "); digitalWrite(led_s[j], HIGH);
tft.drawText(0, 120, 'L', " "); }
tft.drawText(0, 180, 'L', " "); delay(100);
tft.drawText(15, 68, 'L', modeanzeige); if (!tft.disconnected) {
modecounter = 0; tft.setTextColor(EA_BLACK, EA_WHITE);
modealt = Stw_data.mode; tft.fillDisplayColor(EA_WHITE);
modetimer = true; tft.drawText(5, 68, 'L', text);
} }
else if (modecounter >= 255) for (int j = 0; j < 16; j++) {
{ digitalWrite(led_s[j], LOW);
tft.setDisplayColor(EA_WHITE, EA_BLACK); }
tft.setTextColor(EA_WHITE, EA_BLACK); delay(100);
tft.clear(); if (Stw_data.button_ll & Stw_data.button_rr) {
modetimer = false; x = 0;
} tft.setTextColor(EA_WHITE, EA_BLACK);
else }
{ }
modecounter += 1;
delay(5);
}
}
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.button_ll & Stw_data.button_rr)
{
x = 0;
tft.setTextColor(EA_WHITE, EA_BLACK);
}
}
} }

View File

@ -1,7 +1,7 @@
#include "Arduino.h" #include "Arduino.h"
#include "EDIPTFT.h" #include "EDIPTFT.h"
#include "FT_2018e_STW_CAN.h"
#include "FT18e_STW_INIT.h" #include "FT18e_STW_INIT.h"
#include "FT_2018e_STW_CAN.h"
#ifndef FT18e_STW_DISPLAY_h #ifndef FT18e_STW_DISPLAY_h
#define FT18e_STW_DISPLAY_h #define FT18e_STW_DISPLAY_h

View File

@ -1,14 +1,16 @@
#include "Arduino.h"
#include "FT18e_STW_INIT.h" #include "FT18e_STW_INIT.h"
#include "Arduino.h"
#include "Bounce2.h" #include "Bounce2.h"
#include "RotaryEncoder.h" #include "RotaryEncoder.h"
volatile stw_data_type Stw_data = {0}; //alles mit 0 initialisieren volatile stw_data_type Stw_data = {0}; // alles mit 0 initialisieren
volatile vehicle_data_type Vehicle_data = {0}; //alles mit 0 initialisieren volatile vehicle_data_type Vehicle_data = {0}; // alles mit 0 initialisieren
bool enc1PinALast, enc1PinANow, enc2PinALast, enc2PinANow; bool enc1PinALast, enc1PinANow, enc2PinALast, enc2PinANow;
int led[] = {led1, led2, led3, led4, led5, led6, led7, led8, led9, led10, led11, led12, led13, led14, led15, led16}; int led[] = {led1, led2, led3, led4, led5, led6, led7, led8,
led9, led10, led11, led12, led13, led14, led15, led16};
bool entprell; bool entprell;
int buttons[] = {PIN_BUTTON_LL, PIN_BUTTON_LR, PIN_BUTTON_RL, PIN_BUTTON_RR, enc1PinS, enc2PinS}; int buttons[] = {PIN_BUTTON_LL, PIN_BUTTON_LR, PIN_BUTTON_RL,
PIN_BUTTON_RR, enc1PinS, enc2PinS};
Bounce debouncer[8]; Bounce debouncer[8];
double val = 0; double val = 0;
double val2 = 0; double val2 = 0;
@ -18,67 +20,55 @@ RotaryEncoder encoder2(enc2PinA, enc2PinB, 1, 1, 50);
// functions // functions
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
void set_pins() void set_pins() {
{ for (int thisLed = 0; thisLed < sizeof(led) / sizeof(int); thisLed++) {
for (int thisLed = 0; thisLed < sizeof(led) / sizeof(int); thisLed++) pinMode(led[thisLed], OUTPUT);
{ }
pinMode(led[thisLed], OUTPUT); pinMode(l, OUTPUT);
} /*pinMode(button1, INPUT);
pinMode(l, OUTPUT); pinMode(button2, INPUT);
/*pinMode(button1, INPUT); pinMode(button3, INPUT);
pinMode(button2, INPUT); pinMode(button4, INPUT);
pinMode(button3, INPUT); pinMode(button5, INPUT);
pinMode(button4, INPUT); pinMode(button6, INPUT);*/
pinMode(button5, INPUT); pinMode(enc1PinA, INPUT);
pinMode(button6, INPUT);*/ pinMode(enc1PinB, INPUT);
pinMode(enc1PinA, INPUT); // pinMode(enc1PinS, INPUT);
pinMode(enc1PinB, INPUT); pinMode(enc2PinA, INPUT);
//pinMode(enc1PinS, INPUT); pinMode(enc2PinB, INPUT);
pinMode(enc2PinA, INPUT); // pinMode(enc2PinS, INPUT);
pinMode(enc2PinB, INPUT); // Stw_data.i=0;
//pinMode(enc2PinS, INPUT); enc1PinALast = LOW;
//Stw_data.i=0; enc1PinANow = LOW;
enc1PinALast = LOW; enc2PinALast = LOW;
enc1PinANow = LOW; enc2PinANow = LOW;
enc2PinALast = LOW; for (int i = 0; i < sizeof(buttons) / sizeof(*buttons); i++) {
enc2PinANow = LOW; pinMode(buttons[i], INPUT);
for (int i = 0; i < sizeof(buttons) / sizeof(*buttons); i++) debouncer[i].attach(buttons[i]);
{ debouncer[i].interval(10);
pinMode(buttons[i], INPUT); }
debouncer[i].attach(buttons[i]);
debouncer[i].interval(10);
}
} }
void read_buttons() void read_buttons() {
{ Stw_data.button_ll = digitalRead(PIN_BUTTON_LL);
Stw_data.button_ll = digitalRead(PIN_BUTTON_LL); Stw_data.button_lr = digitalRead(PIN_BUTTON_LR);
Stw_data.button_lr = digitalRead(PIN_BUTTON_LR); Stw_data.button_rl = digitalRead(PIN_BUTTON_RL);
Stw_data.button_rl = digitalRead(PIN_BUTTON_RL); Stw_data.button_rr = digitalRead(PIN_BUTTON_RR);
Stw_data.button_rr = digitalRead(PIN_BUTTON_RR);
} }
void read_rotary() void read_rotary() {
{ int enc2 = encoder2.readEncoder();
int enc2 = encoder2.readEncoder(); if (enc2 != 0) {
if (enc2 != 0) val2 = val2 + 0.5 * enc2;
{ if (val2 == 1 or val2 == -1) {
val2 = val2 + 0.5 * enc2; if ((Stw_data.mode == 1 or Stw_data.mode == 0) and enc2 < 0) {
if (val2 == 1 or val2 == -1) Stw_data.mode = 5;
{ } else if (Stw_data.mode == 5 and enc2 > 0) {
if ((Stw_data.mode == 1 or Stw_data.mode == 0) and enc2 < 0) Stw_data.mode = 1;
{ } else {
Stw_data.mode = 5; Stw_data.mode = Stw_data.mode + enc2;
} }
else if (Stw_data.mode == 5 and enc2 > 0) val2 = 0;
{ }
Stw_data.mode = 1; }
}
else
{
Stw_data.mode = Stw_data.mode + enc2;
}
val2 = 0;
}
}
} }

View File

@ -2,23 +2,23 @@
#ifndef FT18e_STW_Init #ifndef FT18e_STW_Init
#define FT18e_STW_Init #define FT18e_STW_Init
#define l 78 //test_led #define l 78 // test_led
#define led1 12 //PD8 #define led1 12 // PD8
#define led2 11 //PD7 #define led2 11 // PD7
#define led3 9 //PC21 #define led3 9 // PC21
#define led4 8 //PC22 #define led4 8 // PC22
#define led5 7 //PC23 #define led5 7 // PC23
#define led6 6 //PC24 #define led6 6 // PC24
#define led7 5 //PC25 #define led7 5 // PC25
#define led8 4 //PC26 und PA29 #define led8 4 // PC26 und PA29
#define led9 3 //PC28 #define led9 3 // PC28
#define led10 2 //PB25 #define led10 2 // PB25
#define led11 10 //PC29 und PA28 #define led11 10 // PC29 und PA28
#define led12 22 //PB26 #define led12 22 // PB26
#define led13 19 //PA10 #define led13 19 // PA10
#define led14 13 //PB27 #define led14 13 // PB27
#define led15 17 //PA12 #define led15 17 // PA12
#define led16 18 //PA11 #define led16 18 // PA11
#define enc1PinA 37 #define enc1PinA 37
#define enc1PinB 38 #define enc1PinB 38
#define enc1PinS 35 #define enc1PinS 35
@ -42,54 +42,51 @@ constexpr int16_t RPM_THRESH_8 = 16000;
constexpr int16_t RPM_THRESH_9 = 18000; constexpr int16_t RPM_THRESH_9 = 18000;
constexpr int16_t RPM_THRESH_10 = 20000; constexpr int16_t RPM_THRESH_10 = 20000;
constexpr int16_t LED_THRESH_T_MOT = 7000; // 1/100°C constexpr int16_t LED_THRESH_T_MOT = 7000; // 1/100°C
constexpr int16_t LED_THRESH_T_INV = 6000; // 1/100°C constexpr int16_t LED_THRESH_T_INV = 6000; // 1/100°C
constexpr int16_t LED_THRESH_T_BAT = 5000; // 1/100°C constexpr int16_t LED_THRESH_T_BAT = 5000; // 1/100°C
constexpr uint16_t LED_THRESH_U_BATT = 350; // 1/100V constexpr uint16_t LED_THRESH_U_BATT = 350; // 1/100V
void set_pins(void); void set_pins(void);
void read_buttons(void); void read_buttons(void);
void read_rotary(void); // read rotary switches void read_rotary(void); // read rotary switches
typedef struct typedef struct {
{ bool button_ll; // Left side, left button
bool button_ll; // Left side, left button bool button_lr; // Left side, right button
bool button_lr; // Left side, right button bool button_rl; // Right side, left button
bool button_rl; // Right side, left button bool button_rr; // Right side, right button
bool button_rr; // Right side, right button uint8_t mode;
uint8_t mode; 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
} stw_data_type; } stw_data_type;
struct InverterData struct InverterData {
{ bool ready;
bool ready; bool derating;
bool derating; bool warning;
bool warning; bool error;
bool error; bool on;
bool on; bool precharge;
bool precharge; bool ams_emerg;
bool ams_emerg; bool ts_active;
bool ts_active;
}; };
typedef struct typedef struct {
{ uint16_t u_cell_min; // Minimale Zellspannung
uint16_t u_cell_min; // Minimale Zellspannung uint16_t u_batt; // Batteriespannung (pre-AIR-voltage)
uint16_t u_batt; // Batteriespannung (pre-AIR-voltage) int16_t t_mot_l; // Motor-Wasser-Temperatur Links
int16_t t_mot_l; // Motor-Wasser-Temperatur Links int16_t t_mot_r; // Motor-Wasser-Temperatur Rechts
int16_t t_mot_r; // Motor-Wasser-Temperatur Rechts int16_t t_cell_max; // Maximale Zelltemperatur
int16_t t_cell_max; // Maximale Zelltemperatur int16_t t_inv;
int16_t t_inv; int16_t t_wat;
int16_t t_wat; int16_t p_wat;
int16_t p_wat; uint8_t speed;
uint8_t speed; InverterData inverter;
InverterData inverter; bool rev_lim; // Drehzahllimit Bit
bool rev_lim; // Drehzahllimit Bit int16_t revol; // Drehzahl
int16_t revol; // Drehzahl int16_t wheel_speed;
int16_t wheel_speed;
} vehicle_data_type; } vehicle_data_type;
extern volatile stw_data_type Stw_data; extern volatile stw_data_type Stw_data;

View File

@ -2,268 +2,280 @@
FT_2018_STW_CAN.cpp FT_2018_STW_CAN.cpp
*/ */
#include "FT_2018_STW_CAN.h"
#include "Arduino.h" #include "Arduino.h"
#include "DueTimer.h" #include "DueTimer.h"
#include "due_can.h"
#include "FT_2018_STW_CAN.h"
#include "FT18_STW_INIT.h" #include "FT18_STW_INIT.h"
#include "due_can.h"
CAN_FRAME can_0_msg; CAN_FRAME can_0_msg;
//can_1_msg.id = 0x110; // can_1_msg.id = 0x110;
int can_0_temp_data = 0; int can_0_temp_data = 0;
int leds[] = {led1,led2,led3,led4,led5,led6,led7,led8,led9,led10,led11,led12,led13,led14,led15,led16}; int leds[] = {led1, led2, led3, led4, led5, led6, led7, led8,
led9, led10, led11, led12, led13, led14, led15, led16};
void Init_Can_0() {
void Init_Can_0(){ Can0.begin(1000000); // set CAN0 baud to 1kbit/s and don`t use enable pin!
Can0.begin(1000000); // set CAN0 baud to 1kbit/s and don`t use enable pin! 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)
Can0.watchFor(0x502); // set CAN RX filter for ID 0x502 and reserves mailbox 1 for rx Can0.watchFor(
Can0.watchFor(0x504); 0x502); // set CAN RX filter for ID 0x502 and reserves mailbox 1 for rx
Can0.watchFor(0x500); Can0.watchFor(0x504);
Can0.watchFor(0x773); // set CAN RX filter for ID 0x773 and reserves mailbox 3 for rx Can0.watchFor(0x500);
Can0.watchFor(0x775); Can0.watchFor(
// Can0.watchFor(0x777); // set CAN RX filter for ID 0x777 and reserves mailbox 5 for rx 0x773); // set CAN RX filter for ID 0x773 and reserves mailbox 3 for rx
Can0.watchFor(0x779); // set CAN RX filter for ID 0x779 and reserves mailbox 6 for rx Can0.watchFor(0x775);
Can0.watchFor(0x77A); // Can0.watchFor(0x777); // set CAN RX filter
Can0.setGeneralCallback(Receive_Can_0); //for ID 0x777 and reserves mailbox 5 for rx
Timer3.attachInterrupt(Send_0x110); // set send interrupt Can0.watchFor(
Timer3.start(10000); // Calls every 10ms 0x779); // set CAN RX filter for ID 0x779 and reserves mailbox 6 for rx
Can0.watchFor(0x77A);
Can0.setGeneralCallback(Receive_Can_0);
Timer3.attachInterrupt(Send_0x110); // set send interrupt
Timer3.start(10000); // Calls every 10ms
} }
void Send_0x110(){ void Send_0x110() {
read_buttons(); read_buttons();
read_rotary(); read_rotary();
can_0_msg.id = 0x110; can_0_msg.id = 0x110;
can_0_msg.fid = 0; can_0_msg.fid = 0;
can_0_msg.rtr = 0; can_0_msg.rtr = 0;
can_0_msg.priority = 0; can_0_msg.priority = 0;
can_0_msg.length = 2; can_0_msg.length = 2;
can_0_msg.extended = 0; can_0_msg.extended = 0;
can_0_temp_data = 0; can_0_temp_data = 0;
can_0_temp_data |= Stw_data.Stw_shift_up & 0b00000001; can_0_temp_data |= Stw_data.Stw_shift_up & 0b00000001;
can_0_temp_data |= Stw_data.Stw_shift_down << 1 & 0b00000010; can_0_temp_data |= Stw_data.Stw_shift_down << 1 & 0b00000010;
can_0_temp_data |= Stw_data.Stw_neutral << 2 & 0b00000100; can_0_temp_data |= Stw_data.Stw_neutral << 2 & 0b00000100;
can_0_temp_data |= Stw_data.Stw_auto_shift << 3 & 0b00001000; can_0_temp_data |= Stw_data.Stw_auto_shift << 3 & 0b00001000;
can_0_temp_data |= Stw_data.buttonStateEnc1 << 5 & 0b00100000; //pitlane can_0_temp_data |= Stw_data.buttonStateEnc1 << 5 & 0b00100000; // pitlane
can_0_msg.data.byte[0] = can_0_temp_data; can_0_msg.data.byte[0] = can_0_temp_data;
can_0_msg.data.byte[1] = Stw_data.trc & 0b00001111; can_0_msg.data.byte[1] = Stw_data.trc & 0b00001111;
can_0_msg.data.byte[2] = Stw_data.mode & 0b00000111; can_0_msg.data.byte[2] = Stw_data.mode & 0b00000111;
if ((Stw_data.Stw_auto_shift << 3 & 0b00001000)){ if ((Stw_data.Stw_auto_shift << 3 & 0b00001000)) {
if(Vehicle_data.g_auto){ if (Vehicle_data.g_auto) {
Vehicle_data.g_auto = false; Vehicle_data.g_auto = false;
}else{ } else {
Vehicle_data.g_auto = true; Vehicle_data.g_auto = true;
} }
} }
Can0.sendFrame(can_0_msg); Can0.sendFrame(can_0_msg);
} }
void Receive_Can_0(CAN_FRAME *temp_message){ void Receive_Can_0(CAN_FRAME *temp_message) {
switch (temp_message->id) { switch (temp_message->id) {
//g_auto // g_auto
case 0x502:{ // eDrossel error bit case 0x502: { // eDrossel error bit
Vehicle_data.e_thro = (temp_message->data.byte[0] & 0x80) | (temp_message->data.byte[0] & 0x40) | (temp_message->data.byte[0] & 0x20) | (temp_message->data.byte[0] & 0x10); // bit 4-7 Vehicle_data.e_thro = (temp_message->data.byte[0] & 0x80) |
(temp_message->data.byte[0] & 0x40) |
(temp_message->data.byte[0] & 0x20) |
(temp_message->data.byte[0] & 0x10); // bit 4-7
if(temp_message->data.byte[0] & 0x80){ if (temp_message->data.byte[0] & 0x80) {
Stw_data.error_type = 1;//"pc_error"; Stw_data.error_type = 1; //"pc_error";
} }
if(temp_message->data.byte[0] & 0x40){ if (temp_message->data.byte[0] & 0x40) {
Stw_data.error_type = 2;//"bse_error"; Stw_data.error_type = 2; //"bse_error";
} }
if(temp_message->data.byte[0] & 0x20){ if (temp_message->data.byte[0] & 0x20) {
Stw_data.error_type = 3;//"aps_error"; Stw_data.error_type = 3; //"aps_error";
} }
if(temp_message->data.byte[0] & 0x10){ if (temp_message->data.byte[0] & 0x10) {
Stw_data.error_type = 4;//"etb_error"; Stw_data.error_type = 4; //"etb_error";
} }
//can_1_temp_data |= g_etb_e << 4; // can_1_temp_data |= g_etb_e << 4;
//can_1_temp_data |= g_aps_e << 5; // can_1_temp_data |= g_aps_e << 5;
//can_1_temp_data |= g_bse_e << 6; // can_1_temp_data |= g_bse_e << 6;
//can_1_temp_data |= g_pc_e << 7; // can_1_temp_data |= g_pc_e << 7;
break; break;
} }
case 0x504:{ //autoshift+gear case 0x504: { // autoshift+gear
//Vehicle_data.g_auto = (temp_message->data.byte[1]) >> 4; // Vehicle_data.g_auto =
Vehicle_data.gear = (temp_message->data.byte[1]) >> 5; // (temp_message->data.byte[1])
break; // >> 4;
} Vehicle_data.gear = (temp_message->data.byte[1]) >> 5;
case 0x773:{ // rpm break;
Vehicle_data.revol = (temp_message->data.byte[4] | temp_message->data.byte[3] << 8); }
break; case 0x773: { // rpm
} Vehicle_data.revol =
case 0x779:{ // battery voltage (temp_message->data.byte[4] | temp_message->data.byte[3] << 8);
Vehicle_data.u_batt = temp_message->data.byte[6]; break;
break; }
} case 0x779: { // battery voltage
/*case 0x77A: // revolution limit bit Vehicle_data.u_batt = temp_message->data.byte[6];
Vehicle_data.rev_lim = (temp_message->data.byte[3] & 0x20) >> 4; break;
switch(temp_message->data.byte[0]) { }
case 0x02: // temp. intercooler /*case 0x77A: // revolution limit bit
Vehicle_data.t_air = temp_message->data.byte[7]; Vehicle_data.rev_lim =
break; (temp_message->data.byte[3] & 0x20) >> 4;
case 0x05: // temp. water switch(temp_message->data.byte[0]) {
Vehicle_data.t_mot = temp_message->data.byte[4]; case 0x02: // temp. intercooler
break; Vehicle_data.t_air =
case 0x04: // temp. oil temp_message->data.byte[7]; break; case 0x05: // temp. water
Vehicle_data.t_oil = temp_message->data.byte[5]; Vehicle_data.t_mot =
case 0x01: { temp_message->data.byte[4]; break; case 0x04: // temp. oil
Vehicle_data.p_wat = temp_message->data.byte[6]; Vehicle_data.t_oil =
Vehicle_data.p_fuel = temp_message->data.byte[7]; temp_message->data.byte[5]; case 0x01: {
Vehicle_data.p_oil = temp_message->data.byte[5]; Vehicle_data.p_wat =
break; temp_message->data.byte[6]; Vehicle_data.p_fuel =
} temp_message->data.byte[7]; Vehicle_data.p_oil =
} temp_message->data.byte[5]; break;
break;*/ }
case 0x77A:{//temp und p }
//g_ms4_idle_b = (temp_message->data.byte[2] & 0b10000000) >> 7; break;*/
//g_ms4_engine_status = (temp_message->data.byte[3] & 0b01000000) >> 6; case 0x77A: { // temp und p
//g_ms4_ignoff_b = (temp_message->data.byte[3] & 0b10000000) >> 7; // g_ms4_idle_b = (temp_message->data.byte[2] &
// Serial.println("CAN 77A"); // 0b10000000)
// for (int i = 0; i < 8; i++) { // >> 7; g_ms4_engine_status = (temp_message->data.byte[3] &
// Serial.print('['); // 0b01000000) >> 6; g_ms4_ignoff_b =
// Serial.print(i); // (temp_message->data.byte[3] & 0b10000000) >> 7;
// Serial.print("] "); // Serial.println("CAN 77A");
// Serial.println(temp_message->data.byte[i], HEX); // for (int i = 0; i < 8; i++) {
// } // Serial.print('[');
// Serial.print(i);
// Serial.print("] ");
// Serial.println(temp_message->data.byte[i], HEX);
// }
if ( temp_message->data.byte[0] == 1){ if (temp_message->data.byte[0] == 1) {
Vehicle_data.p_oil = temp_message->data.byte[5]; Vehicle_data.p_oil = temp_message->data.byte[5];
Vehicle_data.p_fuel = temp_message->data.byte[7]; Vehicle_data.p_fuel = temp_message->data.byte[7];
} } else if (temp_message->data.byte[0] == 2) {
else if ( temp_message->data.byte[0] == 2){ Vehicle_data.t_air = temp_message->data.byte[7];
Vehicle_data.t_air = temp_message->data.byte[7]; } else if (temp_message->data.byte[0] == 4) {
} Vehicle_data.t_oil = temp_message->data.byte[5];
else if ( temp_message->data.byte[0] == 4){ } else if (temp_message->data.byte[0] == 5) {
Vehicle_data.t_oil = temp_message->data.byte[5]; Vehicle_data.t_mot = temp_message->data.byte[4];
} }
else if ( temp_message->data.byte[0] == 5){ break;
Vehicle_data.t_mot = temp_message->data.byte[4]; }
} case 0x775: { // speed
break; Vehicle_data.speed_fl = 2 * (temp_message->data.byte[2]);
} Vehicle_data.speed_fr = 2 * (temp_message->data.byte[3]);
case 0x775:{//speed Vehicle_data.speed = (Vehicle_data.speed_fl + Vehicle_data.speed_fr) / 2;
Vehicle_data.speed_fl = 2*(temp_message->data.byte[2]); break;
Vehicle_data.speed_fr = 2*(temp_message->data.byte[3]); }
Vehicle_data.speed = (Vehicle_data.speed_fl+Vehicle_data.speed_fr)/2; /*case 0x777:{//m4_gear
break; Vehicle_data.gear =
} temp_message->data.byte[0]; break;
/*case 0x777:{//m4_gear }*/
Vehicle_data.gear = temp_message->data.byte[0]; case 0x500: {
break; Vehicle_data.p_brake_front = temp_message->data.byte[1];
}*/ Vehicle_data.p_brake_rear = temp_message->data.byte[2];
case 0x500:{ break;
Vehicle_data.p_brake_front = temp_message->data.byte[1]; }
Vehicle_data.p_brake_rear = temp_message->data.byte[2]; }
break;
}
}
} }
void update_LED(){ void update_LED() {
//Copyright Michael Dietzel // Copyright Michael Dietzel
//m.dietzel@fasttube.de // m.dietzel@fasttube.de
//Edit Michael Witt 05-2015 // Edit Michael Witt 05-2015
//m.witt@fasttube.de // m.witt@fasttube.de
//EDIT BAHA ZARROUKI 05-2107 // EDIT BAHA ZARROUKI 05-2107
//z.baha@fasttube.de // z.baha@fasttube.de
// alle Werte als Hex-Werte angegeben // alle Werte als Hex-Werte angegeben
bool t_oil = (Vehicle_data.t_oil - 40) >= 0x96; // 150°C temp.oil bool t_oil = (Vehicle_data.t_oil - 40) >= 0x96; // 150°C temp.oil
bool t_air = (Vehicle_data.t_air - 40) >= 0x3C; // 60°C temp.llk bool t_air = (Vehicle_data.t_air - 40) >= 0x3C; // 60°C temp.llk
bool t_mot = ((Vehicle_data.t_mot - 40) >= 0x69) and ((Vehicle_data.t_mot - 40)!=0xC8); // 105°C temp.water und !=200 bool t_mot =
((Vehicle_data.t_mot - 40) >= 0x69) and
((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 <= 0xB1; // 12.5V 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;
uint16_t rev = Vehicle_data.revol; uint16_t rev = Vehicle_data.revol;
/*if(Vehicle_data.rev_lim){ /*if(Vehicle_data.rev_lim){
for (int j = 0; j < 10; j++){ for (int j = 0; j < 10; j++){
digitalWrite(leds[j], HIGH); digitalWrite(leds[j], HIGH);
//analogWrite(leds[j], STW_data.br); //nur eine der zwei zeilen //analogWrite(leds[j], STW_data.br); //nur eine der zwei
} zeilen
delay(100); }
for (int j = 0; j < 10; j++){ delay(100);
digitalWrite(leds[j], LOW); for (int j = 0; j < 10; j++){
} digitalWrite(leds[j], LOW);
delay(100); }
}else{*/ delay(100);
/*uint8_t helligkeit = 20; }else{*/
if(RPM_THRES_1 <= rev){ /*uint8_t helligkeit = 20;
analogWrite(led1, helligkeit); if(RPM_THRES_1 <= rev){
}else{ analogWrite(led1, helligkeit);
analogWrite(led1, 0); }else{
} analogWrite(led1, 0);
if(RPM_THRES_2 <= rev){ }
analogWrite(led2, helligkeit); if(RPM_THRES_2 <= rev){
}else{ analogWrite(led2, helligkeit);
analogWrite(led2, 0); }else{
} analogWrite(led2, 0);
if(RPM_THRES_3 <= rev){ }
analogWrite(led3, helligkeit); if(RPM_THRES_3 <= rev){
}else{ analogWrite(led3, helligkeit);
analogWrite(led3, 0); }else{
} analogWrite(led3, 0);
if(RPM_THRES_4 <= rev){ }
analogWrite(led4, helligkeit); if(RPM_THRES_4 <= rev){
}else{ analogWrite(led4, helligkeit);
analogWrite(led4, 0); }else{
} analogWrite(led4, 0);
if(RPM_THRES_5 <= rev){ }
analogWrite(led5, helligkeit); if(RPM_THRES_5 <= rev){
}else{ analogWrite(led5, helligkeit);
analogWrite(led5, 0); }else{
} analogWrite(led5, 0);
if(RPM_THRES_6 <= rev){ }
analogWrite(led6, helligkeit); if(RPM_THRES_6 <= rev){
}else{ analogWrite(led6, helligkeit);
analogWrite(led6, 0); }else{
} analogWrite(led6, 0);
if(RPM_THRES_7 <= rev){ }
analogWrite(led7, helligkeit); if(RPM_THRES_7 <= rev){
}else{ analogWrite(led7, helligkeit);
analogWrite(led7, 0); }else{
} analogWrite(led7, 0);
if(RPM_THRES_8 <= rev){ }
analogWrite(led8, helligkeit); if(RPM_THRES_8 <= rev){
}else{ analogWrite(led8, helligkeit);
analogWrite(led8, 0); }else{
} analogWrite(led8, 0);
if(RPM_THRES_9 <= rev){ }
analogWrite(led9, helligkeit); if(RPM_THRES_9 <= rev){
}else{ analogWrite(led9, helligkeit);
analogWrite(led9, 0); }else{
} analogWrite(led9, 0);
if(RPM_THRES_10 <= rev){ }
analogWrite(led10, helligkeit); if(RPM_THRES_10 <= rev){
}else{ analogWrite(led10, helligkeit);
analogWrite(led10, 0); }else{
}*/ analogWrite(led10, 0);
digitalWrite(led1, RPM_THRES_1 <= rev); }*/
digitalWrite(led2, RPM_THRES_2 <= rev); digitalWrite(led1, RPM_THRES_1 <= rev);
digitalWrite(led3, RPM_THRES_3 <= rev); digitalWrite(led2, RPM_THRES_2 <= rev);
digitalWrite(led4, RPM_THRES_4 <= rev); digitalWrite(led3, RPM_THRES_3 <= rev);
digitalWrite(led5, RPM_THRES_5 <= rev); digitalWrite(led4, RPM_THRES_4 <= rev);
digitalWrite(led6, RPM_THRES_6 <= rev); digitalWrite(led5, RPM_THRES_5 <= rev);
digitalWrite(led7, RPM_THRES_7 <= rev); digitalWrite(led6, RPM_THRES_6 <= rev);
digitalWrite(led8, RPM_THRES_8 <= rev); digitalWrite(led7, RPM_THRES_7 <= rev);
digitalWrite(led9, RPM_THRES_9 <= rev); digitalWrite(led8, RPM_THRES_8 <= rev);
digitalWrite(led10, RPM_THRES_10 <= rev); digitalWrite(led9, RPM_THRES_9 <= rev);
digitalWrite(led10, RPM_THRES_10 <= rev);
digitalWrite(led11, t_mot); // rot, links, oben digitalWrite(led11, t_mot); // rot, links, oben
digitalWrite(led12, t_air); // rot, links, mitte digitalWrite(led12, t_air); // rot, links, mitte
digitalWrite(led13, t_oil); // rot, links, unten digitalWrite(led13, t_oil); // rot, links, unten
digitalWrite(led14, e_dros); // rot, rechts, oben digitalWrite(led14, e_dros); // rot, rechts, oben
digitalWrite(led15, u_batt); // rot rechts, mitte digitalWrite(led15, u_batt); // rot rechts, mitte
digitalWrite(led16, g_auto); // blau rechts, unten digitalWrite(led16, g_auto); // blau rechts, unten
/*if(Vehicle_data.g_auto){ /*if(Vehicle_data.g_auto){
digitalWrite(led16, HIGH); digitalWrite(led16, HIGH);
}else{ }else{
digitalWrite(led16, LOW); digitalWrite(led16, LOW);
}*/ }*/
} }

View File

@ -2,142 +2,136 @@
FT_2018_STW_CAN.cpp FT_2018_STW_CAN.cpp
*/ */
#include "FT_2018e_STW_CAN.h"
#include "Arduino.h" #include "Arduino.h"
#include "DueTimer.h" #include "DueTimer.h"
#include "due_can.h"
#include "FT_2018e_STW_CAN.h"
#include "FT18e_STW_INIT.h" #include "FT18e_STW_INIT.h"
#include "due_can.h"
CAN_FRAME can_0_msg; CAN_FRAME can_0_msg;
//can_1_msg.id = 0x110; // can_1_msg.id = 0x110;
int can_0_temp_data = 0; int can_0_temp_data = 0;
int leds[] = {led1, led2, led3, led4, led5, led6, led7, led8, led9, led10, led11, led12, led13, led14, led15, led16}; int leds[] = {led1, led2, led3, led4, led5, led6, led7, led8,
led9, led10, led11, led12, led13, led14, led15, led16};
void Init_Can_0() void Init_Can_0() {
{ Serial.begin(9600);
Serial.begin(9600); Can0.begin(1000000); // set CAN0 baud to 1kbit/s and don`t use enable pin!
Can0.begin(1000000); // set CAN0 baud to 1kbit/s and don`t use enable pin! 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)
Can0.watchFor(CAN_CELL_STATS_ID); Can0.watchFor(CAN_CELL_STATS_ID);
Can0.watchFor(CAN_BATTERY_STATS_ID); Can0.watchFor(CAN_BATTERY_STATS_ID);
Can0.watchFor(CAN_COOLING_STATS_ID); Can0.watchFor(CAN_COOLING_STATS_ID);
Can0.watchFor(CAN_INVERTER_STATS_ID); Can0.watchFor(CAN_INVERTER_STATS_ID);
Can0.setGeneralCallback(Receive_Can_0); Can0.setGeneralCallback(Receive_Can_0);
Timer3.attachInterrupt(Send_0x110); // set send interrupt Timer3.attachInterrupt(Send_0x110); // set send interrupt
Timer3.start(10000); // Calls every 10ms Timer3.start(10000); // Calls every 10ms
} }
void Send_0x110() void Send_0x110() {
{ read_buttons();
read_buttons(); read_rotary();
read_rotary(); can_0_msg.id = 0x110;
can_0_msg.id = 0x110; can_0_msg.fid = 0;
can_0_msg.fid = 0; can_0_msg.rtr = 0;
can_0_msg.rtr = 0; can_0_msg.priority = 0;
can_0_msg.priority = 0; can_0_msg.length = 2;
can_0_msg.length = 2; can_0_msg.extended = 0;
can_0_msg.extended = 0; can_0_temp_data = 0;
can_0_temp_data = 0; can_0_temp_data |= Stw_data.button_ll << 0;
can_0_temp_data |= Stw_data.button_ll << 0; can_0_temp_data |= Stw_data.button_lr << 1;
can_0_temp_data |= Stw_data.button_lr << 1; can_0_temp_data |= Stw_data.button_rl << 2;
can_0_temp_data |= Stw_data.button_rl << 2; can_0_temp_data |= Stw_data.button_rr << 3;
can_0_temp_data |= Stw_data.button_rr << 3; can_0_msg.data.byte[0] = can_0_temp_data;
can_0_msg.data.byte[0] = can_0_temp_data; can_0_msg.data.byte[1] = Stw_data.mode;
can_0_msg.data.byte[1] = Stw_data.mode; Can0.sendFrame(can_0_msg);
Can0.sendFrame(can_0_msg);
} }
void Receive_Can_0(CAN_FRAME *temp_message) void Receive_Can_0(CAN_FRAME *temp_message) {
{ switch (temp_message->id) {
switch (temp_message->id) case CAN_CELL_STATS_ID:
{ process_cell_stats(temp_message);
case CAN_CELL_STATS_ID: break;
process_cell_stats(temp_message); case CAN_BATTERY_STATS_ID:
break; process_battery_stats(temp_message);
case CAN_BATTERY_STATS_ID: break;
process_battery_stats(temp_message); case CAN_COOLING_STATS_ID:
break; process_cooling_stats(temp_message);
case CAN_COOLING_STATS_ID: break;
process_cooling_stats(temp_message); case CAN_INVERTER_STATS_ID:
break; process_inverter_stats(temp_message);
case CAN_INVERTER_STATS_ID: break;
process_inverter_stats(temp_message); default:
break; // TODO: How to handle this in the car?
default: Serial.print("ERROR: Unknown CAN ID: ");
// TODO: How to handle this in the car? Serial.println(temp_message->id);
Serial.print("ERROR: Unknown CAN ID: "); }
Serial.println(temp_message->id);
}
} }
void process_cell_stats(CAN_FRAME *frame) void process_cell_stats(CAN_FRAME *frame) {
{ CellStats *data = (CellStats *)&frame->data;
CellStats *data = (CellStats *)&frame->data; Vehicle_data.t_cell_max = data->max_cell_temp;
Vehicle_data.t_cell_max = data->max_cell_temp; Vehicle_data.u_cell_min = data->min_cell_voltage;
Vehicle_data.u_cell_min = data->min_cell_voltage;
} }
void process_battery_stats(CAN_FRAME *frame) void process_battery_stats(CAN_FRAME *frame) {
{ BatteryStats *data = (BatteryStats *)&frame->data;
BatteryStats *data = (BatteryStats *)&frame->data; Vehicle_data.u_batt = data->pre_air_voltage;
Vehicle_data.u_batt = data->pre_air_voltage;
} }
void process_cooling_stats(CAN_FRAME *frame) void process_cooling_stats(CAN_FRAME *frame) {
{ CoolingStats *data = (CoolingStats *)&frame->data;
CoolingStats *data = (CoolingStats *)&frame->data; Vehicle_data.p_wat = data->water_pressure;
Vehicle_data.p_wat = data->water_pressure; Vehicle_data.t_wat = data->water_temp;
Vehicle_data.t_wat = data->water_temp; Vehicle_data.t_mot_l = data->motor_l_temp;
Vehicle_data.t_mot_l = data->motor_l_temp; Vehicle_data.t_mot_r = data->motor_r_temp;
Vehicle_data.t_mot_r = data->motor_r_temp;
} }
void process_inverter_stats(CAN_FRAME *frame) void process_inverter_stats(CAN_FRAME *frame) {
{ InverterStats *data = (InverterStats *)&frame->data;
InverterStats *data = (InverterStats *)&frame->data; uint8_t status = data->status;
uint8_t status = data->status; Vehicle_data.inverter.ready = status & CAN_INVERTER_STATS_READY;
Vehicle_data.inverter.ready = status & CAN_INVERTER_STATS_READY; Vehicle_data.inverter.derating = status & CAN_INVERTER_STATS_DERATING;
Vehicle_data.inverter.derating = status & CAN_INVERTER_STATS_DERATING; Vehicle_data.inverter.warning = status & CAN_INVERTER_STATS_WARNING;
Vehicle_data.inverter.warning = status & CAN_INVERTER_STATS_WARNING; Vehicle_data.inverter.error = status & CAN_INVERTER_STATS_ERROR;
Vehicle_data.inverter.error = status & CAN_INVERTER_STATS_ERROR; Vehicle_data.inverter.on = status & CAN_INVERTER_STATS_ON;
Vehicle_data.inverter.on = status & CAN_INVERTER_STATS_ON; Vehicle_data.inverter.precharge = status & CAN_INVERTER_STATS_PRECHARGE;
Vehicle_data.inverter.precharge = status & CAN_INVERTER_STATS_PRECHARGE; Vehicle_data.inverter.ams_emerg = status & CAN_INVERTER_STATS_AMS_EMERG;
Vehicle_data.inverter.ams_emerg = status & CAN_INVERTER_STATS_AMS_EMERG; Vehicle_data.inverter.ts_active = status & CAN_INVERTER_STATS_TS_ACTIVE;
Vehicle_data.inverter.ts_active = status & CAN_INVERTER_STATS_TS_ACTIVE; Vehicle_data.t_inv = data->temp;
Vehicle_data.t_inv = data->temp; Vehicle_data.revol = data->velocity;
Vehicle_data.revol = data->velocity; Vehicle_data.wheel_speed = data->wheel_speed;
Vehicle_data.wheel_speed = data->wheel_speed;
} }
void update_LED() void update_LED() {
{ bool t_mot = (Vehicle_data.t_mot_l > LED_THRESH_T_MOT) ||
bool t_mot = (Vehicle_data.t_mot_l > LED_THRESH_T_MOT) || (Vehicle_data.t_mot_r > LED_THRESH_T_MOT); (Vehicle_data.t_mot_r > LED_THRESH_T_MOT);
bool t_inv = Vehicle_data.t_inv > LED_THRESH_T_INV; bool t_inv = Vehicle_data.t_inv > LED_THRESH_T_INV;
bool t_bat = Vehicle_data.t_cell_max > LED_THRESH_T_BAT; bool t_bat = Vehicle_data.t_cell_max > LED_THRESH_T_BAT;
bool precharge_active = !Vehicle_data.inverter.precharge; bool precharge_active = !Vehicle_data.inverter.precharge;
bool derating = Vehicle_data.inverter.derating; bool derating = Vehicle_data.inverter.derating;
bool u_batt = Vehicle_data.u_cell_min < LED_THRESH_U_BATT; bool u_batt = Vehicle_data.u_cell_min < LED_THRESH_U_BATT;
digitalWrite(led11, t_mot); // rot, links, oben digitalWrite(led11, t_mot); // rot, links, oben
digitalWrite(led12, t_inv); // rot, links, mitte digitalWrite(led12, t_inv); // rot, links, mitte
digitalWrite(led13, t_bat); // rot, links, unten digitalWrite(led13, t_bat); // rot, links, unten
digitalWrite(led14, precharge_active); // rot, rechts, oben digitalWrite(led14, precharge_active); // rot, rechts, oben
digitalWrite(led15, derating); // rot rechts, mitte digitalWrite(led15, derating); // rot rechts, mitte
digitalWrite(led16, u_batt); // blau rechts, unten digitalWrite(led16, u_batt); // blau rechts, unten
bool rev_lim = Vehicle_data.rev_lim; bool rev_lim = Vehicle_data.rev_lim;
int16_t rev = Vehicle_data.revol; int16_t rev = Vehicle_data.revol;
digitalWrite(led1, RPM_THRESH_1 <= rev); digitalWrite(led1, RPM_THRESH_1 <= rev);
digitalWrite(led2, RPM_THRESH_2 <= rev); digitalWrite(led2, RPM_THRESH_2 <= rev);
digitalWrite(led3, RPM_THRESH_3 <= rev); digitalWrite(led3, RPM_THRESH_3 <= rev);
digitalWrite(led4, RPM_THRESH_4 <= rev); digitalWrite(led4, RPM_THRESH_4 <= rev);
digitalWrite(led5, RPM_THRESH_5 <= rev); digitalWrite(led5, RPM_THRESH_5 <= rev);
digitalWrite(led6, RPM_THRESH_6 <= rev); digitalWrite(led6, RPM_THRESH_6 <= rev);
digitalWrite(led7, RPM_THRESH_7 <= rev); digitalWrite(led7, RPM_THRESH_7 <= rev);
digitalWrite(led8, RPM_THRESH_8 <= rev); digitalWrite(led8, RPM_THRESH_8 <= rev);
digitalWrite(led9, RPM_THRESH_9 <= rev); digitalWrite(led9, RPM_THRESH_9 <= rev);
digitalWrite(led10, RPM_THRESH_10 <= rev); digitalWrite(led10, RPM_THRESH_10 <= rev);
} }

View File

@ -31,35 +31,31 @@ void process_cooling_stats(CAN_FRAME *frame);
void process_inverter_stats(CAN_FRAME *frame); void process_inverter_stats(CAN_FRAME *frame);
void update_LED(void); void update_LED(void);
struct CellStats struct CellStats {
{ uint16_t sum_cell_voltage;
uint16_t sum_cell_voltage; int16_t max_cell_temp;
int16_t max_cell_temp; uint16_t max_cell_voltage;
uint16_t max_cell_voltage; uint16_t min_cell_voltage;
uint16_t min_cell_voltage;
}; };
struct BatteryStats struct BatteryStats {
{ uint16_t battery_current;
uint16_t battery_current; uint16_t pre_air_voltage;
uint16_t pre_air_voltage; uint16_t post_air_voltage;
uint16_t post_air_voltage; uint16_t battery_power;
uint16_t battery_power;
}; };
struct CoolingStats struct CoolingStats {
{ int16_t water_pressure;
int16_t water_pressure; int16_t water_temp;
int16_t water_temp; int16_t motor_l_temp;
int16_t motor_l_temp; int16_t motor_r_temp;
int16_t motor_r_temp;
}; };
struct InverterStats struct InverterStats {
{ uint8_t status;
uint8_t status; uint8_t _reserved;
uint8_t _reserved; uint16_t temp;
uint16_t temp; int16_t velocity;
int16_t velocity; int16_t wheel_speed;
int16_t wheel_speed;
}; };

File diff suppressed because it is too large Load Diff

View File

@ -26,15 +26,15 @@
#include "Arduino.h" #include "Arduino.h"
//Devices // Devices
#define EDIP128 1 #define EDIP128 1
#define EDIP160 1 #define EDIP160 1
#define EDIP240 1 #define EDIP240 1
#define EDIP320 2 #define EDIP320 2
//Set your device // Set your device
#define DEVICE EDIP320 #define DEVICE EDIP320
#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_TRANSPARENT 0
@ -72,382 +72,384 @@
#define uint unsigned int #define uint unsigned int
class EDIPTFT { class EDIPTFT {
public: public:
EDIPTFT(boolean smallprotocol=true, boolean disconnected=false); EDIPTFT(boolean smallprotocol = true, boolean disconnected = false);
boolean disconnected; boolean disconnected;
void begin(long baud=115200); void begin(long baud = 115200);
// helper functions // helper functions
char readByte(); char readByte();
char waitandreadByte(); char waitandreadByte();
unsigned char datainBuffer(); unsigned char datainBuffer();
int readBuffer(char* data); int readBuffer(char* data);
void smallProtoSelect(char address); void smallProtoSelect(char address);
void smallProtoDeselect(char address); void smallProtoDeselect(char address);
void sendData(char* data, char len); void sendData(char* data, char len);
// Basic display functions // Basic display functions
/*! \brief Clear display /*! \brief Clear display
* *
* Clear display contents (all pixels off) and remove touch areas * Clear display contents (all pixels off) and remove touch areas
*/ */
void clear(); void clear();
/*! \brief Delete display /*! \brief Delete display
* *
* Delete display contents (all pixels off). Touch areas are still active. * Delete display contents (all pixels off). Touch areas are still active.
*/ */
void deleteDisplay(); void deleteDisplay();
/*! \brief Invert display /*! \brief Invert display
* *
* Invert display contents (invert all pixels) * Invert display contents (invert all pixels)
*/ */
void invert(); void invert();
void setDisplayColor(char fg, char bg); void setDisplayColor(char fg, char bg);
void fillDisplayColor(char bg); void fillDisplayColor(char bg);
/*! \brief Terminal on /*! \brief Terminal on
* *
* Terminal display is switched on if \a on is true * Terminal display is switched on if \a on is true
* *
* \param on determine if terminal is switched on * \param on determine if terminal is switched on
*/ */
void terminalOn(boolean on); void terminalOn(boolean on);
/*! \brief Load internal image /*! \brief Load internal image
* *
* Load internal image with the \a nr (0..255) from the *EEPROM* memory to * Load internal image with the \a nr (0..255) from the *EEPROM* memory to
* \a x1, \a y1 * \a x1, \a y1
* *
* \param x1 x position of image on the display * \param x1 x position of image on the display
* \param y1 y position of image on the display * \param y1 y position of image on the display
* \param nr number of the image on the *EEPROM* * \param nr number of the image on the *EEPROM*
*/ */
void loadImage(int x1, int y1, int nr); void loadImage(int x1, int y1, int nr);
/*! \brief Cursor on/off /*! \brief Cursor on/off
* *
* Switch cursor on/off * Switch cursor on/off
* *
* \param on `n1=0`: cursor is invisible, `n1=1`: cursor flashes * \param on `n1=0`: cursor is invisible, `n1=1`: cursor flashes
*/ */
void cursorOn(boolean on); void cursorOn(boolean on);
/*! \brief Position cursor /*! \brief Position cursor
* *
* origin upper-left corner `(1, 1)` * origin upper-left corner `(1, 1)`
* *
* \param col new cursor column * \param col new cursor column
* \param row new cursor row * \param row new cursor row
*/ */
void setCursor(char col, char row); void setCursor(char col, char row);
void displayLight(char no); void displayLight(char no);
// Bargraph // Bargraph
/*! \brief Define bargraph /*! \brief Define bargraph
* *
* Define bargraph to form the rectangle enclosing the * Define bargraph to form the rectangle enclosing the
* bargraph. \a sv and \a ev are the values for `0%` and `100%`. * bargraph. \a sv and \a ev are the values for `0%` and `100%`.
* *
* \param dir direction ('L'eft, 'R'ight, 'O'up, 'U'down) * \param dir direction ('L'eft, 'R'ight, 'O'up, 'U'down)
* \param no bargraph number `1..32` * \param no bargraph number `1..32`
* \param x1 upper left x coordinate * \param x1 upper left x coordinate
* \param y1 upper left y coordinate * \param y1 upper left y coordinate
* \param x2 lower right x coordinate * \param x2 lower right x coordinate
* \param y2 lower right y coordinate * \param y2 lower right y coordinate
* \param sv start value (0%) * \param sv start value (0%)
* \param ev end value (100%) * \param ev end value (100%)
* \param type set the style of the bargraph:\n * \param type set the style of the bargraph:\n
* `type=0`: pattern bar, \a mst=bar pattern,\n * `type=0`: pattern bar, \a mst=bar pattern,\n
* `type=1`: pattern bar in rectangle, \a mst=bar pattern,\n * `type=1`: pattern bar in rectangle, \a mst=bar pattern,\n
* `type=2`: pattern line, \a mst=line width,\n * `type=2`: pattern line, \a mst=line width,\n
* `type=3`: pattern line in rectangle, \a mst=line width * `type=3`: pattern line in rectangle, \a mst=line width
* *
* \param mst additional parameter for type specification * \param mst additional parameter for type specification
*/ */
void defineBargraph(char dir, char no, int x1, int y1, int x2, int y2, void defineBargraph(char dir, char no, int x1, int y1, int x2, int y2,
byte sv, byte ev, char type, char mst); byte sv, byte ev, char type, char mst);
/*! \brief Update bargraph /*! \brief Update bargraph
* *
* Set and draw the bargraph *no* to the new *value* * Set and draw the bargraph *no* to the new *value*
* *
* \param no number of the bargraph `1..32` * \param no number of the bargraph `1..32`
* \param val new value of the bargraph * \param val new value of the bargraph
*/ */
void updateBargraph(char no, char val); void updateBargraph(char no, char val);
void setBargraphColor(char no, char fg, char bg, char fr); void setBargraphColor(char no, char fg, char bg, char fr);
/*! \brief Set bargraph by touch /*! \brief Set bargraph by touch
* *
* The bargraph with number *no* is defined for input by touch panel * The bargraph with number *no* is defined for input by touch panel
* *
* \param no number of the bargraph `1..32` * \param no number of the bargraph `1..32`
*/ */
void makeBargraphTouch(char no); void makeBargraphTouch(char no);
void linkBargraphLight(char no); void linkBargraphLight(char no);
/*! \brief Delete bargraph /*! \brief Delete bargraph
* *
* The definition of the bargraph with number *no* becomes invalid. If the * The definition of the bargraph with number *no* becomes invalid. If the
* bargraph was defined as input with touch, the touchfield will also be * bargraph was defined as input with touch, the touchfield will also be
* deleted. * deleted.
* *
* \param no number of the bargraph `1..32` * \param no number of the bargraph `1..32`
* \param n1 additional parameter\n * \param n1 additional parameter\n
* `n1=0`: bargraph remains visible\n * `n1=0`: bargraph remains visible\n
* `n1=1`: bargraph is deleted * `n1=1`: bargraph is deleted
*/ */
void deleteBargraph(char no, char n1); void deleteBargraph(char no, char n1);
// Instrument // Instrument
void defineInstrument(char no, int x1, int y1, char image, void defineInstrument(char no, int x1, int y1, char image, char angle,
char angle, char sv, char ev); char sv, char ev);
void updateInstrument(char no, char val); void updateInstrument(char no, char val);
void redrawInstrument(char no); void redrawInstrument(char no);
void deleteInstrument(char no, char n1, char n2); void deleteInstrument(char no, char n1, char n2);
// Text // Text
void setTextColor(char fg, char bg); void setTextColor(char fg, char bg);
/*! \brief Set font /*! \brief Set font
* *
* Set font with the number *font* * Set font with the number *font*
* *
* \param font font number `font=0..15`, use font defines here * \param font font number `font=0..15`, use font defines here
*/ */
void setTextFont(char font); void setTextFont(char font);
void setTextSize(int xsize, int ysize); void setTextSize(int xsize, int ysize);
/*! \brief Set text angle /*! \brief Set text angle
* *
* Set text output angle * Set text output angle
* *
* \param angle text output angle\n * \param angle text output angle\n
`angle=0`: 0° `angle=0`: 0°
`angle=1`: 90° `angle=1`: 90°
*/ */
void setTextAngle(char angle); void setTextAngle(char angle);
/*! \brief Draw text on display /*! \brief Draw text on display
* *
* Draw a *text* on screen. Several lines are separated by the character `|` * Draw a *text* on screen. Several lines are separated by the character `|`
* ($7C). * ($7C).
* * place text between `~`: characters flash on/off * * place text between `~`: characters flash on/off
* * place text between `@`: characters flash inversely * * place text between `@`: characters flash inversely
* * use `\\` as to escape special characters * * use `\\` as to escape special characters
* *
* \param x1: x coordinate * \param x1: x coordinate
* \param y1: y coordinate * \param y1: y coordinate
* \param justification set text justification to `L`(eft), `R`(ight), * \param justification set text justification to `L`(eft), `R`(ight),
* `C`(enter) * `C`(enter)
* \param text text to draw on display * \param text text to draw on display
*/ */
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 /*! \brief Draw text on display in an area
* *
* Draw a *text* on screen. Several lines are separated by the character `|` * Draw a *text* on screen. Several lines are separated by the character `|`
* ($7C). * ($7C).
* * place text between `~`: characters flash on/off * * place text between `~`: characters flash on/off
* * place text between `@`: characters flash inversely * * place text between `@`: characters flash inversely
* * use `\\` as to escape special characters * * use `\\` as to escape special characters
* *
* \param align set alignment in the rectangle. 1 = top left, 2 = top * \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 = * center, 3 = top right, 4 = center left, 5 = center, 6 = center right, 7 =
* bottom left, 8 = bottom center, 9 = bottom right. * bottom left, 8 = bottom center, 9 = bottom right.
* \param text text to draw on display * \param text text to draw on display
*/ */
void drawTextInRect(int x1, int y1, int x2, int y2, uint8_t align, const char* text); 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);
/*! \brief Point size/line thickness /*! \brief Point size/line thickness
* *
* \param x x-point size (1..15) * \param x x-point size (1..15)
* \param y y-point size (1..15) * \param y y-point size (1..15)
*/ */
void setLineThick(char x, char y); void setLineThick(char x, char y);
/*! \brief Draw straight line /*! \brief Draw straight line
* *
* Draw straight line from point *x1*, *y1* to point *x2*, *y2* * Draw straight line from point *x1*, *y1* to point *x2*, *y2*
*/ */
void drawLine(int x1, int y1, int x2, int y2); void drawLine(int x1, int y1, int x2, int y2);
/*! \brief Draw rectangle /*! \brief Draw rectangle
* *
* Draw four straight lines as a rectangle from *x1*, *y1* to *x2*, *y2* * Draw four straight lines as a rectangle from *x1*, *y1* to *x2*, *y2*
*/ */
void drawRect(int x1, int y1, int x2, int y2); void drawRect(int x1, int y1, int x2, int y2);
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 */ /*! \brief Clear rectangular area */
void clearRect(int x1, int y1, int x2, int y2); void clearRect(int x1, int y1, int x2, int y2);
// Touch keys // Touch keys
/*! \brief Define touch key /*! \brief Define touch key
* *
* Key remains pressed as long as there is contact. The area from *x1*, *y1* * Key remains pressed as long as there is contact. The area from *x1*, *y1*
* to *x2*, *y2* is drawn with actual border and defined as a key. * to *x2*, *y2* is drawn with actual border and defined as a key.
* The label is drawn with the current touch font. The first character * The label is drawn with the current touch font. The first character
* determines the alignment of the text (`L`(eft), `R`(ight), `C`(enter)). * determines the alignment of the text (`L`(eft), `R`(ight), `C`(enter)).
* Multiline texts are separated by the character `|`. * Multiline texts are separated by the character `|`.
* *
* \param down return/touchmacro (1-255) if pressed * \param down return/touchmacro (1-255) if pressed
* \param up return/touchmacro (1-255) if released * \param up return/touchmacro (1-255) if released
* \param text label of the touch key * \param text label of the touch key
*/ */
void defineTouchKey(int x1, int y1, int x2, int y2, void defineTouchKey(int x1, int y1, int x2, int y2, char down, char up,
char down, char up, const char* text); const char* text);
/*! \brief Define touch switch /*! \brief Define touch switch
* *
* Status of the switch toggles after each contact. The area from *x1*, *y1* * Status of the switch toggles after each contact. The area from *x1*, *y1*
* to *x2*, *y2* is drawn with actual border and defined as a key. * to *x2*, *y2* is drawn with actual border and defined as a key.
* The label is drawn with the current touch font. The first character * The label is drawn with the current touch font. The first character
* determines the alignment of the text (`L`(eft), `R`(ight), `C`(enter)). * determines the alignment of the text (`L`(eft), `R`(ight), `C`(enter)).
* Multiline texts are separated by the character `|`. * Multiline texts are separated by the character `|`.
* *
* \param down return/touchmacro (1-255) if pressed * \param down return/touchmacro (1-255) if pressed
* \param up return/touchmacro (1-255) if released * \param up return/touchmacro (1-255) if released
* \param text label of the touch key * \param text label of the touch key
*/ */
void defineTouchSwitch(int x1, int y1, int x2, int y2, void defineTouchSwitch(int x1, int y1, int x2, int y2, char down, char up,
char down, char up, const char* text); const char* text);
/*! \brief Define touch switch with image /*! \brief Define touch switch with image
* *
* Status of the switch toggles after each contact. Image number *img* is * Status of the switch toggles after each contact. Image number *img* is
* loaded to *x*, *y* and defined as a switch. * loaded to *x*, *y* and defined as a switch.
* The label is drawn with the current touch font. The first character * The label is drawn with the current touch font. The first character
* determines the alignment of the text (`L`(eft), `R`(ight), `C`(enter)). * determines the alignment of the text (`L`(eft), `R`(ight), `C`(enter)).
* Multiline texts are separated by the character `|`. * Multiline texts are separated by the character `|`.
* *
* \param down return/touchmacro (1-255) if pressed * \param down return/touchmacro (1-255) if pressed
* \param up return/touchmacro (1-255) if released * \param up return/touchmacro (1-255) if released
* \param text label of the touch switch * \param text label of the touch switch
*/ */
void defineTouchSwitch(int x, int y, int img, char downcode, void defineTouchSwitch(int x, int y, int img, char downcode, char upcode,
char upcode, const char* text); const char* text);
/*! \brief Set touch switch /*! \brief Set touch switch
* *
* Set the status of the touch switch with the return code *code* * Set the status of the touch switch with the return code *code*
* to *value*. * to *value*.
* *
* \param code Return code of the switch * \param code Return code of the switch
* \param value `value=0`: OFF, `value=1`: ON * \param value `value=0`: OFF, `value=1`: ON
*/ */
void setTouchSwitch(char code,char value); void setTouchSwitch(char code, char value);
void setTouchkeyColors(char n1, char n2, char n3, void setTouchkeyColors(char n1, char n2, char n3, char s1, char s2, char s3);
char s1, char s2, char s3);
/*! \brief Label font /*! \brief Label font
* *
* Apply font with number *font* for touch key labels * Apply font with number *font* for touch key labels
*/ */
void setTouchkeyFont(char font); void setTouchkeyFont(char font);
void setTouchkeyLabelColors(char nf,char sf); void setTouchkeyLabelColors(char nf, char sf);
/*! \brief Radio group for switches /*! \brief Radio group for switches
* *
* `group=0`: newly defined switches don't belong to a group * `group=0`: newly defined switches don't belong to a group
* `group=1..255`: newly defined switches are assigned to the group with * `group=1..255`: newly defined switches are assigned to the group with
* the given number * the given number
* Only one switch in a group is active at once. All others are deactivated. * Only one switch in a group is active at once. All others are deactivated.
* For switches only the *down code* is applicable. The *up code* will be * For switches only the *down code* is applicable. The *up code* will be
* ignored. * ignored.
*/ */
void setTouchGroup(char group); void setTouchGroup(char group);
/*! \brief Delete toch area by up- or downcode /*! \brief Delete toch area by up- or downcode
* *
* The touch area with the return code is removed from the touch query * The touch area with the return code is removed from the touch query
* *
* \param code the code of the touch area (code=0: all touch areas) * \param code the code of the touch area (code=0: all touch areas)
* \param n1 n1==0: the area remains visible on the display, * \param n1 n1==0: the area remains visible on the display,
* n1==1: the area is deleted * n1==1: the area is deleted
*/ */
void removeTouchArea(char code,char n1); void removeTouchArea(char code, char n1);
// Macro Calls // Macro Calls
/*! \brief Run macro /*! \brief Run macro
* *
* Call the (normal) macro with number *nr* (max. 7 levels). * Call the (normal) macro with number *nr* (max. 7 levels).
*/ */
void callMacro(uint nr); void callMacro(uint nr);
/*! \brief Run touch macro /*! \brief Run touch macro
* *
* Call touch macro with number *nr* (max. 7 levels) * Call touch macro with number *nr* (max. 7 levels)
*/ */
void callTouchMacro(uint nr); void callTouchMacro(uint nr);
/*! \brief Run menu macro /*! \brief Run menu macro
* *
* Call menu macro with number *nr* (max. 7 levels) * Call menu macro with number *nr* (max. 7 levels)
*/ */
void callMenuMacro(uint nr); void callMenuMacro(uint nr);
/*! \brief Define touch key with menu function /*! \brief Define touch key with menu function
* *
* Define the area from *x1*, *y1* to *x2*, *y2* as a menu key. * Define the area from *x1*, *y1* to *x2*, *y2* as a menu key.
* The first character determines the direction in which the menu opens (R=right,L=left,O=up,U=down) * The first character determines the direction in which the menu opens
* The second character determines the alignment of the touch text (C=center,L=left-,R=right justified) * (R=right,L=left,O=up,U=down) The second character determines the alignment
* The menu items are separated by the character '|' ($7C,dec:124) (e.g. "UCkey|item1|item2|item3". * of the touch text (C=center,L=left-,R=right justified) The menu items are
* The key text is written with the current touch font and the menu items are written with the current menu font. The background of the menu is saved automatically. * separated by the character '|' ($7C,dec:124) (e.g.
* \param downcode `1-255` return/touchmacro if pressed * "UCkey|item1|item2|item3". The key text is written with the current touch
* \param upcode `1-255` return/touchmacro if released * font and the menu items are written with the current menu font. The
* \param mnucode return/menumacro+(item nr - 1) after selection of a * background of the menu is saved automatically. \param downcode `1-255`
* menu item * return/touchmacro if pressed \param upcode `1-255` return/touchmacro if
* \param text string with the key text and menu items * released \param mnucode return/menumacro+(item nr - 1) after selection of a
*/ * menu item
void defineTouchMenu(int x1, int y1, int x2, int y2, * \param text string with the key text and menu items
char downcode, char upcode, char mnucode, */
const char *text); void defineTouchMenu(int x1, int y1, int x2, int y2, char downcode,
char upcode, char mnucode, const char* text);
/*! \brief Send *open* signal after a Menu open request has been sent from TFT. /*! \brief Send *open* signal after a Menu open request has been sent from
* * TFT.
* If a touch menu is not set to open automatically the TFT sends a *
* request 'ESC T 0'. This function sends 'ESC N T 2' to open the menu. * If a touch menu is not set to open automatically the TFT sends a
*/ * request 'ESC T 0'. This function sends 'ESC N T 2' to open the menu.
void openTouchMenu(); */
void openTouchMenu();
/*! \brief Set menu font /*! \brief Set menu font
* *
* Set font with number *font* (`0..15`) for menu display * Set font with number *font* (`0..15`) for menu display
*/ */
void setMenuFont(char font); void setMenuFont(char font);
/*! \brief enable/disable touchmenu automation /*! \brief enable/disable touchmenu automation
* *
* if val==true touch menu opens automatically, if val==false touchmenu * if val==true touch menu opens automatically, if val==false touchmenu
* doesn' t open automatically, instead a request is sent to the * doesn' t open automatically, instead a request is sent to the
* host computer, which can then open the menu with openTouchMenu() * host computer, which can then open the menu with openTouchMenu()
*/ */
void setTouchMenuAutomation(bool val); void setTouchMenuAutomation(bool val);
private: private:
boolean _smallprotocol; boolean _smallprotocol;
int _counter; int _counter;
unsigned char bytesAvailable(); unsigned char bytesAvailable();
void waitBytesAvailable(); void waitBytesAvailable();
void sendByte(char data); void sendByte(char data);
void sendSmall(char* data, char len); void sendSmall(char* data, char len);
void sendSmallDC2(char* data, char len); void sendSmallDC2(char* data, char len);
}; };
#endif #endif