Small project to display some OBD values from the Toyota GT86/ Subaru BRZ/ Scion FRS on an OLED display.
Dependencies: Adafruit_GFX MODSERIAL mbed-rtos mbed
Revision 6:506b703a8acf, committed 2014-05-01
- Comitter:
- chrta
- Date:
- Thu May 01 09:29:29 2014 +0000
- Parent:
- 5:0b229ba8ede5
- Child:
- 7:a19b63c0a0fa
- Commit message:
- Changes for display.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Adafruit_GFX.lib Thu May 01 09:29:29 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/nkhorman/code/Adafruit_GFX/#853097cfa773
--- a/EngineCoolantTemperature.cpp Sun Apr 27 19:13:35 2014 +0000 +++ b/EngineCoolantTemperature.cpp Thu May 01 09:29:29 2014 +0000 @@ -1,7 +1,9 @@ #include "EngineCoolantTemperature.h" +const char EngineCoolantTemp::REQUEST_DATA[8] = {0x02, 0x01, 0x05, 0, 0, 0, 0, 0}; + EngineCoolantTemp::EngineCoolantTemp() -: PidValue("Engine Coolant Temperature", "deg C") +: PidValue("Coolant Temp", "C") { }
--- a/EngineCoolantTemperature.h Sun Apr 27 19:13:35 2014 +0000 +++ b/EngineCoolantTemperature.h Thu May 01 09:29:29 2014 +0000 @@ -8,6 +8,8 @@ public: EngineCoolantTemp(); virtual bool decode(const uint8_t* data, uint16_t length); + + static const char REQUEST_DATA[8]; };
--- a/EngineRpm.cpp Sun Apr 27 19:13:35 2014 +0000 +++ b/EngineRpm.cpp Thu May 01 09:29:29 2014 +0000 @@ -1,5 +1,7 @@ #include "EngineRpm.h" +const char EngineRpm::REQUEST_DATA[8] = {0x02, 0x01, 0x0C, 0, 0, 0, 0, 0}; + EngineRpm::EngineRpm() : PidValue("Engine RPM", "rpm") {
--- a/EngineRpm.h Sun Apr 27 19:13:35 2014 +0000 +++ b/EngineRpm.h Thu May 01 09:29:29 2014 +0000 @@ -8,6 +8,8 @@ public: EngineRpm(); virtual bool decode(const uint8_t* data, uint16_t length); + + static const char REQUEST_DATA[8]; }; #endif //ENGINERPM_H \ No newline at end of file
--- a/OilTemperature.cpp Sun Apr 27 19:13:35 2014 +0000 +++ b/OilTemperature.cpp Thu May 01 09:29:29 2014 +0000 @@ -1,8 +1,10 @@ #include "OilTemperature.h" +const char OilTemperature::REQUEST_DATA[8] = {0x02, 0x21, 0x01, 0, 0, 0, 0, 0}; +const char OilTemperature::SECOND_MESSAGE[8] = {0x30, 0, 0, 0, 0, 0, 0, 0}; OilTemperature::OilTemperature() -: PidValue("Oil Temperature", "deg C") +: PidValue("Oil Temp", "C") { }
--- a/OilTemperature.h Sun Apr 27 19:13:35 2014 +0000 +++ b/OilTemperature.h Thu May 01 09:29:29 2014 +0000 @@ -8,5 +8,8 @@ public: OilTemperature(); virtual bool decode(const uint8_t* data, uint16_t length); + + static const char REQUEST_DATA[8]; + static const char SECOND_MESSAGE[8]; }; #endif //OILTEMPERATURE_H
--- a/PidDecoder.cpp Sun Apr 27 19:13:35 2014 +0000 +++ b/PidDecoder.cpp Thu May 01 09:29:29 2014 +0000 @@ -6,6 +6,7 @@ #include "OilTemperature.h" #include "DebugPrint.h" +#include "display.h" static VehicleSpeed speed; static EngineRpm rpm; @@ -14,7 +15,10 @@ OilTemperature oilTemperature; static PidValue* pids[] = { &speed, &rpm, &temp, &throttle, &oilTemperature -}; +}; + +extern Display display; +char buf[128]; void PidDecoder::decode(const uint8_t* data, uint16_t length) { @@ -24,6 +28,9 @@ { pc.printf("New Value for %s: ", pids[i]->getName()); pids[i]->print(); + snprintf(buf, sizeof(buf), "%s: %d %s", pids[i]->getName(), pids[i]->getValue(), pids[i]->getUnit()); + display.sendTo(buf); + display.display(); } } }
--- a/PidValue.cpp Sun Apr 27 19:13:35 2014 +0000 +++ b/PidValue.cpp Thu May 01 09:29:29 2014 +0000 @@ -16,4 +16,13 @@ const char* PidValue::getName() { return m_name; +} + +const char* PidValue::getUnit() +{ + return m_unit; +} +unsigned int PidValue::getValue() +{ + return m_value; } \ No newline at end of file
--- a/PidValue.h Sun Apr 27 19:13:35 2014 +0000 +++ b/PidValue.h Thu May 01 09:29:29 2014 +0000 @@ -10,6 +10,8 @@ virtual bool decode(const uint8_t* data, uint16_t length) = 0; void print(); const char* getName(); + const char* getUnit(); + unsigned int getValue(); protected: unsigned int m_value; const char* m_unit;
--- a/Throttle.cpp Sun Apr 27 19:13:35 2014 +0000 +++ b/Throttle.cpp Thu May 01 09:29:29 2014 +0000 @@ -1,5 +1,6 @@ #include "Throttle.h" +const char Throttle::REQUEST_DATA[8] = {0x02, 0x01, 0x11, 0, 0, 0, 0, 0}; Throttle::Throttle() : PidValue("Throttle", "%")
--- a/Throttle.h Sun Apr 27 19:13:35 2014 +0000 +++ b/Throttle.h Thu May 01 09:29:29 2014 +0000 @@ -8,6 +8,8 @@ public: Throttle(); virtual bool decode(const uint8_t* data, uint16_t length); + + static const char REQUEST_DATA[8]; }; #endif //THROTTLE_H \ No newline at end of file
--- a/VehicleSpeed.cpp Sun Apr 27 19:13:35 2014 +0000 +++ b/VehicleSpeed.cpp Thu May 01 09:29:29 2014 +0000 @@ -1,5 +1,7 @@ #include "VehicleSpeed.h" +const char VehicleSpeed::REQUEST_DATA[8] = {0x02, 0x01, 0x0D, 0, 0, 0, 0, 0}; + VehicleSpeed::VehicleSpeed() : PidValue("Speed", "km/h") {
--- a/VehicleSpeed.h Sun Apr 27 19:13:35 2014 +0000 +++ b/VehicleSpeed.h Thu May 01 09:29:29 2014 +0000 @@ -8,6 +8,8 @@ public: VehicleSpeed(); virtual bool decode(const uint8_t* data, uint16_t length); + + static const char REQUEST_DATA[8]; }; #endif //VEHICLESPEED_H \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/display.cpp Thu May 01 09:29:29 2014 +0000 @@ -0,0 +1,51 @@ +#include "display.h" + +Display::SPI2::SPI2(PinName mosi, PinName miso, PinName clk) +: SPI(mosi, miso, clk) +{ + format(8,3); + frequency(2000000); +}; + + +Display::Display() +: m_spi(p5, NC, p7) +, m_oled(m_spi, p18, p19, p20) +{ +} + + +void Display::clear() +{ + m_oled.clearDisplay(); +} + +void Display::display() +{ + m_oled.display(); +} + +void Display::sendTo(const char* text) +{ + uint8_t line = 0; + if (strstr(text, "RPM")) + { + line = 1; + } + else if (strstr(text, "Oil")) + { + line = 2; + } + else if (strstr(text, "Coolant")) + { + line = 3; + } + else if (strstr(text, "Speed")) + { + return; + } + + m_oled.setCursor(0, line * 8); + m_oled.printf("%s", text); + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/display.h Thu May 01 09:29:29 2014 +0000 @@ -0,0 +1,31 @@ +#ifndef DISPLAY_H +#define DISPLAY_H + +#include "mbed.h" + +#include "Adafruit_SSD1306.h" + +class Display +{ +public: + + Display(); + + void clear(); + + void display(); + + void sendTo(const char* text); + +private: + // an SPI sub-class that provides a constructed default format and frequency + class SPI2 : public SPI + { + public: + SPI2(PinName mosi, PinName miso, PinName clk); + }; + + SPI2 m_spi; + Adafruit_SSD1306 m_oled; +}; +#endif //DISPLAY_H \ No newline at end of file
--- a/main.cpp Sun Apr 27 19:13:35 2014 +0000 +++ b/main.cpp Thu May 01 09:29:29 2014 +0000 @@ -2,9 +2,16 @@ #include "rtos.h" #include "IsoTpHandler.h" #include "MODSERIAL.h" +#include "display.h" -#define CAN1_TEST -#define CAN1_OBD_CAR_SIMULATOR +#include "EngineCoolantTemperature.h" +#include "OilTemperature.h" +#include "VehicleSpeed.h" +#include "Throttle.h" +#include "EngineRpm.h" + +//#define CAN1_TEST +//#define CAN1_OBD_CAR_SIMULATOR // Make TX buffer 1024bytes and RX buffer use 512bytes. MODSERIAL pc(USBTX, USBRX, 2 * 1024, 512); // tx, rx @@ -20,13 +27,15 @@ IsoTpHandler tpHandler(&can2); +Display display; + //#define ACTIVATE_DEBUG_OUTPUT #ifdef ACTIVATE_DEBUG_OUTPUT #define DEBUG_PRINT(format, ...) pc.printf(format, ##__VA_ARGS__) #else #define DEBUG_PRINT(format, ...) #endif - + void led2_thread(void const *args) { while (true) { led2 = !led2; @@ -107,20 +116,21 @@ struct behaviour_t { - unsigned char rxData[8]; + const char *rxData; //[8]; char txData[8]; }; - +const char broken_message[] = {0x02, 0x01, 0x21, 0, 0, 0, 0, 0}; behaviour_t behaviour[] = { - {{0x02, 0x21, 0x01, 0, 0, 0, 0, 0}, {0x10, 0x1F, 0x61, 0x01, 0x51, 0, 0x37, 0x01}}, //first oil temp packet - {{0x30, 0, 0, 0, 0, 0, 0, 0}, {0x21, 0x1F, 0x61, 0x01, 0x51, 0, 0x37, 0x01}}, //second oil temp packet, TODO more pakets must be sent - {{0x02, 0x01, 0x21, 0, 0, 0, 0, 0}, {0x04, 0x41, 0x21, 0, 0, 0, 0, 0}}, - {{0x02, 0x01, 0x0C, 0, 0, 0, 0, 0}, {0x04, 0x41, 0x0C, 0x0F, 0xA2, 0, 0, 0}}, - {{0x02, 0x01, 0x11, 0, 0, 0, 0, 0}, {0x03, 0x41, 0x11, 0x26, 0, 0, 0, 0}}, - {{0x02, 0x01, 0x05, 0, 0, 0, 0, 0}, {0x03, 0x41, 0x05, 0x4D, 0, 0, 0, 0}}, //engine coolant temp + {OilTemperature::REQUEST_DATA, {0x10, 0x1F, 0x61, 0x01, 0x51, 0, 0x37, 0x01}}, //first oil temp packet + {OilTemperature::SECOND_MESSAGE, {0x21, 0x1F, 0x61, 0x01, 0x51, 0, 0x37, 0x01}}, //second oil temp packet, TODO more pakets must be sent + {broken_message, {0x04, 0x41, 0x21, 0, 0, 0, 0, 0}}, + {VehicleSpeed::REQUEST_DATA, {0x03, 0x41, 0x0D, 0x26, 0, 0, 0, 0}}, + {EngineRpm::REQUEST_DATA, {0x04, 0x41, 0x0C, 0x0F, 0xA2, 0, 0, 0}}, + {Throttle::REQUEST_DATA, {0x03, 0x41, 0x11, 0x26, 0, 0, 0, 0}}, + {EngineCoolantTemp::REQUEST_DATA, {0x03, 0x41, 0x05, 0x4D, 0, 0, 0, 0}}, //engine coolant temp }; void can2_send_requests(void const *args) { @@ -140,6 +150,10 @@ *msg = sendMsg; can2_tx_queue.put(msg); Thread::wait(200); + sendMsg.data[2] = behaviour[6].rxData[2]; + *msg = sendMsg; + can2_tx_queue.put(msg); + Thread::wait(200); CANMessage sendMsg2(0x7E0, (char*) behaviour[0].rxData, 8); msg = can2_tx_queue.alloc(); *msg = sendMsg2; @@ -297,6 +311,10 @@ } int main() { + display.clear(); + display.sendTo("Starting...\r\n"); + display.display(); + pc.baud(921600); //pc.attach(&serial_int_handler); can2_disable = 0; @@ -317,6 +335,9 @@ #endif //CAN1_TEST Thread can2_send_request_thread(can2_send_requests); Thread can2_tx_thread(can2_send_packets); + display.sendTo("Init done.\r\n"); + display.display(); + pc.printf("Start\r\n"); while (true) { led1 = !led1;