Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some features #25

Merged
merged 21 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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