mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
ims: Updated IMS sensor addressing
The IMS library will now change its I2C address after resetting the HW to a new address. It will attempt to close the mraa context and re-init each time. Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
@ -46,19 +46,25 @@ int main(int argc, char **argv)
|
||||
// Instantiate a IMS instance using i2c bus 0 and default address
|
||||
upm::IMS sensor(0);
|
||||
|
||||
int i2c_addr_cur = IMS_ADDRESS_DEFAULT + 1;
|
||||
while (shouldRun)
|
||||
{
|
||||
std::cout << "Version: "
|
||||
std::cout << std::hex << "Version: 0x"
|
||||
<< sensor.get_version()
|
||||
<< " light: "
|
||||
<< " light: 0x"
|
||||
<< sensor.get_light()
|
||||
<< " moisture: "
|
||||
<< " moisture: 0x"
|
||||
<< sensor.get_moisture()
|
||||
<< " temp: "
|
||||
<< sensor.get_temperature()
|
||||
<< " C"
|
||||
<< std::endl;
|
||||
|
||||
// Change the address and continue
|
||||
if (i2c_addr_cur >= 128) i2c_addr_cur = 1;
|
||||
std::cout << "Changing device address to 0x" << i2c_addr_cur
|
||||
<< std::endl;
|
||||
sensor.reset_i2c_address(i2c_addr_cur++);
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
@ -50,6 +50,8 @@ int main()
|
||||
return 1;
|
||||
}
|
||||
|
||||
int i2c_addr_cur = IMS_ADDRESS_DEFAULT + 1;
|
||||
|
||||
// Every second, sample the sensor outputs
|
||||
while (shouldRun)
|
||||
{
|
||||
@ -62,8 +64,19 @@ int main()
|
||||
printf("Version: %d light: 0x%04x moisture: 0x%04x temp: %3.2f C\n",
|
||||
version, light, moisture, temp/10.0);
|
||||
else
|
||||
{
|
||||
printf("Failed to read IMS sensor data...\n");
|
||||
break;
|
||||
}
|
||||
|
||||
// Change the address and continue
|
||||
if (i2c_addr_cur >= 128) i2c_addr_cur = 1;
|
||||
printf("Changing device address to 0x%02x\n", i2c_addr_cur);
|
||||
if (ims_reset_i2c_address(sensor, i2c_addr_cur++) != UPM_SUCCESS)
|
||||
{
|
||||
printf("Failed to change IMS I2C address...\n");
|
||||
break;
|
||||
}
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user