Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-STM32F103C8T6
Diff: main.cpp
- Revision:
- 10:a82e51837e2b
- Parent:
- 9:6126b83608be
- Child:
- 11:b571de4666c9
--- a/main.cpp Thu Jun 11 21:57:29 2020 +0000 +++ b/main.cpp Fri Jun 12 23:28:43 2020 +0000 @@ -19,7 +19,9 @@ //#include "ecu_simulator.h" #include "globals.h" #include "heatcontrol.h" - +#include "spl0601.h" +#include "i2c_base.h" +extern I2C* spl_i2c; // pinout for Maple Mini DigitalIn click(PA_1); // Button inputs // pinout for lpc1768 @@ -51,6 +53,7 @@ // external variables volatile unsigned char idletimer; extern char otherControllerDetected; +wiced_bool_t hasOnboardAltimeter = WICED_FALSE; char printbuff[256]; @@ -139,7 +142,7 @@ wait(1); - + spl_i2c = new I2C(SDA, SCL); //canspeed = CAN500; // ecu.dtc = false; // ecu.active_fault = false; @@ -155,23 +158,20 @@ initHeaterState(&heaterState[0]); - initHeaterState(&heaterState[1]); heaterState[0].bustype = HEATERTYPECAN; heaterState[0].heaternum = 1; - heaterState[1].bustype = HEATERTYPENONE; - InitCAN(); - + double presComp; while(1) { // Main CAN loop for (int i = 0; i < HEATERSTATECOUNT; i++) { -// wiced_update_system_monitor(&main_thread_monitor, 10 * 1000); + // wiced_update_system_monitor(&main_thread_monitor, 10 * 1000); doHeatTaskCAN(&heaterState[i]); -// wiced_update_system_monitor(&main_thread_monitor, 10 * 1000); + // wiced_update_system_monitor(&main_thread_monitor, 10 * 1000); doHeatLogicTask(&heaterState[i]); if (i < HEATERSTATECOUNT) { wait_ms(50); @@ -188,15 +188,39 @@ set_heat_con(&heaterState[0], HEATCALLOFF); } } + + if (secondFlag > 0) { secondFlag = 0; + + DebugWrite("About to clean I2C\r\n"); + cleanI2CLines(spl_i2c, SDA, SCL); + + DebugWrite("Done clean I2C, get pressure\r\n"); + + hasOnboardAltimeter = getPressure(&presComp); + if (hasOnboardAltimeter) { + int hpa = presComp / 100; // convert to HPA + sprintf(printbuff, "Pressure %0.5lf vs %d\r\n", presComp, hpa); + DebugWrite(printbuff); + + //sprintf(printbuff, "Pressure is %.1f (%d)\r\n", presComp, hpa); + //DebugWrite(printbuff); + if (hpa < 600) { + hpa = 680; + } + if (hpa > 1105) { + hpa = 680; + } + heaterState[0].rawAltitude = presComp; + heaterState[0].internalAltitude = hpa; + } else { + DebugWrite("No altimeter\r\n"); + } if (heaterState[0].initTimer > 0) { heaterState[0].initTimer--; } - if (heaterState[1].initTimer > 0) { - heaterState[1].initTimer--; - } // DebugWrite("Doing re-init of I2c\r\n"); // check I2C