Arslan Test
Dependencies: AMS_ENS210_temp_humid_sensor
Diff: AMS_CCS811.cpp
- Revision:
- 13:a74306788df7
- Parent:
- 12:45065badca0f
- Child:
- 14:0e8f5bf68b50
--- a/AMS_CCS811.cpp Tue Jan 24 14:14:50 2017 +0000 +++ b/AMS_CCS811.cpp Tue Jan 24 15:09:29 2017 +0000 @@ -1,12 +1,12 @@ #include "AMS_CCS811.h" -AMS_CCS811::AMS_CCS811(I2C * i2c, PinName n_wake_pin) : _n_wake_out(), _addr_out(), _int_data(), _ens210(), i2c() { +AMS_CCS811::AMS_CCS811(I2C * i2c, PinName n_wake_pin) : _n_wake_out(), _addr_out(), _int_data(), _ens210(), _i2c() { _n_wake_out = new (std::nothrow) DigitalOut(n_wake_pin, 1); _i2c = i2c; } -AMS_CCS811::AMS_CCS811(I2C * i2c, PinName n_wake_pin, I2C * ens210_i2c) : _n_wake_out(), _addr_out(), _int_data(), _ens210(), i2c() { +AMS_CCS811::AMS_CCS811(I2C * i2c, PinName n_wake_pin, I2C * ens210_i2c) : _n_wake_out(), _addr_out(), _int_data(), _ens210(), _i2c() { _n_wake_out = new (std::nothrow) DigitalOut(n_wake_pin, 1); _i2c = i2c; ens210_i2c_interface(ens210_i2c); @@ -23,6 +23,7 @@ bool success = false; + _init_errors(); _init_fractions(); set_defaults(); @@ -35,14 +36,15 @@ int fw_mode = firmware_mode(); if (fw_mode == 1) { + success = write_config(); enable_ens210(true); - success = write_config(); } else if (fw_mode == 0) { // is in boot mode, needs to be loaded into app mode if (boot_app_start()) // if succesfully writes to app_start, retry init - init(); + success = init(); } } + return success; } @@ -145,6 +147,7 @@ } bool AMS_CCS811::addr_mode() { + _addr_dir = false; if (_addr_out != NULL) { _addr_dir = _addr_out->read(); } @@ -411,7 +414,7 @@ } void AMS_CCS811::update_slave_addr() { - _slave_addr = addr_mode() ? CCS811_SLAVE_ADDR_RAW_H : CCS811_SLAVE_ADDR_RAW_L; + _slave_addr = addr_mode() ? CCS811_SLAVE_ADDR_RAW_H : CCS811_SLAVE_ADDR_RAW_L; } void AMS_CCS811::_isr_data() { @@ -457,7 +460,7 @@ } int AMS_CCS811::i2c_read(char reg_addr, char* output, int len) { - + int read_count = 0; if (_n_wake_out != NULL) { // check nWAKE pin is set _n_wake_out->write(0); // Hold low