Skip to content

Commit

Permalink
Added setSyncDir and setSyncPullup (#25)
Browse files Browse the repository at this point in the history
* Update keywords.txt

* Update thyristor.h

* Update thyristor.cpp

* Update readme.md

* uniforming license

* remove setGateTurnOffTime, cleanup

* fixing dimmable_light_linearized

* fix PinStatus incompatibility

* typo

---------

Co-authored-by: Fabiano Riccardi <fabiano.riccardi@outlook.com>
  • Loading branch information
SupremeSports and fabianoriccardi authored Nov 22, 2023
1 parent dda54f7 commit 3137e9e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
15 changes: 15 additions & 0 deletions src/dimmable_light.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ class DimmableLight {
Thyristor::setSyncPin(pin);
}

/**
* Set the pin direction (RISING (default), FALLING, CHANGE).
*/
static void setSyncDir(decltype(RISING) dir) {
Thyristor::setSyncDir(dir);
}

/**
* 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) {
Thyristor::setSyncPullup(pullup);
}

/**
* Return the number of instantiated lights.
*/
Expand Down
15 changes: 15 additions & 0 deletions src/dimmable_light_linearized.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ class DimmableLightLinearized {
Thyristor::setSyncPin(pin);
}

/**
* Set the pin direction (RISING (default), FALLING, CHANGE).
*/
static void setSyncDir(decltype(RISING) dir) {
Thyristor::setSyncDir(dir);
}

/**
* 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) {
Thyristor::setSyncPullup(pullup);
}

/**
* Return the number of instantiated lights.
*/
Expand Down
10 changes: 6 additions & 4 deletions src/thyristor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,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) {
Expand All @@ -611,7 +611,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);
Expand All @@ -632,7 +632,7 @@ void Thyristor::begin() {
// Starts immediately to sense the eletricity grid

interruptEnabled = true;
attachInterrupt(digitalPinToInterrupt(syncPin), zero_cross_int, RISING);
attachInterrupt(digitalPinToInterrupt(syncPin), zero_cross_int, syncDir);
#endif
}

Expand Down Expand Up @@ -699,7 +699,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;

Expand Down Expand Up @@ -783,4 +783,6 @@ bool Thyristor::newDelayValues = false;
bool Thyristor::updatingStruct = false;
bool Thyristor::allThyristorsOnOff = true;
uint8_t Thyristor::syncPin = 255;
decltype(RISING) Thyristor::syncDir = RISING;
bool Thyristor::syncPullup = false;
bool Thyristor::frequencyMonitorAlwaysEnabled = true;
27 changes: 26 additions & 1 deletion src/thyristor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef THYRISTOR_H
#define THYRISTOR_H

#include <stdint.h>
#include <Arduino.h>

/**
* These defines affect the declaration of this class and the relative wrappers.
Expand Down Expand Up @@ -114,6 +114,21 @@ class Thyristor {
syncPin = pin;
}

/**
* Set the pin direction (RISING (default), FALLING, CHANGE).
*/
static void setSyncDir(decltype(RISING) dir) {
syncDir = dir;
}

/**
* 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) {
syncPullup = pullup;
}

/**
* Get frequency.
*/
Expand Down Expand Up @@ -214,6 +229,16 @@ class Thyristor {
*/
static uint8_t syncPin;

/**
* Pin direction (FALLING, RISING, CHANGE).
*/
static decltype(RISING) syncDir;

/**
* Pin pullup active.
*/
static bool syncPullup;

/**
* 0) no messages
* 1) error messages
Expand Down

0 comments on commit 3137e9e

Please sign in to comment.