AmbiMate Sensor Module
Diff: AMBIMATE_MS4.h
- Revision:
- 0:8d9328d3ff35
- Child:
- 1:f0711d344f71
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AMBIMATE_MS4.h Thu Jun 03 17:02:20 2021 +0000 @@ -0,0 +1,192 @@ +/** + * @brief AMBIMATE_MS4.h + * @details AmbiMate Sensor Module. + * Header file. + * + * + * @return NA + * + * @author Manuel Caballero + * @date 03/June/2021 + * @version 03/June/2021 The ORIGIN + * @pre N/A. + * @warning N/A + * @pre This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ). + */ +#ifndef AMBIMATE_MS4_H +#define AMBIMATE_MS4_H + +#include "mbed.h" + + +/** + Example: +@code + +@endcode +*/ + + +/*! + Library for the AMBIMATE_MS4 Digital humidity sensor with temperature output. +*/ +class AMBIMATE_MS4 +{ +public: + /** + * @brief DEFAULT ADDRESSES + */ + typedef enum { + AMBIMATE_MS4_ADDRESS = ( 0x40 << 1 ) + } AMBIMATE_MS4_address_t; + + + /** + * @brief COMMAND REGISTERS + */ +#define AMBIMATE_MS4_TRIGGER_TEMPERATURE_MEASUREMENT_HOLD_MASTER 0xE3 +#define AMBIMATE_MS4_TRIGGER_HUMIDITY_MEASUREMENT_HOLD_MASTER 0xE5 +#define AMBIMATE_MS4_TRIGGER_TEMPERATURE_MEASUREMENT_NO_HOLD_MASTER 0xF3 +#define AMBIMATE_MS4_TRIGGER_HUMIDITY_MEASUREMENT_NO_HOLD_MASTER 0xF5 +#define AMBIMATE_MS4_WRITE_REGISTER 0xE6 +#define AMBIMATE_MS4_READ_REGISTER 0xE7 +#define AMBIMATE_MS4_SOFT_RESET 0xFE + + + /* User Register */ + /** + * @brief RESOLUTION + */ + typedef enum { + RESOLUTION_12RH_14TEMP = 0, /*!< Resolution: RH 12-bits, T 14-bits */ + RESOLUTION_8RH_12TEMP = 1, /*!< Resolution: RH 8-bits, T 12-bits */ + RESOLUTION_10RH_13TEMP = 2, /*!< Resolution: RH 10-bits, T 13-bits */ + RESOLUTION_11RH_11TEMP = 3 /*!< Resolution: RH 11-bits, T 11-bits */ + } AMBIMATE_MS4_user_register_resolution_t; + + /** + * @brief STATUS: END OF BATTERY + */ + typedef enum { + STATUS_END_BATTERY_HIGH_2V25 = 0, /*!< Status: RH 12-bits, T 14-bits */ + STATUS_END_BATTERY_LOW_2V25 = 1 /*!< Status: RH 8-bits, T 12-bits */ + } AMBIMATE_MS4_user_register_status_t; + + /** + * @brief ON-CHIP HEATER + */ + typedef enum { + HEATER_ENABLED = 0, /*!< Heater enabled */ + HEATER_DISABLED = 1 /*!< Heater disabled */ + } AMBIMATE_MS4_user_register_heater_t; + + /** + * @brief OTP RELOAD + */ + typedef enum { + OTP_ENABLED = 0, /*!< OTP enabled */ + OTP_DISABLED = 1 /*!< OTP disabled */ + } AMBIMATE_MS4_user_register_otp_t; + + + + /* Mode of working */ + /** + * @brief MODE + */ + typedef enum { + MODE_HOLD_MASTER = 0, /*!< Mode Hold master */ + MODE_NO_HOLD_MASTER = 1 /*!< Mode No hold master */ + } AMBIMATE_MS4_master_mode_t; + + + + + +#ifndef VECTOR_STRUCT_H +#define VECTOR_STRUCT_H + typedef struct { + char RawTemperature[3]; + } Vector_raw_temperature_t; + + typedef struct { + char RawHumidity[3]; + } Vector_raw_humidity_t; + + typedef struct { + float Temperature; + } Vector_temperature_f; + + typedef struct { + float Humidity; + } Vector_humidity_f; +#endif + + + /** + * @brief INTERNAL CONSTANTS + */ + typedef enum { + AMBIMATE_MS4_SUCCESS = 0, + AMBIMATE_MS4_FAILURE = 1, + I2C_SUCCESS = 0 /*!< I2C communication was fine */ + } AMBIMATE_MS4_status_t; + + + + + /** Create an AMBIMATE_MS4 object connected to the specified I2C pins. + * + * @param sda I2C data pin + * @param scl I2C clock pin + * @param addr I2C slave address + * @param freq I2C frequency in Hz. + */ + AMBIMATE_MS4 ( PinName sda, PinName scl, uint32_t addr, uint32_t freq ); + + /** Delete AMBIMATE_MS4 object. + */ + ~AMBIMATE_MS4(); + + /** It configures the device. + */ + AMBIMATE_MS4_status_t AMBIMATE_MS4_Init ( AMBIMATE_MS4_master_mode_t myMode, AMBIMATE_MS4_user_register_resolution_t myResolution, AMBIMATE_MS4_user_register_heater_t myHeater ); + + /** It resets the device by software. + */ + AMBIMATE_MS4_status_t AMBIMATE_MS4_SoftReset ( void ); + + /** It triggers a new temperature measurement. + */ + AMBIMATE_MS4_status_t AMBIMATE_MS4_TriggerTemperature ( void ); + + /** It reads the raw temperature. + */ + AMBIMATE_MS4_status_t AMBIMATE_MS4_ReadRawTemperature ( Vector_raw_temperature_t* myRawTemperature ); + + /** It reads the temperature. + */ + AMBIMATE_MS4_status_t AMBIMATE_MS4_ReadTemperature ( Vector_temperature_f* myTemperature ); + + /** It triggers a new humidity measurement. + */ + AMBIMATE_MS4_status_t AMBIMATE_MS4_TriggerHumidity ( void ); + + /** It reads the raw humidity. + */ + AMBIMATE_MS4_status_t AMBIMATE_MS4_ReadRawHumidity ( Vector_raw_humidity_t* myRawHumidity ); + + /** It reads the humidity. + */ + AMBIMATE_MS4_status_t AMBIMATE_MS4_ReadHumidity ( Vector_humidity_f* myHumidity ); + + /** It gets the battery status. + */ + AMBIMATE_MS4_status_t AMBIMATE_MS4_BatteryStatus ( AMBIMATE_MS4_user_register_status_t* myBattStatus ); + +private: + I2C _i2c; + uint32_t _AMBIMATE_MS4_Addr; +}; + +#endif