AmbiMate Sensor Module
Diff: AMBIMATE_MS4.h
- Revision:
- 3:891e0af7da10
- Parent:
- 2:6c5fac3dfd44
--- a/AMBIMATE_MS4.h Thu Jun 03 17:42:11 2021 +0000 +++ b/AMBIMATE_MS4.h Thu Jun 03 18:04:59 2021 +0000 @@ -22,7 +22,108 @@ /** Example: @code +#include "mbed.h" +#include "AMBIMATE_MS4.h" +AMBIMATE_MS4 myAMBIMATE_MS4 ( I2C_SDA, I2C_SCL, AMBIMATE_MS4::AMBIMATE_MS4_ADDRESS, 100000 ); // I2C_SDA | I2C_SCL +Serial pc ( USBTX, USBRX ); // tx, rx + +DigitalOut myled ( LED1 ); +Ticker newAction; + + +//@brief Constants. + + +//@brief Variables. +volatile uint32_t myState; // State that indicates when to perform a new sample + + +//@brief FUNCTION PROTOTYPES +void changeDATA ( void ); + + +//@brief FUNCTION FOR APPLICATION MAIN ENTRY. +int main() +{ + AMBIMATE_MS4::AMBIMATE_MS4_status_t aux; + AMBIMATE_MS4::AMBIMATE_MS4_data_t myAMBIMATE_MS4_Data; + + pc.baud ( 115200 ); + + myled = 1; + wait(3); + myled = 0; + + // Get the firmware version + aux = myAMBIMATE_MS4.AMBIMATE_MS4_GetFirmwareVersion ( &myAMBIMATE_MS4_Data.info.firmware_version ); + + // Get the firmware sub-version + aux = myAMBIMATE_MS4.AMBIMATE_MS4_GetFirmwareSubVersion ( &myAMBIMATE_MS4_Data.info.firmware_sub_version ); + + // Get the optional sensors on the board + aux = myAMBIMATE_MS4.AMBIMATE_MS4_GetOptionalSensorsByte ( &myAMBIMATE_MS4_Data.info.optional_sensors ); + + pc.printf ( "FW version: %d | FW subversion: %d | Optional sensors: %d\r\n", myAMBIMATE_MS4_Data.info.firmware_version,myAMBIMATE_MS4_Data.info.firmware_sub_version, myAMBIMATE_MS4_Data.info.optional_sensors ); + + + myState = 0UL; // Reset the variable + newAction.attach( &changeDATA, 5U ); // the address of the function to be attached ( changeDATA ) and the interval ( 5s ) + + // Let the callbacks take care of everything + while(1) { + sleep(); + + if ( myState == 1UL ) { + myled = 1U; + + aux = myAMBIMATE_MS4.AMBIMATE_MS4_ScanStartByte ( AMBIMATE_MS4::WRITEABLE_REGISTERS_GAS_INITIATE_NEW_MEASUREMENT, AMBIMATE_MS4::WRITEABLE_REGISTERS_BATT_INITIATE_NEW_MEASUREMENT, AMBIMATE_MS4::WRITEABLE_REGISTERS_AUD_INITIATE_NEW_MEASUREMENT, AMBIMATE_MS4::WRITEABLE_REGISTERS_LIGHT_INITIATE_NEW_MEASUREMENT, AMBIMATE_MS4::WRITEABLE_REGISTERS_HUM_INITIATE_NEW_MEASUREMENT, AMBIMATE_MS4::WRITEABLE_REGISTERS_TEMP_INITIATE_NEW_MEASUREMENT, AMBIMATE_MS4::WRITEABLE_REGISTERS_STATUS_INITIATE_NEW_MEASUREMENT ); + + // Wait for a new data set value + do { + // Reset the variable + myAMBIMATE_MS4_Data.start_scan_byte = (uint8_t)( AMBIMATE_MS4::WRITEABLE_REGISTERS_GAS_INITIATE_NEW_MEASUREMENT | AMBIMATE_MS4::WRITEABLE_REGISTERS_BATT_INITIATE_NEW_MEASUREMENT | AMBIMATE_MS4::WRITEABLE_REGISTERS_AUD_INITIATE_NEW_MEASUREMENT | AMBIMATE_MS4::WRITEABLE_REGISTERS_LIGHT_INITIATE_NEW_MEASUREMENT | AMBIMATE_MS4::WRITEABLE_REGISTERS_HUM_INITIATE_NEW_MEASUREMENT | AMBIMATE_MS4::WRITEABLE_REGISTERS_TEMP_INITIATE_NEW_MEASUREMENT | AMBIMATE_MS4::WRITEABLE_REGISTERS_STATUS_INITIATE_NEW_MEASUREMENT ); + + aux = myAMBIMATE_MS4.AMBIMATE_MS4_GetScanStartByte ( &myAMBIMATE_MS4_Data.start_scan_byte ); + wait_ms (700); + } while( ( myAMBIMATE_MS4_Data.start_scan_byte & ( AMBIMATE_MS4::WRITEABLE_REGISTERS_GAS_MASK | AMBIMATE_MS4::WRITEABLE_REGISTERS_BATT_MASK | AMBIMATE_MS4::WRITEABLE_REGISTERS_AUD_MASK | AMBIMATE_MS4::WRITEABLE_REGISTERS_LIGHT_MASK | AMBIMATE_MS4::WRITEABLE_REGISTERS_HUM_MASK | AMBIMATE_MS4::WRITEABLE_REGISTERS_TEMP_MASK | AMBIMATE_MS4::WRITEABLE_REGISTERS_STATUS_MASK ) ) != 0x00 ); + + // Get all the raw values + aux = myAMBIMATE_MS4.AMBIMATE_MS4_GetRawAllSensors ( &myAMBIMATE_MS4_Data.status, &myAMBIMATE_MS4_Data.raw_data ); + + // Process all the data + myAMBIMATE_MS4_Data.data = myAMBIMATE_MS4.AMBIMATE_MS4_ProcessAllData ( myAMBIMATE_MS4_Data.raw_data ); + + // Send data through the UART + pc.printf ( "CO2: %d ppm, VOC: %d, T: %d C, RH: %d %%, Lux: %d, Batt: %d V, Aud: %d db\r\n", (uint32_t)myAMBIMATE_MS4_Data.data.eco2, (uint32_t)myAMBIMATE_MS4_Data.data.voc, (uint32_t)myAMBIMATE_MS4_Data.data.temperature, (uint32_t)myAMBIMATE_MS4_Data.data.humidity, myAMBIMATE_MS4_Data.data.light, (uint32_t)myAMBIMATE_MS4_Data.data.battery_volts, myAMBIMATE_MS4_Data.data.audio ); + + // Reset the variables + myState = 0UL; + myled = 0U; + } + } +} + + +// @brief changeDATA ( void ) +// +// @details It changes myState variable +// +// @param[in] N/A +// +// @param[out] N/A. +// +// @return N/A. +// +// @author Manuel Caballero +// @date 03/June/2021 +// @version 03/June/2021 The ORIGIN +// @pre N/A +// @warning N/A. +void changeDATA ( void ) +{ + myState = 1UL; +} @endcode */