mirror of https://github.com/arendst/Tasmota.git
Add support for user defined GUI button text
Add commands ``WebButton1`` until ``WebButton16`` to support user defined GUI button text (#7166)
This commit is contained in:
parent
5b9ab0a60f
commit
b66cc3479f
|
@ -56,6 +56,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
|
||||||
- Change Smoother ``Fade`` using 100Hz instead of 20Hz animation (#7179)
|
- Change Smoother ``Fade`` using 100Hz instead of 20Hz animation (#7179)
|
||||||
- Change number of rule ``Var``s and ``Mem``s from 5 to 16 (#4933)
|
- Change number of rule ``Var``s and ``Mem``s from 5 to 16 (#4933)
|
||||||
- Change number of ``FriendlyName``s from 4 to 8
|
- Change number of ``FriendlyName``s from 4 to 8
|
||||||
|
- Add commands ``WebButton1`` until ``WebButton16`` to support user defined GUI button text (#7166)
|
||||||
- Add support for max 150 characters in most command parameter strings (#3686, #4754)
|
- Add support for max 150 characters in most command parameter strings (#3686, #4754)
|
||||||
- Add support for GPS as NTP server by Christian Baars and Adrian Scillato
|
- Add support for GPS as NTP server by Christian Baars and Adrian Scillato
|
||||||
- Add support for ``AdcParam`` parameters to control ADC0 Moisture formula by Federico Leoni (#7309)
|
- Add support for ``AdcParam`` parameters to control ADC0 Moisture formula by Federico Leoni (#7309)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
- Change number of ``FriendlyName``s from 4 to 8
|
- Change number of ``FriendlyName``s from 4 to 8
|
||||||
- Add Zigbee better support for Xiaomi Double Switch and Xiaomi Vibration sensor
|
- Add Zigbee better support for Xiaomi Double Switch and Xiaomi Vibration sensor
|
||||||
- Add support for ``AdcParam`` parameters to control ADC0 Moisture formula by Federico Leoni (#7309)
|
- Add support for ``AdcParam`` parameters to control ADC0 Moisture formula by Federico Leoni (#7309)
|
||||||
|
- Add commands ``WebButton1`` until ``WebButton16`` to support user defined GUI button text (#7166)
|
||||||
|
|
||||||
### 8.0.0.1 20191221
|
### 8.0.0.1 20191221
|
||||||
|
|
||||||
|
|
|
@ -334,6 +334,7 @@
|
||||||
#define D_CMND_WEBREFRESH "WebRefresh"
|
#define D_CMND_WEBREFRESH "WebRefresh"
|
||||||
#define D_CMND_WEBSEND "WebSend"
|
#define D_CMND_WEBSEND "WebSend"
|
||||||
#define D_CMND_WEBCOLOR "WebColor"
|
#define D_CMND_WEBCOLOR "WebColor"
|
||||||
|
#define D_CMND_WEBBUTTON "WebButton"
|
||||||
#define D_CMND_WEBSENSOR "WebSensor"
|
#define D_CMND_WEBSENSOR "WebSensor"
|
||||||
#define D_CMND_EMULATION "Emulation"
|
#define D_CMND_EMULATION "Emulation"
|
||||||
#define D_CMND_SENDMAIL "Sendmail"
|
#define D_CMND_SENDMAIL "Sendmail"
|
||||||
|
|
|
@ -551,14 +551,15 @@ bool SettingsUpdateText(uint32_t index, const char* replace_me)
|
||||||
|
|
||||||
char* SettingsText(uint32_t index)
|
char* SettingsText(uint32_t index)
|
||||||
{
|
{
|
||||||
if (index >= SET_MAX) {
|
|
||||||
return nullptr; // Setting not supported - internal error
|
|
||||||
}
|
|
||||||
|
|
||||||
char* position = Settings.text_pool;
|
char* position = Settings.text_pool;
|
||||||
|
|
||||||
|
if (index >= SET_MAX) {
|
||||||
|
position += settings_text_size -1; // Setting not supported - internal error - return empty string
|
||||||
|
} else {
|
||||||
for (;index > 0; index--) {
|
for (;index > 0; index--) {
|
||||||
while (*position++ != '\0') { }
|
while (*position++ != '\0') { }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1311,7 +1311,7 @@ void CmndFriendlyname(void)
|
||||||
} else {
|
} else {
|
||||||
snprintf_P(stemp1, sizeof(stemp1), PSTR(FRIENDLY_NAME "%d"), XdrvMailbox.index);
|
snprintf_P(stemp1, sizeof(stemp1), PSTR(FRIENDLY_NAME "%d"), XdrvMailbox.index);
|
||||||
}
|
}
|
||||||
SettingsUpdateText(SET_FRIENDLYNAME1 + XdrvMailbox.index -1, (SC_DEFAULT == Shortcut()) ? stemp1 : XdrvMailbox.data);
|
SettingsUpdateText(SET_FRIENDLYNAME1 + XdrvMailbox.index -1, ('"' == XdrvMailbox.data[0]) ? "" : (SC_DEFAULT == Shortcut()) ? stemp1 : XdrvMailbox.data);
|
||||||
}
|
}
|
||||||
ResponseCmndIdxChar(SettingsText(SET_FRIENDLYNAME1 + XdrvMailbox.index -1));
|
ResponseCmndIdxChar(SettingsText(SET_FRIENDLYNAME1 + XdrvMailbox.index -1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,8 +73,9 @@ const uint8_t MAX_RULE_SETS = 3; // Max number of rule sets of size 5
|
||||||
const uint16_t MAX_RULE_SIZE = 512; // Max number of characters in rules
|
const uint16_t MAX_RULE_SIZE = 512; // Max number of characters in rules
|
||||||
|
|
||||||
// Changes to the following MAX_ defines need to be in line with enum SettingsTextIndex
|
// Changes to the following MAX_ defines need to be in line with enum SettingsTextIndex
|
||||||
const uint8_t MAX_FRIENDLYNAMES = 8; // Max number of Friendly names
|
|
||||||
const uint8_t MAX_RULE_MEMS = 16; // Max number of saved vars
|
const uint8_t MAX_RULE_MEMS = 16; // Max number of saved vars
|
||||||
|
const uint8_t MAX_FRIENDLYNAMES = 8; // Max number of Friendly names
|
||||||
|
const uint8_t MAX_BUTTON_TEXT = 16; // Max number of GUI button labels
|
||||||
|
|
||||||
const uint8_t MAX_HUE_DEVICES = 15; // Max number of Philips Hue device per emulation
|
const uint8_t MAX_HUE_DEVICES = 15; // Max number of Philips Hue device per emulation
|
||||||
|
|
||||||
|
@ -290,10 +291,8 @@ enum SettingsTextIndex { SET_OTAURL,
|
||||||
SET_MEM9, SET_MEM10, SET_MEM11, SET_MEM12, SET_MEM13, SET_MEM14, SET_MEM15, SET_MEM16,
|
SET_MEM9, SET_MEM10, SET_MEM11, SET_MEM12, SET_MEM13, SET_MEM14, SET_MEM15, SET_MEM16,
|
||||||
SET_FRIENDLYNAME1, SET_FRIENDLYNAME2, SET_FRIENDLYNAME3, SET_FRIENDLYNAME4,
|
SET_FRIENDLYNAME1, SET_FRIENDLYNAME2, SET_FRIENDLYNAME3, SET_FRIENDLYNAME4,
|
||||||
SET_FRIENDLYNAME5, SET_FRIENDLYNAME6, SET_FRIENDLYNAME7, SET_FRIENDLYNAME8,
|
SET_FRIENDLYNAME5, SET_FRIENDLYNAME6, SET_FRIENDLYNAME7, SET_FRIENDLYNAME8,
|
||||||
SET_BUTTON1, SET_BUTTON2, SET_BUTTON3, SET_BUTTON4,
|
SET_BUTTON1, SET_BUTTON2, SET_BUTTON3, SET_BUTTON4, SET_BUTTON5, SET_BUTTON6, SET_BUTTON7, SET_BUTTON8,
|
||||||
SET_BUTTON5, SET_BUTTON6, SET_BUTTON7, SET_BUTTON8,
|
SET_BUTTON9, SET_BUTTON10, SET_BUTTON11, SET_BUTTON12, SET_BUTTON13, SET_BUTTON14, SET_BUTTON15, SET_BUTTON16,
|
||||||
SET_BUTTON9, SET_BUTTON10, SET_BUTTON11, SET_BUTTON12,
|
|
||||||
SET_BUTTON13, SET_BUTTON14, SET_BUTTON15, SET_BUTTON16,
|
|
||||||
SET_MAX };
|
SET_MAX };
|
||||||
|
|
||||||
enum CommandSource { SRC_IGNORE, SRC_MQTT, SRC_RESTART, SRC_BUTTON, SRC_SWITCH, SRC_BACKLOG, SRC_SERIAL, SRC_WEBGUI, SRC_WEBCOMMAND, SRC_WEBCONSOLE, SRC_PULSETIMER,
|
enum CommandSource { SRC_IGNORE, SRC_MQTT, SRC_RESTART, SRC_BUTTON, SRC_SWITCH, SRC_BACKLOG, SRC_SERIAL, SRC_WEBGUI, SRC_WEBCOMMAND, SRC_WEBCONSOLE, SRC_PULSETIMER,
|
||||||
|
|
|
@ -1014,7 +1014,7 @@ void HandleRoot(void)
|
||||||
|
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_MAIN_MENU);
|
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_MAIN_MENU);
|
||||||
|
|
||||||
char stemp[10];
|
char stemp[33];
|
||||||
|
|
||||||
WSContentStart_P(S_MAIN_MENU);
|
WSContentStart_P(S_MAIN_MENU);
|
||||||
#ifdef USE_SCRIPT_WEB_DISPLAY
|
#ifdef USE_SCRIPT_WEB_DISPLAY
|
||||||
|
@ -1106,14 +1106,19 @@ void HandleRoot(void)
|
||||||
WSContentSend_P(PSTR("<tr>"));
|
WSContentSend_P(PSTR("<tr>"));
|
||||||
#ifdef USE_SONOFF_IFAN
|
#ifdef USE_SONOFF_IFAN
|
||||||
if (IsModuleIfan()) {
|
if (IsModuleIfan()) {
|
||||||
WSContentSend_P(HTTP_DEVICE_CONTROL, 36, 1, D_BUTTON_TOGGLE, "");
|
WSContentSend_P(HTTP_DEVICE_CONTROL, 36, 1,
|
||||||
|
(strlen(SettingsText(SET_BUTTON1))) ? SettingsText(SET_BUTTON1) : D_BUTTON_TOGGLE,
|
||||||
|
"");
|
||||||
for (uint32_t i = 0; i < MaxFanspeed(); i++) {
|
for (uint32_t i = 0; i < MaxFanspeed(); i++) {
|
||||||
snprintf_P(stemp, sizeof(stemp), PSTR("%d"), i);
|
snprintf_P(stemp, sizeof(stemp), PSTR("%d"), i);
|
||||||
WSContentSend_P(HTTP_DEVICE_CONTROL, 16, i +2, stemp, "");
|
WSContentSend_P(HTTP_DEVICE_CONTROL, 16, i +2,
|
||||||
|
(strlen(SettingsText(SET_BUTTON2 + i))) ? SettingsText(SET_BUTTON2 + i) : stemp,
|
||||||
|
"");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#endif // USE_SONOFF_IFAN
|
#endif // USE_SONOFF_IFAN
|
||||||
for (uint32_t idx = 1; idx <= devices_present; idx++) {
|
for (uint32_t idx = 1; idx <= devices_present; idx++) {
|
||||||
|
bool set_button = ((idx <= MAX_BUTTON_TEXT) && strlen(SettingsText(SET_BUTTON1 + idx -1)));
|
||||||
#ifdef USE_SHUTTER
|
#ifdef USE_SHUTTER
|
||||||
if (Settings.flag3.shutter_mode) { // SetOption80 - Enable shutter support
|
if (Settings.flag3.shutter_mode) { // SetOption80 - Enable shutter support
|
||||||
bool shutter_used = false;
|
bool shutter_used = false;
|
||||||
|
@ -1124,13 +1129,17 @@ void HandleRoot(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (shutter_used) {
|
if (shutter_used) {
|
||||||
WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx, (idx % 2) ? "▲" : "▼" , "");
|
WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx,
|
||||||
|
(set_button) ? SettingsText(SET_BUTTON1 + idx -1) : (idx % 2) ? "▲" : "▼",
|
||||||
|
"");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // USE_SHUTTER
|
#endif // USE_SHUTTER
|
||||||
snprintf_P(stemp, sizeof(stemp), PSTR(" %d"), idx);
|
snprintf_P(stemp, sizeof(stemp), PSTR(" %d"), idx);
|
||||||
WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx, (devices_present < 5) ? D_BUTTON_TOGGLE : "", (devices_present > 1) ? stemp : "");
|
WSContentSend_P(HTTP_DEVICE_CONTROL, 100 / devices_present, idx,
|
||||||
|
(set_button) ? SettingsText(SET_BUTTON1 + idx -1) : (devices_present < 5) ? D_BUTTON_TOGGLE : "",
|
||||||
|
(set_button) ? "" : (devices_present > 1) ? stemp : "");
|
||||||
}
|
}
|
||||||
#ifdef USE_SONOFF_IFAN
|
#ifdef USE_SONOFF_IFAN
|
||||||
}
|
}
|
||||||
|
@ -1146,7 +1155,9 @@ void HandleRoot(void)
|
||||||
if (idx > 0) { WSContentSend_P(PSTR("</tr><tr>")); }
|
if (idx > 0) { WSContentSend_P(PSTR("</tr><tr>")); }
|
||||||
for (uint32_t j = 0; j < 4; j++) {
|
for (uint32_t j = 0; j < 4; j++) {
|
||||||
idx++;
|
idx++;
|
||||||
WSContentSend_P(PSTR("<td style='width:25%%'><button onclick='la(\"&k=%d\");'>%d</button></td>"), idx, idx); // &k is related to WebGetArg("k", tmp, sizeof(tmp));
|
snprintf_P(stemp, sizeof(stemp), PSTR("%d"), idx);
|
||||||
|
WSContentSend_P(PSTR("<td style='width:25%%'><button onclick='la(\"&k=%d\");'>%s</button></td>"), idx, // &k is related to WebGetArg("k", tmp, sizeof(tmp));
|
||||||
|
(strlen(SettingsText(SET_BUTTON1 + idx -1))) ? SettingsText(SET_BUTTON1 + idx -1) : stemp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WSContentSend_P(PSTR("</tr></table>"));
|
WSContentSend_P(PSTR("</tr></table>"));
|
||||||
|
@ -2733,7 +2744,8 @@ const char kWebCommands[] PROGMEM = "|" // No prefix
|
||||||
#ifdef USE_SENDMAIL
|
#ifdef USE_SENDMAIL
|
||||||
D_CMND_SENDMAIL "|"
|
D_CMND_SENDMAIL "|"
|
||||||
#endif
|
#endif
|
||||||
D_CMND_WEBSERVER "|" D_CMND_WEBPASSWORD "|" D_CMND_WEBLOG "|" D_CMND_WEBREFRESH "|" D_CMND_WEBSEND "|" D_CMND_WEBCOLOR "|" D_CMND_WEBSENSOR "|" D_CMND_CORS;
|
D_CMND_WEBSERVER "|" D_CMND_WEBPASSWORD "|" D_CMND_WEBLOG "|" D_CMND_WEBREFRESH "|" D_CMND_WEBSEND "|" D_CMND_WEBCOLOR "|"
|
||||||
|
D_CMND_WEBSENSOR "|" D_CMND_WEBBUTTON "|" D_CMND_CORS;
|
||||||
|
|
||||||
void (* const WebCommand[])(void) PROGMEM = {
|
void (* const WebCommand[])(void) PROGMEM = {
|
||||||
#ifdef USE_EMULATION
|
#ifdef USE_EMULATION
|
||||||
|
@ -2742,7 +2754,8 @@ void (* const WebCommand[])(void) PROGMEM = {
|
||||||
#ifdef USE_SENDMAIL
|
#ifdef USE_SENDMAIL
|
||||||
&CmndSendmail,
|
&CmndSendmail,
|
||||||
#endif
|
#endif
|
||||||
&CmndWebServer, &CmndWebPassword, &CmndWeblog, &CmndWebRefresh, &CmndWebSend, &CmndWebColor, &CmndWebSensor, &CmndCors };
|
&CmndWebServer, &CmndWebPassword, &CmndWeblog, &CmndWebRefresh, &CmndWebSend, &CmndWebColor,
|
||||||
|
&CmndWebSensor, &CmndWebButton, &CmndCors };
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Commands
|
* Commands
|
||||||
|
@ -2863,6 +2876,24 @@ void CmndWebSensor(void)
|
||||||
ResponseJsonEnd();
|
ResponseJsonEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CmndWebButton(void)
|
||||||
|
{
|
||||||
|
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_BUTTON_TEXT)) {
|
||||||
|
if (!XdrvMailbox.usridx) {
|
||||||
|
mqtt_data[0] = '\0';
|
||||||
|
for (uint32_t i = 0; i < MAX_BUTTON_TEXT; i++) {
|
||||||
|
ResponseAppend_P(PSTR("%c\"WebButton%d\":\"%s\""), (i) ? ',' : '{', i +1, SettingsText(SET_BUTTON1 +i));
|
||||||
|
}
|
||||||
|
ResponseJsonEnd();
|
||||||
|
} else {
|
||||||
|
if (XdrvMailbox.data_len > 0) {
|
||||||
|
SettingsUpdateText(SET_BUTTON1 + XdrvMailbox.index -1, ('"' == XdrvMailbox.data[0]) ? "" : XdrvMailbox.data);
|
||||||
|
}
|
||||||
|
ResponseCmndIdxChar(SettingsText(SET_BUTTON1 + XdrvMailbox.index -1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CmndCors(void)
|
void CmndCors(void)
|
||||||
{
|
{
|
||||||
if (XdrvMailbox.data_len > 0) {
|
if (XdrvMailbox.data_len > 0) {
|
||||||
|
|
Loading…
Reference in New Issue