updating main code to incorporate new Blinkable class/interface
This commit is contained in:
parent
294b8d8d71
commit
6fecf2c29f
|
|
@ -41,6 +41,7 @@
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
|
|
||||||
#include "extras/Blinker.h"
|
#include "extras/Blinker.h"
|
||||||
|
#include "extras/Pixel.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "Network.h"
|
#include "Network.h"
|
||||||
|
|
@ -255,8 +256,9 @@ class Span{
|
||||||
boolean deleteAccessory(uint32_t aid); // deletes Accessory with matching aid; returns true if found, else returns false
|
boolean deleteAccessory(uint32_t aid); // deletes Accessory with matching aid; returns true if found, else returns false
|
||||||
|
|
||||||
void setControlPin(uint8_t pin){controlButton=new PushButton(pin);} // sets Control Pin
|
void setControlPin(uint8_t pin){controlButton=new PushButton(pin);} // sets Control Pin
|
||||||
void setStatusPin(uint8_t pin){statusLED=new Blinker(new LED(pin),0,autoOffLED);} // sets Status Pin
|
// void setStatusPin(uint8_t pin){statusLED=new Blinker(new LED(pin),autoOffLED);} // sets Status Pin
|
||||||
// void setStatusPin(Blinkable *led){statusLED=new Blinker(led,0,autoOffLED);} // sets Status Blinkable LED
|
void setStatusPin(uint8_t pin){statusLED=new Blinker(new Pixel(8),autoOffLED);} // sets Status Pin
|
||||||
|
// void setStatusPin(Blinkable *led){statusLED=new Blinker(led,autoOffLED);} // sets Status Blinkable LED
|
||||||
|
|
||||||
void setStatusAutoOff(uint16_t duration){autoOffLED=duration;} // sets Status LED auto off (seconds)
|
void setStatusAutoOff(uint16_t duration){autoOffLED=duration;} // sets Status LED auto off (seconds)
|
||||||
int getStatusPin(){return(statusLED?statusLED->getPin():-1);} // get Status Pin (returns -1 if undefined)
|
int getStatusPin(){return(statusLED?statusLED->getPin():-1);} // get Status Pin (returns -1 if undefined)
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,6 @@
|
||||||
#include "Network.h"
|
#include "Network.h"
|
||||||
#include "HomeSpan.h"
|
#include "HomeSpan.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "extras/Blinker.h"
|
|
||||||
|
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
|
|
|
||||||
149
src/Utils.cpp
149
src/Utils.cpp
|
|
@ -35,7 +35,6 @@
|
||||||
// Utils::mask - masks a string with asterisks (good for displaying passwords)
|
// Utils::mask - masks a string with asterisks (good for displaying passwords)
|
||||||
//
|
//
|
||||||
// class PushButton - tracks Single, Double, and Long Presses of a pushbutton that connects a specified pin to ground
|
// class PushButton - tracks Single, Double, and Long Presses of a pushbutton that connects a specified pin to ground
|
||||||
// class Blinker - creates customized blinking patterns on an LED connected to a specified pin
|
|
||||||
//
|
//
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
@ -226,151 +225,3 @@ void PushButton::reset(){
|
||||||
#if SOC_TOUCH_SENSOR_NUM > 0
|
#if SOC_TOUCH_SENSOR_NUM > 0
|
||||||
touch_value_t PushButton::threshold=0;
|
touch_value_t PushButton::threshold=0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//////////////////////////////////
|
|
||||||
//// Blinker //
|
|
||||||
//////////////////////////////////
|
|
||||||
//
|
|
||||||
//Blinker::Blinker(Blinkable *led, int timerNum, uint16_t autoOffDuration){
|
|
||||||
//
|
|
||||||
// this->led=led;
|
|
||||||
//
|
|
||||||
// pauseDuration=autoOffDuration*1000;
|
|
||||||
//
|
|
||||||
//#if SOC_TIMER_GROUP_TIMERS_PER_GROUP>1 // ESP32 and ESP32-S2 contains two timers per timer group
|
|
||||||
// group=((timerNum/2)%2==0)?TIMER_GROUP_0:TIMER_GROUP_1;
|
|
||||||
// idx=(timerNum%2==0)?TIMER_0:TIMER_1; // ESP32-C3 only contains one timer per timer group
|
|
||||||
//#else
|
|
||||||
// group=(timerNum%2==0)?TIMER_GROUP_0:TIMER_GROUP_1;
|
|
||||||
// idx=TIMER_0;
|
|
||||||
//#endif
|
|
||||||
//
|
|
||||||
// timer_config_t conf;
|
|
||||||
// conf.alarm_en=TIMER_ALARM_EN;
|
|
||||||
// conf.counter_en=TIMER_PAUSE;
|
|
||||||
// conf.intr_type=TIMER_INTR_LEVEL;
|
|
||||||
// conf.counter_dir=TIMER_COUNT_UP;
|
|
||||||
// conf.auto_reload=TIMER_AUTORELOAD_EN;
|
|
||||||
// conf.divider=getApbFrequency()/10000; // set divider to yield 10 kHz clock (0.1 ms pulses)
|
|
||||||
//
|
|
||||||
//#ifdef SOC_TIMER_GROUP_SUPPORT_XTAL // set clock to APB (default is XTAL!) if clk_src is defined in conf structure
|
|
||||||
// conf.clk_src=TIMER_SRC_CLK_APB;
|
|
||||||
//#endif
|
|
||||||
//
|
|
||||||
// timer_init(group,idx,&conf);
|
|
||||||
// timer_isr_register(group,idx,Blinker::isrTimer,(void *)this,0,NULL);
|
|
||||||
// timer_enable_intr(group,idx);
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//void Blinker::isrTimer(void *arg){
|
|
||||||
//
|
|
||||||
// Blinker *b=(Blinker *)arg;
|
|
||||||
//
|
|
||||||
//#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) // use new method that is generic to ESP32, S2, and C3
|
|
||||||
// timer_group_clr_intr_status_in_isr(b->group,b->idx);
|
|
||||||
//#else // use older method that is only for ESP32
|
|
||||||
// if(b->group){
|
|
||||||
// if(b->idx)
|
|
||||||
// TIMERG1.int_clr_timers.t1=1;
|
|
||||||
// else
|
|
||||||
// TIMERG1.int_clr_timers.t0=1;
|
|
||||||
// } else {
|
|
||||||
// if(b->idx)
|
|
||||||
// TIMERG0.int_clr_timers.t1=1;
|
|
||||||
// else
|
|
||||||
// TIMERG0.int_clr_timers.t0=1;
|
|
||||||
// }
|
|
||||||
//#endif
|
|
||||||
//
|
|
||||||
// if(!(b->led->isOn())){
|
|
||||||
// b->led->on();
|
|
||||||
// timer_set_alarm_value(b->group,b->idx,b->onTime);
|
|
||||||
// b->count--;
|
|
||||||
// } else {
|
|
||||||
// b->led->off();
|
|
||||||
// if(b->count){
|
|
||||||
// timer_set_alarm_value(b->group,b->idx,b->offTime);
|
|
||||||
// } else {
|
|
||||||
// timer_set_alarm_value(b->group,b->idx,b->delayTime);
|
|
||||||
// b->count=b->nBlinks;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// timer_set_alarm(b->group,b->idx,TIMER_ALARM_EN);
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//void Blinker::start(int period, float dutyCycle){
|
|
||||||
//
|
|
||||||
// start(period, dutyCycle, 1, 0);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//void Blinker::start(int period, float dutyCycle, int nBlinks, int delayTime){
|
|
||||||
//
|
|
||||||
// pauseTime=millis();
|
|
||||||
// isPaused=false;
|
|
||||||
//
|
|
||||||
// period*=10;
|
|
||||||
// onTime=dutyCycle*period;
|
|
||||||
// offTime=period-onTime;
|
|
||||||
// this->delayTime=delayTime*10+offTime;
|
|
||||||
// this->nBlinks=nBlinks;
|
|
||||||
// count=nBlinks;
|
|
||||||
// timer_set_counter_value(group,idx,0);
|
|
||||||
// timer_set_alarm_value(group,idx,0);
|
|
||||||
// timer_start(group,idx);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//void Blinker::stop(){
|
|
||||||
//
|
|
||||||
// timer_pause(group,idx);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//void Blinker::on(){
|
|
||||||
//
|
|
||||||
// pauseTime=millis();
|
|
||||||
// isPaused=false;
|
|
||||||
//
|
|
||||||
// stop();
|
|
||||||
// led->on();
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//void Blinker::off(){
|
|
||||||
//
|
|
||||||
// pauseTime=millis();
|
|
||||||
// isPaused=false;
|
|
||||||
//
|
|
||||||
// stop();
|
|
||||||
// led->off();
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//void Blinker::check(){
|
|
||||||
//
|
|
||||||
// if(pauseDuration==0 || isPaused || (millis()-pauseTime)<pauseDuration)
|
|
||||||
// return;
|
|
||||||
//
|
|
||||||
// Serial.print("Pausing Status LED\n");
|
|
||||||
// isPaused=true;
|
|
||||||
// led->off();
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//int Blinker::getPin(){
|
|
||||||
// return(led->getPin());
|
|
||||||
//}
|
|
||||||
|
|
|
||||||
118
src/Utils.h
118
src/Utils.h
|
|
@ -29,7 +29,6 @@
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <driver/timer.h>
|
#include <driver/timer.h>
|
||||||
#include "extras/Blinker.h"
|
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
|
|
@ -38,21 +37,6 @@ String mask(char *c, int n); // simply utility that creates a String fr
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
// Blinkable Interface //
|
|
||||||
////////////////////////////////
|
|
||||||
|
|
||||||
//class Blinkable {
|
|
||||||
// protected:
|
|
||||||
// boolean onState=false;
|
|
||||||
//
|
|
||||||
// public:
|
|
||||||
// virtual void on()=0;
|
|
||||||
// virtual void off()=0;
|
|
||||||
// virtual int getPin()=0;
|
|
||||||
// boolean isOn() {return(onState);}
|
|
||||||
//};
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
// Creates a temporary buffer that is freed after
|
// Creates a temporary buffer that is freed after
|
||||||
// going out of scope
|
// going out of scope
|
||||||
|
|
@ -197,105 +181,3 @@ class PushButton{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////
|
|
||||||
//// Generic_LED //
|
|
||||||
//////////////////////////////////
|
|
||||||
//
|
|
||||||
//class LED : public Blinkable {
|
|
||||||
// int pin;
|
|
||||||
//
|
|
||||||
// public:
|
|
||||||
//
|
|
||||||
// LED(int pin) : pin{pin} {pinMode(pin,OUTPUT);digitalWrite(pin,0);}
|
|
||||||
// void on() {digitalWrite(pin,HIGH);onState=true;}
|
|
||||||
// void off() {digitalWrite(pin,LOW);onState=false;}
|
|
||||||
// int getPin() {return(pin);}
|
|
||||||
//};
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
// Blinker //
|
|
||||||
////////////////////////////////
|
|
||||||
|
|
||||||
//class Blinker {
|
|
||||||
//
|
|
||||||
// timer_group_t group;
|
|
||||||
// timer_idx_t idx;
|
|
||||||
//
|
|
||||||
// Blinkable *led;
|
|
||||||
//
|
|
||||||
// int nBlinks;
|
|
||||||
// int onTime;
|
|
||||||
// int offTime;
|
|
||||||
// int delayTime;
|
|
||||||
// int count;
|
|
||||||
//
|
|
||||||
// unsigned long pauseDuration;
|
|
||||||
// unsigned long pauseTime;
|
|
||||||
// boolean isPaused=false;
|
|
||||||
//
|
|
||||||
// static void isrTimer(void *arg);
|
|
||||||
//
|
|
||||||
// public:
|
|
||||||
//
|
|
||||||
// Blinker(Blinkable *led, int timerNum=0, uint16_t autoOffDuration=0);
|
|
||||||
//
|
|
||||||
//// Creates a generic blinking LED on specified pin controlled
|
|
||||||
//// in background via interrupts generated by an ESP32 Alarm Timer.
|
|
||||||
////
|
|
||||||
//// In the first form, a Blinker is instantiated without specifying
|
|
||||||
//// the pin. In this case the pin must be specified in a subsequent call
|
|
||||||
//// to init() before the Blinker can be used.
|
|
||||||
////
|
|
||||||
//// In the second form, a Blinker is instantiated and initialized with
|
|
||||||
//// the specified pin, obviating the need for a separate call to init().
|
|
||||||
////
|
|
||||||
//// led: An initialized LED device that implements the Blinkable Interface
|
|
||||||
////
|
|
||||||
//// timerNum: ESP32 Alarm Timer to use.
|
|
||||||
//// For ESP32 and ESP32-S2: 0=Group0/Timer0, 1=Group0/Timer1, 2=Group1/Timer0, 3=Group1/Timer1
|
|
||||||
//// For ESP32-C3: 0=Group0/Timer0, 1=Group1/Timer0
|
|
||||||
////
|
|
||||||
//// autoOffDuration: If greater than zero, Blinker will automatically turn off after autoOffDuration (in seconds) has elapsed
|
|
||||||
//// Blinker will resume normal operation upon next call to start(), on(), or off()
|
|
||||||
//// Program must periodically call check() for auto-off functionality to work
|
|
||||||
//
|
|
||||||
// void start(int period, float dutyCycle=0.5);
|
|
||||||
//
|
|
||||||
//// Starts simple ON/OFF blinking.
|
|
||||||
////
|
|
||||||
//// period: ON/OFF blinking period, in milliseconds
|
|
||||||
//// dutyCycle: Fraction of period that LED is ON (default=50%)
|
|
||||||
//
|
|
||||||
// void start(int period, float dutyCycle, int nBlinks, int delayTime);
|
|
||||||
//
|
|
||||||
//// Starts ON/OFF blinking pattern.
|
|
||||||
////
|
|
||||||
//// period: ON/OFF blinking period, in milliseconds, used for blinking portion of pattern
|
|
||||||
//// dutyCycle: Fraction of period that LED is ON (default=50%)
|
|
||||||
//// nBlinks: Number of blinks in blinking portion of pattern
|
|
||||||
//// delayTime: delay, in milliseconds, during which LED is off before restarting blinking pattern
|
|
||||||
//
|
|
||||||
// void stop();
|
|
||||||
//
|
|
||||||
//// Stops current blinking pattern.
|
|
||||||
//
|
|
||||||
// void on();
|
|
||||||
//
|
|
||||||
//// Stops current blinking pattern and turns on LED
|
|
||||||
//
|
|
||||||
// void off();
|
|
||||||
//
|
|
||||||
//// Stops current blinking pattern and turns off LED
|
|
||||||
//
|
|
||||||
// void check();
|
|
||||||
//
|
|
||||||
//// Optional check to see if LED output should be paused (check is bypassed if pauseDuration=0)
|
|
||||||
//
|
|
||||||
// int getPin();
|
|
||||||
//
|
|
||||||
//// Returns pin number of connected LED
|
|
||||||
//
|
|
||||||
//};
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ void Blinker::start(int period, float dutyCycle, int nBlinks, int delayTime){
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
Serial.printf("Starting Blink Task\n");
|
Serial.printf("Starting Blink Task\n");
|
||||||
xTaskCreate( blinkTask, "BlinkTask", 1024, (void *)this, 0, &blinkHandle );
|
xTaskCreate( blinkTask, "BlinkTask", 1024, (void *)this, 2, &blinkHandle );
|
||||||
|
|
||||||
pauseTime=millis();
|
pauseTime=millis();
|
||||||
isPaused=false;
|
isPaused=false;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include "Pixel.h"
|
#include "Pixel.h"
|
||||||
|
|
||||||
//Blinker p(new LED(26));
|
//Blinker p(new LED(26));
|
||||||
Blinker p(new Pixel(27),20);
|
Blinker p(new Pixel(8));
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
#include "HomeSpan.h"
|
#include "HomeSpan.h"
|
||||||
#include "FeatherPins.h"
|
#include "FeatherPins.h"
|
||||||
#include "extras/Pixel.h"
|
#include "extras/Pixel.h"
|
||||||
#include "extras/Blinker.h"
|
|
||||||
|
|
||||||
#define STRING_t const char * // WORK-AROUND
|
#define STRING_t const char * // WORK-AROUND
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue