Gabor Feher
/
BMWE90-InstrumentCluster
Making a BMW E90 instrument cluster alive for demonstration purposes
Revision 3:4a4463380739, committed 2017-03-11
- Comitter:
- gume
- Date:
- Sat Mar 11 10:03:52 2017 +0000
- Parent:
- 2:ef9a8a114395
- Commit message:
- Initial Speed module (not yet working); Fuel data
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SpeedMsg.cpp Sat Mar 11 10:03:52 2017 +0000 @@ -0,0 +1,44 @@ +#include "SpeedMsg.h" + +SpeedMsg::SpeedMsg () { + + counter1 = counter2 = 0; + //c2inc = { 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 2 }; + char x = 0; + for (int i = 0; i < 16; i++) { + c2inc[i] = 1 + x; + if (i != 5 && i != 14) x = 1 - x; + } + c2incp = 0; + + spb[0] = 0; spb[1] = 0; + spb[2] = 0; spb[3] = 0; + spb[4] = 0; spb[5] = 0; +} + +void SpeedMsg::setSpeed(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5) { + + spb[0] = b0; spb[1] = b1; + spb[2] = b2; spb[3] = b3; + spb[4] = b4; spb[5] = b5; +} + +bool SpeedMsg::sendMessage(CAN *can) { + + uint8_t data[8]; + + data[0] = spb[0]; data[1] = spb[1]; + data[2] = spb[2]; data[3] = spb[3]; + data[4] = spb[4]; data[5] = spb[5]; + + data[6] = counter1; + data[7] = 0xF0 + counter2; + + bool ok = can->write(CANMessage(0x1A6, (char*) data, 8)); + + counter1 = counter1 + 0x90; + counter2 = (counter2 + c2inc[c2incp++]) & 0x0f; + if (c2incp > 15) c2incp = 0; + + return ok; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SpeedMsg.h Sat Mar 11 10:03:52 2017 +0000 @@ -0,0 +1,23 @@ +#ifndef SPEEDMSG_H +#define SPEEDMSG_H + +#include "mbed.h" + +class SpeedMsg { + + char counter1; // Increase by 144 (0x90) + char counter2; // Increase by: 1 2 1 2 1 2 2 1 2 1 2 1 2 1 2 2 (then repeated) + + char c2inc[16]; + char c2incp; + + uint8_t spb[6]; + + public: + SpeedMsg(); + + void setSpeed(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5); + bool sendMessage(CAN *can); +}; + +#endif \ No newline at end of file
--- a/main.cpp Fri Mar 10 09:03:10 2017 +0000 +++ b/main.cpp Sat Mar 11 10:03:52 2017 +0000 @@ -1,5 +1,6 @@ #include "mbed.h" #include "T15Msg.h" +#include "SpeedMsg.h" Timer timer100; Timer timer200; @@ -7,7 +8,9 @@ Serial pc(USBTX, USBRX); DigitalOut led1(PA_5); CAN can1(PB_8, PB_9); // rd, td Transmitter + T15Msg t15; +SpeedMsg speed; int fuel1 = 0x4F04; int fuel2 = 0x2312; @@ -157,6 +160,7 @@ if (timer100.read_ms() > 100) { sendT15(); + speed.sendMessage(&can1); timer100.reset(); led1 = !led1; @@ -216,10 +220,12 @@ if (strcmp(command, "START") == 0) { pc.printf("Start\r\n"); t15.start(); + speed.setSpeed(0x13, 0x4d, 0x46, 0x4d, 0x33, 0x4d); } else if (strcmp(command, "STOP") == 0) { pc.printf("Stop\n"); + speed.setSpeed(0x0, 0x0, 0x0, 0x0, 0x0, 0x0); t15.stop(); }