Skip to content

Commit

Permalink
Rename files related to SHT3x to EnvironmentSht3x
Browse files Browse the repository at this point in the history
  • Loading branch information
lptr committed Jan 31, 2024
1 parent bf0eb16 commit 23d6b5c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ lib_deps =
https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2
arduino-libraries/NTPClient@^3.2.1
thijse/ArduinoLog@^1.1.1
# SHT31
# SHT3x support
robtillaart/SHT31@~0.5.0

[debug]
Expand Down
6 changes: 3 additions & 3 deletions src/devices/DeviceDefinition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <kernel/drivers/BatteryDriver.hpp>
#include <kernel/drivers/LedDriver.hpp>

#include <peripherals/environment/Environment.hpp>
#include <peripherals/environment/EnvironmentSht3x.hpp>

#include <version.h>

Expand Down Expand Up @@ -53,7 +53,7 @@ class DeviceDefinition {
}

virtual void registerPeripheralFactories(PeripheralManager& peripheralManager) {
peripheralManager.registerFactory(sht31Factory);
peripheralManager.registerFactory(sht3xFactory);
registerDeviceSpecificPeripheralFactories(peripheralManager);
}

Expand All @@ -78,7 +78,7 @@ class DeviceDefinition {
TDeviceConfiguration& config = configFile.config;

private:
EnvironmentSht31Factory sht31Factory;
EnvironmentSht3xFactory sht3xFactory;
};

template <typename TDeviceConfiguration>
Expand Down
2 changes: 1 addition & 1 deletion src/devices/UglyDucklingMk4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class UglyDucklingMk4 : public DeviceDefinition<Mk4Config> {
// Device address is 0x44 = 68
return {
R"({
"type": "environment:sht31",
"type": "environment:sht3x",
"name": "environment",
"params": {
"address": "0x44",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <kernel/drivers/MqttDriver.hpp>
#include <peripherals/I2CConfig.hpp>

#include "EnvironmentComponent.hpp"
#include "EnvironmentSht3xComponent.hpp"

using namespace farmhub::devices;
using namespace farmhub::kernel;
Expand All @@ -16,33 +16,33 @@ using std::make_unique;
using std::unique_ptr;
namespace farmhub::peripherals::environment {

class EnvironmentSht31
class EnvironmentSht3x
: public Peripheral<EmptyConfiguration> {
public:
EnvironmentSht31(const String& name, shared_ptr<MqttDriver::MqttRoot> mqttRoot, I2CConfig config)
EnvironmentSht3x(const String& name, shared_ptr<MqttDriver::MqttRoot> mqttRoot, I2CConfig config)
: Peripheral<EmptyConfiguration>(name, mqttRoot)
, sht31(name, mqttRoot, config) {
, sht3x(name, mqttRoot, config) {
}

void populateTelemetry(JsonObject& telemetryJson) override {
sht31.populateTelemetry(telemetryJson);
sht3x.populateTelemetry(telemetryJson);
}

private:
Sht31Component sht31;
EnvironmentSht3xComponent sht3x;
};

class EnvironmentSht31Factory
class EnvironmentSht3xFactory
: public PeripheralFactory<I2CDeviceConfig, EmptyConfiguration> {
public:
EnvironmentSht31Factory()
: PeripheralFactory<I2CDeviceConfig, EmptyConfiguration>("environment:sht31", "environment") {
EnvironmentSht3xFactory()
: PeripheralFactory<I2CDeviceConfig, EmptyConfiguration>("environment:sht3x", "environment") {
}

unique_ptr<Peripheral<EmptyConfiguration>> createPeripheral(const String& name, const I2CDeviceConfig& deviceConfig, shared_ptr<MqttDriver::MqttRoot> mqttRoot) override {
auto i2cConfig = deviceConfig.parse(SHT_DEFAULT_ADDRESS, GPIO_NUM_NC, GPIO_NUM_NC);
Log.infoln("Creating SHT31 environment sensor %s with %s", name.c_str(), i2cConfig.toString().c_str());
return make_unique<EnvironmentSht31>(name, mqttRoot, i2cConfig);
Log.infoln("Creating SHT3x environment sensor %s with %s", name.c_str(), i2cConfig.toString().c_str());
return make_unique<EnvironmentSht3x>(name, mqttRoot, i2cConfig);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,36 @@ using namespace farmhub::kernel;

namespace farmhub::peripherals::environment {

class Sht31Component
class EnvironmentSht3xComponent
: public Component,
public TelemetryProvider {
public:
Sht31Component(
EnvironmentSht3xComponent(
const String& name,
shared_ptr<MqttDriver::MqttRoot> mqttRoot,
I2CConfig config)
: Component(name, mqttRoot)
// TODO Add I2C manager to hand out wires
, wire(1)
, sht31(config.address, &wire) {
, sht3x(config.address, &wire) {

// TODO Add commands to soft/hard reset the sensor
// TODO Add configuration for fast / slow measurement
// TODO Add a separate task to do measurements to unblock telemetry collection?

Log.infoln("Initializing SHT31 environment sensor with %s", config.toString().c_str());
Log.infoln("Initializing SHT3s environment sensor with %s", config.toString().c_str());
if (!wire.begin(config.sda, config.scl, 100000L)) {
Log.errorln("Failed to initialize I2C bus for SHT31 environment sensor");
Log.errorln("Failed to initialize I2C bus for SHT3x environment sensor");
return;
}
if (!sht31.begin()) {
Log.errorln("Failed to initialize SHT31 environment sensor: %d",
sht31.getError());
if (!sht3x.begin()) {
Log.errorln("Failed to initialize SHT3x environment sensor: %d",
sht3x.getError());
return;
}
if (!sht31.isConnected()) {
Log.errorln("SHT31 environment sensor is not connected: %d",
sht31.getError());
if (!sht3x.isConnected()) {
Log.errorln("SHT3x environment sensor is not connected: %d",
sht3x.getError());
return;
}
initialized = true;
Expand All @@ -54,18 +54,18 @@ class Sht31Component
if (!initialized) {
return;
}
if (!sht31.read()) {
Log.errorln("Failed to read SHT31 environment sensor: %d",
sht31.getError());
if (!sht3x.read()) {
Log.errorln("Failed to read SHT3x environment sensor: %d",
sht3x.getError());
return;
}
json["temperature"] = sht31.getTemperature();
json["humidity"] = sht31.getHumidity();
json["temperature"] = sht3x.getTemperature();
json["humidity"] = sht3x.getHumidity();
}

private:
TwoWire wire;
SHT31 sht31;
SHT31 sht3x;
bool initialized = false;
};

Expand Down

0 comments on commit 23d6b5c

Please sign in to comment.