Gabor Feher
/
BMWE90-InstrumentCluster
Making a BMW E90 instrument cluster alive for demonstration purposes
Embed:
(wiki syntax)
Show/hide line numbers
SpeedMsg.cpp
00001 #include "SpeedMsg.h" 00002 00003 SpeedMsg::SpeedMsg () { 00004 00005 counter1 = counter2 = 0; 00006 //c2inc = { 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 2 }; 00007 char x = 0; 00008 for (int i = 0; i < 16; i++) { 00009 c2inc[i] = 1 + x; 00010 if (i != 5 && i != 14) x = 1 - x; 00011 } 00012 c2incp = 0; 00013 00014 spb[0] = 0; spb[1] = 0; 00015 spb[2] = 0; spb[3] = 0; 00016 spb[4] = 0; spb[5] = 0; 00017 } 00018 00019 void SpeedMsg::setSpeed(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5) { 00020 00021 spb[0] = b0; spb[1] = b1; 00022 spb[2] = b2; spb[3] = b3; 00023 spb[4] = b4; spb[5] = b5; 00024 } 00025 00026 bool SpeedMsg::sendMessage(CAN *can) { 00027 00028 uint8_t data[8]; 00029 00030 data[0] = spb[0]; data[1] = spb[1]; 00031 data[2] = spb[2]; data[3] = spb[3]; 00032 data[4] = spb[4]; data[5] = spb[5]; 00033 00034 data[6] = counter1; 00035 data[7] = 0xF0 + counter2; 00036 00037 bool ok = can->write(CANMessage(0x1A6, (char*) data, 8)); 00038 00039 counter1 = counter1 + 0x90; 00040 counter2 = (counter2 + c2inc[c2incp++]) & 0x0f; 00041 if (c2incp > 15) c2incp = 0; 00042 00043 return ok; 00044 }
Generated on Sat Jul 23 2022 09:24:36 by 1.7.2