mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-25 11:46:31 +00:00
Added encoder support in scripter (#23706)
Co-authored-by: a.spirenkov@vk.team <a.spirenkov@vk.team>
This commit is contained in:
parent
fee8198e64
commit
aa7d74dec0
@ -70,6 +70,7 @@ struct tEncoder {
|
|||||||
volatile int8_t pinb;
|
volatile int8_t pinb;
|
||||||
uint8_t timeout = 0; // Disallow direction change within 0.5 second
|
uint8_t timeout = 0; // Disallow direction change within 0.5 second
|
||||||
int8_t abs_position[2] = { 0 };
|
int8_t abs_position[2] = { 0 };
|
||||||
|
int8_t rel_position = 0; // Relative position for scripter. Cleared after being read.
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
};
|
};
|
||||||
tEncoder Encoder[MAX_ROTARIES];
|
tEncoder Encoder[MAX_ROTARIES];
|
||||||
@ -260,6 +261,14 @@ void RotaryHandler(void) {
|
|||||||
if (Encoder[index].abs_position[button_pressed] > Settings->param[P_ROTARY_MAX_STEP]) { // SetOption43 - Rotary steps
|
if (Encoder[index].abs_position[button_pressed] > Settings->param[P_ROTARY_MAX_STEP]) { // SetOption43 - Rotary steps
|
||||||
Encoder[index].abs_position[button_pressed] = Settings->param[P_ROTARY_MAX_STEP]; // SetOption43 - Rotary steps
|
Encoder[index].abs_position[button_pressed] = Settings->param[P_ROTARY_MAX_STEP]; // SetOption43 - Rotary steps
|
||||||
}
|
}
|
||||||
|
Encoder[index].rel_position += rotary_position;
|
||||||
|
if (Encoder[index].rel_position > Settings->param[P_ROTARY_MAX_STEP]) {
|
||||||
|
Encoder[index].rel_position = Settings->param[P_ROTARY_MAX_STEP];
|
||||||
|
}
|
||||||
|
if (Encoder[index].rel_position < -(Settings->param[P_ROTARY_MAX_STEP])) {
|
||||||
|
Encoder[index].rel_position = -(Settings->param[P_ROTARY_MAX_STEP]);
|
||||||
|
}
|
||||||
|
|
||||||
Response_P(PSTR("{\"Rotary%d\":{\"Pos1\":%d,\"Pos2\":%d}}"), index +1, Encoder[index].abs_position[0], Encoder[index].abs_position[1]);
|
Response_P(PSTR("{\"Rotary%d\":{\"Pos1\":%d,\"Pos2\":%d}}"), index +1, Encoder[index].abs_position[0], Encoder[index].abs_position[1]);
|
||||||
XdrvRulesProcess(0);
|
XdrvRulesProcess(0);
|
||||||
#ifdef USE_LIGHT
|
#ifdef USE_LIGHT
|
||||||
|
@ -3742,6 +3742,25 @@ _Pragma("GCC warning \"'EXT 1 wakeup' not supported using gpio mode\"")
|
|||||||
tind->index = SCRIPT_EVENT_HANDLED;
|
tind->index = SCRIPT_EVENT_HANDLED;
|
||||||
goto exit_settable;
|
goto exit_settable;
|
||||||
}
|
}
|
||||||
|
#ifdef ROTARY_V1
|
||||||
|
if (!strncmp_XP(lp, XPSTR("encabs["), 7)) { // Absolute encoder value
|
||||||
|
GetNumericArgument(lp + 7, OPER_EQU, &fvar, gv);
|
||||||
|
uint8_t index = fvar;
|
||||||
|
if (index < 1 || index > MAX_ROTARIES) index = 1;
|
||||||
|
fvar = Encoder[index - 1].abs_position[0];
|
||||||
|
len += 1;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if (!strncmp_XP(lp, XPSTR("encrel["), 7)) { // Relative encoder value (will be reset after reading)
|
||||||
|
GetNumericArgument(lp + 7, OPER_EQU, &fvar, gv);
|
||||||
|
uint8_t index = fvar;
|
||||||
|
if (index < 1 || index > MAX_ROTARIES) index = 1;
|
||||||
|
fvar = Encoder[index - 1].rel_position;
|
||||||
|
Encoder[index - 1].rel_position = 0;
|
||||||
|
len += 1;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef USE_ENERGY_SENSOR
|
#ifdef USE_ENERGY_SENSOR
|
||||||
if (!strncmp_XP(lp, XPSTR("enrg["), 5)) {
|
if (!strncmp_XP(lp, XPSTR("enrg["), 5)) {
|
||||||
lp = GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv);
|
lp = GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user