From 2df9c852f38bb962ccaac2af675f631813327363 Mon Sep 17 00:00:00 2001 From: Jean Gauthier Date: Wed, 2 Dec 2020 11:59:11 -0500 Subject: [PATCH 01/18] Update keywords.txt Added extra keywords for new functions --- keywords.txt | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/keywords.txt b/keywords.txt index 4da65b8..d94e5e5 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,11 +1,14 @@ -DimmableLight KEYWORD1 -DimmableLightLinearized KEYWORD1 -DimmableLightManager KEYWORD1 -getBrightness KEYWORD2 -setBrightness KEYWORD2 -begin KEYWORD2 -get KEYWORD2 -add KEYWORD2 -getCount KEYWORD2 -turnOff KEYWORD2 -setSyncPin KEYWORD2 +DimmableLight KEYWORD1 +DimmableLightLinearized KEYWORD1 +DimmableLightManager KEYWORD1 +getBrightness KEYWORD2 +setBrightness KEYWORD2 +begin KEYWORD2 +get KEYWORD2 +add KEYWORD2 +getCount KEYWORD2 +turnOff KEYWORD2 +setSyncPin KEYWORD2 +setSyncDir KEYWORD2 +setSyncPullup KEYWORD2 +setGateTurnOffTime KEYWORD2 From baa0a91239bc33b87e9d1d2da3b7efc1db9a5323 Mon Sep 17 00:00:00 2001 From: Jean Gauthier Date: Wed, 2 Dec 2020 12:05:05 -0500 Subject: [PATCH 02/18] Update thyristor.h Added new functions - setSyncDir(uint8_t dir) to adjust the interrupt direction FALLING, RISING, CHANGE - setSyncPullup(bool pullup) to activate internal pull-up resistor on zero-crossing detection - setGateTurnOffTime(uint16_t timeOff) to change the value of the gate turn off time --- src/thyristor.h | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/thyristor.h b/src/thyristor.h index b286239..7040f26 100644 --- a/src/thyristor.h +++ b/src/thyristor.h @@ -32,12 +32,12 @@ // enables the setFrequency() method. The main drawback is that it is a bit more // inefficient w.r.t the "fixed frequency" alternatives. // Select one and ONLY one among the following alternatives: -#define NETWORK_FREQ_FIXED_50HZ -//#define NETWORK_FREQ_FIXED_60HZ +//#define NETWORK_FREQ_FIXED_50HZ +#define NETWORK_FREQ_FIXED_60HZ //#define NETWORK_FREQ_RUNTIME // If enabled, you can monitor the actual frequency of the electrical network. -//#define MONITOR_FREQUENCY +#define MONITOR_FREQUENCY /** @@ -110,9 +110,31 @@ class Thyristor{ /** * Set the pin dedicated to receive the AC zero cross signal. */ - static void setSyncPin(uint8_t pin){ + static uint8_t setSyncPin(uint8_t pin){ syncPin = pin; + return syncPin; } + + /** + * Set the pin direction (RISING, FALLING, CHANGE) + */ + static uint8_t setSyncDir(uint8_t dir){ + syncDir = dir; + return syncDir; + } + + /** + * Set the pin pullup + */ + static bool setSyncPullup(bool pullup){ + syncPullup = pullup; + return syncPullup; + } + + /** + * Set the gate turn off time + */ + static uint16_t setGateTurnOffTime(uint16_t timeOff); /** * Get frequency. @@ -158,6 +180,8 @@ class Thyristor{ #endif static const uint8_t N = 8; + + private: /** @@ -213,6 +237,16 @@ class Thyristor{ * Pin receiving the external Zero Cross signal. */ static uint8_t syncPin; + + /** + * Pin direction (FALLING, RISING, CHANGE). + */ + static uint8_t syncDir; + + /** + * Pin pullup active. + */ + static bool syncPullup; /** * 0) no messages From c66f562e4a0b45b03d7346784e63bb06f444c827 Mon Sep 17 00:00:00 2001 From: Jean Gauthier Date: Wed, 2 Dec 2020 12:07:28 -0500 Subject: [PATCH 03/18] Update dimmable_light.h Added new functions - setSyncDir(uint8_t dir) to adjust the interrupt direction FALLING, RISING, CHANGE - setSyncPullup(bool pullup) to activate internal pull-up resistor on zero-crossing detection - setGateTurnOffTime(uint16_t timeOff) to change the value of the gate turn off time --- src/dimmable_light.h | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/dimmable_light.h b/src/dimmable_light.h index e11d72f..30c4251 100644 --- a/src/dimmable_light.h +++ b/src/dimmable_light.h @@ -112,8 +112,29 @@ class DimmableLight{ /** * Set the pin dedicated to receive the AC zero cross signal. */ - static void setSyncPin(uint8_t pin){ - Thyristor::setSyncPin(pin); + static uint8_t setSyncPin(uint8_t pin){ + return Thyristor::setSyncPin(pin); + } + + /** + * Set the pin direction (FALLING, RISING, CHANGE) + */ + static uint8_t setSyncDir(uint8_t dir){ + return Thyristor::setSyncDir(dir); + } + + /** + * Set the pin direction (FALLING, RISING, CHANGE) + */ + static bool setSyncPullup(bool pullup){ + return Thyristor::setSyncPullup(pullup); + } + + /** + * Set the gate turn off time + */ + static bool setGateTurnOffTime(uint16_t turnOffTime){ + return Thyristor::setGateTurnOffTime(turnOffTime); } /** From 6fb660ac047cba2cdb15b71321676cc576f843a3 Mon Sep 17 00:00:00 2001 From: Jean Gauthier Date: Wed, 2 Dec 2020 12:08:53 -0500 Subject: [PATCH 04/18] Update dimmable_light_linearized.h Added new functions - setSyncDir(uint8_t dir) to adjust the interrupt direction FALLING, RISING, CHANGE - setSyncPullup(bool pullup) to activate internal pull-up resistor on zero-crossing detection - setGateTurnOffTime(uint16_t timeOff) to change the value of the gate turn off time --- src/dimmable_light_linearized.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/dimmable_light_linearized.h b/src/dimmable_light_linearized.h index 5a09ee4..c0d3534 100644 --- a/src/dimmable_light_linearized.h +++ b/src/dimmable_light_linearized.h @@ -145,6 +145,27 @@ class DimmableLightLinearized{ static void setSyncPin(uint8_t pin){ Thyristor::setSyncPin(pin); } + + /** + * Set the pin direction (FALLING, RISING, CHANGE) + */ + static void setSyncDir(uint8_t dir){ + Thyristor::setSyncDir(dir); + } + + /** + * Set the pin direction (FALLING, RISING, CHANGE) + */ + static void setSyncPullup(bool pullup){ + Thyristor::setSyncPullup(pullup); + } + + /** + * Set the gate turn off time + */ + static void setGateTurnOffTime(uint16_t turnOffTime){ + Thyristor::setGateTurnOffTime(turnOffTime); + } /** * Return the number of instantiated lights. From 18adab1d7b2cebb20c40f5507ae1a24b7c6eb226 Mon Sep 17 00:00:00 2001 From: Jean Gauthier Date: Wed, 2 Dec 2020 12:10:01 -0500 Subject: [PATCH 05/18] Update dimmable_light.h --- src/dimmable_light.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/dimmable_light.h b/src/dimmable_light.h index 30c4251..36905d2 100644 --- a/src/dimmable_light.h +++ b/src/dimmable_light.h @@ -112,29 +112,29 @@ class DimmableLight{ /** * Set the pin dedicated to receive the AC zero cross signal. */ - static uint8_t setSyncPin(uint8_t pin){ - return Thyristor::setSyncPin(pin); + static void setSyncPin(uint8_t pin){ + Thyristor::setSyncPin(pin); } /** * Set the pin direction (FALLING, RISING, CHANGE) */ - static uint8_t setSyncDir(uint8_t dir){ - return Thyristor::setSyncDir(dir); + static void setSyncDir(uint8_t dir){ + Thyristor::setSyncDir(dir); } /** * Set the pin direction (FALLING, RISING, CHANGE) */ - static bool setSyncPullup(bool pullup){ - return Thyristor::setSyncPullup(pullup); + static void setSyncPullup(bool pullup){ + Thyristor::setSyncPullup(pullup); } /** * Set the gate turn off time */ - static bool setGateTurnOffTime(uint16_t turnOffTime){ - return Thyristor::setGateTurnOffTime(turnOffTime); + static void setGateTurnOffTime(uint16_t turnOffTime){ + Thyristor::setGateTurnOffTime(turnOffTime); } /** From fe353fb2d8399501e94d04c7b6034566291e28f7 Mon Sep 17 00:00:00 2001 From: Jean Gauthier Date: Wed, 2 Dec 2020 12:15:05 -0500 Subject: [PATCH 06/18] Update thyristor.cpp Added new functions - setSyncDir(uint8_t dir) to adjust the interrupt direction FALLING, RISING, CHANGE - setSyncPullup(bool pullup) to activate internal pull-up resistor on zero-crossing detection - setGateTurnOffTime(uint16_t timeOff) to change the value of the gate turn off time --- src/thyristor.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/thyristor.cpp b/src/thyristor.cpp index fe47e40..d8e8d26 100644 --- a/src/thyristor.cpp +++ b/src/thyristor.cpp @@ -87,13 +87,13 @@ static const uint16_t mergePeriod = 20; // Period (in us) before the end of the semiperiod, when an interrupt is trigged to // turn off each gate signal. Ignore this parameter if you use a predefined pulse length. // Look at PREDEFINED_PULSE_LENGTH constant for more info. -static const uint16_t gateTurnOffTime = 300; +static uint16_t gateTurnOffTime = 300; -static_assert( endMargin - gateTurnOffTime > mergePeriod, "endMargin must be greater than (gateTurnOffTime + mergePeriod)"); +//static_assert( endMargin - gateTurnOffTime > mergePeriod, "endMargin must be greater than (gateTurnOffTime + mergePeriod)"); #ifdef PREDEFINED_PULSE_LENGTH // Length of pulse of sync gate. this parameter is not applied if thyristor is fully on or off -static uint8_t pulseWidth = 15; +static uint8_t pulseWidth = 100; #endif @@ -512,7 +512,7 @@ void Thyristor::setDelay(uint16_t newDelay){ if(enableInt){ if(verbosity>2) Serial.println("Re-enabling interrupt"); interruptEnabled = true; - attachInterrupt(digitalPinToInterrupt(syncPin), zero_cross_int, RISING); + attachInterrupt(digitalPinToInterrupt(syncPin), zero_cross_int, syncDir); } if(verbosity>2){ @@ -529,7 +529,7 @@ void Thyristor::turnOn(){ } void Thyristor::begin(){ - pinMode(digitalPinToInterrupt(syncPin), INPUT); + pinMode(syncPin, syncPullup ? INPUT_PULLUP : INPUT); #if defined(ARDUINO_ARCH_ESP8266) timer1_attachInterrupt(activate_thyristors); @@ -548,7 +548,7 @@ void Thyristor::begin(){ // Starts immediatly to sense the electrical network interruptEnabled = true; - attachInterrupt(digitalPinToInterrupt(syncPin), zero_cross_int, RISING); + attachInterrupt(digitalPinToInterrupt(syncPin), zero_cross_int, syncDir); #endif } @@ -619,7 +619,7 @@ void Thyristor::frequencyMonitorAlwaysOn(bool enable){ if(enable && !interruptEnabled){ interruptEnabled = true; - attachInterrupt(digitalPinToInterrupt(syncPin), zero_cross_int, RISING); + attachInterrupt(digitalPinToInterrupt(syncPin), zero_cross_int, syncDir); } frequencyMonitorAlwaysEnabled = enable; @@ -699,10 +699,21 @@ bool Thyristor::mustInterruptBeReEnabled(uint16_t newDelay){ return !interruptEnabled && interruptMustBeEnabled; } + /** + * Set the gate turn off time + */ + uint16_t Thyristor::setGateTurnOffTime(uint16_t timeOff){ + gateTurnOffTime = timeOff; + return gateTurnOffTime; + } + + uint8_t Thyristor::nThyristors = 0; Thyristor* Thyristor::thyristors[Thyristor::N] = {nullptr}; bool Thyristor::newDelayValues = false; bool Thyristor::updatingStruct = false; bool Thyristor::allThyristorsOnOff = true; uint8_t Thyristor::syncPin = 255; -bool Thyristor:: frequencyMonitorAlwaysEnabled = true; +uint8_t Thyristor::syncDir = RISING; +bool Thyristor::syncPullup = false; +bool Thyristor::frequencyMonitorAlwaysEnabled = true; From 77f18e95b5fafd43facb08b582e3413441ee8e61 Mon Sep 17 00:00:00 2001 From: Jean Gauthier Date: Wed, 2 Dec 2020 12:24:35 -0500 Subject: [PATCH 07/18] Update thyristor.h --- src/thyristor.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/thyristor.h b/src/thyristor.h index 7040f26..f989953 100644 --- a/src/thyristor.h +++ b/src/thyristor.h @@ -37,7 +37,7 @@ //#define NETWORK_FREQ_RUNTIME // If enabled, you can monitor the actual frequency of the electrical network. -#define MONITOR_FREQUENCY +//#define MONITOR_FREQUENCY /** @@ -110,31 +110,28 @@ class Thyristor{ /** * Set the pin dedicated to receive the AC zero cross signal. */ - static uint8_t setSyncPin(uint8_t pin){ + static void setSyncPin(uint8_t pin){ syncPin = pin; - return syncPin; } /** * Set the pin direction (RISING, FALLING, CHANGE) */ - static uint8_t setSyncDir(uint8_t dir){ + static void setSyncDir(uint8_t dir){ syncDir = dir; - return syncDir; } /** * Set the pin pullup */ - static bool setSyncPullup(bool pullup){ + static void setSyncPullup(bool pullup){ syncPullup = pullup; - return syncPullup; } /** * Set the gate turn off time */ - static uint16_t setGateTurnOffTime(uint16_t timeOff); + static void setGateTurnOffTime(uint16_t timeOff); /** * Get frequency. From 75bd96efd5fb5eef2e3316281ba3bb588251f63d Mon Sep 17 00:00:00 2001 From: Jean Gauthier Date: Wed, 2 Dec 2020 12:24:51 -0500 Subject: [PATCH 08/18] Update thyristor.cpp --- src/thyristor.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/thyristor.cpp b/src/thyristor.cpp index d8e8d26..e370427 100644 --- a/src/thyristor.cpp +++ b/src/thyristor.cpp @@ -702,9 +702,8 @@ bool Thyristor::mustInterruptBeReEnabled(uint16_t newDelay){ /** * Set the gate turn off time */ - uint16_t Thyristor::setGateTurnOffTime(uint16_t timeOff){ + void Thyristor::setGateTurnOffTime(uint16_t timeOff){ gateTurnOffTime = timeOff; - return gateTurnOffTime; } From 5d913b12d4fe998dca7476c6e49f103192ce80f5 Mon Sep 17 00:00:00 2001 From: Jean Gauthier Date: Wed, 2 Dec 2020 12:28:21 -0500 Subject: [PATCH 09/18] Update thyristor.cpp --- src/thyristor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thyristor.cpp b/src/thyristor.cpp index e370427..301c0ad 100644 --- a/src/thyristor.cpp +++ b/src/thyristor.cpp @@ -93,7 +93,7 @@ static uint16_t gateTurnOffTime = 300; #ifdef PREDEFINED_PULSE_LENGTH // Length of pulse of sync gate. this parameter is not applied if thyristor is fully on or off -static uint8_t pulseWidth = 100; +static uint8_t pulseWidth = 15; #endif From 7c0b134992164ef31067d8af87a2e2e0d34219f9 Mon Sep 17 00:00:00 2001 From: Jean Gauthier Date: Wed, 2 Dec 2020 12:31:31 -0500 Subject: [PATCH 10/18] Update readme.md Explain new functions --- readme.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/readme.md b/readme.md index cd6ce47..b9710af 100644 --- a/readme.md +++ b/readme.md @@ -9,6 +9,13 @@ The main features of this library: 3. Raise interrupts only if strictly necessary (i.e. when the applicance has to turn on, no useless periodic interrupts) 4. Control effective delivered power to appliances, not just thyristor's activation time +## Extra Features added +The extra features of this library: +1. setSyncDir(uint8_t dir) to adjust the interrupt direction FALLING, RISING, CHANGE +2. setSyncPullup(bool pullup) to activate internal pull-up resistor on zero-crossing detection +3. setGateTurnOffTime(uint16_t timeOff) to change the value of the gate turn off time + + Here a complete comparison among the most similar libraries: | | Dimmable Light for Arduino | [RobotDynOfficial/RDBDimmer](https://github.com/RobotDynOfficial/RBDDimmer) | [circuitar/Dimmer](https://github.com/circuitar/Dimmer) | From 8e826ce73a0a18fc0ad58254e2986b4c213667de Mon Sep 17 00:00:00 2001 From: Jean Gauthier Date: Wed, 2 Dec 2020 12:32:51 -0500 Subject: [PATCH 11/18] Update readme.md --- readme.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/readme.md b/readme.md index b9710af..5a4de2f 100644 --- a/readme.md +++ b/readme.md @@ -52,6 +52,13 @@ If you have strong memory constrain, you can drop the functionalities provided b For more details check the [Wiki](https://github.com/fabiuz7/Dimmable-Light-Arduino/wiki). +## Extra Features usage + DimmableLight::setSyncPin(ZC_PIN); + DimmableLight::setSyncDir(FALLING); //Default = RISING + DimmableLight::setSyncPullup(true); //Default = false + DimmableLight::setGateTurnOffTime(1000); //Default = 300 + DimmableLight::begin(); + ## Examples Along with the library there are 7 examples. If you are a beginner you should start from the first one. Note that examples 3 and 5 work only for esp8266 and esp32 mcu because their dependency on Ticker library. Example number 7 shows how to linearly control dimmer setting the effective energy delivered instead activation time. From a2855548c5522aba8e8487be8b30f97677bf4a27 Mon Sep 17 00:00:00 2001 From: Jean Gauthier Date: Wed, 2 Dec 2020 12:34:53 -0500 Subject: [PATCH 12/18] Update readme.md --- readme.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 5a4de2f..26cf199 100644 --- a/readme.md +++ b/readme.md @@ -53,11 +53,13 @@ If you have strong memory constrain, you can drop the functionalities provided b For more details check the [Wiki](https://github.com/fabiuz7/Dimmable-Light-Arduino/wiki). ## Extra Features usage - DimmableLight::setSyncPin(ZC_PIN); - DimmableLight::setSyncDir(FALLING); //Default = RISING - DimmableLight::setSyncPullup(true); //Default = false - DimmableLight::setGateTurnOffTime(1000); //Default = 300 - DimmableLight::begin(); +``` +DimmableLight::setSyncPin(ZC_PIN); +DimmableLight::setSyncDir(FALLING); //Default = RISING +DimmableLight::setSyncPullup(true); //Default = false +DimmableLight::setGateTurnOffTime(1000); //Default = 300 +DimmableLight::begin(); +``` ## Examples Along with the library there are 7 examples. If you are a beginner you should start from the first one. Note that examples 3 and 5 work only for esp8266 and esp32 mcu because their dependency on Ticker library. Example number 7 shows how to linearly control dimmer setting the effective energy delivered instead activation time. From 09b74beaf21082adad0159184b22a117004ed29e Mon Sep 17 00:00:00 2001 From: adisbladis Date: Thu, 30 Mar 2023 17:50:57 +1300 Subject: [PATCH 13/18] Add Pico RP2040 (non-mbed) support This adds support for RP2040 based boards such as the Pico and the Pico W using arduino-pico. Note that this is distinctly different from the mbed-OS based platform which would have to be implemented separately. I have tested this on a Pico W. --- .github/workflows/LibraryBuild.yml | 10 +++- .../4_lights_manager/4_lights_manager.ino | 3 ++ examples/6_8_lights_effects/effect.cpp | 2 + examples/6_8_lights_effects/effect.h | 2 + library.json | 5 +- library.properties | 2 +- platformio.ini | 10 +++- readme.md | 4 +- src/dimmable_light_manager.cpp | 6 +-- src/dimmable_light_manager.h | 4 +- src/hw_timer_pico.cpp | 54 +++++++++++++++++++ src/hw_timer_pico.h | 45 ++++++++++++++++ src/thyristor.cpp | 30 +++++++++-- 13 files changed, 159 insertions(+), 18 deletions(-) create mode 100644 src/hw_timer_pico.cpp create mode 100644 src/hw_timer_pico.h diff --git a/.github/workflows/LibraryBuild.yml b/.github/workflows/LibraryBuild.yml index 3125892..54d540c 100644 --- a/.github/workflows/LibraryBuild.yml +++ b/.github/workflows/LibraryBuild.yml @@ -26,9 +26,9 @@ jobs: # define each specific configuration include: - + # if the current configuration contains the parameter "config-name" and it is equal to "esp8266-v2", - # add the following parameters to this configuration. If board-type is never matched, + # add the following parameters to this configuration. If board-type is never matched, # a new singular configuration is created - config-name: esp8266-v2 platform-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json @@ -65,6 +65,12 @@ jobs: arduino-boards-fqbn: arduino:samd:nano_33_iot sketches-exclude: 3_dimmable_light_5_light, 5_dimmable_manager_n_lights + - config-name: rpi-pico + platform-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json + arduino-platform: rp2040:rp2040@3.6.0 + arduino-boards-fqbn: rp2040:rp2040:rpipico + sketches-exclude: 3_dimmable_light_5_light, 5_dimmable_manager_n_lights + # Do not cancel all jobs / architectures if one job fails fail-fast: false diff --git a/examples/4_lights_manager/4_lights_manager.ino b/examples/4_lights_manager/4_lights_manager.ino index 5a298bd..85c24eb 100644 --- a/examples/4_lights_manager/4_lights_manager.ino +++ b/examples/4_lights_manager/4_lights_manager.ino @@ -19,6 +19,9 @@ const int pins[N] = { 3, 4, 5 }; #elif defined(ARDUINO_ARCH_SAMD) const int syncPin = 2; const int pins[N] = { 3, 4, 5 }; +#elif (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED)) +const int syncPin = 2; +const int pins[N] = { 3, 4, 5 }; #endif DimmableLightManager dlm; diff --git a/examples/6_8_lights_effects/effect.cpp b/examples/6_8_lights_effects/effect.cpp index 524f7ac..213fc80 100644 --- a/examples/6_8_lights_effects/effect.cpp +++ b/examples/6_8_lights_effects/effect.cpp @@ -26,6 +26,8 @@ extern DimmableLightLinearized lights[N_LIGHTS] = { { 3 }, { 4 }, { 5 }, { 6 }, { 7 }, { 8 }, { 9 }, { 10 } }; #elif defined(ARDUINO_ARCH_SAMD) lights[N_LIGHTS] = { { 3 }, { 4 }, { 5 }, { 6 }, { 7 }, { 8 }, { 9 }, { 10 } }; +#elif (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED)) +lights[N_LIGHTS] = { { 3 }, { 4 }, { 5 }, { 6 }, { 7 }, { 8 }, { 9 }, { 10 } }; #endif /** diff --git a/examples/6_8_lights_effects/effect.h b/examples/6_8_lights_effects/effect.h index fc24b52..486e90b 100644 --- a/examples/6_8_lights_effects/effect.h +++ b/examples/6_8_lights_effects/effect.h @@ -20,6 +20,8 @@ const int syncPin = 23; const int syncPin = 2; #elif defined(ARDUINO_ARCH_SAMD) const int syncPin = 2; +#elif (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED)) +const int syncPin = 2; #endif #if defined(RAW_VALUES) diff --git a/library.json b/library.json index 98f1a79..e9ca67e 100644 --- a/library.json +++ b/library.json @@ -27,7 +27,8 @@ "espressif8266", "espressif32", "atmelavr", - "atmelsam" + "atmelsam", + "raspberrypi" ], "dependencies": [ { @@ -97,4 +98,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/library.properties b/library.properties index 021c682..819647f 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=This library allows to easily control dimmers (also known as thyristors paragraph=This library was born to control dimmable light bulbs, but actually dimmers are fully compatible with other AC loads like electrical heaters and motors (be aware of what you are doing!). Actually it works on ESP8266, ESP32, AVR and SAMD. category=Device Control url=https://github.com/fabianoriccardi/dimmable-light -architectures=esp8266,esp32,avr,samd +architectures=esp8266,esp32,avr,samd,rp2040 depends=ArduinoSTL diff --git a/platformio.ini b/platformio.ini index 4d426cf..93a904a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -31,7 +31,7 @@ framework = arduino platform = atmelavr@4.2.0 board = uno framework = arduino -lib_deps = +lib_deps = ${env.lib_deps} mike-matera/ArduinoSTL@^1.3.3 upload_speed = 115200 @@ -40,7 +40,7 @@ upload_speed = 115200 platform = atmelavr@4.2.0 board = megaatmega2560 framework = arduino -lib_deps = +lib_deps = ${env.lib_deps} mike-matera/ArduinoSTL@^1.3.3 upload_speed = 115200 @@ -49,3 +49,9 @@ upload_speed = 115200 platform = atmelsam@8.2.0 board = nano_33_iot framework = arduino + +[env:rpipico] +platform = https://github.com/maxgerhardt/platform-raspberrypi.git +board = pico +framework = arduino +board_build.core = earlephilhower diff --git a/readme.md b/readme.md index 40d15d9..deb99e3 100644 --- a/readme.md +++ b/readme.md @@ -18,7 +18,7 @@ This brief overview gives a glimpse of the variety of properties to consider whi ## Features 1. Control multiple thyristors using a single hardware timer -2. Compatible with multiple platforms (ESP8266/ESP32/AVR/SAMD) +2. Compatible with multiple platforms (ESP8266/ESP32/AVR/SAMD/RP2040) 3. Interrupt optimization (trigger interrupts only if necessary, no periodic interrupt) 4. Control the load by 2 measurement unit: gate activation time or linearized relative power 5. Documented parameters to finely tune the library on your hardware and requirements @@ -29,7 +29,7 @@ Here the comparison against 2 similar and popular libraries: |------------------------------------------|---------------------------------------------|-----------------------------------------------------------------------------|---------------------------------------------------------| | Multiple dimmers | yes | yes | yes | | Supported Frequencies | 50/60Hz | 50Hz | 50/60Hz | -| Supported architectures | AVR, SAMD, ESP8266, ESP32 | AVR, SAMD, ESP8266, ESP32, STM32F1, STM32F4, SAM | AVR | +| Supported architectures | AVR, SAMD, ESP8266, ESP32, RP2040 | AVR, SAMD, ESP8266, ESP32, STM32F1, STM32F4, SAM | AVR | | Control *effective* delivered power | yes, dynamic calculation | no | yes, static lookup table | | Predefined effects | no | yes, automatic fade to new value | yes, swipe effect | | Optional zero-crossing mode | no | no | yes | diff --git a/src/dimmable_light_manager.cpp b/src/dimmable_light_manager.cpp index 620aa47..547a92d 100644 --- a/src/dimmable_light_manager.cpp +++ b/src/dimmable_light_manager.cpp @@ -21,7 +21,7 @@ bool DimmableLightManager::add(String lightName, uint8_t pin) { const char* temp = lightName.c_str(); -#if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_SAMD) +#if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_RP2040) std::unordered_map::const_iterator it = dla.find(temp); #elif defined(AVR) std::map::const_iterator it = dla.find(temp); @@ -37,7 +37,7 @@ bool DimmableLightManager::add(String lightName, uint8_t pin) { DimmableLight* DimmableLightManager::get(String lightName) { const char* temp = lightName.c_str(); -#if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_SAMD) +#if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_RP2040) std::unordered_map::const_iterator it = dla.find(temp); #elif defined(AVR) std::map::const_iterator it = dla.find(temp); @@ -50,7 +50,7 @@ DimmableLight* DimmableLightManager::get(String lightName) { } std::pair DimmableLightManager::get() { -#if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_SAMD) +#if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_RP2040) static std::unordered_map::const_iterator it = dla.begin(); #elif defined(AVR) static std::map::const_iterator it = dla.begin(); diff --git a/src/dimmable_light_manager.h b/src/dimmable_light_manager.h index 99c2497..c1dccee 100644 --- a/src/dimmable_light_manager.h +++ b/src/dimmable_light_manager.h @@ -22,7 +22,7 @@ #include "dimmable_light.h" -#if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_SAMD) +#if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_RP2040) // Unfortunately Arduino defines max/min macros, those create conflicts with the one // defined by C++/STL environment #undef max @@ -68,7 +68,7 @@ class DimmableLightManager { } private: -#if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_SAMD) +#if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_RP2040) std::unordered_map dla; #elif defined(AVR) std::map dla; diff --git a/src/hw_timer_pico.cpp b/src/hw_timer_pico.cpp new file mode 100644 index 0000000..6ea4b1c --- /dev/null +++ b/src/hw_timer_pico.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** + * This file is part of Dimmable Light for Arduino, a library to * + * control dimmers. * + * * + * Copyright (C) 2018-2022 Fabiano Riccardi * + * * + * Dimmable Light for Arduino is free software; you can redistribute * + * it and/or modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#if defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) + +#include "hw_timer_pico.h" +#include + +static void (*timer_callback)() = nullptr; +static alarm_id_t alarm_id; +static alarm_pool_t *alarm_pool; + +void timerBegin() { + alarm_pool = alarm_pool_get_default(); +} + +void timerSetCallback(void (*callback)()) { + timer_callback = callback; +} + +void timerStart(uint64_t t) { + if (alarm_id) { + cancel_alarm(alarm_id); + alarm_id = 0; + } + + alarm_id = alarm_pool_add_alarm_in_us( + alarm_pool, t, + [](alarm_id_t, void *) -> int64_t { + if (timer_callback != nullptr) { timer_callback(); } + alarm_id = 0; + return 0; // Do not reschedule alarm + }, + NULL, true); +} + +#endif // END ARDUINO_ARCH_RP2040 diff --git a/src/hw_timer_pico.h b/src/hw_timer_pico.h new file mode 100644 index 0000000..e4cc08f --- /dev/null +++ b/src/hw_timer_pico.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * This file is part of Dimmable Light for Arduino, a library to * + * control dimmers. * + * * + * Copyright (C) 2018-2022 Fabiano Riccardi * + * * + * Dimmable Light for Arduino is free software; you can redistribute * + * it and/or modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#if defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) + +#ifndef HW_TIMER_PICO_H +#define HW_TIMER_PICO_H + +#include + +/** + * Initialize the timer. + */ +void timerBegin(); + +/** + * Set callback function on timer triggers + */ +void timerSetCallback(void (*callback)()); + +/** + * Start the timer to trigger after the specified number of microseconds. + */ +void timerStart(uint64_t t); + +#endif // HW_TIMER_PICO_H + +#endif // ARDUINO_ARCH_RP2040 diff --git a/src/thyristor.cpp b/src/thyristor.cpp index 83fd2ba..7b14af0 100644 --- a/src/thyristor.cpp +++ b/src/thyristor.cpp @@ -29,8 +29,10 @@ #include "hw_timer_avr.h" #elif defined(ARDUINO_ARCH_SAMD) #include "hw_timer_samd.h" +#elif defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) +#include "hw_timer_pico.h" #else -#error "only ESP8266, ESP32, AVR, SAMD architectures are supported" +#error "only ESP8266, ESP32, AVR, SAMD & RP2040 (non-mbed) architectures are supported" #endif // Ignore zero-cross interrupts when they occurs too early w.r.t semi-period ideal length. @@ -188,7 +190,7 @@ void activate_thyristors() { if (thyristorManaged < Thyristor::nThyristors) { int delayAbsolute = pinDelay[thyristorManaged].delay; -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD) || (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED)) int delayRelative = delayAbsolute - pinDelay[firstToBeUpdated].delay; #endif @@ -202,6 +204,10 @@ void activate_thyristors() { } #elif defined(ARDUINO_ARCH_SAMD) timerStart(microsecond2Tick(delayRelative)); +#elif defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) + timerStart(delayRelative); +#else + #error "Not implemented" #endif } else { @@ -215,12 +221,14 @@ void activate_thyristors() { stopTimer(); #elif defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD) // Given actual HAL, AVR and SAMD counter automatically stops on interrupt +#elif defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) + // Timer callback is not rescheduled #endif #else // If there are not more thyristors to serve, set timer to turn off gates' signal uint16_t delayAbsolute = semiPeriodLength - gateTurnOffTime; -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD) || (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED)) uint16_t delayRelative = delayAbsolute - pinDelay[firstToBeUpdated].delay; #endif @@ -238,6 +246,11 @@ void activate_thyristors() { #elif defined(ARDUINO_ARCH_SAMD) timerSetCallback(turn_off_gates_int); timerStart(microsecond2Tick(delayRelative)); +#elif defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) + timerSetCallback(turn_off_gates_int); + timerStart(delayRelative); +#else + #error "Not implemented" #endif #endif } @@ -430,6 +443,11 @@ void zero_cross_int() { #elif defined(ARDUINO_ARCH_SAMD) timerSetCallback(activate_thyristors); timerStart(microsecond2Tick(delayAbsolute)); +#elif defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) + timerSetCallback(activate_thyristors); + timerStart(pinDelay[thyristorManaged].delay); +#else + # error "Not implemented" #endif } else { @@ -447,6 +465,8 @@ void zero_cross_int() { stopTimer(); #elif defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD) // Given actual HAL, AVR and SAMD counter automatically stops on interrupt +#elif defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) + // Timer callback is not rescheduled #endif } } @@ -591,9 +611,11 @@ void Thyristor::begin() { T1I = 0; #elif defined(ARDUINO_ARCH_ESP32) timerInit(isr_selector); -#elif defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD) +#elif defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD) || (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED)) timerSetCallback(activate_thyristors); timerBegin(); +#else + #error "Not implemented" #endif #ifdef MONITOR_FREQUENCY From a967a6381896ea17bd782118c2ad20428d69f498 Mon Sep 17 00:00:00 2001 From: Fabiano Riccardi Date: Sun, 19 Nov 2023 12:29:32 +0100 Subject: [PATCH 14/18] uniforming license --- src/hw_timer_pico.cpp | 38 +++++++++++++++++++------------------- src/hw_timer_pico.h | 38 +++++++++++++++++++------------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/hw_timer_pico.cpp b/src/hw_timer_pico.cpp index 6ea4b1c..9e4ff48 100644 --- a/src/hw_timer_pico.cpp +++ b/src/hw_timer_pico.cpp @@ -1,22 +1,22 @@ -/*************************************************************************** - * This file is part of Dimmable Light for Arduino, a library to * - * control dimmers. * - * * - * Copyright (C) 2018-2022 Fabiano Riccardi * - * * - * Dimmable Light for Arduino is free software; you can redistribute * - * it and/or modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2.1 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, see * - ***************************************************************************/ +/****************************************************************************** + * This file is part of Dimmable Light for Arduino, a library to control * + * dimmers. * + * * + * Copyright (C) 2018-2023 Fabiano Riccardi * + * * + * Dimmable Light for Arduino is free software; you can redistribute * + * it and/or modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public License * + * along with this library; if not, see . * + ******************************************************************************/ #if defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) diff --git a/src/hw_timer_pico.h b/src/hw_timer_pico.h index e4cc08f..603b349 100644 --- a/src/hw_timer_pico.h +++ b/src/hw_timer_pico.h @@ -1,22 +1,22 @@ -/*************************************************************************** - * This file is part of Dimmable Light for Arduino, a library to * - * control dimmers. * - * * - * Copyright (C) 2018-2022 Fabiano Riccardi * - * * - * Dimmable Light for Arduino is free software; you can redistribute * - * it and/or modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2.1 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * - * Lesser General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, see * - ***************************************************************************/ +/****************************************************************************** + * This file is part of Dimmable Light for Arduino, a library to control * + * dimmers. * + * * + * Copyright (C) 2018-2023 Fabiano Riccardi * + * * + * Dimmable Light for Arduino is free software; you can redistribute * + * it and/or modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public License * + * along with this library; if not, see . * + ******************************************************************************/ #if defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) From 25752be5a0cbd13863434066a5a46b9a2be04339 Mon Sep 17 00:00:00 2001 From: Fabiano Riccardi Date: Sun, 19 Nov 2023 16:16:13 +0100 Subject: [PATCH 15/18] remove setGateTurnOffTime, cleanup --- src/dimmable_light.h | 20 +++++++------------- src/thyristor.cpp | 13 ++----------- src/thyristor.h | 24 +++++++++--------------- 3 files changed, 18 insertions(+), 39 deletions(-) diff --git a/src/dimmable_light.h b/src/dimmable_light.h index 4ca6c31..679a66e 100644 --- a/src/dimmable_light.h +++ b/src/dimmable_light.h @@ -117,27 +117,21 @@ class DimmableLight { static void setSyncPin(uint8_t pin) { Thyristor::setSyncPin(pin); } - + /** - * Set the pin direction (FALLING, RISING, CHANGE) + * Set the pin direction (RISING (default), FALLING, CHANGE). */ - static void setSyncDir(uint8_t dir){ + static void setSyncDir(uint8_t dir) { Thyristor::setSyncDir(dir); } - + /** - * Set the pin direction (FALLING, RISING, CHANGE) + * Set the pin pullup (true = INPUT_PULLUP, false = INPUT). The internal pullup resistor is not + * available for each platform and each pin. */ - static void setSyncPullup(bool pullup){ + static void setSyncPullup(bool pullup) { Thyristor::setSyncPullup(pullup); } - - /** - * Set the gate turn off time - */ - static void setGateTurnOffTime(uint16_t turnOffTime){ - Thyristor::setGateTurnOffTime(turnOffTime); - } /** * Return the number of instantiated lights. diff --git a/src/thyristor.cpp b/src/thyristor.cpp index fedf93d..2c585fa 100644 --- a/src/thyristor.cpp +++ b/src/thyristor.cpp @@ -85,14 +85,13 @@ static const uint16_t endMargin = 500; // on AVR, you should set a bigger mergePeriod (e.g. 100us). static const uint16_t mergePeriod = 20; - // Period in microseconds before the end of the semiperiod when an interrupt is triggered to // turn off all gate signals. This parameter doesn't have any effect if you enable // PREDEFINED_PULSE_LENGTH. static const uint16_t gateTurnOffTime = 300; static_assert(endMargin - gateTurnOffTime > mergePeriod, "endMargin must be greater than " - "(gateTurnOffTime + mergePeriod)"); + "(gateTurnOffTime + mergePeriod)"); #ifdef PREDEFINED_PULSE_LENGTH // Length of pulse on thyristor's gate pin. This parameter is not applied if thyristor is fully on @@ -610,7 +609,7 @@ void Thyristor::setDelay(uint16_t newDelay) { void Thyristor::turnOn() { setDelay(semiPeriodLength); } -void Thyristor::begin(){ +void Thyristor::begin() { pinMode(syncPin, syncPullup ? INPUT_PULLUP : INPUT); #if defined(ARDUINO_ARCH_ESP8266) @@ -777,14 +776,6 @@ bool Thyristor::mustInterruptBeReEnabled(uint16_t newDelay) { return !interruptEnabled && interruptMustBeEnabled; } - /** - * Set the gate turn off time - */ - void Thyristor::setGateTurnOffTime(uint16_t timeOff){ - gateTurnOffTime = timeOff; - } - - uint8_t Thyristor::nThyristors = 0; Thyristor* Thyristor::thyristors[Thyristor::N] = { nullptr }; bool Thyristor::newDelayValues = false; diff --git a/src/thyristor.h b/src/thyristor.h index edecde9..ee0d671 100644 --- a/src/thyristor.h +++ b/src/thyristor.h @@ -113,25 +113,21 @@ class Thyristor { static void setSyncPin(uint8_t pin) { syncPin = pin; } - + /** - * Set the pin direction (RISING, FALLING, CHANGE) + * Set the pin direction (RISING (default), FALLING, CHANGE). */ - static void setSyncDir(uint8_t dir){ + static void setSyncDir(uint8_t dir) { syncDir = dir; } - + /** - * Set the pin pullup + * Set the pin pullup (true = INPUT_PULLUP, false = INPUT). The internal pullup resistor is not + * available for each platform and each pin. */ - static void setSyncPullup(bool pullup){ + static void setSyncPullup(bool pullup) { syncPullup = pullup; } - - /** - * Set the gate turn off time - */ - static void setGateTurnOffTime(uint16_t timeOff); /** * Get frequency. @@ -177,8 +173,6 @@ class Thyristor { #endif static const uint8_t N = 8; - - private: /** @@ -234,12 +228,12 @@ class Thyristor { * Pin receiving the external Zero Cross signal. */ static uint8_t syncPin; - + /** * Pin direction (FALLING, RISING, CHANGE). */ static uint8_t syncDir; - + /** * Pin pullup active. */ From 458ddea319f63c6af5b98f1af38ef2547d1add6f Mon Sep 17 00:00:00 2001 From: Fabiano Riccardi Date: Sun, 19 Nov 2023 16:20:36 +0100 Subject: [PATCH 16/18] fixing dimmable_light_linearized --- src/dimmable_light_linearized.h | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/dimmable_light_linearized.h b/src/dimmable_light_linearized.h index 80266c0..f65efe4 100644 --- a/src/dimmable_light_linearized.h +++ b/src/dimmable_light_linearized.h @@ -130,27 +130,21 @@ class DimmableLightLinearized { static void setSyncPin(uint8_t pin) { Thyristor::setSyncPin(pin); } - + /** - * Set the pin direction (FALLING, RISING, CHANGE) + * Set the pin direction (RISING (default), FALLING, CHANGE). */ - static void setSyncDir(uint8_t dir){ + static void setSyncDir(uint8_t dir) { Thyristor::setSyncDir(dir); } - + /** - * Set the pin direction (FALLING, RISING, CHANGE) + * Set the pin pullup (true = INPUT_PULLUP, false = INPUT). The internal pullup resistor is not + * available for each platform and each pin. */ - static void setSyncPullup(bool pullup){ + static void setSyncPullup(bool pullup) { Thyristor::setSyncPullup(pullup); } - - /** - * Set the gate turn off time - */ - static void setGateTurnOffTime(uint16_t turnOffTime){ - Thyristor::setGateTurnOffTime(turnOffTime); - } /** * Return the number of instantiated lights. From 1fc93ecfe9772aed212a281b1209e1c165bd72a1 Mon Sep 17 00:00:00 2001 From: Fabiano Riccardi Date: Sun, 19 Nov 2023 16:59:59 +0100 Subject: [PATCH 17/18] fix PinStatus incompatibility --- src/dimmable_light.h | 2 +- src/dimmable_light_linearized.h | 2 +- src/thyristor.cpp | 2 +- src/thyristor.h | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dimmable_light.h b/src/dimmable_light.h index 679a66e..72e33f5 100644 --- a/src/dimmable_light.h +++ b/src/dimmable_light.h @@ -121,7 +121,7 @@ class DimmableLight { /** * Set the pin direction (RISING (default), FALLING, CHANGE). */ - static void setSyncDir(uint8_t dir) { + static void setSyncDir(decltype(RISING) dir) { Thyristor::setSyncDir(dir); } diff --git a/src/dimmable_light_linearized.h b/src/dimmable_light_linearized.h index f65efe4..5490e2f 100644 --- a/src/dimmable_light_linearized.h +++ b/src/dimmable_light_linearized.h @@ -134,7 +134,7 @@ class DimmableLightLinearized { /** * Set the pin direction (RISING (default), FALLING, CHANGE). */ - static void setSyncDir(uint8_t dir) { + static void setSyncDir(decltype(RISING) dir) { Thyristor::setSyncDir(dir); } diff --git a/src/thyristor.cpp b/src/thyristor.cpp index 2c585fa..3c6496e 100644 --- a/src/thyristor.cpp +++ b/src/thyristor.cpp @@ -782,6 +782,6 @@ bool Thyristor::newDelayValues = false; bool Thyristor::updatingStruct = false; bool Thyristor::allThyristorsOnOff = true; uint8_t Thyristor::syncPin = 255; -uint8_t Thyristor::syncDir = RISING; +decltype(RISING) Thyristor::syncDir = RISING; bool Thyristor::syncPullup = false; bool Thyristor::frequencyMonitorAlwaysEnabled = true; diff --git a/src/thyristor.h b/src/thyristor.h index ee0d671..cbb7ca6 100644 --- a/src/thyristor.h +++ b/src/thyristor.h @@ -20,7 +20,7 @@ #ifndef THYRISTOR_H #define THYRISTOR_H -#include +#include /** * These defines affect the declaration of this class and the relative wrappers. @@ -117,7 +117,7 @@ class Thyristor { /** * Set the pin direction (RISING (default), FALLING, CHANGE). */ - static void setSyncDir(uint8_t dir) { + static void setSyncDir(decltype(RISING) dir) { syncDir = dir; } @@ -232,7 +232,7 @@ class Thyristor { /** * Pin direction (FALLING, RISING, CHANGE). */ - static uint8_t syncDir; + static decltype(RISING) syncDir; /** * Pin pullup active. From 12b522b967ff0ec8b6075955907f91ee72f62877 Mon Sep 17 00:00:00 2001 From: Fabiano Riccardi Date: Wed, 22 Nov 2023 22:40:57 +0100 Subject: [PATCH 18/18] typo --- src/thyristor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/thyristor.cpp b/src/thyristor.cpp index 3c6496e..ff950ff 100644 --- a/src/thyristor.cpp +++ b/src/thyristor.cpp @@ -609,6 +609,7 @@ void Thyristor::setDelay(uint16_t newDelay) { void Thyristor::turnOn() { setDelay(semiPeriodLength); } + void Thyristor::begin() { pinMode(syncPin, syncPullup ? INPUT_PULLUP : INPUT);