From db10de101cc2327b4ccefa4a9deffd3182e83cc3 Mon Sep 17 00:00:00 2001 From: Ollo Date: Wed, 15 Dec 2021 17:02:36 +0100 Subject: [PATCH 1/2] Reduced brightness to 50% --- src/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d5bb3bb..cdf904a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -258,9 +258,9 @@ void bmpPublishValues() { String(bmx.readAltitude(SEALEVELPRESSURE_HPA))), MQTT_LOG_I2READ); if ( (rgbTemp.get()) && (!mSomethingReceived) ) { if (bmx.readTemperature() < TEMPBORDER) { - strip.setPixelColor(0, strip.Color(0,0,255)); + strip.setPixelColor(0, strip.Color(0,0,127)); } else { - strip.setPixelColor(0, strip.Color(255,0,0)); + strip.setPixelColor(0, strip.Color(127,0,0)); } strip.show(); } @@ -286,11 +286,11 @@ void loopHandler() particle.setProperty(NODE_PARTICLE).send(String(pM25)); if (!mSomethingReceived) { if (pM25 < 35) { - strip.fill(strip.Color(0, 255, 0)); /* green */ + strip.fill(strip.Color(0, 127, 0)); /* green */ } else if (pM25 < 85) { - strip.fill(strip.Color(255, 127, 0)); /* orange */ + strip.fill(strip.Color(127, 64, 0)); /* orange */ } else { - strip.fill(strip.Color(255, 0, 0)); /* red */ + strip.fill(strip.Color(127, 0, 0)); /* red */ } strip.show(); } From d6e34a8e75791352ecb8a6d58dc14a8f5776ab01 Mon Sep 17 00:00:00 2001 From: Ollo Date: Wed, 15 Dec 2021 17:22:10 +0100 Subject: [PATCH 2/2] Brightness can be configured --- include/HomieSettings.h | 2 +- src/main.cpp | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/HomieSettings.h b/include/HomieSettings.h index 69b47e7..f12788f 100644 --- a/include/HomieSettings.h +++ b/include/HomieSettings.h @@ -13,6 +13,6 @@ #define HOMIE_SETTINGS #define HOMIE_FIRMWARE_NAME "RoomSensor" -#define HOMIE_FIRMWARE_VERSION "2.1.0" +#define HOMIE_FIRMWARE_VERSION "2.2.0" #endif diff --git a/src/main.cpp b/src/main.cpp index cdf904a..f3016bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -74,6 +74,8 @@ strcat(topic, "/"); \ strcat(topic, test); +#define PERCENT2FACTOR(b, a) ((b * a.get()) / 100) + #define NUMBER_TYPE "Number" #define NODE_PARTICLE "particle" #define NODE_TEMPERATUR "temp" @@ -130,6 +132,7 @@ HomieSetting i2cEnable("i2c", ); HomieSetting rgbTemp("rgbTemp", "Show temperature via red (>20 °C) and blue (< 20°C)"); +HomieSetting rgbDim("rgbDim", "Factor (1 to 200%) of the status LEDs"); static SoftwareSerial pmSerial(SENSOR_PM1006_RX, SENSOR_PM1006_TX); #ifdef BME680 @@ -258,9 +261,9 @@ void bmpPublishValues() { String(bmx.readAltitude(SEALEVELPRESSURE_HPA))), MQTT_LOG_I2READ); if ( (rgbTemp.get()) && (!mSomethingReceived) ) { if (bmx.readTemperature() < TEMPBORDER) { - strip.setPixelColor(0, strip.Color(0,0,127)); + strip.setPixelColor(0, strip.Color(0,0,PERCENT2FACTOR(127, rgbDim))); } else { - strip.setPixelColor(0, strip.Color(127,0,0)); + strip.setPixelColor(0, strip.Color(PERCENT2FACTOR(127, rgbDim),0,0)); } strip.show(); } @@ -286,11 +289,11 @@ void loopHandler() particle.setProperty(NODE_PARTICLE).send(String(pM25)); if (!mSomethingReceived) { if (pM25 < 35) { - strip.fill(strip.Color(0, 127, 0)); /* green */ + strip.fill(strip.Color(0, PERCENT2FACTOR(127, rgbDim), 0)); /* green */ } else if (pM25 < 85) { - strip.fill(strip.Color(127, 64, 0)); /* orange */ + strip.fill(strip.Color(PERCENT2FACTOR(127, rgbDim), PERCENT2FACTOR(64, rgbDim), 0)); /* orange */ } else { - strip.fill(strip.Color(127, 0, 0)); /* red */ + strip.fill(strip.Color(PERCENT2FACTOR(127, rgbDim), 0, 0)); /* red */ } strip.show(); } @@ -373,6 +376,9 @@ void setup() Homie.onEvent(onHomieEvent); i2cEnable.setDefaultValue(false); rgbTemp.setDefaultValue(false); + rgbDim.setDefaultValue(100).setValidator([] (long candidate) { + return (candidate > 1) && (candidate <= 200); + }); memset(serialRxBuf, 0, 80); pmSerial.begin(PM1006_BIT_RATE); @@ -420,7 +426,7 @@ void setup() /* Extracted from library's example */ mFailedI2Cinitialization = !bmx.begin(); if (!mFailedI2Cinitialization) { - strip.fill(strip.Color(0,64,0)); + strip.fill(strip.Color(0,PERCENT2FACTOR(64, rgbDim),0)); strip.show(); #ifdef BME680 bmx.setTemperatureOversampling(BME680_OS_8X); @@ -443,7 +449,7 @@ void setup() } strip.fill(strip.Color(0,0,0)); for (int i=0;i < (PIXEL_COUNT / 2); i++) { - strip.setPixelColor(0, strip.Color(0,0,128)); + strip.setPixelColor(0, strip.Color(0,0,128 * rgbDim.get())); } strip.show(); } else { @@ -481,7 +487,7 @@ void loop() if (mButtonPressed > BUTTON_MAX_CYCLE) { mButtonPressed = (BUTTON_MAX_CYCLE -1); if (SPIFFS.exists("/homie/config.json")) { - strip.fill(strip.Color(0,128,0)); + strip.fill(strip.Color(0,PERCENT2FACTOR(127, rgbDim),0)); strip.show(); printf("Resetting config\r\n"); SPIFFS.remove("/homie/config.json");