کد زیر رو آنالیز کن. #if defined(ARDUINOARCHESP32) #include "RBDmcuESP32.h" int…
- User
کد زیر رو آنالیز کن. #if defined(ARDUINO_ARCH_ESP32)
#include "RBDmcuESP32.h"
int pulseWidth = 1; volatile int current_dim = 0; int all_dim = 3; int rise_fall = true; char user_zero_cross = '0';
static int toggleCounter = 0; static int toggleReload = 25;
static dimmerLamp* dimmer[ALL_DIMMERS]; volatile uint16_t dimPower[ALL_DIMMERS]; volatile uint16_t dimOutPin[ALL_DIMMERS]; volatile uint16_t dimZCPin[ALL_DIMMERS]; volatile uint16_t zeroCross[ALL_DIMMERS]; volatile DIMMER_MODE_typedef dimMode[ALL_DIMMERS]; volatile ON_OFF_typedef dimState[ALL_DIMMERS]; volatile uint16_t dimCounter[ALL_DIMMERS]; static uint16_t dimPulseBegin[ALL_DIMMERS]; volatile uint16_t togMax[ALL_DIMMERS]; volatile uint16_t togMin[ALL_DIMMERS]; volatile bool togDir[ALL_DIMMERS];
dimmerLamp::dimmerLamp(int user_dimmer_pin, int zc_dimmer_pin): dimmer_pin(user_dimmer_pin), zc_pin(zc_dimmer_pin) { current_dim++; dimmer[current_dim-1] = this; current_num = current_dim-1; toggle_state = false;
codedimPulseBegin[current_dim-1] = 1; dimOutPin[current_dim-1] = user_dimmer_pin; dimZCPin[current_dim-1] = zc_dimmer_pin; dimCounter[current_dim-1] = 0; zeroCross[current_dim-1] = 0; dimMode[current_dim-1] = NORMAL_MODE; togMin[current_dim-1] = 0; togMax[current_dim-1] = 1; pinMode(user_dimmer_pin, OUTPUT);}
void dimmerLamp::timer_init(void) { hw_timer_t * timer = NULL; // Use 1st timer of 4 (counted from zero). // Set 80 divider for prescaler (see ESP32 Technical Reference Manual for more info). timer = timerBegin(0, 250, true); // Attach onTimer function to our timer. timerAttachInterrupt(timer, &onTimerISR, true); // Set alarm to call onTimer function every second (value in microseconds). // Repeat the alarm (third parameter) timerAlarmWrite(timer, 30, true); // Start an alarm timerAlarmEnable(timer); }
void dimmerLamp::ext_int_init(void) { int inPin = dimZCPin[this->current_num]; pinMode(inPin, INPUT_PULLUP); attachInterrupt(inPin, isr_ext, RISING); }
void dimmerLamp::begin(DIMMER_MODE_typedef DIMMER_MODE, ON_OFF_typedef ON_OFF) { dimMode[this->current_num] = DIMMER_MODE; dimState[this->current_num] = ON_OFF; timer_init(); ext_int_init(); }
void dimmerLamp::setPower(int power) { if (power >= 99) { power = 99; } dimPower[this->current_num] = power; dimPulseBegin[this->current_num] = powerBuf[power];
codedelay(1);}
int dimmerLamp::getPower(void) { if (dimState[this->current_num] == ON) return dimPower[this->current_num]; else return 0; }
void dimmerLamp::setState(ON_OFF_typedef ON_OFF) { dimState[this->current_num] = ON_OFF; }
- Assistant