Skip to content

Commit

Permalink
Fix I2C sensor initialization
Browse files Browse the repository at this point in the history
Otherwise sensor fields don't get 0-initialized, and a lot of crap gets in.
  • Loading branch information
lptr committed Dec 17, 2024
1 parent 1877619 commit 4ef934a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 7 deletions.
3 changes: 1 addition & 2 deletions main/peripherals/environment/Sht2xComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Sht2xComponent
LOGI("Initializing %s environment sensor with %s",
sensorType.c_str(), config.toString().c_str());

memset(&sensor, 0, sizeof(i2c_dev_t));
ESP_ERROR_CHECK(si7021_init_desc(&sensor, bus->port, bus->sda->getGpio(), bus->scl->getGpio()));
}

Expand Down Expand Up @@ -72,7 +71,7 @@ class Sht2xComponent
}

shared_ptr<I2CBus> bus;
i2c_dev_t sensor;
i2c_dev_t sensor {};
};

} // namespace farmhub::peripherals::environment
2 changes: 1 addition & 1 deletion main/peripherals/environment/Sht3xComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Sht3xComponent

private:
shared_ptr<I2CBus> bus;
sht3x_t sensor;
sht3x_t sensor {};
};

} // namespace farmhub::peripherals::environment
4 changes: 1 addition & 3 deletions main/peripherals/light_sensor/Bh1750.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class Bh1750Component
LOGI("Initializing BH1750 light sensor with %s",
config.toString().c_str());

memset(&sensor, 0, sizeof(i2c_dev_t)); // Zero descriptor

// TODO Use I2CManager to create device
ESP_ERROR_CHECK(bh1750_init_desc(&sensor, config.address, I2C_NUM_0, config.sda->getGpio(), config.scl->getGpio()));
ESP_ERROR_CHECK(bh1750_setup(&sensor, BH1750_MODE_CONTINUOUS, BH1750_RES_LOW));
Expand All @@ -65,7 +63,7 @@ class Bh1750Component
}

private:
i2c_dev_t sensor;
i2c_dev_t sensor {};
};

class Bh1750
Expand Down
2 changes: 1 addition & 1 deletion main/peripherals/light_sensor/Tsl2591.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Tsl2591Component

private:
shared_ptr<I2CBus> bus;
tsl2591_t sensor;
tsl2591_t sensor {};
};

class Tsl2591
Expand Down

0 comments on commit 4ef934a

Please sign in to comment.