From 23d6b5c49f77d2f06a03bdfa4acb87ba4c62e1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=B3r=C3=A1nt=20Pint=C3=A9r?= Date: Wed, 31 Jan 2024 18:28:32 +0100 Subject: [PATCH] Rename files related to SHT3x to EnvironmentSht3x --- platformio.ini | 2 +- src/devices/DeviceDefinition.hpp | 6 ++-- src/devices/UglyDucklingMk4.hpp | 2 +- .../{Environment.hpp => EnvironmentSht3x.hpp} | 22 ++++++------ ...nent.hpp => EnvironmentSht3xComponent.hpp} | 34 +++++++++---------- 5 files changed, 33 insertions(+), 33 deletions(-) rename src/peripherals/environment/{Environment.hpp => EnvironmentSht3x.hpp} (68%) rename src/peripherals/environment/{EnvironmentComponent.hpp => EnvironmentSht3xComponent.hpp} (61%) diff --git a/platformio.ini b/platformio.ini index ed8ff164..e60b820c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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] diff --git a/src/devices/DeviceDefinition.hpp b/src/devices/DeviceDefinition.hpp index 03999985..6ca808cf 100644 --- a/src/devices/DeviceDefinition.hpp +++ b/src/devices/DeviceDefinition.hpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include @@ -53,7 +53,7 @@ class DeviceDefinition { } virtual void registerPeripheralFactories(PeripheralManager& peripheralManager) { - peripheralManager.registerFactory(sht31Factory); + peripheralManager.registerFactory(sht3xFactory); registerDeviceSpecificPeripheralFactories(peripheralManager); } @@ -78,7 +78,7 @@ class DeviceDefinition { TDeviceConfiguration& config = configFile.config; private: - EnvironmentSht31Factory sht31Factory; + EnvironmentSht3xFactory sht3xFactory; }; template diff --git a/src/devices/UglyDucklingMk4.hpp b/src/devices/UglyDucklingMk4.hpp index e405bd89..62ee12fb 100644 --- a/src/devices/UglyDucklingMk4.hpp +++ b/src/devices/UglyDucklingMk4.hpp @@ -48,7 +48,7 @@ class UglyDucklingMk4 : public DeviceDefinition { // Device address is 0x44 = 68 return { R"({ - "type": "environment:sht31", + "type": "environment:sht3x", "name": "environment", "params": { "address": "0x44", diff --git a/src/peripherals/environment/Environment.hpp b/src/peripherals/environment/EnvironmentSht3x.hpp similarity index 68% rename from src/peripherals/environment/Environment.hpp rename to src/peripherals/environment/EnvironmentSht3x.hpp index bd90abbc..ac42937d 100644 --- a/src/peripherals/environment/Environment.hpp +++ b/src/peripherals/environment/EnvironmentSht3x.hpp @@ -7,7 +7,7 @@ #include #include -#include "EnvironmentComponent.hpp" +#include "EnvironmentSht3xComponent.hpp" using namespace farmhub::devices; using namespace farmhub::kernel; @@ -16,33 +16,33 @@ using std::make_unique; using std::unique_ptr; namespace farmhub::peripherals::environment { -class EnvironmentSht31 +class EnvironmentSht3x : public Peripheral { public: - EnvironmentSht31(const String& name, shared_ptr mqttRoot, I2CConfig config) + EnvironmentSht3x(const String& name, shared_ptr mqttRoot, I2CConfig config) : Peripheral(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 { public: - EnvironmentSht31Factory() - : PeripheralFactory("environment:sht31", "environment") { + EnvironmentSht3xFactory() + : PeripheralFactory("environment:sht3x", "environment") { } unique_ptr> createPeripheral(const String& name, const I2CDeviceConfig& deviceConfig, shared_ptr 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(name, mqttRoot, i2cConfig); + Log.infoln("Creating SHT3x environment sensor %s with %s", name.c_str(), i2cConfig.toString().c_str()); + return make_unique(name, mqttRoot, i2cConfig); } }; diff --git a/src/peripherals/environment/EnvironmentComponent.hpp b/src/peripherals/environment/EnvironmentSht3xComponent.hpp similarity index 61% rename from src/peripherals/environment/EnvironmentComponent.hpp rename to src/peripherals/environment/EnvironmentSht3xComponent.hpp index e823fd92..96aea71c 100644 --- a/src/peripherals/environment/EnvironmentComponent.hpp +++ b/src/peripherals/environment/EnvironmentSht3xComponent.hpp @@ -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 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; @@ -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; };