Skip to content

Commit 34ebf12

Browse files
authored
Merge pull request #3 from sogidaned/ldr_auswahl
ldr auswahl und homeassistant verbesserung
2 parents 430c486 + d3666d7 commit 34ebf12

File tree

16 files changed

+600
-115
lines changed

16 files changed

+600
-115
lines changed

.github/workflows/clang-format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v4
1111
- uses: DoozyX/clang-format-lint-action@v0.18.2
1212
with:
1313
source: '.'

include/Uhr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ struct GLOBAL {
151151
bool bootShowIP;
152152

153153
Birthday birthday[MAX_BIRTHDAY_COUNT];
154+
155+
uint8_t ldrType; // 0 = 1 LDR, 1 = 4 LDR parallel
154156
};
155157
GLOBAL G = {};
156158

@@ -253,6 +255,7 @@ enum CommandWords {
253255
COMMAND_SET_AUTO_BRIGHT = 102,
254256
COMMAND_SET_LAYOUT_VARIANT = 103,
255257
COMMAND_SET_MQTT_HA_DISCOVERY = 104,
258+
COMMAND_SET_LDR_TYPE = 105,
256259

257260
COMMAND_SPEED = 152,
258261

include/clockWork.hpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,19 @@ void ClockWork::loopAutoBrightLogic() {
4545
if (adcValue < adcValue0Lux)
4646
adcValue0Lux = adcValue;
4747
float ldrValue = adcValue - adcValue0Lux;
48-
// Derive LUX value from ldrValue via a second degree polinomial.
49-
// The polinomial was derived using an Excel trend line, see
50-
// LDR-Calibration.xlsx
51-
const float x2 = 0.0427;
52-
const float x1 = 2.679;
53-
const float x0 = 10.857;
54-
lux = x2 * ldrValue * ldrValue + x1 * ldrValue + x0;
48+
49+
// Derive LUX value from ldrValue via a second degree polinomial based on LDR type
50+
if (G.ldrType == 0) { // 1 LDR Sensor
51+
const float x2 = 0.0427;
52+
const float x1 = 2.679;
53+
const float x0 = 10.857;
54+
lux = x2 * ldrValue * ldrValue + x1 * ldrValue + x0;
55+
} else { // 4 LDR Sensoren parallel
56+
const float x2 = 0.0005;
57+
const float x1 = 0.0687;
58+
const float x0 = 3.9907;
59+
lux = x2 * ldrValue * ldrValue - x1 * ldrValue + x0;
60+
}
5561
}
5662

5763
// Based on the LUX value derive the gain for the LEDs 0.0 - 100.0%
@@ -1178,6 +1184,7 @@ void ClockWork::loop(struct tm &tm) {
11781184
config["bootShowWifi"] = G.bootShowWifi;
11791185
config["bootShowIP"] = G.bootShowIP;
11801186
config["autoBrightEnabled"] = G.autoBrightEnabled;
1187+
config["ldrType"] = G.ldrType;
11811188
config["isRomanLanguage"] = isRomanLanguage();
11821189
config["hasDreiviertel"] = usedUhrType->hasDreiviertel();
11831190
config["hasZwanzig"] = usedUhrType->hasZwanzig();

include/mqtt.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <Arduino.h>
3+
#include <ArduinoJson.h>
44

55
class Mqtt {
66
private:
@@ -11,15 +11,23 @@ class Mqtt {
1111
static void processScrollingText(const JsonDocument &doc);
1212
static void processColor(const JsonDocument &doc);
1313
static void processBrightness(const JsonDocument &doc);
14+
static void processAutobrightSwitch(const JsonDocument &doc);
15+
static void processBrightOffset(const JsonDocument &doc);
16+
static void processBrightSlope(const JsonDocument &doc);
17+
static void processScrollSpeed(const JsonDocument &doc);
18+
static void processEffectSpeed(const JsonDocument &doc);
19+
static bool checkIfMqttUserIsEmpty();
1420

1521
public:
16-
Mqtt() = default;
17-
~Mqtt() = default;
22+
Mqtt();
23+
~Mqtt();
1824

1925
void init();
2026
void loop();
2127
void sendState();
2228
void sendDiscovery();
23-
2429
bool isConnected();
2530
};
31+
32+
// Globale Instanz
33+
extern Mqtt* mqttInstance;

0 commit comments

Comments
 (0)