RE optional

This commit is contained in:
2025-05-01 20:31:31 +03:00
parent 65c07a1881
commit 575e05cd84
2 changed files with 27 additions and 6 deletions

View File

@@ -151,8 +151,9 @@ void Input::Parse(aJsonObject * configObj)
} }
void Input::stop() void Input::stop()
{ {
if (!inputObj || !root || inputObj->type != aJson_Object) return;
#ifdef ROTARYENCODER
aJsonObject *itemBuffer; aJsonObject *itemBuffer;
if (!inputObj || !root || inputObj->type != aJson_Object) return;
itemBuffer = aJson.getObjectItem(inputObj, "#"); itemBuffer = aJson.getObjectItem(inputObj, "#");
if (inType == IN_RE && itemBuffer && itemBuffer->valuestring && itemBuffer->type == aJson_Array) if (inType == IN_RE && itemBuffer && itemBuffer->valuestring && itemBuffer->type == aJson_Array)
{ {
@@ -160,6 +161,7 @@ if (inType == IN_RE && itemBuffer && itemBuffer->valuestring && itemBuffer->type
itemBuffer->valuestring = NULL; itemBuffer->valuestring = NULL;
debugSerial<<F("RE: deleted")<<endl; debugSerial<<F("RE: deleted")<<endl;
} }
#endif
} }
void cleanStore(aJsonObject * input) void cleanStore(aJsonObject * input)
@@ -192,6 +194,7 @@ if (input && (input->type == aJson_Object)) {
void Input::setupRotaryEncoder() void Input::setupRotaryEncoder()
{ {
#ifdef ROTARYENCODER
aJsonObject *itemBuffer; aJsonObject *itemBuffer;
if (!inputObj || !root || inputObj->type != aJson_Object) return; if (!inputObj || !root || inputObj->type != aJson_Object) return;
itemBuffer = aJson.getObjectItem(inputObj, "#"); itemBuffer = aJson.getObjectItem(inputObj, "#");
@@ -206,6 +209,7 @@ if (itemBuffer && !itemBuffer->valuestring && itemBuffer->type == aJson_Array)
debugSerial<<F("RE: configured on pins ")<<pin1<<","<<pin2<< F(" Mode:")<<mode <<endl; debugSerial<<F("RE: configured on pins ")<<pin1<<","<<pin2<< F(" Mode:")<<mode <<endl;
} }
} }
#endif
} }
void Input::setup() void Input::setup()
@@ -315,6 +319,7 @@ switch (cause) {
case IN_CCS811: case IN_CCS811:
case IN_HDC1080: case IN_HDC1080:
break; break;
#ifdef ROTARYENCODER
case IN_RE: case IN_RE:
itemBuffer = aJson.getObjectItem(inputObj, "#"); itemBuffer = aJson.getObjectItem(inputObj, "#");
if (inputObj && inputObj->type == aJson_Object && itemBuffer && itemBuffer->type == aJson_Array && itemBuffer->valuestring) if (inputObj && inputObj->type == aJson_Object && itemBuffer && itemBuffer->type == aJson_Array && itemBuffer->valuestring)
@@ -322,8 +327,10 @@ switch (cause) {
((RotaryEncoder *) itemBuffer->valuestring) ->tick(); ((RotaryEncoder *) itemBuffer->valuestring) ->tick();
contactPoll(cause, ((RotaryEncoder *) itemBuffer->valuestring)); contactPoll(cause, ((RotaryEncoder *) itemBuffer->valuestring));
} }
#endif
} }
break; break;
#ifdef ULTRASONIC
case CHECK_ULTRASONIC: case CHECK_ULTRASONIC:
switch (inType) switch (inType)
{ {
@@ -332,6 +339,7 @@ switch (cause) {
contactPoll(cause); contactPoll(cause);
} }
break; break;
#endif
case CHECK_SENSOR: //Slow polling case CHECK_SENSOR: //Slow polling
switch (inType) switch (inType)
{ {
@@ -811,8 +819,14 @@ if (newState!=store->state && cause!=CHECK_INTERRUPT) debugSerial<<F("#")<<pin<<
} }
static volatile uint8_t contactPollBusy = 0; static volatile uint8_t contactPollBusy = 0;
#ifdef ROTARYENCODER
void Input::contactPoll(short cause, RotaryEncoder * re)
#else
void Input::contactPoll(short cause)
#endif
void Input::contactPoll(short cause, RotaryEncoder * re) {
{
bool currentInputState; bool currentInputState;
if (!store /*|| contactPollBusy*/) return; if (!store /*|| contactPollBusy*/) return;
@@ -931,7 +945,7 @@ switch (store->state) //Timer based transitions
if (isTimeOver(store->timestamp16,millis() & 0xFFFF,T_IDLE,0xFFFF)) changeState(IS_IDLE, cause,currentInputObject); if (isTimeOver(store->timestamp16,millis() & 0xFFFF,T_IDLE,0xFFFF)) changeState(IS_IDLE, cause,currentInputObject);
break; break;
} //switch } //switch
#ifdef ROTARYENCODER
if (re) if (re)
{ {
aJsonObject * bufferItem; aJsonObject * bufferItem;
@@ -946,7 +960,7 @@ if (re)
if (bufferItem=aJson.getObjectItem(currentInputObject, "-")) {checkInstructions(bufferItem);executeCommand(bufferItem,0);}; if (bufferItem=aJson.getObjectItem(currentInputObject, "-")) {checkInstructions(bufferItem);executeCommand(bufferItem,0);};
} }
} }
#endif
} //if not INTERRUPT } //if not INTERRUPT
if (currentInputState != store->lastValue) // value changed if (currentInputState != store->lastValue) // value changed
{ {

View File

@@ -21,7 +21,9 @@ e-mail anklimov@gmail.com
#include <aJSON.h> #include <aJSON.h>
#include "modules/in_ccs811_hdc1080.h" #include "modules/in_ccs811_hdc1080.h"
#include "itemCmd.h" #include "itemCmd.h"
#ifdef ROTARYENCODER
#include "RotaryEncoder.h" #include "RotaryEncoder.h"
#endif
#define IN_ACTIVE_HIGH 2 // High level = PUSHED/ CLOSED/ ON othervise :Low Level. Use INPUT mode instead of INPUT_PULLUP for digital pin #define IN_ACTIVE_HIGH 2 // High level = PUSHED/ CLOSED/ ON othervise :Low Level. Use INPUT mode instead of INPUT_PULLUP for digital pin
#define IN_ANALOG 64 // Analog input #define IN_ANALOG 64 // Analog input
@@ -165,7 +167,12 @@ public:
protected: protected:
void Parse(aJsonObject * configObj = NULL); void Parse(aJsonObject * configObj = NULL);
#ifdef ROTARYENCODER
void contactPoll(short cause, RotaryEncoder * re = NULL); void contactPoll(short cause, RotaryEncoder * re = NULL);
#else
void contactPoll(short cause);
#endif
void analogPoll(short cause); void analogPoll(short cause);
void dht22Poll(); void dht22Poll();