From d2ab1369f665e65db803ed60d67294b3204339da Mon Sep 17 00:00:00 2001 From: Holger Weber Date: Fri, 15 May 2026 00:44:46 +0200 Subject: [PATCH] Working version. --- SPEC.md | 4 +++- include/PulseTimer.h | 6 ++++-- include/config.example.h | 2 ++ include/config.h | 2 ++ src/main.cpp | 2 +- test/test_pulse_timer/test_main.cpp | 8 ++++---- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/SPEC.md b/SPEC.md index 7f8af1e..3c087ba 100644 --- a/SPEC.md +++ b/SPEC.md @@ -18,10 +18,12 @@ Die Datei `include/config.h` enthält: - `WIFI_PASSWORD` - `TASMOTA_HOST` - `INITIAL_TIMER_MS` +- `MIN_TIMER_MS` +- `MAX_TIMER_MS` Als Vorlage liegt `include/config.example.h` bei. ## Hardware Board D1 Mini mit ESP8266. -OLED über I2C an den GPIOs 4 und 5. Rotary Encoder mit A und B an GPIO 14 und 16 und der Taster an 12. +OLED über I2C an den GPIOs 4 und 5. Rotary Encoder mit A und B an GPIO 14 und 13 und der Taster an 12. OLED hat einen SSD1309 Controller mit 128x64 Pixel. diff --git a/include/PulseTimer.h b/include/PulseTimer.h index 46db6ea..c531445 100644 --- a/include/PulseTimer.h +++ b/include/PulseTimer.h @@ -2,10 +2,12 @@ #include +#include "config.h" + namespace trbc { -constexpr uint16_t kMinTimerMs = 2000; -constexpr uint16_t kMaxTimerMs = 10000; +constexpr uint16_t kMinTimerMs = MIN_TIMER_MS; +constexpr uint16_t kMaxTimerMs = MAX_TIMER_MS; constexpr uint16_t kTimerStepMs = 100; uint16_t clampTimerMs(int valueMs); diff --git a/include/config.example.h b/include/config.example.h index dd63df4..630c498 100644 --- a/include/config.example.h +++ b/include/config.example.h @@ -6,3 +6,5 @@ #define WIFI_PASSWORD "your-password" #define TASMOTA_HOST "192.168.1.50" #define INITIAL_TIMER_MS 5000 +#define MIN_TIMER_MS 2000 +#define MAX_TIMER_MS 10000 diff --git a/include/config.h b/include/config.h index ba576c5..bde59ab 100644 --- a/include/config.h +++ b/include/config.h @@ -7,3 +7,5 @@ #define WIFI_PASSWORD "!Sternenlabor99!" #define TASMOTA_HOST "192.168.240.101" #define INITIAL_TIMER_MS 5000 +#define MIN_TIMER_MS 2000 +#define MAX_TIMER_MS 13000 diff --git a/src/main.cpp b/src/main.cpp index 9c1256b..e586a38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,7 +10,7 @@ namespace { constexpr uint8_t kOledAddress = 0x3C; constexpr uint8_t kPinEncoderA = 14; -constexpr uint8_t kPinEncoderB = 16; +constexpr uint8_t kPinEncoderB = 13; constexpr uint8_t kPinButton = 12; constexpr uint8_t kPinSda = 4; constexpr uint8_t kPinScl = 5; diff --git a/test/test_pulse_timer/test_main.cpp b/test/test_pulse_timer/test_main.cpp index df93b5f..3bce6b2 100644 --- a/test/test_pulse_timer/test_main.cpp +++ b/test/test_pulse_timer/test_main.cpp @@ -3,9 +3,9 @@ #include "PulseTimer.h" void test_clamps_timer_range() { - TEST_ASSERT_EQUAL_UINT16(2000, trbc::clampTimerMs(1000)); + TEST_ASSERT_EQUAL_UINT16(MIN_TIMER_MS, trbc::clampTimerMs(MIN_TIMER_MS - 1000)); TEST_ASSERT_EQUAL_UINT16(5000, trbc::clampTimerMs(5000)); - TEST_ASSERT_EQUAL_UINT16(10000, trbc::clampTimerMs(12000)); + TEST_ASSERT_EQUAL_UINT16(MAX_TIMER_MS, trbc::clampTimerMs(MAX_TIMER_MS + 2000)); } void test_adjusts_in_100_ms_steps() { @@ -14,8 +14,8 @@ void test_adjusts_in_100_ms_steps() { } void test_adjustment_stays_in_range() { - TEST_ASSERT_EQUAL_UINT16(2000, trbc::adjustTimerMs(2000, -1)); - TEST_ASSERT_EQUAL_UINT16(10000, trbc::adjustTimerMs(10000, 1)); + TEST_ASSERT_EQUAL_UINT16(MIN_TIMER_MS, trbc::adjustTimerMs(MIN_TIMER_MS, -1)); + TEST_ASSERT_EQUAL_UINT16(MAX_TIMER_MS, trbc::adjustTimerMs(MAX_TIMER_MS, 1)); } void test_converts_to_tasmota_pulsetime_units() {