First working version of CDM7160 library
Revision 1:4a0a9c03afba, committed 2020-04-17
- Comitter:
- MichalKozlowski
- Date:
- Fri Apr 17 10:47:43 2020 +0000
- Parent:
- 0:8fe9c25985e5
- Child:
- 2:207717b5eaee
- Commit message:
- Implementation of Integrated Init, cleaning code
Changed in this revision
| CDM7160.cpp | Show annotated file Show diff for this revision Revisions of this file |
| CDM7160.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/CDM7160.cpp Thu Sep 12 12:53:15 2019 +0000
+++ b/CDM7160.cpp Fri Apr 17 10:47:43 2020 +0000
@@ -44,6 +44,26 @@
return CDM7160_ERROR;
}
+int8_t CDM7160::initIntegrated( uint16_t hpa, uint16_t height,
+ eControlMode mode,
+ eFunctionSetting atm_alt_correct,
+ eFunctionSetting pwm_conce,
+ eFunctionSetting pwm_pin){
+ for(uint8_t i=0 ; i<3 ; i++){
+ if(control(mode) == CDM7160_SUCCESS){
+ if(setSettings(atm_alt_correct, pwm_conce, pwm_pin) == CDM7160_SUCCESS){
+ if(setAirPressureAndAltitude(hpa, height) == CDM7160_SUCCESS){
+ return CDM7160_I2C_ADDR;
+ }
+
+ }
+ }
+ wait_ms(20);
+ }
+
+ return CDM7160_ERROR;
+}
+
int8_t CDM7160::softReset(){
char data[1] = {0x01};
if(write(RST, data, 1) == CDM7160_SUCCESS){
@@ -74,7 +94,6 @@
if(read(data,2) == CDM7160_SUCCESS){
for(int i=0; i<2; i++){buff[i] = data[i];}
cdm7160.co2 = (int16_t)data[1]<<8 | data[0];
- wait(1.7);
return cdm7160.co2;
}
}
@@ -107,7 +126,8 @@
}
int8_t CDM7160::setAlarmLimits(uint16_t high_limit, uint16_t low_limit){
- char data[1] = {high_limit/10};
+ char data[1];
+ data[0] = high_limit/10;
if(write(ALHI, data, 1) == CDM7160_SUCCESS){
wait_ms(1);
data[0] = low_limit/10;
@@ -163,7 +183,8 @@
eFunctionSetting pwm_conce,
eFunctionSetting pwm_pin){
- char data[1] = {pwm_pin | pwm_conce | atm_alt_correct};
+ char data[1];
+ data[0] = pwm_pin | pwm_conce | atm_alt_correct;
if(write(FUNC, data, 1) == CDM7160_SUCCESS){
return CDM7160_SUCCESS;
--- a/CDM7160.h Thu Sep 12 12:53:15 2019 +0000
+++ b/CDM7160.h Fri Apr 17 10:47:43 2020 +0000
@@ -28,48 +28,27 @@
*
* int main()
* {
- * int i=0; // Numer of measurements
+ * int i=0; // Number of measurement
* irq.rise(&irqCallback);
* //irq.fall(&irqCallback);
* sw.rise(&buttonCallback);
*
*
- * if(CO2.init() == CDM7160_I2C_ADDR){
+ * if(CO2.initIntegrated() == CDM7160_I2C_ADDR){
* printf("Initialization Success\r\n\n");
* }
* if(CO2.setAlarmLimits(1500,1450) == CDM7160_SUCCESS){
* printf("Alarm Limits has been set!\r\n");
* }
- * if(CO2.setAirPressureAndAltitude(1001, 130) == CDM7160_SUCCESS){
- * printf("Atmosferic Pressure and Altitude has been set!\r\n");
- * }
- * if(CO2.setSettings(CDM7160::HPAE_ON) == CDM7160_SUCCESS){
- * printf("Function settings has been set!\r\n");
- * }
- * if(CO2.selfDiagnosis() == CDM7160_SUCCESS){
- * printf("Self Diagnosis = %02X\r\n", CO2.cdm7160.selfDiag);
- * }
*
* while (true) {
* if(button){
- * if(CO2.control() == CDM7160_SUCCESS){
- * printf("Control register = %02X\r\n", CO2.cdm7160.control);
- * }
- * if(CO2.getStatus() == CDM7160_SUCCESS){
- * printf("Status register = %02X\r\n", CO2.cdm7160.status);
- * }
* if(CO2.getAlarmLimits() == CDM7160_SUCCESS){
* printf("High Alert Limit = %d Low Alert Limit = %d\r\n", CO2.cdm7160.highAlertLimit, CO2.cdm7160.lowAlertLimit);
* }
* if(CO2.getAirPressureAndAltitude() == CDM7160_SUCCESS){
* printf("Atmosferic Pressure = %d [hPa] Altitude = %d [m]\r\n", CO2.cdm7160.atmosferic_pressure, CO2.cdm7160.altitude);
* }
- * if(CO2.getSettings() == CDM7160_SUCCESS){
- * printf("Function settings = %02X\r\n", CO2.cdm7160.settings);
- * }
- * if(CO2.control(CDM7160::PWR_DOWN) == CDM7160_SUCCESS){
- * printf("Shutdown \r\n");
- * }
* button = false;
* }
*
@@ -79,6 +58,7 @@
* isIrq = false;
* }else{
* printf("CO2 = %d [ppm]\r\n", CO2.getCO2());
+ * wait(2);
* if(isIrq){
* printf("Interrupt !!!\r\n");
* isIrq = false;
@@ -225,6 +205,18 @@
*/
int8_t init();
+ /** Integrated Initialize the CDM7160 sensor
+ * By default: set Atmospheric pressure and altitude, set sensor in countinous mode,
+ * enable atm. pressure and altitude correction in measurement and
+ * disable PWM output PIN
+ * @return CDM7160 address if successful. CDM7160_ERROR if fail
+ */
+ int8_t initIntegrated( uint16_t hpa = 1005, uint16_t height = 130,
+ eControlMode mode = CONTIN,
+ eFunctionSetting atm_alt_correct= HPAE_OFF,
+ eFunctionSetting pwm_conce = PWMR_LOW,
+ eFunctionSetting pwm_pin = PWME_OFF);
+
/** Measure CO2 in ppm
* Measurement is stored in struct variable: int co2
* @return co2 if sucessful. CDM7160_ERROR if fail