Allow increase in friendlynames

Allow increase in friendlynames (#3098)
This commit is contained in:
Theo Arends 2018-06-30 14:17:26 +02:00
parent 03ae4098b5
commit 2a62356172
3 changed files with 12 additions and 14 deletions

View File

@ -986,7 +986,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_NVALUE_SVALUE, command, Settings.sta_config, stemp1);
}
}
else if ((CMND_FRIENDLYNAME == command_code) && (index > 0) && (index <= 4)) {
else if ((CMND_FRIENDLYNAME == command_code) && (index > 0) && (index <= MAX_FRIENDLYNAMES)) {
if ((data_len > 0) && (data_len < sizeof(Settings.friendlyname[0]))) {
if (1 == index) {
snprintf_P(stemp1, sizeof(stemp1), PSTR(FRIENDLY_NAME));
@ -1293,7 +1293,7 @@ void ExecuteCommand(char *cmnd, int source)
void PublishStatus(uint8_t payload)
{
uint8_t option = STAT;
char stemp[MAX_FRIENDLYNAMES * (sizeof(Settings.friendlyname[0]) +4)];
char stemp[MAX_FRIENDLYNAMES * (sizeof(Settings.friendlyname[0]) +MAX_FRIENDLYNAMES)];
// Workaround MQTT - TCP/IP stack queueing when SUB_PREFIX = PUB_PREFIX
if (!strcmp(Settings.mqtt_prefix[0],Settings.mqtt_prefix[1]) && (!payload)) option++; // TELE

View File

@ -1076,16 +1076,14 @@ void HandleSaveSettings()
WebGetArg("b2", tmp, sizeof(tmp));
Settings.flag2.emulation = (!strlen(tmp)) ? 0 : atoi(tmp);
#endif // USE_EMULATION
WebGetArg("a1", tmp, sizeof(tmp));
strlcpy(Settings.friendlyname[0], (!strlen(tmp)) ? FRIENDLY_NAME : tmp, sizeof(Settings.friendlyname[0]));
WebGetArg("a2", tmp, sizeof(tmp));
strlcpy(Settings.friendlyname[1], (!strlen(tmp)) ? FRIENDLY_NAME"2" : tmp, sizeof(Settings.friendlyname[1]));
WebGetArg("a3", tmp, sizeof(tmp));
strlcpy(Settings.friendlyname[2], (!strlen(tmp)) ? FRIENDLY_NAME"3" : tmp, sizeof(Settings.friendlyname[2]));
WebGetArg("a4", tmp, sizeof(tmp));
strlcpy(Settings.friendlyname[3], (!strlen(tmp)) ? FRIENDLY_NAME"4" : tmp, sizeof(Settings.friendlyname[3]));
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_OTHER D_MQTT_ENABLE " %s, " D_CMND_EMULATION " %d, " D_CMND_FRIENDLYNAME " %s, %s, %s, %s"),
GetStateText(Settings.flag.mqtt_enabled), Settings.flag2.emulation, Settings.friendlyname[0], Settings.friendlyname[1], Settings.friendlyname[2], Settings.friendlyname[3]);
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_OTHER D_MQTT_ENABLE " %s, " D_CMND_EMULATION " %d, " D_CMND_FRIENDLYNAME), GetStateText(Settings.flag.mqtt_enabled), Settings.flag2.emulation);
for (byte i = 0; i < MAX_FRIENDLYNAMES; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("a%d"), i +1);
WebGetArg(stemp, tmp, sizeof(tmp));
snprintf_P(stemp2, sizeof(stemp2), PSTR(FRIENDLY_NAME"%d"), i +1);
strlcpy(Settings.friendlyname[i], (!strlen(tmp)) ? (i) ? stemp2 : FRIENDLY_NAME : tmp, sizeof(Settings.friendlyname[i]));
snprintf_P(log_data, sizeof(log_data), PSTR("%s%s %s"), log_data, (i) ? "," : "", Settings.friendlyname[i]);
}
AddLog(LOG_LEVEL_INFO);
break;
case 6:

View File

@ -169,9 +169,9 @@ void TmInit()
void TmLoop()
{
byte buttons = Tm1638GetButtons();
for (byte i = 0; i < 8; i++) {
for (byte i = 0; i < MAX_SWITCHES; i++) {
virtualswitch[i] = buttons &1;
byte color = virtualswitch[i] ? TM1638_COLOR_RED : TM1638_COLOR_NONE;
byte color = (virtualswitch[i]) ? TM1638_COLOR_RED : TM1638_COLOR_NONE;
Tm1638SetLED(color, i);
buttons >>= 1;
}