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
Diff: main.cpp
- Revision:
- 4:0e2d6cc31afb
- Parent:
- 3:eb807d330292
- Child:
- 5:0b229ba8ede5
--- a/main.cpp Sun Apr 27 17:11:32 2014 +0000 +++ b/main.cpp Sun Apr 27 17:42:32 2014 +0000 @@ -4,7 +4,7 @@ #include "MODSERIAL.h" #define CAN1_TEST -// #define CAN1_OBD_CAR_SIMULATOR +#define CAN1_OBD_CAR_SIMULATOR // Make TX buffer 1024bytes and RX buffer use 512bytes. MODSERIAL pc(USBTX, USBRX, 2 * 1024, 512); // tx, rx @@ -19,6 +19,12 @@ DigitalOut can2_disable(p28); IsoTpHandler tpHandler(&can2); + +#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) { @@ -31,17 +37,17 @@ void can_process_packets(void const *args) { while (true) { - pc.printf("Th wait for can packet\r\n"); + //pc.printf("Th wait for can packet\r\n"); osEvent evt = can_rx_queue.get(osWaitForever); - pc.printf("Got evt %d\r\n", evt.status); + //pc.printf("Got evt %d\r\n", evt.status); if (evt.status == osEventMail) { - pc.printf("Got can packet\r\n"); + //pc.printf("Got can packet\r\n"); CANMessage *msg = (CANMessage*) evt.value.p; - pc.printf("Process can packet\r\n"); + //pc.printf("Process can packet\r\n"); tpHandler.processCanMessage(msg); - pc.printf("Processed can packet\r\n"); + //pc.printf("Processed can packet\r\n"); can_rx_queue.free(msg); - pc.printf("Freed can packet\r\n"); + //pc.printf("Freed can packet\r\n"); } } } @@ -175,20 +181,21 @@ #ifdef CAN1_OBD_CAR_SIMULATOR void can1_send_packets(void const *args) { - pc.printf("TX1 start\r\n"); + DEBUG_PRINT("TX1 start\r\n"); while (true) { osEvent evt = can1_tx_queue.get(osWaitForever); if (evt.status == osEventMail) { CANMessage *msg = (CANMessage*) evt.value.p; - pc.printf("TX1 check\r\n"); + DEBUG_PRINT("TX1 check\r\n"); if (can1.write(*msg)) { - pc.printf("TX1 send\r\n"); + DEBUG_PRINT("TX1 send\r\n"); can1_tx_queue.free(msg); + Thread::wait(50); } else { - pc.printf("TX1 wait \r\n"); + DEBUG_PRINT("TX1 wait \r\n"); Thread::wait(50); } } @@ -207,7 +214,7 @@ uint8_t character = pc.getc(); //pc.printf("Received '%c'\r\n", character); - msg.data[0] = 0x02; + msg.data[0] = 0x02; msg.data[1] = 0x01; char pid = 0; switch (character)