starting async implementation
This commit is contained in:
parent
d6057525f7
commit
59a5fd0770
33
src/Controls.cpp
Normal file
33
src/Controls.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include "Controls.h"
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t controlPins[] = {
|
||||||
|
PIN_A,
|
||||||
|
PIN_B,
|
||||||
|
PIN_KEY,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void Controls_setup(){
|
||||||
|
pinMode(PIN_A, INPUT_PULLDOWN);
|
||||||
|
pinMode(PIN_B, INPUT_PULLDOWN);
|
||||||
|
pinMode(PIN_KEY, INPUT_PULLDOWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t prevState[3];
|
||||||
|
|
||||||
|
void Controls_loop(){
|
||||||
|
for(uint8_t a=0; a<sizeof(controlPins); a++){
|
||||||
|
auto pin = controlPins[a];
|
||||||
|
auto currentValue = analogRead(pin);
|
||||||
|
auto prevValue = prevState[a];
|
||||||
|
|
||||||
|
Serial.printf("Pin %d: %d->%d\n", pin, prevValue, currentValue);
|
||||||
|
|
||||||
|
if(abs(currentValue - prevValue) > 100){
|
||||||
|
Serial.println("Changed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
prevState[a] = currentValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/Controls.h
Normal file
11
src/Controls.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#define PIN_A 2
|
||||||
|
#define PIN_B 3
|
||||||
|
#define PIN_KEY 4
|
||||||
|
|
||||||
|
|
||||||
|
void Controls_setup();
|
||||||
|
void Controls_loop();
|
||||||
@ -9,10 +9,12 @@
|
|||||||
#define _TASK_STATUS_REQUEST // Compile with support for StatusRequest functionality - triggering tasks on status change events in addition to time only
|
#define _TASK_STATUS_REQUEST // Compile with support for StatusRequest functionality - triggering tasks on status change events in addition to time only
|
||||||
|
|
||||||
// #define ENABLE_MQTT
|
// #define ENABLE_MQTT
|
||||||
#define ENABLE_WIFI
|
// #define ENABLE_WIFI
|
||||||
// #define ENABLE_FS
|
// #define ENABLE_FS
|
||||||
// #define ENABLE_PINFINDER
|
// #define ENABLE_PINFINDER
|
||||||
#define ENABLE_COLORS
|
#define ENABLE_COLORS
|
||||||
|
// #define ENABLE_PIN_SENSING
|
||||||
|
#define ENABLE_CONTROLS
|
||||||
|
|
||||||
// #include <TaskScheduler.h>
|
// #include <TaskScheduler.h>
|
||||||
|
|
||||||
@ -33,6 +35,10 @@
|
|||||||
#include "PinFinder.h"
|
#include "PinFinder.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ENABLE_CONTROLS
|
||||||
|
#include "Controls.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef ENABLE_COLORS
|
#ifdef ENABLE_COLORS
|
||||||
CRGB colorTable[] = {
|
CRGB colorTable[] = {
|
||||||
@ -88,22 +94,57 @@ CRGB colorTable[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
uint8_t colorIndex = 0;
|
uint8_t colorIndex = 0;
|
||||||
void colors(){
|
void colors(void *pvParameters){
|
||||||
colorIndex++;
|
while(true){
|
||||||
if(colorIndex >= (sizeof(colorTable) / sizeof(CRGB))){
|
colorIndex++;
|
||||||
colorIndex = 0;
|
if(colorIndex >= (sizeof(colorTable) / sizeof(CRGB))){
|
||||||
|
colorIndex = 0;
|
||||||
|
}
|
||||||
|
Serial.printf("colorIndex: %d\n", colorIndex);
|
||||||
|
jumpTo(colorTable[colorIndex]);
|
||||||
|
|
||||||
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
Serial.printf("colorIndex: %d\n", colorIndex);
|
|
||||||
jumpTo(colorTable[colorIndex]);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ENABLE_PIN_SENSING
|
||||||
|
gpio_num_t sensePins[] = {
|
||||||
|
(gpio_num_t) 0,
|
||||||
|
(gpio_num_t) 1,
|
||||||
|
(gpio_num_t) 2,
|
||||||
|
(gpio_num_t) 3,
|
||||||
|
(gpio_num_t) 4,
|
||||||
|
(gpio_num_t) 5,
|
||||||
|
(gpio_num_t) 6,
|
||||||
|
(gpio_num_t) 7,
|
||||||
|
(gpio_num_t) 8,
|
||||||
|
(gpio_num_t) 9,
|
||||||
|
(gpio_num_t) 10,
|
||||||
|
(gpio_num_t) 20,
|
||||||
|
(gpio_num_t) 21,
|
||||||
|
};
|
||||||
|
|
||||||
|
long prevStates[sizeof(sensePins)];
|
||||||
|
#endif
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
delay(500);
|
delay(1500);
|
||||||
|
|
||||||
|
#ifdef ENABLE_PIN_SENSING
|
||||||
|
for(int i=0; i<sizeof(sensePins)/sizeof(gpio_num_t); i++){
|
||||||
|
auto pin = sensePins[i];
|
||||||
|
Serial.printf("Setting pin %d to input\n", pin);
|
||||||
|
// gpio_reset_pin(pin);
|
||||||
|
pinMode(pin, INPUT);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_FS
|
#ifdef ENABLE_FS
|
||||||
if(!LittleFS.begin()){
|
if(!LittleFS.begin()){
|
||||||
@ -124,6 +165,10 @@ void setup() {
|
|||||||
PinFinder_setup();
|
PinFinder_setup();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ENABLE_CONTROLS
|
||||||
|
Controls_setup();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_LED
|
#ifdef INCLUDE_LED
|
||||||
Led_setup();
|
Led_setup();
|
||||||
|
|
||||||
@ -151,10 +196,19 @@ void setup() {
|
|||||||
jumpTo(CRGB(0x00FFFF));
|
jumpTo(CRGB(0x00FFFF));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ENABLE_COLORS
|
||||||
|
TaskHandle_t taskColors = NULL;
|
||||||
|
|
||||||
|
// Create the task, storing the handle.
|
||||||
|
xTaskCreate(colors, "NAME", 1000, NULL, tskIDLE_PRIORITY, &taskColors);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vTaskStartScheduler();
|
||||||
// ESP.wdtEnable(10000);
|
// ESP.wdtEnable(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
#ifdef ENABLE_MQTT
|
#ifdef ENABLE_MQTT
|
||||||
@ -169,13 +223,36 @@ void loop() {
|
|||||||
PinFinder_loop();
|
PinFinder_loop();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_COLORS
|
#ifdef ENABLE_CONTROLS
|
||||||
colors();
|
Controls_loop();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ENABLE_PIN_SENSING
|
||||||
|
for(int i=0; i<sizeof(sensePins)/sizeof(gpio_num_t); i++){
|
||||||
|
auto pin = sensePins[i];
|
||||||
|
pinMode(pin, INPUT);
|
||||||
|
auto currentState = analogRead(pin);
|
||||||
|
long diff = currentState - prevStates[i];
|
||||||
|
// if(abs(diff) > 10){
|
||||||
|
Serial.printf("pin#%02d %d->%d\n", pin, prevStates[i], currentState);
|
||||||
|
// }
|
||||||
|
prevStates[i] = currentState;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(int i=0; i<sizeof(sensePins)/sizeof(gpio_num_t); i++){
|
||||||
|
break;
|
||||||
|
auto pin = sensePins[i];
|
||||||
|
pinMode(pin, OUTPUT);
|
||||||
|
digitalWrite(pin, HIGH);
|
||||||
|
Serial.printf("pin#%02d HIGH\n", pin);
|
||||||
|
delay(1000);
|
||||||
|
digitalWrite(pin, LOW);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
|
|
||||||
// Led_loop();
|
// Led_loop();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user