mirror of https://github.com/arendst/Tasmota.git
Refactor command SetOption
This commit is contained in:
parent
8b9d157e61
commit
23cef04b9e
|
@ -632,25 +632,52 @@ void CmndSetoption(void)
|
||||||
uint32_t ptype;
|
uint32_t ptype;
|
||||||
uint32_t pindex;
|
uint32_t pindex;
|
||||||
if (XdrvMailbox.index <= 31) { // SetOption0 .. 31 = Settings.flag
|
if (XdrvMailbox.index <= 31) { // SetOption0 .. 31 = Settings.flag
|
||||||
ptype = 0;
|
ptype = 2;
|
||||||
pindex = XdrvMailbox.index; // 0 .. 31
|
pindex = XdrvMailbox.index; // 0 .. 31
|
||||||
}
|
}
|
||||||
else if (XdrvMailbox.index <= 49) { // SetOption32 .. 49 = Settings.param
|
else if (XdrvMailbox.index <= 49) { // SetOption32 .. 49 = Settings.param
|
||||||
ptype = 2;
|
ptype = 1;
|
||||||
pindex = XdrvMailbox.index -32; // 0 .. 17 (= PARAM8_SIZE -1)
|
pindex = XdrvMailbox.index -32; // 0 .. 17 (= PARAM8_SIZE -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (XdrvMailbox.index <= 81) { // SetOption50 .. 81 = Settings.flag3
|
else if (XdrvMailbox.index <= 81) { // SetOption50 .. 81 = Settings.flag3
|
||||||
ptype = 1;
|
ptype = 3;
|
||||||
pindex = XdrvMailbox.index -50; // 0 .. 31
|
pindex = XdrvMailbox.index -50; // 0 .. 31
|
||||||
}
|
}
|
||||||
else { // SetOption82 .. 113 = Settings.flag4
|
else { // SetOption82 .. 113 = Settings.flag4
|
||||||
ptype = 3;
|
ptype = 4;
|
||||||
pindex = XdrvMailbox.index -82; // 0 .. 31
|
pindex = XdrvMailbox.index -82; // 0 .. 31
|
||||||
}
|
}
|
||||||
|
|
||||||
if (XdrvMailbox.payload >= 0) {
|
if (XdrvMailbox.payload >= 0) {
|
||||||
if (0 == ptype) { // SetOption0 .. 31
|
if (1 == ptype) { // SetOption32 .. 49
|
||||||
|
uint32_t param_low = 0;
|
||||||
|
uint32_t param_high = 255;
|
||||||
|
switch (pindex) {
|
||||||
|
case P_HOLD_TIME:
|
||||||
|
case P_MAX_POWER_RETRY:
|
||||||
|
param_low = 1;
|
||||||
|
param_high = 250;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((XdrvMailbox.payload >= param_low) && (XdrvMailbox.payload <= param_high)) {
|
||||||
|
Settings.param[pindex] = XdrvMailbox.payload;
|
||||||
|
#ifdef USE_LIGHT
|
||||||
|
if (P_RGB_REMAP == pindex) {
|
||||||
|
LightUpdateColorMapping();
|
||||||
|
restart_flag = 2; // SetOption37 needs a reboot in most cases
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if (defined(USE_IR_REMOTE) && defined(USE_IR_RECEIVE)) || defined(USE_IR_REMOTE_FULL)
|
||||||
|
if (P_IR_UNKNOW_THRESHOLD == pindex) {
|
||||||
|
IrReceiveUpdateThreshold();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
ptype = 99; // Command Error
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (XdrvMailbox.payload <= 1) {
|
if (XdrvMailbox.payload <= 1) {
|
||||||
|
if (2 == ptype) { // SetOption0 .. 31
|
||||||
switch (pindex) {
|
switch (pindex) {
|
||||||
case 5: // mqtt_power_retain (CMND_POWERRETAIN)
|
case 5: // mqtt_power_retain (CMND_POWERRETAIN)
|
||||||
case 6: // mqtt_button_retain (CMND_BUTTONRETAIN)
|
case 6: // mqtt_button_retain (CMND_BUTTONRETAIN)
|
||||||
|
@ -679,65 +706,40 @@ void CmndSetoption(void)
|
||||||
}
|
}
|
||||||
#endif // USE_HOME_ASSISTANT
|
#endif // USE_HOME_ASSISTANT
|
||||||
}
|
}
|
||||||
}
|
else if (3 == ptype) { // SetOption50 .. 81
|
||||||
else if (1 == ptype) { // SetOption50 .. 81
|
|
||||||
if (XdrvMailbox.payload <= 1) {
|
|
||||||
bitWrite(Settings.flag3.data, pindex, XdrvMailbox.payload);
|
bitWrite(Settings.flag3.data, pindex, XdrvMailbox.payload);
|
||||||
if (5 == pindex) { // SetOption55
|
switch (pindex) {
|
||||||
|
case 5: // SetOption55
|
||||||
if (0 == XdrvMailbox.payload) {
|
if (0 == XdrvMailbox.payload) {
|
||||||
restart_flag = 2; // Disable mDNS needs restart
|
restart_flag = 2; // Disable mDNS needs restart
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if (10 == pindex) { // SetOption60 enable or disable traditional sleep
|
case 10: // SetOption60 enable or disable traditional sleep
|
||||||
WiFiSetSleepMode(); // Update WiFi sleep mode accordingly
|
WiFiSetSleepMode(); // Update WiFi sleep mode accordingly
|
||||||
}
|
break;
|
||||||
if (18 == pindex) { // SetOption68 for multi-channel PWM, requires a reboot
|
case 18: // SetOption68 for multi-channel PWM, requires a reboot
|
||||||
restart_flag = 2;
|
restart_flag = 2;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (4 == ptype) { // SetOption82 .. 113
|
||||||
else if (3 == ptype) { // SetOption82 .. 113
|
|
||||||
if (XdrvMailbox.payload <= 1) {
|
|
||||||
bitWrite(Settings.flag4.data, pindex, XdrvMailbox.payload);
|
bitWrite(Settings.flag4.data, pindex, XdrvMailbox.payload);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else { // SetOption32 .. 49
|
ptype = 99; // Command Error
|
||||||
uint32_t param_low = 0;
|
|
||||||
uint32_t param_high = 255;
|
|
||||||
switch (pindex) {
|
|
||||||
case P_HOLD_TIME:
|
|
||||||
case P_MAX_POWER_RETRY:
|
|
||||||
param_low = 1;
|
|
||||||
param_high = 250;
|
|
||||||
break;
|
|
||||||
case P_RGB_REMAP:
|
|
||||||
restart_flag = 2; // SetOption37 needs a reboot in most cases
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ((XdrvMailbox.payload >= param_low) && (XdrvMailbox.payload <= param_high)) {
|
|
||||||
Settings.param[pindex] = XdrvMailbox.payload;
|
|
||||||
#ifdef USE_LIGHT
|
|
||||||
if (P_RGB_REMAP == pindex) {
|
|
||||||
LightUpdateColorMapping();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if (defined(USE_IR_REMOTE) && defined(USE_IR_RECEIVE)) || defined(USE_IR_REMOTE_FULL)
|
|
||||||
if (P_IR_UNKNOW_THRESHOLD == pindex) {
|
|
||||||
IrReceiveUpdateThreshold();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ptype < 99) {
|
if (ptype < 99) {
|
||||||
if (2 == ptype) {
|
if (1 == ptype) {
|
||||||
ResponseCmndIdxNumber(Settings.param[pindex]);
|
ResponseCmndIdxNumber(Settings.param[pindex]);
|
||||||
} else {
|
} else {
|
||||||
uint32_t flag = Settings.flag.data;
|
uint32_t flag = Settings.flag.data;
|
||||||
if (1 == ptype) {
|
if (3 == ptype) {
|
||||||
flag = Settings.flag3.data;
|
flag = Settings.flag3.data;
|
||||||
}
|
}
|
||||||
else if (3 == ptype) {
|
else if (4 == ptype) {
|
||||||
flag = Settings.flag4.data;
|
flag = Settings.flag4.data;
|
||||||
}
|
}
|
||||||
ResponseCmndIdxChar(GetStateText(bitRead(flag, pindex)));
|
ResponseCmndIdxChar(GetStateText(bitRead(flag, pindex)));
|
||||||
|
|
Loading…
Reference in New Issue