Exluding ZMOD

Dependencies:   iAQ_Core Adafruit_SGP30_mbed mbed BME680

Committer:
christodoulos
Date:
Fri May 01 14:31:45 2020 +0000
Revision:
5:44f7dbc5c75d
Parent:
3:3d51f8870e91
Child:
6:96de1304b9e7
iAQ-Core C (used in POCBreath_V2_smd_commercial)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
christodoulos 0:d034cdad5b6d 1 #include "mbed.h"
christodoulos 5:44f7dbc5c75d 2 #include "iAQ_Core.h"
christodoulos 5:44f7dbc5c75d 3
christodoulos 5:44f7dbc5c75d 4 iAQ_Core myiAQ_Core ( PB_11,PB_10, iAQ_Core::iAQ_Core_ADDRESS );
christodoulos 5:44f7dbc5c75d 5 Serial ble(PC_12,PD_2);
christodoulos 5:44f7dbc5c75d 6
christodoulos 5:44f7dbc5c75d 7 Ticker newReading;
christodoulos 0:d034cdad5b6d 8
christodoulos 5:44f7dbc5c75d 9 iAQ_Core::iAQ_Core_status_t aux;
christodoulos 5:44f7dbc5c75d 10 iAQ_Core::iAQ_Core_data_t myiAQ_Core_data;
christodoulos 5:44f7dbc5c75d 11 uint32_t myState = 0;
christodoulos 5:44f7dbc5c75d 12
christodoulos 0:d034cdad5b6d 13
christodoulos 5:44f7dbc5c75d 14 void changeDATA ( void )
christodoulos 5:44f7dbc5c75d 15 {
christodoulos 5:44f7dbc5c75d 16 myState = 1;
christodoulos 5:44f7dbc5c75d 17 }
mehrnaz 3:3d51f8870e91 18
mehrnaz 2:ef98576cd67b 19
mehrnaz 2:ef98576cd67b 20 int main()
christodoulos 0:d034cdad5b6d 21 {
christodoulos 5:44f7dbc5c75d 22 ble.baud(9600);
mehrnaz 3:3d51f8870e91 23
christodoulos 5:44f7dbc5c75d 24 uint32_t myWarmUpCounter = 0;
christodoulos 5:44f7dbc5c75d 25
christodoulos 5:44f7dbc5c75d 26
mehrnaz 3:3d51f8870e91 27
christodoulos 5:44f7dbc5c75d 28 // iAQ-Core warm up is at least 5 minutes ( 300 * 1s ) or when the sensor is ready
christodoulos 5:44f7dbc5c75d 29 do
christodoulos 5:44f7dbc5c75d 30 {
christodoulos 5:44f7dbc5c75d 31 aux = myiAQ_Core.iAQ_Core_GetNewReading ( &myiAQ_Core_data );
christodoulos 5:44f7dbc5c75d 32 wait(1);
christodoulos 5:44f7dbc5c75d 33 myWarmUpCounter++;
christodoulos 5:44f7dbc5c75d 34 } while( ( myWarmUpCounter < 300 ) && ( myiAQ_Core_data.status == iAQ_Core::iAQ_Core_STATUS_RUNIN ) );
christodoulos 5:44f7dbc5c75d 35
christodoulos 5:44f7dbc5c75d 36
christodoulos 5:44f7dbc5c75d 37 newReading.attach( &changeDATA, 0.1); // the address of the function to be attached ( changeDATA ) and the interval ( 1s )
christodoulos 5:44f7dbc5c75d 38
christodoulos 5:44f7dbc5c75d 39 // Let the callbacks take care of everything
mehrnaz 2:ef98576cd67b 40 while(1)
mehrnaz 2:ef98576cd67b 41 {
christodoulos 5:44f7dbc5c75d 42 sleep();
christodoulos 5:44f7dbc5c75d 43
christodoulos 5:44f7dbc5c75d 44
mehrnaz 3:3d51f8870e91 45
christodoulos 5:44f7dbc5c75d 46 if ( myState == 1 ) {
christodoulos 5:44f7dbc5c75d 47 // New reading
christodoulos 5:44f7dbc5c75d 48 do {
christodoulos 5:44f7dbc5c75d 49 aux = myiAQ_Core.iAQ_Core_GetNewReading ( &myiAQ_Core_data );
christodoulos 5:44f7dbc5c75d 50 wait_ms(1);
christodoulos 5:44f7dbc5c75d 51 } while( myiAQ_Core_data.status != iAQ_Core::iAQ_Core_STATUS_OK ); // [TODO] Dangerous!!! The uC may get stuck here if something goes wrong!
christodoulos 5:44f7dbc5c75d 52 // [WORKAROUND] Insert a counter.
christodoulos 5:44f7dbc5c75d 53
christodoulos 5:44f7dbc5c75d 54 // Send data through the UART
christodoulos 5:44f7dbc5c75d 55 ble.printf( "Pred: %d | Tvoc: %d | Resistance: %d\r\n", myiAQ_Core_data.pred, myiAQ_Core_data.Tvoc, myiAQ_Core_data.resistance );
christodoulos 5:44f7dbc5c75d 56 wait(0.01);
christodoulos 5:44f7dbc5c75d 57 myState = 0; // Reset the variable
christodoulos 5:44f7dbc5c75d 58 }
christodoulos 5:44f7dbc5c75d 59
mehrnaz 2:ef98576cd67b 60 }
mehrnaz 2:ef98576cd67b 61 }