e-wagen: Use updated LEDs & kill display
This commit is contained in:
parent
4faddf9248
commit
4d62419d72
|
@ -4,10 +4,10 @@
|
|||
#include "FT18e_STW_INIT.h"
|
||||
#include "FT18e_STW_DISPLAY.h"
|
||||
|
||||
EDIPTFT tft(true,false);
|
||||
String bezeichnungen[]={"Batterieleistung","Moment","Batterietemp"};
|
||||
//"T_mot","T_oil","P_oil","% fa","U_batt","P_wat","T_air",
|
||||
//"P_b_front","P_b_rear","Error Type","Speed_fl","Speed_fr","Speed"};
|
||||
EDIPTFT tft(true, false);
|
||||
String bezeichnungen[] = {"Batterieleistung", "Moment", "Batterietemp"};
|
||||
//"T_mot","T_oil","P_oil","% fa","U_batt","P_wat","T_air",
|
||||
//"P_b_front","P_b_rear","Error Type","Speed_fl","Speed_fr","Speed"};
|
||||
//"Drehzahl","P_fuel","Index"
|
||||
int vergleichsindex;
|
||||
int sizeaalt;
|
||||
|
@ -21,13 +21,12 @@ int sizedneu;
|
|||
int sizeealt;
|
||||
int sizeeneu;
|
||||
uint8_t clearcounter = 56;
|
||||
uint8_t trcalt = Stw_data.trc;
|
||||
uint8_t modealt = Stw_data.mode;
|
||||
uint8_t trccounter;// = Stw_data.trc;
|
||||
uint8_t modecounter;// = Stw_data.mode;
|
||||
uint8_t trccounter; // = Stw_data.trc;
|
||||
uint8_t modecounter; // = Stw_data.mode;
|
||||
bool trctimer;
|
||||
bool modetimer;
|
||||
int led_s[] = {led1,led2,led3,led4,led5,led6,led7,led8,led9,led10,led11,led12,led13,led14,led15,led16};
|
||||
int led_s[] = {led1, led2, led3, led4, led5, led6, led7, led8, led9, led10, led11, led12, led13, led14, led15, led16};
|
||||
unsigned long poiltimer;
|
||||
unsigned long tmottimer;
|
||||
unsigned long toiltimer;
|
||||
|
@ -35,7 +34,8 @@ bool poilbool = true;
|
|||
bool tmotbool = true;
|
||||
bool toilbool = true;
|
||||
|
||||
void init_display() {
|
||||
void init_display()
|
||||
{
|
||||
pinMode(writeprotect, OUTPUT);
|
||||
digitalWrite(writeprotect, HIGH);
|
||||
pinMode(reset, OUTPUT);
|
||||
|
@ -47,11 +47,11 @@ void init_display() {
|
|||
digitalWrite(MOSI, HIGH);
|
||||
digitalWrite(MISO, HIGH);
|
||||
digitalWrite(reset, LOW);
|
||||
//edip.smallProtoSelect(7);
|
||||
//edip.setNewColor(EA_GREY, 0xe3, 0xe3,0xe3); // redefine r-g-b-values of EA_GREY
|
||||
//edip.drawImage(0,50,FASTTUBE_LOGO_PNG);
|
||||
digitalWrite(reset,HIGH);
|
||||
tft.begin(115200); // start display communication
|
||||
//edip.smallProtoSelect(7);
|
||||
//edip.setNewColor(EA_GREY, 0xe3, 0xe3,0xe3); // redefine r-g-b-values of EA_GREY
|
||||
//edip.drawImage(0,50,FASTTUBE_LOGO_PNG);
|
||||
digitalWrite(reset, HIGH);
|
||||
tft.begin(115200); // start display communication
|
||||
/*int h = 20;
|
||||
char charh[2];
|
||||
String strh = String(h);
|
||||
|
@ -59,349 +59,113 @@ void init_display() {
|
|||
tft.DisplayLight(charh);*/
|
||||
tft.cursorOn(false);
|
||||
tft.terminalOn(false);
|
||||
tft.setDisplayColor(EA_WHITE,EA_BLACK);
|
||||
tft.setTextColor(EA_WHITE,EA_BLACK);
|
||||
tft.setDisplayColor(EA_WHITE, EA_BLACK);
|
||||
tft.setTextColor(EA_WHITE, EA_BLACK);
|
||||
//tft.setTextFont('4');
|
||||
tft.setTextSize(5,8);
|
||||
tft.setTextSize(5, 8);
|
||||
tft.clear();
|
||||
//tft.displayLight('30');
|
||||
tft.drawText(0, 14, 'C', "FaSTTUBe"); //draw some text
|
||||
//tft.loadImage(0,0,1);
|
||||
//delay(2000);
|
||||
tft.drawText(0, 14, 'C', "FaSTTUBe"); //draw some text
|
||||
//tft.loadImage(0,0,1);
|
||||
//delay(2000);
|
||||
}
|
||||
|
||||
double get_value(int a){
|
||||
double value;
|
||||
if (a == 0){
|
||||
value = Vehicle_data.gear;
|
||||
//}else if (a == 11){
|
||||
// value = Stw_data.i;
|
||||
//}else if (a == 1){
|
||||
// value = Vehicle_data.revol/2;
|
||||
}else if (a == 1){
|
||||
value = Vehicle_data.t_mot;//-40;
|
||||
}else if (a == 5){
|
||||
value = 0.0706949*Vehicle_data.u_batt;
|
||||
}else if (a == 7){
|
||||
value = Vehicle_data.t_air;//-40;
|
||||
}else if(a == 10){
|
||||
value = Stw_data.error_type;
|
||||
}else if (a == 2){
|
||||
value = Vehicle_data.t_oil;//-40;
|
||||
}else if (a == 6){
|
||||
value = 0.0514*Vehicle_data.p_wat;
|
||||
//}else if (a == 7){
|
||||
// value = 0.0514*Vehicle_data.p_fuel;
|
||||
}else if (a == 3){
|
||||
value = 0.0514*Vehicle_data.p_oil;
|
||||
}else if (a == 8){
|
||||
value = Vehicle_data.p_brake_front;
|
||||
}else if (a == 9){
|
||||
value = Vehicle_data.p_brake_rear;
|
||||
}else if(a == 4){
|
||||
value = 200*Vehicle_data.p_brake_front/(Vehicle_data.p_brake_rear+(2*Vehicle_data.p_brake_front));
|
||||
}else if (a == 11){
|
||||
value = Vehicle_data.speed_fl;
|
||||
}else if (a == 12){
|
||||
value = Vehicle_data.speed_fr;
|
||||
}else if(a == 13){
|
||||
value = Vehicle_data.speed;
|
||||
}
|
||||
return value;
|
||||
double get_value(int a)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void update_display(){
|
||||
/*if(((millis()-poiltimer)>=20000) and poilbool){
|
||||
poilbool = false;
|
||||
alarm("P_oil");
|
||||
}
|
||||
if(((millis()-tmottimer)>=20000) and tmotbool){
|
||||
tmotbool = false;
|
||||
alarm("T_mot");
|
||||
}
|
||||
if(((millis()-toiltimer)>=10000) and toilbool){
|
||||
toilbool = false;
|
||||
alarm("T_oil");
|
||||
}
|
||||
if((0.0514*Vehicle_data.p_oil)>=0,1 or Vehicle_data.speed == 0){
|
||||
poiltimer = millis();
|
||||
}
|
||||
if(((Vehicle_data.t_mot - 40) <= 0x69) or ((Vehicle_data.t_mot - 40)==0xC8)){
|
||||
tmottimer = millis();
|
||||
}
|
||||
if((Vehicle_data.t_oil - 40) <= 0x96){
|
||||
toiltimer = millis();
|
||||
}*/
|
||||
if(Stw_data.buttonState1 & Stw_data.buttonState4){
|
||||
alarm("");
|
||||
}
|
||||
if(!tft._displaybool){
|
||||
void update_display()
|
||||
{
|
||||
if (!tft._displaybool)
|
||||
{
|
||||
tft.cursorOn(false);
|
||||
if(trcalt!=Stw_data.trc or trctimer == true or Stw_data.buttonStateEnc1 == HIGH){
|
||||
display_trc();
|
||||
}else if(modealt!=Stw_data.mode or modetimer == true or Stw_data.buttonStateEnc2 == HIGH){
|
||||
if (modealt != Stw_data.mode || modetimer == true)
|
||||
{
|
||||
display_mode();
|
||||
}else{
|
||||
if(clearcounter>=56){
|
||||
}
|
||||
else
|
||||
{
|
||||
if (clearcounter >= 56)
|
||||
{
|
||||
tft.clear();
|
||||
clearcounter = 0;
|
||||
}
|
||||
clearcounter+=1;
|
||||
if(Stw_data.buttonState4){
|
||||
if(Stw_data.displayindex>=sizeof(bezeichnungen)/sizeof(String)-3){
|
||||
Stw_data.displayindex = 0;
|
||||
delay(250);
|
||||
}else{
|
||||
Stw_data.displayindex+=1;
|
||||
delay(250);
|
||||
}
|
||||
}
|
||||
if(Stw_data.buttonState1){
|
||||
if(Stw_data.displayindex<=0){
|
||||
Stw_data.displayindex = sizeof(bezeichnungen)/sizeof(String)-3;
|
||||
delay(250);
|
||||
}else{
|
||||
Stw_data.displayindex-=1;
|
||||
delay(250);
|
||||
}
|
||||
}
|
||||
if(vergleichsindex!=Stw_data.displayindex){
|
||||
tft.clear();
|
||||
vergleichsindex=Stw_data.displayindex;
|
||||
}
|
||||
int a = sizeof(bezeichnungen[Stw_data.displayindex]);
|
||||
int g = sizeof(bezeichnungen[Stw_data.displayindex+1]);
|
||||
int h = sizeof(bezeichnungen[Stw_data.displayindex+2]);
|
||||
char d[a];
|
||||
char e[g];
|
||||
char f[h];
|
||||
bezeichnungen[Stw_data.displayindex].toCharArray(d,a);
|
||||
bezeichnungen[Stw_data.displayindex+1].toCharArray(e,g);
|
||||
bezeichnungen[Stw_data.displayindex+2].toCharArray(f,h);
|
||||
char b[2];
|
||||
char c[5];
|
||||
char i[5];
|
||||
char j[5];
|
||||
char k[5];
|
||||
char m[5];
|
||||
String str=String(int(get_value(0)));
|
||||
/*if(str.equals(String(0))){
|
||||
str = "N";
|
||||
}*/
|
||||
String str1;
|
||||
String str2;
|
||||
String str3;
|
||||
if(Stw_data.displayindex+1==0 or Stw_data.displayindex+1==2 or Stw_data.displayindex+1==1 or Stw_data.displayindex+1==10 or Stw_data.displayindex+1==7 or Stw_data.displayindex+1==11 or Stw_data.displayindex+1==12 or Stw_data.displayindex+1==13){
|
||||
str1=String(int(get_value(Stw_data.displayindex+1)));
|
||||
}else{
|
||||
str1=String(get_value(Stw_data.displayindex+1));
|
||||
}
|
||||
/*if(Stw_data.displayindex+1 == 10){
|
||||
if(str1.equals(String(1))){
|
||||
str1 = "PC";
|
||||
}else if(str1.equals(String(2))){
|
||||
str1 = "BSE";
|
||||
}else if(str1.equals(String(3))){
|
||||
str1 = "APS";
|
||||
}else if(str1.equals(String(4))){
|
||||
str1 = "ETB";
|
||||
}else if(str1.equals(String(0))){
|
||||
str1 = "None";
|
||||
}
|
||||
}*/
|
||||
if(Stw_data.displayindex+2==0 or Stw_data.displayindex+2==2 or Stw_data.displayindex+2==1 or Stw_data.displayindex+2==10 or Stw_data.displayindex+2==7 or Stw_data.displayindex+2==11 or Stw_data.displayindex+2==12 or Stw_data.displayindex+2==13){
|
||||
str2=String(int(get_value(Stw_data.displayindex+2)));
|
||||
}else{
|
||||
str2=String(get_value(Stw_data.displayindex+2));
|
||||
}
|
||||
/*if(Stw_data.displayindex+2 == 10){
|
||||
if(str2.equals(String(1))){
|
||||
str2 = "PC";
|
||||
}else if(str2.equals(String(2))){
|
||||
str2 = "BSE";
|
||||
}else if(str2.equals(String(3))){
|
||||
str2 = "APS";
|
||||
}else if(str2.equals(String(4))){
|
||||
str2 = "ETB";
|
||||
}else if(str2.equals(String(0))){
|
||||
str2 = "None";
|
||||
}
|
||||
}*/
|
||||
if(Stw_data.displayindex+3==0 or Stw_data.displayindex+3==2 or Stw_data.displayindex+3==1 or Stw_data.displayindex+3==10 or Stw_data.displayindex+3==7 or Stw_data.displayindex+3==11 or Stw_data.displayindex+3==12 or Stw_data.displayindex+3==13){
|
||||
str3=String(int(get_value(Stw_data.displayindex+3)));
|
||||
}else{
|
||||
str3=String(get_value(Stw_data.displayindex+3));
|
||||
}
|
||||
/*if(Stw_data.displayindex+3 == 10){
|
||||
if(str3.equals(String(1))){
|
||||
str3 = "PC";
|
||||
}else if(str3.equals(String(2))){
|
||||
str3 = "BSE";
|
||||
}else if(str3.equals(String(3))){
|
||||
str3 = "APS";
|
||||
}else if(str3.equals(String(4))){
|
||||
str3 = "ETB";
|
||||
}else if(str3.equals(String(0))){
|
||||
str3 = "None";
|
||||
}
|
||||
}*/
|
||||
String str5=String(Vehicle_data.revol/2);
|
||||
String str4=String(0.0514*Vehicle_data.p_fuel);
|
||||
str.toCharArray(b,2);
|
||||
str1.toCharArray(c,5);
|
||||
str2.toCharArray(i,5);
|
||||
str3.toCharArray(j,5);
|
||||
str4.toCharArray(k,5);
|
||||
str5.toCharArray(m,5);
|
||||
sizeaneu = strlen(c);
|
||||
sizebneu = strlen(i);
|
||||
sizecneu = strlen(j);
|
||||
sizedneu = strlen(k);
|
||||
sizeeneu = strlen(m);
|
||||
if(sizeaalt!=sizeaneu){
|
||||
tft.clear();
|
||||
sizeaalt=sizeaneu;
|
||||
}
|
||||
if(sizebalt!=sizebneu){
|
||||
tft.clear();
|
||||
sizebalt=sizebneu;
|
||||
}
|
||||
if(sizecalt!=sizecneu){
|
||||
tft.clear();
|
||||
sizecalt=sizecneu;
|
||||
}
|
||||
if(sizedalt!=sizedneu){
|
||||
tft.clear();
|
||||
sizedalt=sizedneu;
|
||||
}
|
||||
if(sizeealt!=sizeeneu){
|
||||
tft.clear();
|
||||
sizeealt=sizeeneu;
|
||||
}
|
||||
tft.setTextSize(6,8);
|
||||
tft.drawText(132, 0, 'L', b);
|
||||
tft.setTextSize(2,7);
|
||||
tft.drawText(0, 20, 'L', k);
|
||||
tft.drawText(240, 20, 'L', m);
|
||||
tft.drawText(0,130, 'L', c);
|
||||
tft.drawText(120, 130, 'L', i);
|
||||
tft.drawText(240,130, 'L', j);
|
||||
tft.setTextSize(1,1);
|
||||
tft.drawText(136,116, 'L', "Energiemodus");
|
||||
tft.drawText(0,116, 'L', "U_Batt");
|
||||
tft.drawText(240,116, 'L', "Drehzahl");
|
||||
tft.drawText(0,226, 'L', d);
|
||||
tft.drawText(120,226, 'L', e);
|
||||
tft.drawText(240,226, 'L', f);
|
||||
/*if (cleaner){
|
||||
tft.setTextSize(5,8);
|
||||
tft.drawText(0, 14, 'C', "FaSTTUBe"); // draw some text
|
||||
tft.setTextSize(4,4);
|
||||
tft.drawText(24, 120, 'C', "insert coin"); // draw some text
|
||||
tft.drawText(0, 180, 'C', "to continue");
|
||||
cleaner = false;
|
||||
}else{
|
||||
tft.setTextSize(5,8);
|
||||
tft.drawText(0, 14, 'C', "FaSTTUBe"); // draw some text
|
||||
tft.setTextSize(4,4);
|
||||
tft.drawText(24, 120, 'C', " "); // draw some text
|
||||
tft.drawText(0, 180, 'C', " ");
|
||||
cleaner = true;
|
||||
}
|
||||
delay(80);*/
|
||||
clearcounter += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void display_trc(){
|
||||
if(trcalt!=Stw_data.trc or Stw_data.buttonStateEnc1 == HIGH){
|
||||
void display_mode()
|
||||
{
|
||||
if (modealt != Stw_data.mode)
|
||||
{
|
||||
tft.clear();
|
||||
tft.setTextSize(7,8);
|
||||
tft.setDisplayColor(EA_WHITE,EA_RED);
|
||||
tft.setTextColor(EA_WHITE,EA_RED);
|
||||
char trcanzeige[7];
|
||||
String str = String("ARB:");
|
||||
if(Stw_data.trc==11){
|
||||
str+="ED";
|
||||
}else{
|
||||
str+=String(Stw_data.trc);
|
||||
}
|
||||
str.toCharArray(trcanzeige,7);
|
||||
tft.drawText(0,0,'L'," ");
|
||||
tft.drawText(0,60,'L'," ");
|
||||
tft.drawText(0,120,'L'," ");
|
||||
tft.drawText(0,180,'L'," ");
|
||||
tft.drawText(15,68,'L',trcanzeige);
|
||||
trccounter = 0;
|
||||
trcalt = Stw_data.trc;
|
||||
trctimer = true;
|
||||
}else if(trccounter >= 255){
|
||||
tft.setDisplayColor(EA_WHITE,EA_BLACK);
|
||||
tft.setTextColor(EA_WHITE,EA_BLACK);
|
||||
tft.clear();
|
||||
trctimer = false;
|
||||
}else{
|
||||
trccounter+=1;
|
||||
delay(5);
|
||||
}
|
||||
}
|
||||
|
||||
void display_mode(){
|
||||
if(modealt!=Stw_data.mode or Stw_data.buttonStateEnc2 == HIGH){
|
||||
tft.clear();
|
||||
tft.setTextSize(6,8);
|
||||
tft.setDisplayColor(EA_WHITE,EA_RED);
|
||||
tft.setTextColor(EA_WHITE,EA_RED);
|
||||
tft.setTextSize(6, 8);
|
||||
tft.setDisplayColor(EA_WHITE, EA_RED);
|
||||
tft.setTextColor(EA_WHITE, EA_RED);
|
||||
char modeanzeige[7];
|
||||
String str = String("MODE:");
|
||||
str+=String(Stw_data.mode);
|
||||
str.toCharArray(modeanzeige,7);
|
||||
tft.drawText(0,0,'L'," ");
|
||||
tft.drawText(0,60,'L'," ");
|
||||
tft.drawText(0,120,'L'," ");
|
||||
tft.drawText(0,180,'L'," ");
|
||||
tft.drawText(15,68,'L',modeanzeige);
|
||||
str += String(Stw_data.mode);
|
||||
str.toCharArray(modeanzeige, 7);
|
||||
tft.drawText(0, 0, 'L', " ");
|
||||
tft.drawText(0, 60, 'L', " ");
|
||||
tft.drawText(0, 120, 'L', " ");
|
||||
tft.drawText(0, 180, 'L', " ");
|
||||
tft.drawText(15, 68, 'L', modeanzeige);
|
||||
modecounter = 0;
|
||||
modealt = Stw_data.mode;
|
||||
modetimer = true;
|
||||
}else if(modecounter >= 255){
|
||||
tft.setDisplayColor(EA_WHITE,EA_BLACK);
|
||||
tft.setTextColor(EA_WHITE,EA_BLACK);
|
||||
}
|
||||
else if (modecounter >= 255)
|
||||
{
|
||||
tft.setDisplayColor(EA_WHITE, EA_BLACK);
|
||||
tft.setTextColor(EA_WHITE, EA_BLACK);
|
||||
tft.clear();
|
||||
modetimer = false;
|
||||
}else{
|
||||
modecounter+=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
modecounter += 1;
|
||||
delay(5);
|
||||
}
|
||||
}
|
||||
|
||||
void alarm(String textstr){
|
||||
uint8_t x = 1;;
|
||||
void alarm(String textstr)
|
||||
{
|
||||
uint8_t x = 1;
|
||||
;
|
||||
char text[7];
|
||||
textstr.toCharArray(text,7);
|
||||
tft.setTextSize(8,8);
|
||||
while(x==1){
|
||||
if(!tft._displaybool){
|
||||
tft.setTextColor(EA_BLACK,EA_RED);
|
||||
textstr.toCharArray(text, 7);
|
||||
tft.setTextSize(8, 8);
|
||||
while (x == 1)
|
||||
{
|
||||
if (!tft._displaybool)
|
||||
{
|
||||
tft.setTextColor(EA_BLACK, EA_RED);
|
||||
tft.fillDisplayColor(EA_RED);
|
||||
tft.drawText(5,68,'L',text);
|
||||
tft.drawText(5, 68, 'L', text);
|
||||
}
|
||||
for (int j = 0; j < 16; j++){
|
||||
for (int j = 0; j < 16; j++)
|
||||
{
|
||||
digitalWrite(led_s[j], HIGH);
|
||||
}
|
||||
delay(100);
|
||||
if(!tft._displaybool){
|
||||
tft.setTextColor(EA_BLACK,EA_WHITE);
|
||||
if (!tft._displaybool)
|
||||
{
|
||||
tft.setTextColor(EA_BLACK, EA_WHITE);
|
||||
tft.fillDisplayColor(EA_WHITE);
|
||||
tft.drawText(5,68,'L',text);
|
||||
tft.drawText(5, 68, 'L', text);
|
||||
}
|
||||
for (int j = 0; j < 16; j++){
|
||||
for (int j = 0; j < 16; j++)
|
||||
{
|
||||
digitalWrite(led_s[j], LOW);
|
||||
}
|
||||
delay(100);
|
||||
if(Stw_data.buttonState1 & Stw_data.buttonState4){
|
||||
x=0;
|
||||
tft.setTextColor(EA_WHITE,EA_BLACK);
|
||||
if (Stw_data.button_ll & Stw_data.button_rr)
|
||||
{
|
||||
x = 0;
|
||||
tft.setTextColor(EA_WHITE, EA_BLACK);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,26 +3,24 @@
|
|||
#include "FT_2018e_STW_CAN.h"
|
||||
#include "FT18e_STW_INIT.h"
|
||||
#ifndef FT18e_STW_DISPLAY_h
|
||||
#define FT18e_STW_DISPLAY_h
|
||||
|
||||
#define EA_BLACK 1
|
||||
#define EA_RED 3
|
||||
#define EA_GREY 10
|
||||
#define EA_WHITE 8
|
||||
#define FT18e_STW_DISPLAY_h
|
||||
|
||||
#define MOSI 75
|
||||
#define MISO 74
|
||||
#define CLK 76
|
||||
#define disp_cs 42
|
||||
#define reset 43
|
||||
#define writeprotect 52
|
||||
#define EA_BLACK 1
|
||||
#define EA_RED 3
|
||||
#define EA_GREY 10
|
||||
#define EA_WHITE 8
|
||||
|
||||
#define MOSI 75
|
||||
#define MISO 74
|
||||
#define CLK 76
|
||||
#define disp_cs 42
|
||||
#define reset 43
|
||||
#define writeprotect 52
|
||||
|
||||
void init_display(void);
|
||||
void update_display(void);
|
||||
double get_value(int a);
|
||||
void display_mode(void);
|
||||
void alarm(String text);
|
||||
|
||||
void init_display(void);
|
||||
void update_display(void);
|
||||
double get_value(int a);
|
||||
void display_trc(void);
|
||||
void display_mode(void);
|
||||
void alarm(String text);
|
||||
|
||||
#endif
|
|
@ -3,26 +3,28 @@
|
|||
#include "Bounce2.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
|
||||
bool enc1PinALast,enc1PinANow,enc2PinALast,enc2PinANow;
|
||||
int led[] = {led1,led2,led3,led4,led5,led6,led7,led8,led9,led10,led11,led12,led13,led14,led15,led16};
|
||||
bool enc1PinALast, enc1PinANow, enc2PinALast, enc2PinANow;
|
||||
int led[] = {led1, led2, led3, led4, led5, led6, led7, led8, led9, led10, led11, led12, led13, led14, led15, led16};
|
||||
bool entprell;
|
||||
int buttons[] = {button1,button2,button3,button4,button5,button6,enc1PinS,enc2PinS};
|
||||
int buttons[] = {PIN_BUTTON_LL, PIN_BUTTON_LR, PIN_BUTTON_RL, PIN_BUTTON_RR, enc1PinS, enc2PinS};
|
||||
Bounce debouncer[8];
|
||||
double val = 0;
|
||||
double val2 = 0;
|
||||
RotaryEncoder encoder(enc1PinA,enc1PinB,1,1,50);
|
||||
RotaryEncoder encoder2(enc2PinA,enc2PinB,1,1,50);
|
||||
RotaryEncoder encoder(enc1PinA, enc1PinB, 1, 1, 50);
|
||||
RotaryEncoder encoder2(enc2PinA, enc2PinB, 1, 1, 50);
|
||||
///////////////////////////////////////////////////
|
||||
// functions
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
void set_pins(){
|
||||
pinMode (l,OUTPUT);
|
||||
for (int thisLed = 0; thisLed < sizeof(led)/sizeof(int); thisLed++) {
|
||||
void set_pins()
|
||||
{
|
||||
for (int thisLed = 0; thisLed < sizeof(led) / sizeof(int); thisLed++)
|
||||
{
|
||||
pinMode(led[thisLed], OUTPUT);
|
||||
}
|
||||
pinMode(l, OUTPUT);
|
||||
/*pinMode(button1, INPUT);
|
||||
pinMode(button2, INPUT);
|
||||
pinMode(button3, INPUT);
|
||||
|
@ -36,165 +38,47 @@ void set_pins(){
|
|||
pinMode(enc2PinB, INPUT);
|
||||
//pinMode(enc2PinS, INPUT);
|
||||
//Stw_data.i=0;
|
||||
enc1PinALast=LOW;
|
||||
enc1PinANow=LOW;
|
||||
enc2PinALast=LOW;
|
||||
enc2PinANow=LOW;
|
||||
for(int i = 0; i < 8; i++){
|
||||
enc1PinALast = LOW;
|
||||
enc1PinANow = LOW;
|
||||
enc2PinALast = LOW;
|
||||
enc2PinANow = LOW;
|
||||
for (int i = 0; i < sizeof(buttons) / sizeof(*buttons); i++)
|
||||
{
|
||||
pinMode(buttons[i], INPUT);
|
||||
debouncer[i].attach(buttons[i]);
|
||||
debouncer[i].interval(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void read_buttons(){
|
||||
/*entprell = digitalRead(button3);
|
||||
delay(10);
|
||||
if(digitalRead(button3)){
|
||||
Stw_data.Stw_auto_shift = entprell;
|
||||
}
|
||||
entprell = digitalRead(button2);
|
||||
delay(10);
|
||||
if(digitalRead(button2)){
|
||||
Stw_data.Stw_neutral = entprell;
|
||||
}
|
||||
entprell = digitalRead(button1);
|
||||
delay(10);
|
||||
if(digitalRead(button1)){
|
||||
Stw_data.buttonState1 = entprell;
|
||||
}
|
||||
entprell = digitalRead(button6);
|
||||
delay(10);
|
||||
if(digitalRead(button6)){
|
||||
Stw_data.Stw_shift_up = entprell;
|
||||
}
|
||||
entprell = digitalRead(button5);
|
||||
delay(10);
|
||||
if(digitalRead(button5)){
|
||||
Stw_data.Stw_shift_down = entprell;
|
||||
}
|
||||
entprell = digitalRead(button4);
|
||||
delay(10);
|
||||
if(digitalRead(button4)){
|
||||
Stw_data.buttonState4 = entprell;
|
||||
}
|
||||
entprell = digitalRead(enc1PinS);
|
||||
delay(10);
|
||||
if(digitalRead(enc1PinS)){
|
||||
Stw_data.buttonStateEnc1 = entprell;
|
||||
}
|
||||
entprell = digitalRead(enc2PinS);
|
||||
delay(10);
|
||||
if(digitalRead(enc2PinS)){
|
||||
Stw_data.buttonStateEnc2 = entprell;
|
||||
}*/
|
||||
Stw_data.Stw_auto_shift = digitalRead(button3);
|
||||
Stw_data.Stw_neutral = digitalRead(button2);
|
||||
Stw_data.buttonState1 = digitalRead(button1);
|
||||
Stw_data.Stw_shift_up = digitalRead(button6);
|
||||
Stw_data.Stw_shift_down = digitalRead(button5);
|
||||
Stw_data.buttonState4 = digitalRead(button4);
|
||||
Stw_data.buttonStateEnc1 = digitalRead(enc1PinS);
|
||||
Stw_data.buttonStateEnc2 = digitalRead(enc2PinS);
|
||||
|
||||
/*for(int i = 0;i < 8; i++){
|
||||
debouncer[i].update();
|
||||
}
|
||||
debouncer[2].update();
|
||||
if(debouncer[2].fell()){
|
||||
Stw_data.Stw_auto_shift = HIGH;
|
||||
}
|
||||
if(debouncer[1].fell()){
|
||||
Stw_data.Stw_neutral = digitalRead(button2);
|
||||
}
|
||||
if(debouncer[0].fell()){
|
||||
Stw_data.buttonState1 = digitalRead(button1);
|
||||
}
|
||||
if(debouncer[5].fell()){
|
||||
Stw_data.Stw_shift_up = digitalRead(button6);
|
||||
}
|
||||
if(debouncer[4].fell()){
|
||||
Stw_data.Stw_shift_down = digitalRead(button5);
|
||||
}
|
||||
if(debouncer[3].fell()){
|
||||
Stw_data.buttonState4 = digitalRead(button4);
|
||||
}
|
||||
if(debouncer[6].fell()){
|
||||
Stw_data.buttonStateEnc1 = digitalRead(enc1PinS);
|
||||
}
|
||||
if(debouncer[7].fell()){
|
||||
Stw_data.buttonStateEnc2 = digitalRead(enc2PinS);
|
||||
}*/
|
||||
}
|
||||
|
||||
void read_rotary(){
|
||||
int enc = encoder.readEncoder();
|
||||
void read_buttons()
|
||||
{
|
||||
Stw_data.button_ll = digitalRead(PIN_BUTTON_LL);
|
||||
Stw_data.button_lr = digitalRead(PIN_BUTTON_LR);
|
||||
Stw_data.button_rl = digitalRead(PIN_BUTTON_RL);
|
||||
Stw_data.button_rr = digitalRead(PIN_BUTTON_RR);
|
||||
}
|
||||
|
||||
void read_rotary()
|
||||
{
|
||||
int enc2 = encoder2.readEncoder();
|
||||
if(enc != 0){
|
||||
val = val +0.5*enc;
|
||||
if (val==1 or val ==-1){
|
||||
if(Stw_data.trc==0 and enc<0){
|
||||
Stw_data.trc = 11;
|
||||
}else if(Stw_data.trc==11 and enc>0){
|
||||
Stw_data.trc=0;
|
||||
}else{
|
||||
Stw_data.trc = Stw_data.trc + enc;
|
||||
}
|
||||
val = 0;
|
||||
}
|
||||
}
|
||||
/*enc1PinANow = digitalRead(enc1PinA);
|
||||
enc2PinANow = digitalRead(enc2PinA);
|
||||
if ((enc1PinALast == LOW) && (enc1PinANow == HIGH)) {
|
||||
if (digitalRead(enc1PinB) == HIGH) {
|
||||
if(Stw_data.trc==0){
|
||||
Stw_data.trc = 5;
|
||||
}else{
|
||||
Stw_data.trc--;
|
||||
}
|
||||
}else {
|
||||
if(Stw_data.trc==5){
|
||||
Stw_data.trc=0;
|
||||
}else{
|
||||
Stw_data.trc++;
|
||||
}
|
||||
}
|
||||
}
|
||||
enc1PinALast = enc1PinANow;
|
||||
/*if (Stw_data.buttonStateEnc1 == HIGH){
|
||||
digitalWrite(led[Stw_data.i], HIGH);
|
||||
}*/
|
||||
if(enc2 != 0){
|
||||
val2 = val2 +0.5*enc2;
|
||||
if(val2==1 or val2==-1){
|
||||
if((Stw_data.mode==1 or Stw_data.mode==0) and enc2<0){
|
||||
if (enc2 != 0)
|
||||
{
|
||||
val2 = val2 + 0.5 * enc2;
|
||||
if (val2 == 1 or val2 == -1)
|
||||
{
|
||||
if ((Stw_data.mode == 1 or Stw_data.mode == 0) and enc2 < 0)
|
||||
{
|
||||
Stw_data.mode = 5;
|
||||
}else if(Stw_data.mode==5 and enc2>0){
|
||||
Stw_data.mode=1;
|
||||
}else{
|
||||
}
|
||||
else if (Stw_data.mode == 5 and enc2 > 0)
|
||||
{
|
||||
Stw_data.mode = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
Stw_data.mode = Stw_data.mode + enc2;
|
||||
}
|
||||
val2=0;
|
||||
val2 = 0;
|
||||
}
|
||||
}
|
||||
/*if ((enc2PinALast == LOW) && (enc2PinANow == HIGH)) {
|
||||
//if(enc2PinALast != enc2PinANow){
|
||||
if (digitalRead(enc2PinB) == HIGH) {
|
||||
if(Stw_data.i==0){
|
||||
Stw_data.i = sizeof(led)/sizeof(int)-1;
|
||||
}else{
|
||||
Stw_data.i--;
|
||||
}
|
||||
}else {
|
||||
if(Stw_data.i==sizeof(led)/sizeof(int)-1){
|
||||
Stw_data.i=0;
|
||||
}else{
|
||||
Stw_data.i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
enc2PinALast = enc2PinANow;*/
|
||||
/*if (Stw_data.buttonStateEnc2 == HIGH){
|
||||
digitalWrite(led[Stw_data.i], HIGH);
|
||||
}*/
|
||||
}
|
|
@ -2,100 +2,97 @@
|
|||
#ifndef FT18e_STW_Init
|
||||
#define FT18e_STW_Init
|
||||
|
||||
#define l 78 //test_led
|
||||
#define led1 12//PD8
|
||||
#define led2 11//PD7
|
||||
#define led3 9//PC21
|
||||
#define led4 8//PC22
|
||||
#define led5 7//PC23
|
||||
#define led6 6//PC24
|
||||
#define led7 5//PC25
|
||||
#define led8 4//PC26 und PA29
|
||||
#define led9 3//PC28
|
||||
#define led10 2//PB25
|
||||
#define led11 10//PC29 und PA28
|
||||
#define led12 22//PB26
|
||||
#define led13 19//PA10
|
||||
#define led14 13//PB27
|
||||
#define led15 17//PA12
|
||||
#define led16 18//PA11
|
||||
#define button1 48//bl
|
||||
#define button2 47//gl
|
||||
#define button3 44//gr
|
||||
#define button4 46//br
|
||||
#define button5 45//sl
|
||||
#define button6 49//sr
|
||||
#define enc1PinA 37
|
||||
#define enc1PinB 38
|
||||
#define enc1PinS 35
|
||||
#define enc2PinA 40
|
||||
#define enc2PinB 41
|
||||
#define enc2PinS 39
|
||||
#define l 78 //test_led
|
||||
#define led1 12 //PD8
|
||||
#define led2 11 //PD7
|
||||
#define led3 9 //PC21
|
||||
#define led4 8 //PC22
|
||||
#define led5 7 //PC23
|
||||
#define led6 6 //PC24
|
||||
#define led7 5 //PC25
|
||||
#define led8 4 //PC26 und PA29
|
||||
#define led9 3 //PC28
|
||||
#define led10 2 //PB25
|
||||
#define led11 10 //PC29 und PA28
|
||||
#define led12 22 //PB26
|
||||
#define led13 19 //PA10
|
||||
#define led14 13 //PB27
|
||||
#define led15 17 //PA12
|
||||
#define led16 18 //PA11
|
||||
#define enc1PinA 37
|
||||
#define enc1PinB 38
|
||||
#define enc1PinS 35
|
||||
#define enc2PinA 40
|
||||
#define enc2PinB 41
|
||||
#define enc2PinS 39
|
||||
|
||||
constexpr int PIN_BUTTON_LL = 47;
|
||||
constexpr int PIN_BUTTON_LR = 48;
|
||||
constexpr int PIN_BUTTON_RL = 46;
|
||||
constexpr int PIN_BUTTON_RR = 44;
|
||||
|
||||
// define Drehzahlgrenzen TODOOOO
|
||||
#define RPM_THRES_1 1000
|
||||
#define RPM_THRES_2 6000
|
||||
#define RPM_THRES_3 7000
|
||||
#define RPM_THRES_4 8000
|
||||
#define RPM_THRES_5 10000
|
||||
#define RPM_THRES_6 14000
|
||||
#define RPM_THRES_7 17000
|
||||
#define RPM_THRES_8 18000
|
||||
#define RPM_THRES_9 20000
|
||||
#define RPM_THRES_10 20000
|
||||
constexpr int16_t RPM_THRESH_1 = 1000;
|
||||
constexpr int16_t RPM_THRESH_2 = 4000;
|
||||
constexpr int16_t RPM_THRESH_3 = 6000;
|
||||
constexpr int16_t RPM_THRESH_4 = 8000;
|
||||
constexpr int16_t RPM_THRESH_5 = 10000;
|
||||
constexpr int16_t RPM_THRESH_6 = 12000;
|
||||
constexpr int16_t RPM_THRESH_7 = 14000;
|
||||
constexpr int16_t RPM_THRESH_8 = 16000;
|
||||
constexpr int16_t RPM_THRESH_9 = 18000;
|
||||
constexpr int16_t RPM_THRESH_10 = 20000;
|
||||
|
||||
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_BAT = 5000; // 1/100°C
|
||||
constexpr uint16_t LED_THRESH_U_BATT = 350; // 1/100V
|
||||
|
||||
void set_pins(void);
|
||||
void read_buttons(void);
|
||||
void read_rotary(void); // read rotary switches
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Stw_shift_up; // 1 Bit 0
|
||||
uint8_t Stw_shift_down; // 1 Bit 1
|
||||
uint8_t Stw_neutral; // 1 Bit 2
|
||||
uint8_t Stw_auto_shift; // 1 Bit 3
|
||||
uint8_t buttonState1; // 1 Bit 4
|
||||
uint8_t buttonState4; // 1 Bit 5
|
||||
//bool CAN_toggle;
|
||||
//bool CAN_check;
|
||||
//uint8_t i; //Index linker Drehschalter
|
||||
uint8_t buttonStateEnc1; // button
|
||||
//uint8_t br; //test mode : mittlere Drehschalter position
|
||||
uint8_t buttonStateEnc2; //button
|
||||
uint8_t displayindex; //index für Displayanzeige
|
||||
uint8_t error_type; //Extrainfos über Error-LED
|
||||
uint8_t trc;
|
||||
uint8_t mode;
|
||||
|
||||
} stw_data_type;
|
||||
{
|
||||
bool button_ll; // Left side, left button
|
||||
bool button_lr; // Left side, right button
|
||||
bool button_rl; // Right side, left button
|
||||
bool button_rr; // Right side, right button
|
||||
uint8_t mode;
|
||||
uint8_t displayindex; //index für Displayanzeige
|
||||
uint8_t error_type; //Extrainfos über Error-LED
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t e_thro; // E-Drossel
|
||||
uint8_t g_auto; // Auto-Shift
|
||||
uint8_t gear; // Gang
|
||||
uint16_t revol; // Drehzahl
|
||||
uint8_t t_oil; // Öl-Motor-Temperatur
|
||||
uint8_t t_mot; // Wasser-Motor-Temperatur
|
||||
uint8_t t_air; // LLK-Temperatur
|
||||
uint8_t u_batt; // Batteriespannung
|
||||
uint8_t rev_lim; // Drehzahllimit Bit
|
||||
uint8_t p_wat;
|
||||
uint8_t p_fuel;
|
||||
uint8_t p_oil;
|
||||
uint8_t p_brake_front;
|
||||
uint8_t p_brake_rear;
|
||||
uint8_t speed_fl;
|
||||
uint8_t speed_fr;
|
||||
uint8_t speed;
|
||||
|
||||
} vehicle_data_type;
|
||||
} stw_data_type;
|
||||
|
||||
|
||||
extern volatile stw_data_type Stw_data;
|
||||
extern volatile vehicle_data_type Vehicle_data;
|
||||
struct InverterData
|
||||
{
|
||||
bool ready;
|
||||
bool derating;
|
||||
bool warning;
|
||||
bool error;
|
||||
bool on;
|
||||
bool precharge;
|
||||
bool ams_emerg;
|
||||
bool ts_active;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t e_thro; // E-Drossel
|
||||
int16_t revol; // Drehzahl
|
||||
int16_t t_mot_l; // Motor-Wasser-Temperatur Links
|
||||
int16_t t_mot_r; // Motor-Wasser-Temperatur Rechts
|
||||
int16_t t_cell_max; // Maximale Zelltemperatur
|
||||
uint16_t u_cell_min; // Minimale Zellspannung
|
||||
uint16_t u_batt; // Batteriespannung (pre-AIR-voltage)
|
||||
bool rev_lim; // Drehzahllimit Bit
|
||||
int16_t p_wat;
|
||||
int16_t t_wat;
|
||||
uint8_t speed;
|
||||
InverterData inverter;
|
||||
int16_t t_inv;
|
||||
} vehicle_data_type;
|
||||
|
||||
extern volatile stw_data_type Stw_data;
|
||||
extern volatile vehicle_data_type Vehicle_data;
|
||||
|
||||
#endif
|
|
@ -11,26 +11,24 @@ FT_2018_STW_CAN.cpp
|
|||
CAN_FRAME can_0_msg;
|
||||
//can_1_msg.id = 0x110;
|
||||
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(){
|
||||
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 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(0x504);
|
||||
Can0.watchFor(0x500);
|
||||
Can0.watchFor(0x773); // set CAN RX filter for ID 0x773 and reserves mailbox 3 for rx
|
||||
Can0.watchFor(0x775);
|
||||
// Can0.watchFor(0x777); // set CAN RX filter for ID 0x777 and reserves mailbox 5 for rx
|
||||
Can0.watchFor(0x779); // set CAN RX filter for ID 0x779 and reserves mailbox 6 for rx
|
||||
Can0.watchFor(0x77A);
|
||||
void Init_Can_0()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
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 available (the other 7 mailboxes are for rx)
|
||||
Can0.watchFor(CAN_CELL_STATS_ID);
|
||||
Can0.watchFor(CAN_BATTERY_STATS_ID);
|
||||
Can0.watchFor(CAN_COOLING_STATS_ID);
|
||||
Can0.watchFor(CAN_INVERTER_STATS_ID);
|
||||
Can0.setGeneralCallback(Receive_Can_0);
|
||||
Timer3.attachInterrupt(Send_0x110); // set send interrupt
|
||||
Timer3.start(10000); // Calls every 10ms
|
||||
Timer3.attachInterrupt(Send_0x110); // set send interrupt
|
||||
Timer3.start(10000); // Calls every 10ms
|
||||
}
|
||||
|
||||
void Send_0x110(){
|
||||
void Send_0x110()
|
||||
{
|
||||
read_buttons();
|
||||
read_rotary();
|
||||
can_0_msg.id = 0x110;
|
||||
|
@ -40,223 +38,106 @@ void Send_0x110(){
|
|||
can_0_msg.length = 2;
|
||||
can_0_msg.extended = 0;
|
||||
can_0_temp_data = 0;
|
||||
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_neutral << 2 & 0b00000100;
|
||||
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.button_ll << 0;
|
||||
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_rr << 3;
|
||||
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[2] = Stw_data.mode & 0b00000111;
|
||||
if ((Stw_data.Stw_auto_shift << 3 & 0b00001000)){
|
||||
if(Vehicle_data.g_auto){
|
||||
Vehicle_data.g_auto = false;
|
||||
}else{
|
||||
Vehicle_data.g_auto = true;
|
||||
}
|
||||
}
|
||||
can_0_msg.data.byte[1] = Stw_data.mode;
|
||||
Can0.sendFrame(can_0_msg);
|
||||
}
|
||||
|
||||
void Receive_Can_0(CAN_FRAME *temp_message){
|
||||
switch (temp_message->id) {
|
||||
//g_auto
|
||||
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
|
||||
|
||||
if(temp_message->data.byte[0] & 0x80){
|
||||
Stw_data.error_type = 1;//"pc_error";
|
||||
}
|
||||
if(temp_message->data.byte[0] & 0x40){
|
||||
Stw_data.error_type = 2;//"bse_error";
|
||||
}
|
||||
if(temp_message->data.byte[0] & 0x20){
|
||||
Stw_data.error_type = 3;//"aps_error";
|
||||
}
|
||||
if(temp_message->data.byte[0] & 0x10){
|
||||
Stw_data.error_type = 4;//"etb_error";
|
||||
}
|
||||
//can_1_temp_data |= g_etb_e << 4;
|
||||
//can_1_temp_data |= g_aps_e << 5;
|
||||
//can_1_temp_data |= g_bse_e << 6;
|
||||
//can_1_temp_data |= g_pc_e << 7;
|
||||
break;
|
||||
}
|
||||
case 0x504:{ //autoshift+gear
|
||||
//Vehicle_data.g_auto = (temp_message->data.byte[1]) >> 4;
|
||||
Vehicle_data.gear = (temp_message->data.byte[1]) >> 5;
|
||||
break;
|
||||
}
|
||||
case 0x773:{ // rpm
|
||||
Vehicle_data.revol = (temp_message->data.byte[4] | temp_message->data.byte[3] << 8);
|
||||
break;
|
||||
}
|
||||
case 0x779:{ // battery voltage
|
||||
Vehicle_data.u_batt = temp_message->data.byte[6];
|
||||
break;
|
||||
}
|
||||
/*case 0x77A: // revolution limit bit
|
||||
Vehicle_data.rev_lim = (temp_message->data.byte[3] & 0x20) >> 4;
|
||||
switch(temp_message->data.byte[0]) {
|
||||
case 0x02: // temp. intercooler
|
||||
Vehicle_data.t_air = temp_message->data.byte[7];
|
||||
break;
|
||||
case 0x05: // temp. water
|
||||
Vehicle_data.t_mot = temp_message->data.byte[4];
|
||||
break;
|
||||
case 0x04: // temp. oil
|
||||
Vehicle_data.t_oil = temp_message->data.byte[5];
|
||||
case 0x01: {
|
||||
Vehicle_data.p_wat = 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;
|
||||
//g_ms4_engine_status = (temp_message->data.byte[3] & 0b01000000) >> 6;
|
||||
//g_ms4_ignoff_b = (temp_message->data.byte[3] & 0b10000000) >> 7;
|
||||
|
||||
if ( temp_message->data.byte[0] == 1){
|
||||
Vehicle_data.p_oil = temp_message->data.byte[5];
|
||||
Vehicle_data.p_fuel = temp_message->data.byte[7];
|
||||
}
|
||||
else if ( temp_message->data.byte[0] == 2){
|
||||
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] == 5){
|
||||
Vehicle_data.t_mot = temp_message->data.byte[4];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 0x775:{//speed
|
||||
Vehicle_data.speed_fl = 2*(temp_message->data.byte[2]);
|
||||
Vehicle_data.speed_fr = 2*(temp_message->data.byte[3]);
|
||||
Vehicle_data.speed = (Vehicle_data.speed_fl+Vehicle_data.speed_fr)/2;
|
||||
break;
|
||||
}
|
||||
/*case 0x777:{//m4_gear
|
||||
Vehicle_data.gear = temp_message->data.byte[0];
|
||||
break;
|
||||
}*/
|
||||
case 0x500:{
|
||||
Vehicle_data.p_brake_front = temp_message->data.byte[1];
|
||||
Vehicle_data.p_brake_rear = temp_message->data.byte[2];
|
||||
break;
|
||||
}
|
||||
void Receive_Can_0(CAN_FRAME *temp_message)
|
||||
{
|
||||
switch (temp_message->id)
|
||||
{
|
||||
case CAN_CELL_STATS_ID:
|
||||
process_cell_stats(temp_message);
|
||||
break;
|
||||
case CAN_BATTERY_STATS_ID:
|
||||
process_battery_stats(temp_message);
|
||||
break;
|
||||
case CAN_COOLING_STATS_ID:
|
||||
process_cooling_stats(temp_message);
|
||||
break;
|
||||
case CAN_INVERTER_STATS_ID:
|
||||
process_inverter_stats(temp_message);
|
||||
break;
|
||||
default:
|
||||
// TODO: How to handle this in the car?
|
||||
Serial.print("ERROR: Unknown CAN ID: ");
|
||||
Serial.println(temp_message->id);
|
||||
}
|
||||
}
|
||||
|
||||
void update_LED(){
|
||||
//Copyright Michael Dietzel
|
||||
//m.dietzel@fasttube.de
|
||||
//Edit Michael Witt 05-2015
|
||||
//m.witt@fasttube.de
|
||||
void process_cell_stats(CAN_FRAME *frame)
|
||||
{
|
||||
CellStats *data = (CellStats *)&frame->data;
|
||||
Vehicle_data.t_cell_max = data->max_cell_temp;
|
||||
Vehicle_data.u_cell_min = data->min_cell_voltage;
|
||||
}
|
||||
|
||||
//EDIT BAHA ZARROUKI 05-2107
|
||||
//z.baha@fasttube.de
|
||||
void process_battery_stats(CAN_FRAME *frame)
|
||||
{
|
||||
BatteryStats *data = (BatteryStats *)&frame->data;
|
||||
Vehicle_data.u_batt = data->pre_air_voltage;
|
||||
}
|
||||
|
||||
void process_cooling_stats(CAN_FRAME *frame)
|
||||
{
|
||||
CoolingStats *data = (CoolingStats *)&frame->data;
|
||||
Vehicle_data.p_wat = data->water_pressure;
|
||||
Vehicle_data.t_wat = data->water_temp;
|
||||
Vehicle_data.t_mot_l = data->motor_l_temp;
|
||||
Vehicle_data.t_mot_r = data->motor_r_temp;
|
||||
}
|
||||
|
||||
void process_inverter_stats(CAN_FRAME *frame)
|
||||
{
|
||||
InverterStats *data = (InverterStats *)&frame->data;
|
||||
uint8_t status = data->status;
|
||||
Vehicle_data.inverter.ready = status & CAN_INVERTER_STATS_READY;
|
||||
Vehicle_data.inverter.derating = status & CAN_INVERTER_STATS_DERATING;
|
||||
Vehicle_data.inverter.warning = status & CAN_INVERTER_STATS_WARNING;
|
||||
Vehicle_data.inverter.error = status & CAN_INVERTER_STATS_ERROR;
|
||||
Vehicle_data.inverter.on = status & CAN_INVERTER_STATS_ON;
|
||||
Vehicle_data.inverter.precharge = status & CAN_INVERTER_STATS_PRECHARGE;
|
||||
Vehicle_data.inverter.ams_emerg = status & CAN_INVERTER_STATS_AMS_EMERG;
|
||||
Vehicle_data.inverter.ts_active = status & CAN_INVERTER_STATS_TS_ACTIVE;
|
||||
Vehicle_data.t_inv = data->temp;
|
||||
Vehicle_data.revol = data->velocity;
|
||||
Serial.print("invVelocity: ");
|
||||
Serial.println(data->velocity);
|
||||
}
|
||||
|
||||
void update_LED()
|
||||
{
|
||||
bool t_mot = (Vehicle_data.t_mot_l > 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_bat = Vehicle_data.t_cell_max > LED_THRESH_T_BAT;
|
||||
|
||||
bool u_batt = Vehicle_data.u_cell_min < LED_THRESH_U_BATT;
|
||||
bool precharge_active = !Vehicle_data.inverter.precharge;
|
||||
|
||||
digitalWrite(led11, t_mot); // rot, links, oben
|
||||
digitalWrite(led12, t_inv); // rot, links, mitte
|
||||
digitalWrite(led13, t_bat); // rot, links, unten
|
||||
|
||||
digitalWrite(led14, precharge_active); // rot, rechts, oben
|
||||
digitalWrite(led15, LOW); // rot rechts, mitte
|
||||
digitalWrite(led16, u_batt); // blau rechts, unten
|
||||
|
||||
// alle Werte als Hex-Werte angegeben
|
||||
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_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 u_batt = Vehicle_data.u_batt <= 0xB1; // 12.5V batt.spann.
|
||||
bool e_dros = Vehicle_data.e_thro; // error-bit
|
||||
|
||||
bool rev_lim = Vehicle_data.rev_lim;
|
||||
|
||||
uint16_t rev = Vehicle_data.revol;
|
||||
|
||||
/*if(Vehicle_data.rev_lim){
|
||||
for (int j = 0; j < 10; j++){
|
||||
digitalWrite(leds[j], HIGH);
|
||||
//analogWrite(leds[j], STW_data.br); //nur eine der zwei zeilen
|
||||
}
|
||||
delay(100);
|
||||
for (int j = 0; j < 10; j++){
|
||||
digitalWrite(leds[j], LOW);
|
||||
}
|
||||
delay(100);
|
||||
}else{*/
|
||||
/*uint8_t helligkeit = 20;
|
||||
if(RPM_THRES_1 <= rev){
|
||||
analogWrite(led1, helligkeit);
|
||||
}else{
|
||||
analogWrite(led1, 0);
|
||||
}
|
||||
if(RPM_THRES_2 <= rev){
|
||||
analogWrite(led2, helligkeit);
|
||||
}else{
|
||||
analogWrite(led2, 0);
|
||||
}
|
||||
if(RPM_THRES_3 <= rev){
|
||||
analogWrite(led3, helligkeit);
|
||||
}else{
|
||||
analogWrite(led3, 0);
|
||||
}
|
||||
if(RPM_THRES_4 <= rev){
|
||||
analogWrite(led4, helligkeit);
|
||||
}else{
|
||||
analogWrite(led4, 0);
|
||||
}
|
||||
if(RPM_THRES_5 <= rev){
|
||||
analogWrite(led5, helligkeit);
|
||||
}else{
|
||||
analogWrite(led5, 0);
|
||||
}
|
||||
if(RPM_THRES_6 <= rev){
|
||||
analogWrite(led6, helligkeit);
|
||||
}else{
|
||||
analogWrite(led6, 0);
|
||||
}
|
||||
if(RPM_THRES_7 <= rev){
|
||||
analogWrite(led7, helligkeit);
|
||||
}else{
|
||||
analogWrite(led7, 0);
|
||||
}
|
||||
if(RPM_THRES_8 <= rev){
|
||||
analogWrite(led8, helligkeit);
|
||||
}else{
|
||||
analogWrite(led8, 0);
|
||||
}
|
||||
if(RPM_THRES_9 <= rev){
|
||||
analogWrite(led9, helligkeit);
|
||||
}else{
|
||||
analogWrite(led9, 0);
|
||||
}
|
||||
if(RPM_THRES_10 <= rev){
|
||||
analogWrite(led10, helligkeit);
|
||||
}else{
|
||||
analogWrite(led10, 0);
|
||||
}*/
|
||||
digitalWrite(led1, RPM_THRES_1 <= rev);
|
||||
digitalWrite(led2, RPM_THRES_2 <= rev);
|
||||
digitalWrite(led3, RPM_THRES_3 <= rev);
|
||||
digitalWrite(led4, RPM_THRES_4 <= rev);
|
||||
digitalWrite(led5, RPM_THRES_5 <= rev);
|
||||
digitalWrite(led6, RPM_THRES_6 <= rev);
|
||||
digitalWrite(led7, RPM_THRES_7 <= rev);
|
||||
digitalWrite(led8, RPM_THRES_8 <= rev);
|
||||
digitalWrite(led9, RPM_THRES_9 <= rev);
|
||||
digitalWrite(led10, RPM_THRES_10 <= rev);
|
||||
|
||||
digitalWrite(led11, t_mot); // rot, links, oben
|
||||
digitalWrite(led12, t_air); // rot, links, mitte
|
||||
digitalWrite(led13, t_oil); // rot, links, unten
|
||||
|
||||
digitalWrite(led14, e_dros); // rot, rechts, oben
|
||||
digitalWrite(led15, u_batt); // rot rechts, mitte
|
||||
digitalWrite(led16, g_auto); // blau rechts, unten
|
||||
/*if(Vehicle_data.g_auto){
|
||||
digitalWrite(led16, HIGH);
|
||||
}else{
|
||||
digitalWrite(led16, LOW);
|
||||
}*/
|
||||
int16_t rev = Vehicle_data.revol;
|
||||
digitalWrite(led1, RPM_THRESH_1 <= rev);
|
||||
digitalWrite(led2, RPM_THRESH_2 <= rev);
|
||||
digitalWrite(led3, RPM_THRESH_3 <= rev);
|
||||
digitalWrite(led4, RPM_THRESH_4 <= rev);
|
||||
digitalWrite(led5, RPM_THRESH_5 <= rev);
|
||||
digitalWrite(led6, RPM_THRESH_6 <= rev);
|
||||
digitalWrite(led7, RPM_THRESH_7 <= rev);
|
||||
digitalWrite(led8, RPM_THRESH_8 <= rev);
|
||||
digitalWrite(led9, RPM_THRESH_9 <= rev);
|
||||
digitalWrite(led10, RPM_THRESH_10 <= rev);
|
||||
}
|
||||
|
|
|
@ -2,11 +2,64 @@
|
|||
FT_2018e_STW_CAN.h
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "DueTimer.h"
|
||||
#include "due_can.h"
|
||||
|
||||
constexpr uint32_t CAN_CELL_STATS_ID = 0x101;
|
||||
constexpr uint32_t CAN_BATTERY_STATS_ID = 0x102;
|
||||
constexpr uint32_t CAN_COOLING_STATS_ID = 0x103;
|
||||
constexpr uint32_t CAN_INVERTER_STATS_ID = 0x104;
|
||||
|
||||
constexpr uint8_t CAN_INVERTER_STATS_READY = (1 << 0);
|
||||
constexpr uint8_t CAN_INVERTER_STATS_DERATING = (1 << 1);
|
||||
constexpr uint8_t CAN_INVERTER_STATS_WARNING = (1 << 2);
|
||||
constexpr uint8_t CAN_INVERTER_STATS_ERROR = (1 << 3);
|
||||
constexpr uint8_t CAN_INVERTER_STATS_ON = (1 << 4);
|
||||
constexpr uint8_t CAN_INVERTER_STATS_PRECHARGE = (1 << 5);
|
||||
constexpr uint8_t CAN_INVERTER_STATS_AMS_EMERG = (1 << 6);
|
||||
constexpr uint8_t CAN_INVERTER_STATS_TS_ACTIVE = (1 << 7);
|
||||
|
||||
void Init_Can_0();
|
||||
void Send_0x110();
|
||||
void Receive_Can_0(CAN_FRAME *frame);
|
||||
void update_LED(void);
|
||||
void process_cell_stats(CAN_FRAME *frame);
|
||||
void process_battery_stats(CAN_FRAME *frame);
|
||||
void process_cooling_stats(CAN_FRAME *frame);
|
||||
void process_inverter_stats(CAN_FRAME *frame);
|
||||
void update_LED(void);
|
||||
|
||||
struct CellStats
|
||||
{
|
||||
uint16_t sum_cell_voltage;
|
||||
int16_t max_cell_temp;
|
||||
uint16_t max_cell_voltage;
|
||||
uint16_t min_cell_voltage;
|
||||
};
|
||||
|
||||
struct BatteryStats
|
||||
{
|
||||
uint16_t battery_current;
|
||||
uint16_t pre_air_voltage;
|
||||
uint16_t post_air_voltage;
|
||||
uint16_t battery_power;
|
||||
};
|
||||
|
||||
struct CoolingStats
|
||||
{
|
||||
int16_t water_pressure;
|
||||
int16_t water_temp;
|
||||
int16_t motor_l_temp;
|
||||
int16_t motor_r_temp;
|
||||
};
|
||||
|
||||
struct InverterStats
|
||||
{
|
||||
uint8_t status;
|
||||
uint8_t _reserved;
|
||||
uint16_t temp;
|
||||
int16_t velocity;
|
||||
uint16_t error;
|
||||
};
|
|
@ -5,21 +5,23 @@
|
|||
#include <FT_2018e_STW_CAN.h>
|
||||
#include <EDIPTFT.h>
|
||||
#include <FT18e_STW_DISPLAY.h>
|
||||
#include <Bounce2.h>
|
||||
#include <Bounce2.h>
|
||||
#include <RotaryEncoder.h>
|
||||
|
||||
void setup(){
|
||||
void setup()
|
||||
{
|
||||
set_pins();
|
||||
//Serial.begin(9600);
|
||||
//Serial.println("Hi");
|
||||
Init_Can_0();
|
||||
init_display();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
//read_buttons(); //in Send_0x110() aufgerufen
|
||||
//read_rotary(); //in Send_0x110() aufgerufen
|
||||
//Send_0x110(); //alle 10 ms als interrupt aufgerufen
|
||||
update_LED();
|
||||
update_display();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue