mirror of https://github.com/arendst/Tasmota.git
parent
15d475c3e6
commit
5e1cbcf94f
|
@ -874,35 +874,40 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
|
||||||
}
|
}
|
||||||
else if (CMND_MODULE == command_code) {
|
else if (CMND_MODULE == command_code) {
|
||||||
if ((payload >= 0) && (payload <= MAXMODULE)) {
|
if ((payload >= 0) && (payload <= MAXMODULE)) {
|
||||||
if (0 == payload) { payload = 256; }
|
bool present = false;
|
||||||
payload--;
|
if (0 == payload) {
|
||||||
Settings.last_module = Settings.module;
|
payload = 255;
|
||||||
Settings.module = payload;
|
present = true;
|
||||||
SetModuleType();
|
} else {
|
||||||
if (Settings.last_module != payload) {
|
payload--;
|
||||||
for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
|
present = ValidModule(payload);
|
||||||
Settings.my_gp.io[i] = GPIO_NONE;
|
}
|
||||||
}
|
if (present) {
|
||||||
|
Settings.last_module = Settings.module;
|
||||||
|
Settings.module = payload;
|
||||||
|
SetModuleType();
|
||||||
|
if (Settings.last_module != payload) {
|
||||||
|
for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) {
|
||||||
|
Settings.my_gp.io[i] = GPIO_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
restart_flag = 2;
|
||||||
}
|
}
|
||||||
restart_flag = 2;
|
|
||||||
}
|
}
|
||||||
Response_P(S_JSON_COMMAND_NVALUE_SVALUE, command, ModuleNr(), ModuleName().c_str());
|
Response_P(S_JSON_COMMAND_NVALUE_SVALUE, command, ModuleNr(), ModuleName().c_str());
|
||||||
}
|
}
|
||||||
else if (CMND_MODULES == command_code) {
|
else if (CMND_MODULES == command_code) {
|
||||||
for (uint8_t i = 0; i <= MAXMODULE; i++) {
|
uint8_t midx = USER_MODULE;
|
||||||
|
for (uint8_t i = 0; i <= sizeof(kModuleNiceList); i++) {
|
||||||
|
if (i > 0) { midx = pgm_read_byte(kModuleNiceList + i -1); }
|
||||||
if (!jsflg) {
|
if (!jsflg) {
|
||||||
Response_P(PSTR("{\"" D_CMND_MODULES "%d\":["), lines);
|
Response_P(PSTR("{\"" D_CMND_MODULES "%d\":["), lines);
|
||||||
} else {
|
} else {
|
||||||
ResponseAppend_P(PSTR(","));
|
ResponseAppend_P(PSTR(","));
|
||||||
}
|
}
|
||||||
jsflg = true;
|
jsflg = true;
|
||||||
uint8_t j = i;
|
uint8_t j = i ? midx +1 : 0;
|
||||||
if (0 == i) { j = USER_MODULE; } else { j--; }
|
if ((ResponseAppend_P(PSTR("\"%d (%s)\""), j, AnyModuleName(midx).c_str()) > (LOGSZ - TOPSZ)) || (i == sizeof(kModuleNiceList))) {
|
||||||
|
|
||||||
// ResponseAppend_P(PSTR("\"%d (%s)\""), i, AnyModuleName(j).c_str());
|
|
||||||
// if ((strlen(mqtt_data) > (LOGSZ - TOPSZ)) || (i == MAXMODULE)) {
|
|
||||||
|
|
||||||
if ((ResponseAppend_P(PSTR("\"%d (%s)\""), i, AnyModuleName(j).c_str()) > (LOGSZ - TOPSZ)) || (i == MAXMODULE)) {
|
|
||||||
ResponseAppend_P(PSTR("]}"));
|
ResponseAppend_P(PSTR("]}"));
|
||||||
MqttPublishPrefixTopic_P(RESULT_OR_STAT, type);
|
MqttPublishPrefixTopic_P(RESULT_OR_STAT, type);
|
||||||
jsflg = false;
|
jsflg = false;
|
||||||
|
@ -957,10 +962,6 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
|
||||||
ResponseAppend_P(PSTR(","));
|
ResponseAppend_P(PSTR(","));
|
||||||
}
|
}
|
||||||
jsflg = true;
|
jsflg = true;
|
||||||
|
|
||||||
// ResponseAppend_P(PSTR("\"%d (%s)\""), midx, GetTextIndexed(stemp1, sizeof(stemp1), midx, kSensorNames));
|
|
||||||
// if ((strlen(mqtt_data) > (LOGSZ - TOPSZ)) || (i == sizeof(kGpioNiceList) -1)) {
|
|
||||||
|
|
||||||
if ((ResponseAppend_P(PSTR("\"%d (%s)\""), midx, GetTextIndexed(stemp1, sizeof(stemp1), midx, kSensorNames)) > (LOGSZ - TOPSZ)) || (i == sizeof(kGpioNiceList) -1)) {
|
if ((ResponseAppend_P(PSTR("\"%d (%s)\""), midx, GetTextIndexed(stemp1, sizeof(stemp1), midx, kSensorNames)) > (LOGSZ - TOPSZ)) || (i == sizeof(kGpioNiceList) -1)) {
|
||||||
ResponseAppend_P(PSTR("]}"));
|
ResponseAppend_P(PSTR("]}"));
|
||||||
MqttPublishPrefixTopic_P(RESULT_OR_STAT, type);
|
MqttPublishPrefixTopic_P(RESULT_OR_STAT, type);
|
||||||
|
@ -2324,9 +2325,11 @@ void GpioInit(void)
|
||||||
{
|
{
|
||||||
uint8_t mpin;
|
uint8_t mpin;
|
||||||
|
|
||||||
if ((Settings.module >= MAXMODULE) && (Settings.module < USER_MODULE)) {
|
if (!ValidModule(Settings.module)) {
|
||||||
Settings.module = MODULE;
|
uint8_t module = MODULE;
|
||||||
Settings.last_module = MODULE;
|
if (!ValidModule(MODULE)) { module = SONOFF_BASIC; }
|
||||||
|
Settings.module = module;
|
||||||
|
Settings.last_module = module;
|
||||||
}
|
}
|
||||||
SetModuleType();
|
SetModuleType();
|
||||||
|
|
||||||
|
|
|
@ -596,7 +596,7 @@ const uint8_t kGpioNiceList[] PROGMEM = {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = {
|
const uint8_t kModuleNiceList[] PROGMEM = {
|
||||||
SONOFF_BASIC, // Sonoff Relay Devices
|
SONOFF_BASIC, // Sonoff Relay Devices
|
||||||
SONOFF_RF,
|
SONOFF_RF,
|
||||||
SONOFF_TH,
|
SONOFF_TH,
|
||||||
|
|
|
@ -846,6 +846,16 @@ uint8_t ModuleNr()
|
||||||
return (USER_MODULE == Settings.module) ? 0 : Settings.module +1;
|
return (USER_MODULE == Settings.module) ? 0 : Settings.module +1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ValidModule(uint8_t index)
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0; i < sizeof(kModuleNiceList); i++) {
|
||||||
|
if (index == pgm_read_byte(kModuleNiceList + i)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
String AnyModuleName(uint8_t index)
|
String AnyModuleName(uint8_t index)
|
||||||
{
|
{
|
||||||
if (USER_MODULE == index) {
|
if (USER_MODULE == index) {
|
||||||
|
|
|
@ -1038,7 +1038,7 @@ void HandleTemplateConfiguration(void)
|
||||||
|
|
||||||
if (WebServer->hasArg("m")) {
|
if (WebServer->hasArg("m")) {
|
||||||
WSContentBegin(200, CT_PLAIN);
|
WSContentBegin(200, CT_PLAIN);
|
||||||
for (uint8_t i = 0; i < MAXMODULE; i++) { // "}2'%d'>%s (%d)}3" - "}2'0'>Sonoff Basic (1)}3"
|
for (uint8_t i = 0; i < sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'0'>Sonoff Basic (1)}3"
|
||||||
uint8_t midx = pgm_read_byte(kModuleNiceList + i);
|
uint8_t midx = pgm_read_byte(kModuleNiceList + i);
|
||||||
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, AnyModuleName(midx).c_str(), midx +1);
|
WSContentSend_P(HTTP_MODULE_TEMPLATE_REPLACE, midx, AnyModuleName(midx).c_str(), midx +1);
|
||||||
}
|
}
|
||||||
|
@ -1159,7 +1159,7 @@ void HandleModuleConfiguration(void)
|
||||||
if (WebServer->hasArg("m")) {
|
if (WebServer->hasArg("m")) {
|
||||||
WSContentBegin(200, CT_PLAIN);
|
WSContentBegin(200, CT_PLAIN);
|
||||||
uint8_t vidx = 0;
|
uint8_t vidx = 0;
|
||||||
for (uint8_t i = 0; i <= MAXMODULE; i++) { // "}2'%d'>%s (%d)}3" - "}2'255'>UserTemplate (0)}3" - "}2'0'>Sonoff Basic (1)}3"
|
for (uint8_t i = 0; i <= sizeof(kModuleNiceList); i++) { // "}2'%d'>%s (%d)}3" - "}2'255'>UserTemplate (0)}3" - "}2'0'>Sonoff Basic (1)}3"
|
||||||
if (0 == i) {
|
if (0 == i) {
|
||||||
midx = USER_MODULE;
|
midx = USER_MODULE;
|
||||||
vidx = 0;
|
vidx = 0;
|
||||||
|
|
Loading…
Reference in New Issue