|
@@ -31,6 +31,10 @@ MICSV89::MICSV89 (int bus, uint8_t address) {
|
31
|
31
|
m_valid = false;
|
32
|
32
|
m_address = address;
|
33
|
33
|
i2c = new mraa::I2c(bus);
|
|
34
|
+ if(i2c->frequency(mraa::I2C_STD) != mraa::SUCCESS){
|
|
35
|
+ throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.frequency(I2C_STD) failed");
|
|
36
|
+ return;
|
|
37
|
+ }
|
34
|
38
|
tx_buf[0] = 0x09;
|
35
|
39
|
tx_buf[1] = 0x00;
|
36
|
40
|
tx_buf[2] = 0x00;
|
|
@@ -38,13 +42,23 @@ MICSV89::MICSV89 (int bus, uint8_t address) {
|
38
|
42
|
|
39
|
43
|
void MICSV89::update() {
|
40
|
44
|
m_valid = false;
|
41
|
|
- i2c->address(m_address);
|
42
|
|
- i2c->frequency(MRAA_I2C_STD);
|
43
|
|
- i2c->write(tx_buf, 3);
|
|
45
|
+ if(i2c->address(m_address) != mraa::SUCCESS){
|
|
46
|
+ throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.address() failed");
|
|
47
|
+ return;
|
|
48
|
+ }
|
|
49
|
+ if(i2c->write(tx_buf, 3) != mraa::SUCCESS){
|
|
50
|
+ throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.write() failed");
|
|
51
|
+ return;
|
|
52
|
+ }
|
44
|
53
|
sleep(1); //Give the device time to make the measurement.
|
45
|
|
- i2c->address(m_address);
|
46
|
|
- i2c->frequency(MRAA_I2C_STD);
|
47
|
|
- i2c->read(rx_buf, 6);
|
|
54
|
+ if(i2c->address(m_address) != mraa::SUCCESS){
|
|
55
|
+ throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.address() failed");
|
|
56
|
+ return;
|
|
57
|
+ }
|
|
58
|
+ if(i2c->read(rx_buf, 6) != 6){
|
|
59
|
+ throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.read() failed");
|
|
60
|
+ return;
|
|
61
|
+ }
|
48
|
62
|
m_valid = true;
|
49
|
63
|
}
|
50
|
64
|
|