-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a custom setup script to check for the dependencies and pass along the required compile flags to the module; also split the object definitions for the target modules from their source so as to allow #including them.
- Loading branch information
1 parent
b3f9983
commit 7a40ef7
Showing
13 changed files
with
220 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name:": "PWM_fan", | ||
"build": { | ||
"extraScript": "setup_deps.py" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Import('env') | ||
|
||
|
||
usermods = env.GetProjectOption("custom_usermods","").split(" ") | ||
# Check for dependencies | ||
if "Temperature" in usermods: | ||
env.Append(CPPDEFINES=[("USERMOD_DALLASTEMPERATURE")]) | ||
elif "sht" in usermods: | ||
env.Append(CPPDEFINES=[("USERMOD_SHT")]) | ||
else: | ||
raise RuntimeError("PWM_fan usermod requires Temperature or sht to be enabled") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#pragma once | ||
#include "wled.h" | ||
#include "OneWire.h" | ||
|
||
//Pin defaults for QuinLed Dig-Uno if not overriden | ||
#ifndef TEMPERATURE_PIN | ||
#ifdef ARDUINO_ARCH_ESP32 | ||
#define TEMPERATURE_PIN 18 | ||
#else //ESP8266 boards | ||
#define TEMPERATURE_PIN 14 | ||
#endif | ||
#endif | ||
|
||
// the frequency to check temperature, 1 minute | ||
#ifndef USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL | ||
#define USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL 60000 | ||
#endif | ||
|
||
class UsermodTemperature : public Usermod { | ||
|
||
private: | ||
|
||
bool initDone = false; | ||
OneWire *oneWire; | ||
// GPIO pin used for sensor (with a default compile-time fallback) | ||
int8_t temperaturePin = TEMPERATURE_PIN; | ||
// measurement unit (true==°C, false==°F) | ||
bool degC = true; | ||
// using parasite power on the sensor | ||
bool parasite = false; | ||
int8_t parasitePin = -1; | ||
// how often do we read from sensor? | ||
unsigned long readingInterval = USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL; | ||
// set last reading as "40 sec before boot", so first reading is taken after 20 sec | ||
unsigned long lastMeasurement = UINT32_MAX - USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL; | ||
// last time requestTemperatures was called | ||
// used to determine when we can read the sensors temperature | ||
// we have to wait at least 93.75 ms after requestTemperatures() is called | ||
unsigned long lastTemperaturesRequest; | ||
float temperature; | ||
// indicates requestTemperatures has been called but the sensor measurement is not complete | ||
bool waitingForConversion = false; | ||
// flag set at startup if DS18B20 sensor not found, avoids trying to keep getting | ||
// temperature if flashed to a board without a sensor attached | ||
byte sensorFound; | ||
|
||
bool enabled = true; | ||
|
||
bool HApublished = false; | ||
int16_t idx = -1; // Domoticz virtual sensor idx | ||
|
||
// strings to reduce flash memory usage (used more than twice) | ||
static const char _name[]; | ||
static const char _enabled[]; | ||
static const char _readInterval[]; | ||
static const char _parasite[]; | ||
static const char _parasitePin[]; | ||
static const char _domoticzIDX[]; | ||
static const char _sensor[]; | ||
static const char _temperature[]; | ||
static const char _Temperature[]; | ||
static const char _data_fx[]; | ||
|
||
//Dallas sensor quick (& dirty) reading. Credit to - Author: Peter Scargill, August 17th, 2013 | ||
float readDallas(); | ||
void requestTemperatures(); | ||
void readTemperature(); | ||
bool findSensor(); | ||
#ifndef WLED_DISABLE_MQTT | ||
void publishHomeAssistantAutodiscovery(); | ||
#endif | ||
|
||
static UsermodTemperature* _instance; // to overcome nonstatic getTemperatureC() method and avoid UsermodManager::lookup(USERMOD_ID_TEMPERATURE); | ||
|
||
public: | ||
|
||
UsermodTemperature() { _instance = this; } | ||
static UsermodTemperature *getInstance() { return UsermodTemperature::_instance; } | ||
|
||
/* | ||
* API calls te enable data exchange between WLED modules | ||
*/ | ||
inline float getTemperatureC() { return temperature; } | ||
inline float getTemperatureF() { return temperature * 1.8f + 32.0f; } | ||
float getTemperature(); | ||
const char *getTemperatureUnit(); | ||
uint16_t getId() override { return USERMOD_ID_TEMPERATURE; } | ||
|
||
void setup() override; | ||
void loop() override; | ||
//void connected() override; | ||
#ifndef WLED_DISABLE_MQTT | ||
void onMqttConnect(bool sessionPresent) override; | ||
#endif | ||
//void onUpdateBegin(bool init) override; | ||
|
||
//bool handleButton(uint8_t b) override; | ||
//void handleOverlayDraw() override; | ||
|
||
void addToJsonInfo(JsonObject& root) override; | ||
//void addToJsonState(JsonObject &root) override; | ||
//void readFromJsonState(JsonObject &root) override; | ||
void addToConfig(JsonObject &root) override; | ||
bool readFromConfig(JsonObject &root) override; | ||
|
||
void appendConfigData() override; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
; Options | ||
; ------- | ||
; USERMOD_DALLASTEMPERATURE - define this to have this user mod included wled00\usermods_list.cpp | ||
; USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL - the number of milliseconds between measurements, defaults to 60 seconds | ||
; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#pragma once | ||
#include "wled.h" | ||
|
||
#ifdef WLED_DISABLE_MQTT | ||
#error "This user mod requires MQTT to be enabled." | ||
#endif | ||
|
||
#define USERMOD_SHT_TYPE_SHT30 0 | ||
#define USERMOD_SHT_TYPE_SHT31 1 | ||
#define USERMOD_SHT_TYPE_SHT35 2 | ||
#define USERMOD_SHT_TYPE_SHT85 3 | ||
|
||
class SHT; | ||
|
||
class ShtUsermod : public Usermod | ||
{ | ||
private: | ||
bool enabled = false; // Is usermod enabled or not | ||
bool firstRunDone = false; // Remembers if the first config load run had been done | ||
bool initDone = false; // Remembers if the mod has been completely initialised | ||
bool haMqttDiscovery = false; // Is MQTT discovery enabled or not | ||
bool haMqttDiscoveryDone = false; // Remembers if we already published the HA discovery topics | ||
|
||
// SHT vars | ||
SHT *shtTempHumidSensor = nullptr; // Instance of SHT lib | ||
byte shtType = 0; // SHT sensor type to be used. Default: SHT30 | ||
byte unitOfTemp = 0; // Temperature unit to be used. Default: Celsius (0 = Celsius, 1 = Fahrenheit) | ||
bool shtInitDone = false; // Remembers if SHT sensor has been initialised | ||
bool shtReadDataSuccess = false; // Did we have a successful data read and is a valid temperature and humidity available? | ||
const byte shtI2cAddress = 0x44; // i2c address of the sensor. 0x44 is the default for all SHT sensors. Change this, if needed | ||
unsigned long shtLastTimeUpdated = 0; // Remembers when we read data the last time | ||
bool shtDataRequested = false; // Reading data is done async. This remembers if we asked the sensor to read data | ||
float shtCurrentTempC = 0.0f; // Last read temperature in Celsius | ||
float shtCurrentHumidity = 0.0f; // Last read humidity in RH% | ||
|
||
|
||
void initShtTempHumiditySensor(); | ||
void cleanupShtTempHumiditySensor(); | ||
void cleanup(); | ||
inline bool isShtReady() { return shtInitDone; } // Checks if the SHT sensor has been initialised. | ||
|
||
void publishTemperatureAndHumidityViaMqtt(); | ||
void publishHomeAssistantAutodiscovery(); | ||
void appendDeviceToMqttDiscoveryMessage(JsonDocument& root); | ||
|
||
public: | ||
// Strings to reduce flash memory usage (used more than twice) | ||
static const char _name[]; | ||
static const char _enabled[]; | ||
static const char _shtType[]; | ||
static const char _unitOfTemp[]; | ||
static const char _haMqttDiscovery[]; | ||
|
||
void setup(); | ||
void loop(); | ||
void onMqttConnect(bool sessionPresent); | ||
void appendConfigData(); | ||
void addToConfig(JsonObject &root); | ||
bool readFromConfig(JsonObject &root); | ||
void addToJsonInfo(JsonObject& root); | ||
|
||
bool isEnabled() { return enabled; } | ||
|
||
float getTemperature(); | ||
float getTemperatureC() { return roundf(shtCurrentTempC * 10.0f) / 10.0f; } | ||
float getTemperatureF() { return (getTemperatureC() * 1.8f) + 32.0f; } | ||
float getHumidity() { return roundf(shtCurrentHumidity * 10.0f) / 10.0f; } | ||
const char* getUnitString(); | ||
|
||
uint16_t getId() { return USERMOD_ID_SHT; } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name:": "sht", | ||
"dependencies": { | ||
"robtillaart/SHT85": "~0.3.3" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.