mirror of
https://github.com/wled/WLED.git
synced 2025-07-19 08:46:34 +00:00
usermods: Fix 7sd_reloaded cross module binding
Fix up the cross module binding for usermods/seven_segment_display_reloaded. This requires splitting off headers for BH1750_v2 and SN_Photoresistor.
This commit is contained in:
parent
ff99c7de70
commit
1cd3a97c51
@ -2,244 +2,176 @@
|
|||||||
#warning **** Included USERMOD_BH1750 ****
|
#warning **** Included USERMOD_BH1750 ****
|
||||||
|
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
#include <BH1750.h>
|
#include "BH1750_v2.h"
|
||||||
|
|
||||||
#ifdef WLED_DISABLE_MQTT
|
#ifdef WLED_DISABLE_MQTT
|
||||||
#error "This user mod requires MQTT to be enabled."
|
#error "This user mod requires MQTT to be enabled."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// the max frequency to check photoresistor, 10 seconds
|
static bool checkBoundSensor(float newValue, float prevValue, float maxDiff)
|
||||||
#ifndef USERMOD_BH1750_MAX_MEASUREMENT_INTERVAL
|
|
||||||
#define USERMOD_BH1750_MAX_MEASUREMENT_INTERVAL 10000
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// the min frequency to check photoresistor, 500 ms
|
|
||||||
#ifndef USERMOD_BH1750_MIN_MEASUREMENT_INTERVAL
|
|
||||||
#define USERMOD_BH1750_MIN_MEASUREMENT_INTERVAL 500
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// how many seconds after boot to take first measurement, 10 seconds
|
|
||||||
#ifndef USERMOD_BH1750_FIRST_MEASUREMENT_AT
|
|
||||||
#define USERMOD_BH1750_FIRST_MEASUREMENT_AT 10000
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// only report if difference grater than offset value
|
|
||||||
#ifndef USERMOD_BH1750_OFFSET_VALUE
|
|
||||||
#define USERMOD_BH1750_OFFSET_VALUE 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class Usermod_BH1750 : public Usermod
|
|
||||||
{
|
{
|
||||||
private:
|
return isnan(prevValue) || newValue <= prevValue - maxDiff || newValue >= prevValue + maxDiff || (newValue == 0.0 && prevValue > 0.0);
|
||||||
int8_t offset = USERMOD_BH1750_OFFSET_VALUE;
|
}
|
||||||
|
|
||||||
unsigned long maxReadingInterval = USERMOD_BH1750_MAX_MEASUREMENT_INTERVAL;
|
void Usermod_BH1750::_mqttInitialize()
|
||||||
unsigned long minReadingInterval = USERMOD_BH1750_MIN_MEASUREMENT_INTERVAL;
|
{
|
||||||
unsigned long lastMeasurement = UINT32_MAX - (USERMOD_BH1750_MAX_MEASUREMENT_INTERVAL - USERMOD_BH1750_FIRST_MEASUREMENT_AT);
|
mqttLuminanceTopic = String(mqttDeviceTopic) + F("/brightness");
|
||||||
unsigned long lastSend = UINT32_MAX - (USERMOD_BH1750_MAX_MEASUREMENT_INTERVAL - USERMOD_BH1750_FIRST_MEASUREMENT_AT);
|
|
||||||
// flag to indicate we have finished the first readLightLevel call
|
|
||||||
// allows this library to report to the user how long until the first
|
|
||||||
// measurement
|
|
||||||
bool getLuminanceComplete = false;
|
|
||||||
|
|
||||||
// flag set at startup
|
if (HomeAssistantDiscovery) _createMqttSensor(F("Brightness"), mqttLuminanceTopic, F("Illuminance"), F(" lx"));
|
||||||
bool enabled = true;
|
}
|
||||||
|
|
||||||
// strings to reduce flash memory usage (used more than twice)
|
// Create an MQTT Sensor for Home Assistant Discovery purposes, this includes a pointer to the topic that is published to in the Loop.
|
||||||
static const char _name[];
|
void Usermod_BH1750::_createMqttSensor(const String &name, const String &topic, const String &deviceClass, const String &unitOfMeasurement)
|
||||||
static const char _enabled[];
|
{
|
||||||
static const char _maxReadInterval[];
|
String t = String(F("homeassistant/sensor/")) + mqttClientID + F("/") + name + F("/config");
|
||||||
static const char _minReadInterval[];
|
|
||||||
static const char _offset[];
|
|
||||||
static const char _HomeAssistantDiscovery[];
|
|
||||||
|
|
||||||
bool initDone = false;
|
StaticJsonDocument<600> doc;
|
||||||
bool sensorFound = false;
|
|
||||||
|
|
||||||
// Home Assistant and MQTT
|
doc[F("name")] = String(serverDescription) + " " + name;
|
||||||
String mqttLuminanceTopic;
|
doc[F("state_topic")] = topic;
|
||||||
bool mqttInitialized = false;
|
doc[F("unique_id")] = String(mqttClientID) + name;
|
||||||
bool HomeAssistantDiscovery = true; // Publish Home Assistant Discovery messages
|
if (unitOfMeasurement != "")
|
||||||
|
doc[F("unit_of_measurement")] = unitOfMeasurement;
|
||||||
|
if (deviceClass != "")
|
||||||
|
doc[F("device_class")] = deviceClass;
|
||||||
|
doc[F("expire_after")] = 1800;
|
||||||
|
|
||||||
BH1750 lightMeter;
|
JsonObject device = doc.createNestedObject(F("device")); // attach the sensor to the same device
|
||||||
float lastLux = -1000;
|
device[F("name")] = serverDescription;
|
||||||
|
device[F("identifiers")] = "wled-sensor-" + String(mqttClientID);
|
||||||
|
device[F("manufacturer")] = F(WLED_BRAND);
|
||||||
|
device[F("model")] = F(WLED_PRODUCT_NAME);
|
||||||
|
device[F("sw_version")] = versionString;
|
||||||
|
|
||||||
bool checkBoundSensor(float newValue, float prevValue, float maxDiff)
|
String temp;
|
||||||
|
serializeJson(doc, temp);
|
||||||
|
DEBUG_PRINTLN(t);
|
||||||
|
DEBUG_PRINTLN(temp);
|
||||||
|
|
||||||
|
mqtt->publish(t.c_str(), 0, true, temp.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Usermod_BH1750::setup()
|
||||||
|
{
|
||||||
|
if (i2c_scl<0 || i2c_sda<0) { enabled = false; return; }
|
||||||
|
sensorFound = lightMeter.begin();
|
||||||
|
initDone = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Usermod_BH1750::loop()
|
||||||
|
{
|
||||||
|
if ((!enabled) || strip.isUpdating())
|
||||||
|
return;
|
||||||
|
|
||||||
|
unsigned long now = millis();
|
||||||
|
|
||||||
|
// check to see if we are due for taking a measurement
|
||||||
|
// lastMeasurement will not be updated until the conversion
|
||||||
|
// is complete the the reading is finished
|
||||||
|
if (now - lastMeasurement < minReadingInterval)
|
||||||
{
|
{
|
||||||
return isnan(prevValue) || newValue <= prevValue - maxDiff || newValue >= prevValue + maxDiff || (newValue == 0.0 && prevValue > 0.0);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up Home Assistant discovery entries
|
bool shouldUpdate = now - lastSend > maxReadingInterval;
|
||||||
void _mqttInitialize()
|
|
||||||
{
|
|
||||||
mqttLuminanceTopic = String(mqttDeviceTopic) + F("/brightness");
|
|
||||||
|
|
||||||
if (HomeAssistantDiscovery) _createMqttSensor(F("Brightness"), mqttLuminanceTopic, F("Illuminance"), F(" lx"));
|
float lux = lightMeter.readLightLevel();
|
||||||
|
lastMeasurement = millis();
|
||||||
|
getLuminanceComplete = true;
|
||||||
|
|
||||||
|
if (shouldUpdate || checkBoundSensor(lux, lastLux, offset))
|
||||||
|
{
|
||||||
|
lastLux = lux;
|
||||||
|
lastSend = millis();
|
||||||
|
|
||||||
|
if (WLED_MQTT_CONNECTED)
|
||||||
|
{
|
||||||
|
if (!mqttInitialized)
|
||||||
|
{
|
||||||
|
_mqttInitialize();
|
||||||
|
mqttInitialized = true;
|
||||||
|
}
|
||||||
|
mqtt->publish(mqttLuminanceTopic.c_str(), 0, true, String(lux).c_str());
|
||||||
|
DEBUG_PRINTLN(F("Brightness: ") + String(lux) + F("lx"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DEBUG_PRINTLN(F("Missing MQTT connection. Not publishing data"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create an MQTT Sensor for Home Assistant Discovery purposes, this includes a pointer to the topic that is published to in the Loop.
|
|
||||||
void _createMqttSensor(const String &name, const String &topic, const String &deviceClass, const String &unitOfMeasurement)
|
|
||||||
{
|
|
||||||
String t = String(F("homeassistant/sensor/")) + mqttClientID + F("/") + name + F("/config");
|
|
||||||
|
|
||||||
StaticJsonDocument<600> doc;
|
void Usermod_BH1750::addToJsonInfo(JsonObject &root)
|
||||||
|
{
|
||||||
|
JsonObject user = root[F("u")];
|
||||||
|
if (user.isNull())
|
||||||
|
user = root.createNestedObject(F("u"));
|
||||||
|
|
||||||
doc[F("name")] = String(serverDescription) + " " + name;
|
JsonArray lux_json = user.createNestedArray(F("Luminance"));
|
||||||
doc[F("state_topic")] = topic;
|
if (!enabled) {
|
||||||
doc[F("unique_id")] = String(mqttClientID) + name;
|
lux_json.add(F("disabled"));
|
||||||
if (unitOfMeasurement != "")
|
} else if (!sensorFound) {
|
||||||
doc[F("unit_of_measurement")] = unitOfMeasurement;
|
// if no sensor
|
||||||
if (deviceClass != "")
|
lux_json.add(F("BH1750 "));
|
||||||
doc[F("device_class")] = deviceClass;
|
lux_json.add(F("Not Found"));
|
||||||
doc[F("expire_after")] = 1800;
|
} else if (!getLuminanceComplete) {
|
||||||
|
// if we haven't read the sensor yet, let the user know
|
||||||
JsonObject device = doc.createNestedObject(F("device")); // attach the sensor to the same device
|
// that we are still waiting for the first measurement
|
||||||
device[F("name")] = serverDescription;
|
lux_json.add((USERMOD_BH1750_FIRST_MEASUREMENT_AT - millis()) / 1000);
|
||||||
device[F("identifiers")] = "wled-sensor-" + String(mqttClientID);
|
lux_json.add(F(" sec until read"));
|
||||||
device[F("manufacturer")] = F(WLED_BRAND);
|
|
||||||
device[F("model")] = F(WLED_PRODUCT_NAME);
|
|
||||||
device[F("sw_version")] = versionString;
|
|
||||||
|
|
||||||
String temp;
|
|
||||||
serializeJson(doc, temp);
|
|
||||||
DEBUG_PRINTLN(t);
|
|
||||||
DEBUG_PRINTLN(temp);
|
|
||||||
|
|
||||||
mqtt->publish(t.c_str(), 0, true, temp.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
if (i2c_scl<0 || i2c_sda<0) { enabled = false; return; }
|
|
||||||
sensorFound = lightMeter.begin();
|
|
||||||
initDone = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
if ((!enabled) || strip.isUpdating())
|
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
unsigned long now = millis();
|
lux_json.add(lastLux);
|
||||||
|
lux_json.add(F(" lx"));
|
||||||
// check to see if we are due for taking a measurement
|
|
||||||
// lastMeasurement will not be updated until the conversion
|
|
||||||
// is complete the the reading is finished
|
|
||||||
if (now - lastMeasurement < minReadingInterval)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool shouldUpdate = now - lastSend > maxReadingInterval;
|
|
||||||
|
|
||||||
float lux = lightMeter.readLightLevel();
|
|
||||||
lastMeasurement = millis();
|
|
||||||
getLuminanceComplete = true;
|
|
||||||
|
|
||||||
if (shouldUpdate || checkBoundSensor(lux, lastLux, offset))
|
|
||||||
{
|
|
||||||
lastLux = lux;
|
|
||||||
lastSend = millis();
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
|
||||||
if (WLED_MQTT_CONNECTED)
|
|
||||||
{
|
|
||||||
if (!mqttInitialized)
|
|
||||||
{
|
|
||||||
_mqttInitialize();
|
|
||||||
mqttInitialized = true;
|
|
||||||
}
|
|
||||||
mqtt->publish(mqttLuminanceTopic.c_str(), 0, true, String(lux).c_str());
|
|
||||||
DEBUG_PRINTLN(F("Brightness: ") + String(lux) + F("lx"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DEBUG_PRINTLN(F("Missing MQTT connection. Not publishing data"));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline float getIlluminance() {
|
// (called from set.cpp) stores persistent properties to cfg.json
|
||||||
return (float)lastLux;
|
void Usermod_BH1750::addToConfig(JsonObject &root)
|
||||||
}
|
{
|
||||||
|
// we add JSON object.
|
||||||
|
JsonObject top = root.createNestedObject(FPSTR(_name)); // usermodname
|
||||||
|
top[FPSTR(_enabled)] = enabled;
|
||||||
|
top[FPSTR(_maxReadInterval)] = maxReadingInterval;
|
||||||
|
top[FPSTR(_minReadInterval)] = minReadingInterval;
|
||||||
|
top[FPSTR(_HomeAssistantDiscovery)] = HomeAssistantDiscovery;
|
||||||
|
top[FPSTR(_offset)] = offset;
|
||||||
|
|
||||||
void addToJsonInfo(JsonObject &root)
|
DEBUG_PRINTLN(F("BH1750 config saved."));
|
||||||
|
}
|
||||||
|
|
||||||
|
// called before setup() to populate properties from values stored in cfg.json
|
||||||
|
bool Usermod_BH1750::readFromConfig(JsonObject &root)
|
||||||
|
{
|
||||||
|
// we look for JSON object.
|
||||||
|
JsonObject top = root[FPSTR(_name)];
|
||||||
|
if (top.isNull())
|
||||||
{
|
{
|
||||||
JsonObject user = root[F("u")];
|
|
||||||
if (user.isNull())
|
|
||||||
user = root.createNestedObject(F("u"));
|
|
||||||
|
|
||||||
JsonArray lux_json = user.createNestedArray(F("Luminance"));
|
|
||||||
if (!enabled) {
|
|
||||||
lux_json.add(F("disabled"));
|
|
||||||
} else if (!sensorFound) {
|
|
||||||
// if no sensor
|
|
||||||
lux_json.add(F("BH1750 "));
|
|
||||||
lux_json.add(F("Not Found"));
|
|
||||||
} else if (!getLuminanceComplete) {
|
|
||||||
// if we haven't read the sensor yet, let the user know
|
|
||||||
// that we are still waiting for the first measurement
|
|
||||||
lux_json.add((USERMOD_BH1750_FIRST_MEASUREMENT_AT - millis()) / 1000);
|
|
||||||
lux_json.add(F(" sec until read"));
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
lux_json.add(lastLux);
|
|
||||||
lux_json.add(F(" lx"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// (called from set.cpp) stores persistent properties to cfg.json
|
|
||||||
void addToConfig(JsonObject &root)
|
|
||||||
{
|
|
||||||
// we add JSON object.
|
|
||||||
JsonObject top = root.createNestedObject(FPSTR(_name)); // usermodname
|
|
||||||
top[FPSTR(_enabled)] = enabled;
|
|
||||||
top[FPSTR(_maxReadInterval)] = maxReadingInterval;
|
|
||||||
top[FPSTR(_minReadInterval)] = minReadingInterval;
|
|
||||||
top[FPSTR(_HomeAssistantDiscovery)] = HomeAssistantDiscovery;
|
|
||||||
top[FPSTR(_offset)] = offset;
|
|
||||||
|
|
||||||
DEBUG_PRINTLN(F("BH1750 config saved."));
|
|
||||||
}
|
|
||||||
|
|
||||||
// called before setup() to populate properties from values stored in cfg.json
|
|
||||||
bool readFromConfig(JsonObject &root)
|
|
||||||
{
|
|
||||||
// we look for JSON object.
|
|
||||||
JsonObject top = root[FPSTR(_name)];
|
|
||||||
if (top.isNull())
|
|
||||||
{
|
|
||||||
DEBUG_PRINT(FPSTR(_name));
|
|
||||||
DEBUG_PRINT(F("BH1750"));
|
|
||||||
DEBUG_PRINTLN(F(": No config found. (Using defaults.)"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool configComplete = !top.isNull();
|
|
||||||
|
|
||||||
configComplete &= getJsonValue(top[FPSTR(_enabled)], enabled, false);
|
|
||||||
configComplete &= getJsonValue(top[FPSTR(_maxReadInterval)], maxReadingInterval, 10000); //ms
|
|
||||||
configComplete &= getJsonValue(top[FPSTR(_minReadInterval)], minReadingInterval, 500); //ms
|
|
||||||
configComplete &= getJsonValue(top[FPSTR(_HomeAssistantDiscovery)], HomeAssistantDiscovery, false);
|
|
||||||
configComplete &= getJsonValue(top[FPSTR(_offset)], offset, 1);
|
|
||||||
|
|
||||||
DEBUG_PRINT(FPSTR(_name));
|
DEBUG_PRINT(FPSTR(_name));
|
||||||
if (!initDone) {
|
DEBUG_PRINT(F("BH1750"));
|
||||||
DEBUG_PRINTLN(F(" config loaded."));
|
DEBUG_PRINTLN(F(": No config found. (Using defaults.)"));
|
||||||
} else {
|
return false;
|
||||||
DEBUG_PRINTLN(F(" config (re)loaded."));
|
}
|
||||||
}
|
bool configComplete = !top.isNull();
|
||||||
|
|
||||||
return configComplete;
|
configComplete &= getJsonValue(top[FPSTR(_enabled)], enabled, false);
|
||||||
|
configComplete &= getJsonValue(top[FPSTR(_maxReadInterval)], maxReadingInterval, 10000); //ms
|
||||||
|
configComplete &= getJsonValue(top[FPSTR(_minReadInterval)], minReadingInterval, 500); //ms
|
||||||
|
configComplete &= getJsonValue(top[FPSTR(_HomeAssistantDiscovery)], HomeAssistantDiscovery, false);
|
||||||
|
configComplete &= getJsonValue(top[FPSTR(_offset)], offset, 1);
|
||||||
|
|
||||||
|
DEBUG_PRINT(FPSTR(_name));
|
||||||
|
if (!initDone) {
|
||||||
|
DEBUG_PRINTLN(F(" config loaded."));
|
||||||
|
} else {
|
||||||
|
DEBUG_PRINTLN(F(" config (re)loaded."));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t getId()
|
return configComplete;
|
||||||
{
|
|
||||||
return USERMOD_ID_BH1750;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// strings to reduce flash memory usage (used more than twice)
|
// strings to reduce flash memory usage (used more than twice)
|
||||||
const char Usermod_BH1750::_name[] PROGMEM = "BH1750";
|
const char Usermod_BH1750::_name[] PROGMEM = "BH1750";
|
||||||
|
92
usermods/BH1750_v2/BH1750_v2.h
Normal file
92
usermods/BH1750_v2/BH1750_v2.h
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "wled.h"
|
||||||
|
#include <BH1750.h>
|
||||||
|
|
||||||
|
#ifdef WLED_DISABLE_MQTT
|
||||||
|
#error "This user mod requires MQTT to be enabled."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// the max frequency to check photoresistor, 10 seconds
|
||||||
|
#ifndef USERMOD_BH1750_MAX_MEASUREMENT_INTERVAL
|
||||||
|
#define USERMOD_BH1750_MAX_MEASUREMENT_INTERVAL 10000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// the min frequency to check photoresistor, 500 ms
|
||||||
|
#ifndef USERMOD_BH1750_MIN_MEASUREMENT_INTERVAL
|
||||||
|
#define USERMOD_BH1750_MIN_MEASUREMENT_INTERVAL 500
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// how many seconds after boot to take first measurement, 10 seconds
|
||||||
|
#ifndef USERMOD_BH1750_FIRST_MEASUREMENT_AT
|
||||||
|
#define USERMOD_BH1750_FIRST_MEASUREMENT_AT 10000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// only report if difference grater than offset value
|
||||||
|
#ifndef USERMOD_BH1750_OFFSET_VALUE
|
||||||
|
#define USERMOD_BH1750_OFFSET_VALUE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class Usermod_BH1750 : public Usermod
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
int8_t offset = USERMOD_BH1750_OFFSET_VALUE;
|
||||||
|
|
||||||
|
unsigned long maxReadingInterval = USERMOD_BH1750_MAX_MEASUREMENT_INTERVAL;
|
||||||
|
unsigned long minReadingInterval = USERMOD_BH1750_MIN_MEASUREMENT_INTERVAL;
|
||||||
|
unsigned long lastMeasurement = UINT32_MAX - (USERMOD_BH1750_MAX_MEASUREMENT_INTERVAL - USERMOD_BH1750_FIRST_MEASUREMENT_AT);
|
||||||
|
unsigned long lastSend = UINT32_MAX - (USERMOD_BH1750_MAX_MEASUREMENT_INTERVAL - USERMOD_BH1750_FIRST_MEASUREMENT_AT);
|
||||||
|
// flag to indicate we have finished the first readLightLevel call
|
||||||
|
// allows this library to report to the user how long until the first
|
||||||
|
// measurement
|
||||||
|
bool getLuminanceComplete = false;
|
||||||
|
|
||||||
|
// flag set at startup
|
||||||
|
bool enabled = true;
|
||||||
|
|
||||||
|
// strings to reduce flash memory usage (used more than twice)
|
||||||
|
static const char _name[];
|
||||||
|
static const char _enabled[];
|
||||||
|
static const char _maxReadInterval[];
|
||||||
|
static const char _minReadInterval[];
|
||||||
|
static const char _offset[];
|
||||||
|
static const char _HomeAssistantDiscovery[];
|
||||||
|
|
||||||
|
bool initDone = false;
|
||||||
|
bool sensorFound = false;
|
||||||
|
|
||||||
|
// Home Assistant and MQTT
|
||||||
|
String mqttLuminanceTopic;
|
||||||
|
bool mqttInitialized = false;
|
||||||
|
bool HomeAssistantDiscovery = true; // Publish Home Assistant Discovery messages
|
||||||
|
|
||||||
|
BH1750 lightMeter;
|
||||||
|
float lastLux = -1000;
|
||||||
|
|
||||||
|
// set up Home Assistant discovery entries
|
||||||
|
void _mqttInitialize();
|
||||||
|
|
||||||
|
// Create an MQTT Sensor for Home Assistant Discovery purposes, this includes a pointer to the topic that is published to in the Loop.
|
||||||
|
void _createMqttSensor(const String &name, const String &topic, const String &deviceClass, const String &unitOfMeasurement);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void setup();
|
||||||
|
void loop();
|
||||||
|
inline float getIlluminance() {
|
||||||
|
return (float)lastLux;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addToJsonInfo(JsonObject &root);
|
||||||
|
|
||||||
|
// (called from set.cpp) stores persistent properties to cfg.json
|
||||||
|
void addToConfig(JsonObject &root);
|
||||||
|
|
||||||
|
// called before setup() to populate properties from values stored in cfg.json
|
||||||
|
bool readFromConfig(JsonObject &root);
|
||||||
|
|
||||||
|
inline uint16_t getId()
|
||||||
|
{
|
||||||
|
return USERMOD_ID_BH1750;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
@ -1,204 +1,137 @@
|
|||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
|
#include "SN_Photoresistor.h"
|
||||||
|
|
||||||
//Pin defaults for QuinLed Dig-Uno (A0)
|
//Pin defaults for QuinLed Dig-Uno (A0)
|
||||||
#ifndef PHOTORESISTOR_PIN
|
#ifndef PHOTORESISTOR_PIN
|
||||||
#define PHOTORESISTOR_PIN A0
|
#define PHOTORESISTOR_PIN A0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// the frequency to check photoresistor, 10 seconds
|
static bool checkBoundSensor(float newValue, float prevValue, float maxDiff)
|
||||||
#ifndef USERMOD_SN_PHOTORESISTOR_MEASUREMENT_INTERVAL
|
|
||||||
#define USERMOD_SN_PHOTORESISTOR_MEASUREMENT_INTERVAL 10000
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// how many seconds after boot to take first measurement, 10 seconds
|
|
||||||
#ifndef USERMOD_SN_PHOTORESISTOR_FIRST_MEASUREMENT_AT
|
|
||||||
#define USERMOD_SN_PHOTORESISTOR_FIRST_MEASUREMENT_AT 10000
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// supplied voltage
|
|
||||||
#ifndef USERMOD_SN_PHOTORESISTOR_REFERENCE_VOLTAGE
|
|
||||||
#define USERMOD_SN_PHOTORESISTOR_REFERENCE_VOLTAGE 5
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// 10 bits
|
|
||||||
#ifndef USERMOD_SN_PHOTORESISTOR_ADC_PRECISION
|
|
||||||
#define USERMOD_SN_PHOTORESISTOR_ADC_PRECISION 1024.0f
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// resistor size 10K hms
|
|
||||||
#ifndef USERMOD_SN_PHOTORESISTOR_RESISTOR_VALUE
|
|
||||||
#define USERMOD_SN_PHOTORESISTOR_RESISTOR_VALUE 10000.0f
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// only report if difference grater than offset value
|
|
||||||
#ifndef USERMOD_SN_PHOTORESISTOR_OFFSET_VALUE
|
|
||||||
#define USERMOD_SN_PHOTORESISTOR_OFFSET_VALUE 5
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class Usermod_SN_Photoresistor : public Usermod
|
|
||||||
{
|
{
|
||||||
private:
|
return isnan(prevValue) || newValue <= prevValue - maxDiff || newValue >= prevValue + maxDiff;
|
||||||
float referenceVoltage = USERMOD_SN_PHOTORESISTOR_REFERENCE_VOLTAGE;
|
}
|
||||||
float resistorValue = USERMOD_SN_PHOTORESISTOR_RESISTOR_VALUE;
|
|
||||||
float adcPrecision = USERMOD_SN_PHOTORESISTOR_ADC_PRECISION;
|
|
||||||
int8_t offset = USERMOD_SN_PHOTORESISTOR_OFFSET_VALUE;
|
|
||||||
|
|
||||||
unsigned long readingInterval = USERMOD_SN_PHOTORESISTOR_MEASUREMENT_INTERVAL;
|
uint16_t Usermod_SN_Photoresistor::getLuminance()
|
||||||
// set last reading as "40 sec before boot", so first reading is taken after 20 sec
|
{
|
||||||
unsigned long lastMeasurement = UINT32_MAX - (USERMOD_SN_PHOTORESISTOR_MEASUREMENT_INTERVAL - USERMOD_SN_PHOTORESISTOR_FIRST_MEASUREMENT_AT);
|
// http://forum.arduino.cc/index.php?topic=37555.0
|
||||||
// flag to indicate we have finished the first getTemperature call
|
// https://forum.arduino.cc/index.php?topic=185158.0
|
||||||
// allows this library to report to the user how long until the first
|
float volts = analogRead(PHOTORESISTOR_PIN) * (referenceVoltage / adcPrecision);
|
||||||
// measurement
|
float amps = volts / resistorValue;
|
||||||
bool getLuminanceComplete = false;
|
float lux = amps * 1000000 * 2.0;
|
||||||
uint16_t lastLDRValue = -1000;
|
|
||||||
|
|
||||||
// flag set at startup
|
lastMeasurement = millis();
|
||||||
bool disabled = false;
|
getLuminanceComplete = true;
|
||||||
|
return uint16_t(lux);
|
||||||
|
}
|
||||||
|
|
||||||
// strings to reduce flash memory usage (used more than twice)
|
void Usermod_SN_Photoresistor::setup()
|
||||||
static const char _name[];
|
{
|
||||||
static const char _enabled[];
|
// set pinmode
|
||||||
static const char _readInterval[];
|
pinMode(PHOTORESISTOR_PIN, INPUT);
|
||||||
static const char _referenceVoltage[];
|
}
|
||||||
static const char _resistorValue[];
|
|
||||||
static const char _adcPrecision[];
|
|
||||||
static const char _offset[];
|
|
||||||
|
|
||||||
bool checkBoundSensor(float newValue, float prevValue, float maxDiff)
|
void Usermod_SN_Photoresistor::loop()
|
||||||
|
{
|
||||||
|
if (disabled || strip.isUpdating())
|
||||||
|
return;
|
||||||
|
|
||||||
|
unsigned long now = millis();
|
||||||
|
|
||||||
|
// check to see if we are due for taking a measurement
|
||||||
|
// lastMeasurement will not be updated until the conversion
|
||||||
|
// is complete the the reading is finished
|
||||||
|
if (now - lastMeasurement < readingInterval)
|
||||||
{
|
{
|
||||||
return isnan(prevValue) || newValue <= prevValue - maxDiff || newValue >= prevValue + maxDiff;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t getLuminance()
|
uint16_t currentLDRValue = getLuminance();
|
||||||
|
if (checkBoundSensor(currentLDRValue, lastLDRValue, offset))
|
||||||
{
|
{
|
||||||
// http://forum.arduino.cc/index.php?topic=37555.0
|
lastLDRValue = currentLDRValue;
|
||||||
// https://forum.arduino.cc/index.php?topic=185158.0
|
|
||||||
float volts = analogRead(PHOTORESISTOR_PIN) * (referenceVoltage / adcPrecision);
|
|
||||||
float amps = volts / resistorValue;
|
|
||||||
float lux = amps * 1000000 * 2.0;
|
|
||||||
|
|
||||||
lastMeasurement = millis();
|
|
||||||
getLuminanceComplete = true;
|
|
||||||
return uint16_t(lux);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
// set pinmode
|
|
||||||
pinMode(PHOTORESISTOR_PIN, INPUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
if (disabled || strip.isUpdating())
|
|
||||||
return;
|
|
||||||
|
|
||||||
unsigned long now = millis();
|
|
||||||
|
|
||||||
// check to see if we are due for taking a measurement
|
|
||||||
// lastMeasurement will not be updated until the conversion
|
|
||||||
// is complete the the reading is finished
|
|
||||||
if (now - lastMeasurement < readingInterval)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t currentLDRValue = getLuminance();
|
|
||||||
if (checkBoundSensor(currentLDRValue, lastLDRValue, offset))
|
|
||||||
{
|
|
||||||
lastLDRValue = currentLDRValue;
|
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_MQTT
|
#ifndef WLED_DISABLE_MQTT
|
||||||
if (WLED_MQTT_CONNECTED)
|
if (WLED_MQTT_CONNECTED)
|
||||||
{
|
|
||||||
char subuf[45];
|
|
||||||
strcpy(subuf, mqttDeviceTopic);
|
|
||||||
strcat_P(subuf, PSTR("/luminance"));
|
|
||||||
mqtt->publish(subuf, 0, true, String(lastLDRValue).c_str());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DEBUG_PRINTLN(F("Missing MQTT connection. Not publishing data"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t getLastLDRValue()
|
|
||||||
{
|
|
||||||
return lastLDRValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addToJsonInfo(JsonObject &root)
|
|
||||||
{
|
|
||||||
JsonObject user = root[F("u")];
|
|
||||||
if (user.isNull())
|
|
||||||
user = root.createNestedObject(F("u"));
|
|
||||||
|
|
||||||
JsonArray lux = user.createNestedArray(F("Luminance"));
|
|
||||||
|
|
||||||
if (!getLuminanceComplete)
|
|
||||||
{
|
{
|
||||||
// if we haven't read the sensor yet, let the user know
|
char subuf[45];
|
||||||
// that we are still waiting for the first measurement
|
strcpy(subuf, mqttDeviceTopic);
|
||||||
lux.add((USERMOD_SN_PHOTORESISTOR_FIRST_MEASUREMENT_AT - millis()) / 1000);
|
strcat_P(subuf, PSTR("/luminance"));
|
||||||
lux.add(F(" sec until read"));
|
mqtt->publish(subuf, 0, true, String(lastLDRValue).c_str());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
lux.add(lastLDRValue);
|
{
|
||||||
lux.add(F(" lux"));
|
DEBUG_PRINTLN(F("Missing MQTT connection. Not publishing data"));
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t getId()
|
|
||||||
{
|
|
||||||
return USERMOD_ID_SN_PHOTORESISTOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* addToConfig() (called from set.cpp) stores persistent properties to cfg.json
|
|
||||||
*/
|
|
||||||
void addToConfig(JsonObject &root)
|
|
||||||
{
|
|
||||||
// we add JSON object.
|
|
||||||
JsonObject top = root.createNestedObject(FPSTR(_name)); // usermodname
|
|
||||||
top[FPSTR(_enabled)] = !disabled;
|
|
||||||
top[FPSTR(_readInterval)] = readingInterval / 1000;
|
|
||||||
top[FPSTR(_referenceVoltage)] = referenceVoltage;
|
|
||||||
top[FPSTR(_resistorValue)] = resistorValue;
|
|
||||||
top[FPSTR(_adcPrecision)] = adcPrecision;
|
|
||||||
top[FPSTR(_offset)] = offset;
|
|
||||||
|
|
||||||
DEBUG_PRINTLN(F("Photoresistor config saved."));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* readFromConfig() is called before setup() to populate properties from values stored in cfg.json
|
|
||||||
*/
|
|
||||||
bool readFromConfig(JsonObject &root)
|
|
||||||
{
|
|
||||||
// we look for JSON object.
|
|
||||||
JsonObject top = root[FPSTR(_name)];
|
|
||||||
if (top.isNull()) {
|
|
||||||
DEBUG_PRINT(FPSTR(_name));
|
|
||||||
DEBUG_PRINTLN(F(": No config found. (Using defaults.)"));
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
disabled = !(top[FPSTR(_enabled)] | !disabled);
|
|
||||||
readingInterval = (top[FPSTR(_readInterval)] | readingInterval/1000) * 1000; // convert to ms
|
void Usermod_SN_Photoresistor::addToJsonInfo(JsonObject &root)
|
||||||
referenceVoltage = top[FPSTR(_referenceVoltage)] | referenceVoltage;
|
{
|
||||||
resistorValue = top[FPSTR(_resistorValue)] | resistorValue;
|
JsonObject user = root[F("u")];
|
||||||
adcPrecision = top[FPSTR(_adcPrecision)] | adcPrecision;
|
if (user.isNull())
|
||||||
offset = top[FPSTR(_offset)] | offset;
|
user = root.createNestedObject(F("u"));
|
||||||
|
|
||||||
|
JsonArray lux = user.createNestedArray(F("Luminance"));
|
||||||
|
|
||||||
|
if (!getLuminanceComplete)
|
||||||
|
{
|
||||||
|
// if we haven't read the sensor yet, let the user know
|
||||||
|
// that we are still waiting for the first measurement
|
||||||
|
lux.add((USERMOD_SN_PHOTORESISTOR_FIRST_MEASUREMENT_AT - millis()) / 1000);
|
||||||
|
lux.add(F(" sec until read"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lux.add(lastLDRValue);
|
||||||
|
lux.add(F(" lux"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* addToConfig() (called from set.cpp) stores persistent properties to cfg.json
|
||||||
|
*/
|
||||||
|
void Usermod_SN_Photoresistor::addToConfig(JsonObject &root)
|
||||||
|
{
|
||||||
|
// we add JSON object.
|
||||||
|
JsonObject top = root.createNestedObject(FPSTR(_name)); // usermodname
|
||||||
|
top[FPSTR(_enabled)] = !disabled;
|
||||||
|
top[FPSTR(_readInterval)] = readingInterval / 1000;
|
||||||
|
top[FPSTR(_referenceVoltage)] = referenceVoltage;
|
||||||
|
top[FPSTR(_resistorValue)] = resistorValue;
|
||||||
|
top[FPSTR(_adcPrecision)] = adcPrecision;
|
||||||
|
top[FPSTR(_offset)] = offset;
|
||||||
|
|
||||||
|
DEBUG_PRINTLN(F("Photoresistor config saved."));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* readFromConfig() is called before setup() to populate properties from values stored in cfg.json
|
||||||
|
*/
|
||||||
|
bool Usermod_SN_Photoresistor::readFromConfig(JsonObject &root)
|
||||||
|
{
|
||||||
|
// we look for JSON object.
|
||||||
|
JsonObject top = root[FPSTR(_name)];
|
||||||
|
if (top.isNull()) {
|
||||||
DEBUG_PRINT(FPSTR(_name));
|
DEBUG_PRINT(FPSTR(_name));
|
||||||
DEBUG_PRINTLN(F(" config (re)loaded."));
|
DEBUG_PRINTLN(F(": No config found. (Using defaults.)"));
|
||||||
|
return false;
|
||||||
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
disabled = !(top[FPSTR(_enabled)] | !disabled);
|
||||||
|
readingInterval = (top[FPSTR(_readInterval)] | readingInterval/1000) * 1000; // convert to ms
|
||||||
|
referenceVoltage = top[FPSTR(_referenceVoltage)] | referenceVoltage;
|
||||||
|
resistorValue = top[FPSTR(_resistorValue)] | resistorValue;
|
||||||
|
adcPrecision = top[FPSTR(_adcPrecision)] | adcPrecision;
|
||||||
|
offset = top[FPSTR(_offset)] | offset;
|
||||||
|
DEBUG_PRINT(FPSTR(_name));
|
||||||
|
DEBUG_PRINTLN(F(" config (re)loaded."));
|
||||||
|
|
||||||
|
// use "return !top["newestParameter"].isNull();" when updating Usermod with new features
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// strings to reduce flash memory usage (used more than twice)
|
// strings to reduce flash memory usage (used more than twice)
|
||||||
const char Usermod_SN_Photoresistor::_name[] PROGMEM = "Photoresistor";
|
const char Usermod_SN_Photoresistor::_name[] PROGMEM = "Photoresistor";
|
||||||
@ -209,6 +142,5 @@ const char Usermod_SN_Photoresistor::_resistorValue[] PROGMEM = "resistor-value"
|
|||||||
const char Usermod_SN_Photoresistor::_adcPrecision[] PROGMEM = "adc-precision";
|
const char Usermod_SN_Photoresistor::_adcPrecision[] PROGMEM = "adc-precision";
|
||||||
const char Usermod_SN_Photoresistor::_offset[] PROGMEM = "offset";
|
const char Usermod_SN_Photoresistor::_offset[] PROGMEM = "offset";
|
||||||
|
|
||||||
|
|
||||||
static Usermod_SN_Photoresistor sn_photoresistor;
|
static Usermod_SN_Photoresistor sn_photoresistor;
|
||||||
REGISTER_USERMOD(sn_photoresistor);
|
REGISTER_USERMOD(sn_photoresistor);
|
90
usermods/SN_Photoresistor/SN_Photoresistor.h
Normal file
90
usermods/SN_Photoresistor/SN_Photoresistor.h
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "wled.h"
|
||||||
|
|
||||||
|
// the frequency to check photoresistor, 10 seconds
|
||||||
|
#ifndef USERMOD_SN_PHOTORESISTOR_MEASUREMENT_INTERVAL
|
||||||
|
#define USERMOD_SN_PHOTORESISTOR_MEASUREMENT_INTERVAL 10000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// how many seconds after boot to take first measurement, 10 seconds
|
||||||
|
#ifndef USERMOD_SN_PHOTORESISTOR_FIRST_MEASUREMENT_AT
|
||||||
|
#define USERMOD_SN_PHOTORESISTOR_FIRST_MEASUREMENT_AT 10000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// supplied voltage
|
||||||
|
#ifndef USERMOD_SN_PHOTORESISTOR_REFERENCE_VOLTAGE
|
||||||
|
#define USERMOD_SN_PHOTORESISTOR_REFERENCE_VOLTAGE 5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// 10 bits
|
||||||
|
#ifndef USERMOD_SN_PHOTORESISTOR_ADC_PRECISION
|
||||||
|
#define USERMOD_SN_PHOTORESISTOR_ADC_PRECISION 1024.0f
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// resistor size 10K hms
|
||||||
|
#ifndef USERMOD_SN_PHOTORESISTOR_RESISTOR_VALUE
|
||||||
|
#define USERMOD_SN_PHOTORESISTOR_RESISTOR_VALUE 10000.0f
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// only report if difference grater than offset value
|
||||||
|
#ifndef USERMOD_SN_PHOTORESISTOR_OFFSET_VALUE
|
||||||
|
#define USERMOD_SN_PHOTORESISTOR_OFFSET_VALUE 5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class Usermod_SN_Photoresistor : public Usermod
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
float referenceVoltage = USERMOD_SN_PHOTORESISTOR_REFERENCE_VOLTAGE;
|
||||||
|
float resistorValue = USERMOD_SN_PHOTORESISTOR_RESISTOR_VALUE;
|
||||||
|
float adcPrecision = USERMOD_SN_PHOTORESISTOR_ADC_PRECISION;
|
||||||
|
int8_t offset = USERMOD_SN_PHOTORESISTOR_OFFSET_VALUE;
|
||||||
|
|
||||||
|
unsigned long readingInterval = USERMOD_SN_PHOTORESISTOR_MEASUREMENT_INTERVAL;
|
||||||
|
// set last reading as "40 sec before boot", so first reading is taken after 20 sec
|
||||||
|
unsigned long lastMeasurement = UINT32_MAX - (USERMOD_SN_PHOTORESISTOR_MEASUREMENT_INTERVAL - USERMOD_SN_PHOTORESISTOR_FIRST_MEASUREMENT_AT);
|
||||||
|
// flag to indicate we have finished the first getTemperature call
|
||||||
|
// allows this library to report to the user how long until the first
|
||||||
|
// measurement
|
||||||
|
bool getLuminanceComplete = false;
|
||||||
|
uint16_t lastLDRValue = -1000;
|
||||||
|
|
||||||
|
// flag set at startup
|
||||||
|
bool disabled = false;
|
||||||
|
|
||||||
|
// 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 _referenceVoltage[];
|
||||||
|
static const char _resistorValue[];
|
||||||
|
static const char _adcPrecision[];
|
||||||
|
static const char _offset[];
|
||||||
|
|
||||||
|
uint16_t getLuminance();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void setup();
|
||||||
|
void loop();
|
||||||
|
|
||||||
|
uint16_t getLastLDRValue()
|
||||||
|
{
|
||||||
|
return lastLDRValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addToJsonInfo(JsonObject &root);
|
||||||
|
|
||||||
|
uint16_t getId()
|
||||||
|
{
|
||||||
|
return USERMOD_ID_SN_PHOTORESISTOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* addToConfig() (called from set.cpp) stores persistent properties to cfg.json
|
||||||
|
*/
|
||||||
|
void addToConfig(JsonObject &root);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* readFromConfig() is called before setup() to populate properties from values stored in cfg.json
|
||||||
|
*/
|
||||||
|
bool readFromConfig(JsonObject &root);
|
||||||
|
};
|
@ -1,14 +0,0 @@
|
|||||||
#include "wled.h"
|
|
||||||
/*
|
|
||||||
* Register your v2 usermods here!
|
|
||||||
*/
|
|
||||||
#ifdef USERMOD_SN_PHOTORESISTOR
|
|
||||||
#include "../usermods/SN_Photoresistor/usermod_sn_photoresistor.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void registerUsermods()
|
|
||||||
{
|
|
||||||
#ifdef USERMOD_SN_PHOTORESISTOR
|
|
||||||
UsermodManager::add(new Usermod_SN_Photoresistor());
|
|
||||||
#endif
|
|
||||||
}
|
|
@ -1,3 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name:": "seven_segment_display_reloaded"
|
"name": "seven_segment_display_reloaded",
|
||||||
|
"build": {
|
||||||
|
"extraScript": "setup_deps.py"
|
||||||
|
}
|
||||||
}
|
}
|
9
usermods/seven_segment_display_reloaded/setup_deps.py
Normal file
9
usermods/seven_segment_display_reloaded/setup_deps.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
Import('env')
|
||||||
|
|
||||||
|
|
||||||
|
usermods = env.GetProjectOption("custom_usermods","").split()
|
||||||
|
# Check for partner usermods
|
||||||
|
if "SN_Photoresistor" in usermods:
|
||||||
|
env.Append(CPPDEFINES=[("USERMOD_SN_PHOTORESISTOR")])
|
||||||
|
if "BH1750_v2" in usermods:
|
||||||
|
env.Append(CPPDEFINES=[("USERMOD_BH1750")])
|
@ -1,4 +1,10 @@
|
|||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
|
#ifdef USERMOD_SN_PHOTORESISTOR
|
||||||
|
#include "SN_Photoresistor.h"
|
||||||
|
#endif
|
||||||
|
#ifdef USERMOD_BH1750
|
||||||
|
#include "BH1750_v2.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WLED_DISABLE_MQTT
|
#ifdef WLED_DISABLE_MQTT
|
||||||
#error "This user mod requires MQTT to be enabled."
|
#error "This user mod requires MQTT to be enabled."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user