Faster console output. Support longer sensor names

This commit is contained in:
arendst 2018-02-01 16:18:00 +01:00
parent acfcccaf6b
commit 88429fb24c
13 changed files with 43 additions and 118 deletions

View File

@ -381,7 +381,6 @@
#define D_PARTICALS_BEYOND "Particals" #define D_PARTICALS_BEYOND "Particals"
// sonoff_template.h // sonoff_template.h
// Max string length is 8 characters including suffixes
#define D_SENSOR_NONE "None" #define D_SENSOR_NONE "None"
#define D_SENSOR_DHT11 "DHT11" #define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301" #define D_SENSOR_AM2301 "AM2301"

View File

@ -381,7 +381,6 @@
#define D_PARTICALS_BEYOND "Particals" #define D_PARTICALS_BEYOND "Particals"
// sonoff_template.h // sonoff_template.h
// Max string length is 8 characters including suffixes
#define D_SENSOR_NONE "None" #define D_SENSOR_NONE "None"
#define D_SENSOR_DHT11 "DHT11" #define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301" #define D_SENSOR_AM2301 "AM2301"

View File

@ -381,7 +381,6 @@
#define D_PARTICALS_BEYOND "Partículas" #define D_PARTICALS_BEYOND "Partículas"
// sonoff_template.h // sonoff_template.h
// Max string length is 8 characters including suffixes
#define D_SENSOR_NONE "Ninguno" #define D_SENSOR_NONE "Ninguno"
#define D_SENSOR_DHT11 "DHT11" #define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301" #define D_SENSOR_AM2301 "AM2301"

View File

@ -381,7 +381,6 @@
#define D_PARTICALS_BEYOND "Particules" #define D_PARTICALS_BEYOND "Particules"
// sonoff_template.h // sonoff_template.h
// Max string length is 8 characters including suffixes
#define D_SENSOR_NONE "None" #define D_SENSOR_NONE "None"
#define D_SENSOR_DHT11 "DHT11" #define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301" #define D_SENSOR_AM2301 "AM2301"

View File

@ -381,7 +381,6 @@
#define D_PARTICALS_BEYOND "Particelle" #define D_PARTICALS_BEYOND "Particelle"
// sonoff_template.h // sonoff_template.h
// Max string length is 8 characters including suffixes
#define D_SENSOR_NONE "None" #define D_SENSOR_NONE "None"
#define D_SENSOR_DHT11 "DHT11" #define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301" #define D_SENSOR_AM2301 "AM2301"

View File

@ -381,7 +381,6 @@
#define D_PARTICALS_BEYOND "Stofdeeltjes" #define D_PARTICALS_BEYOND "Stofdeeltjes"
// sonoff_template.h // sonoff_template.h
// Max string length is 8 characters including suffixes
#define D_SENSOR_NONE "Geen" #define D_SENSOR_NONE "Geen"
#define D_SENSOR_DHT11 "DHT11" #define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301" #define D_SENSOR_AM2301 "AM2301"

View File

@ -381,7 +381,6 @@
#define D_PARTICALS_BEYOND "Particals" #define D_PARTICALS_BEYOND "Particals"
// sonoff_template.h // sonoff_template.h
// Max string length is 8 characters including suffixes
#define D_SENSOR_NONE "Brak" #define D_SENSOR_NONE "Brak"
#define D_SENSOR_DHT11 "DHT11" #define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301" #define D_SENSOR_AM2301 "AM2301"

View File

@ -381,7 +381,6 @@
#define D_PARTICALS_BEYOND "颗粒物直径大于" #define D_PARTICALS_BEYOND "颗粒物直径大于"
// sonoff_template.h // sonoff_template.h
// Max string length is 8 characters including suffixes
#define D_SENSOR_NONE "None" #define D_SENSOR_NONE "None"
#define D_SENSOR_DHT11 "DHT11" #define D_SENSOR_DHT11 "DHT11"
#define D_SENSOR_AM2301 "AM2301" #define D_SENSOR_AM2301 "AM2301"

View File

@ -1152,8 +1152,8 @@ void MqttDataCallback(char* topic, byte* data, unsigned int data_len)
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,"), mqtt_data); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,"), mqtt_data);
} }
jsflg = 1; jsflg = 1;
snprintf_P(stemp1, sizeof(stemp1), kSensors[Settings.my_gp.io[i]]); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"" D_CMND_GPIO "%d\":\"%d (%s)\""),
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"" D_CMND_GPIO "%d\":\"%d (%s)\""), mqtt_data, i, Settings.my_gp.io[i], stemp1); mqtt_data, i, Settings.my_gp.io[i], GetTextIndexed(stemp1, sizeof(stemp1), Settings.my_gp.io[i], kSensorNames));
} }
} }
if (jsflg) { if (jsflg) {
@ -1170,8 +1170,7 @@ void MqttDataCallback(char* topic, byte* data, unsigned int data_len)
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,"), mqtt_data); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,"), mqtt_data);
} }
jsflg = 1; jsflg = 1;
snprintf_P(stemp1, sizeof(stemp1), kSensors[i]); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"%d (%s)\""), mqtt_data, i, GetTextIndexed(stemp1, sizeof(stemp1), i, kSensorNames));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"%d (%s)\""), mqtt_data, i, stemp1);
if ((strlen(mqtt_data) > (LOGSZ - TOPSZ)) || (i == GPIO_SENSOR_END -1)) { if ((strlen(mqtt_data) > (LOGSZ - TOPSZ)) || (i == GPIO_SENSOR_END -1)) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s]}"), mqtt_data); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s]}"), mqtt_data);
MqttPublishPrefixTopic_P(RESULT_OR_STAT, type); MqttPublishPrefixTopic_P(RESULT_OR_STAT, type);

View File

@ -90,76 +90,6 @@ enum UserSelectablePins {
GPIO_PMS5003, // Plantower PMS5003 Serial interface GPIO_PMS5003, // Plantower PMS5003 Serial interface
GPIO_SENSOR_END }; GPIO_SENSOR_END };
// Text in webpage Module Parameters and commands GPIOS and GPIO
const char kSensors[GPIO_SENSOR_END][9] PROGMEM = {
D_SENSOR_NONE,
D_SENSOR_DHT11,
D_SENSOR_AM2301,
D_SENSOR_SI7021,
D_SENSOR_DS18X20,
D_SENSOR_I2C_SCL,
D_SENSOR_I2C_SDA,
D_SENSOR_WS2812,
D_SENSOR_IRSEND,
D_SENSOR_SWITCH "1",
D_SENSOR_SWITCH "2",
D_SENSOR_SWITCH "3",
D_SENSOR_SWITCH "4",
D_SENSOR_BUTTON "1",
D_SENSOR_BUTTON "2",
D_SENSOR_BUTTON "3",
D_SENSOR_BUTTON "4",
D_SENSOR_RELAY "1",
D_SENSOR_RELAY "2",
D_SENSOR_RELAY "3",
D_SENSOR_RELAY "4",
D_SENSOR_RELAY "5",
D_SENSOR_RELAY "6",
D_SENSOR_RELAY "7",
D_SENSOR_RELAY "8",
D_SENSOR_RELAY "1i",
D_SENSOR_RELAY "2i",
D_SENSOR_RELAY "3i",
D_SENSOR_RELAY "4i",
D_SENSOR_RELAY "5i",
D_SENSOR_RELAY "6i",
D_SENSOR_RELAY "7i",
D_SENSOR_RELAY "8i",
D_SENSOR_PWM "1",
D_SENSOR_PWM "2",
D_SENSOR_PWM "3",
D_SENSOR_PWM "4",
D_SENSOR_PWM "5",
D_SENSOR_COUNTER "1",
D_SENSOR_COUNTER "2",
D_SENSOR_COUNTER "3",
D_SENSOR_COUNTER "4",
D_SENSOR_PWM "1i",
D_SENSOR_PWM "2i",
D_SENSOR_PWM "3i",
D_SENSOR_PWM "4i",
D_SENSOR_PWM "5i",
D_SENSOR_IRRECV,
D_SENSOR_LED "1",
D_SENSOR_LED "2",
D_SENSOR_LED "3",
D_SENSOR_LED "4",
D_SENSOR_LED "1i",
D_SENSOR_LED "2i",
D_SENSOR_LED "3i",
D_SENSOR_LED "4i",
D_SENSOR_MHZ_TX,
D_SENSOR_MHZ_RX,
D_SENSOR_PZEM_TX,
D_SENSOR_PZEM_RX,
D_SENSOR_SAIR_TX,
D_SENSOR_SAIR_RX,
D_SENSOR_SPI_CS,
D_SENSOR_SPI_DC,
D_SENSOR_BACKLIGHT,
D_SENSOR_PMS5003
};
// Programmer selectable GPIO functionality offset by user selectable GPIOs // Programmer selectable GPIO functionality offset by user selectable GPIOs
enum ProgramSelectablePins { enum ProgramSelectablePins {
GPIO_RXD = GPIO_SENSOR_END, // Serial interface GPIO_RXD = GPIO_SENSOR_END, // Serial interface
@ -177,6 +107,30 @@ enum ProgramSelectablePins {
GPIO_USER, // User configurable GPIO_USER, // User configurable
GPIO_MAX }; GPIO_MAX };
// Text in webpage Module Parameters and commands GPIOS and GPIO
const char kSensorNames[] PROGMEM =
D_SENSOR_NONE "|"
D_SENSOR_DHT11 "|" D_SENSOR_AM2301 "|" D_SENSOR_SI7021 "|"
D_SENSOR_DS18X20 "|"
D_SENSOR_I2C_SCL "|" D_SENSOR_I2C_SDA "|"
D_SENSOR_WS2812 "|"
D_SENSOR_IRSEND "|"
D_SENSOR_SWITCH "1|" D_SENSOR_SWITCH "2|" D_SENSOR_SWITCH "3|" D_SENSOR_SWITCH "4|"
D_SENSOR_BUTTON "1|" D_SENSOR_BUTTON "2|" D_SENSOR_BUTTON "3|" D_SENSOR_BUTTON "4|"
D_SENSOR_RELAY "1|" D_SENSOR_RELAY "2|" D_SENSOR_RELAY "3|" D_SENSOR_RELAY "4|" D_SENSOR_RELAY "5|" D_SENSOR_RELAY "6|" D_SENSOR_RELAY "7|" D_SENSOR_RELAY "8|"
D_SENSOR_RELAY "1i|" D_SENSOR_RELAY "2i|" D_SENSOR_RELAY "3i|" D_SENSOR_RELAY "4i|" D_SENSOR_RELAY "5i|" D_SENSOR_RELAY "6i|" D_SENSOR_RELAY "7i|" D_SENSOR_RELAY "8i|"
D_SENSOR_PWM "1|" D_SENSOR_PWM "2|" D_SENSOR_PWM "3|" D_SENSOR_PWM "4|" D_SENSOR_PWM "5|"
D_SENSOR_COUNTER "1|" D_SENSOR_COUNTER "2|" D_SENSOR_COUNTER "3|" D_SENSOR_COUNTER "4|"
D_SENSOR_PWM "1i|" D_SENSOR_PWM "2i|" D_SENSOR_PWM "3i|" D_SENSOR_PWM "4i|" D_SENSOR_PWM "5i|"
D_SENSOR_IRRECV "|"
D_SENSOR_LED "1|" D_SENSOR_LED "2|" D_SENSOR_LED "3|" D_SENSOR_LED "4|"
D_SENSOR_LED "1i|" D_SENSOR_LED "2i|" D_SENSOR_LED "3i|" D_SENSOR_LED "4i|"
D_SENSOR_MHZ_TX "|" D_SENSOR_MHZ_RX "|"
D_SENSOR_PZEM_TX "|" D_SENSOR_PZEM_RX "|"
D_SENSOR_SAIR_TX "|" D_SENSOR_SAIR_RX "|"
D_SENSOR_SPI_CS "|" D_SENSOR_SPI_DC "|" D_SENSOR_BACKLIGHT "|"
D_SENSOR_PMS5003;
/********************************************************************************************/ /********************************************************************************************/
// Supported hardware modules // Supported hardware modules

View File

@ -166,11 +166,12 @@ void* memchr(const void* ptr, int value, size_t num)
} }
// http://clc-wiki.net/wiki/C_standard_library:string.h:strspn // http://clc-wiki.net/wiki/C_standard_library:string.h:strspn
// Get span until any character in string
size_t strcspn(const char *str1, const char *str2) size_t strcspn(const char *str1, const char *str2)
{ {
size_t ret = 0; size_t ret = 0;
while (*str1) { while (*str1) {
if (strchr(str2, *str1)) { if (strchr(str2, *str1)) { // Slow
return ret; return ret;
} else { } else {
str1++; str1++;
@ -179,38 +180,18 @@ size_t strcspn(const char *str1, const char *str2)
} }
return ret; return ret;
} }
/*
* strcspn.c --
*
* Source code for the "strcspn" library routine.
*
* Copyright 1988 Regents of the University of California
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
/*
size_t strcspn(const char* str1, const char* str2)
{
char c;
const char* p;
const char* s;
for (s = str1, c = *s; c != 0; s++, c = *s) {
for (p = str2; *p != 0; p++) {
if (c == *p) return s -str1;
}
}
return s -str1;
}
*/
#endif // ARDUINO_ESP8266_RELEASE_2_3_0 #endif // ARDUINO_ESP8266_RELEASE_2_3_0
// Get span until single character in string
size_t strchrspn(const char *str1, int character)
{
size_t ret = 0;
char *start = (char*)str1;
char *end = strchr(str1, character);
if (end) ret = end - start;
return ret;
}
char* dtostrfd(double number, unsigned char prec, char *s) char* dtostrfd(double number, unsigned char prec, char *s)
{ {
return dtostrf(number, 1, prec, s); return dtostrf(number, 1, prec, s);
@ -1363,7 +1344,7 @@ void GetLog(byte idx, char** entry_pp, size_t* len_p)
do { do {
byte cur_idx = *it; byte cur_idx = *it;
it++; it++;
size_t tmp = strcspn(it, "\1"); size_t tmp = strchrspn(it, '\1');
tmp++; // Skip terminating '\1' tmp++; // Skip terminating '\1'
if (cur_idx == idx) { // Found the requested entry if (cur_idx == idx) { // Found the requested entry
len = tmp; len = tmp;
@ -1421,7 +1402,7 @@ void AddLog(byte loglevel)
{ {
char* it = web_log; char* it = web_log;
it++; // Skip web_log_index it++; // Skip web_log_index
it += strcspn(it, "\1"); // Skip log line it += strchrspn(it, '\1'); // Skip log line
it++; // Skip delimiting "\1" it++; // Skip delimiting "\1"
memmove(web_log, it, WEB_LOG_SIZE -(it-web_log)); // Move buffer forward to remove oldest log line memmove(web_log, it, WEB_LOG_SIZE -(it-web_log)); // Move buffer forward to remove oldest log line
} }

View File

@ -708,8 +708,7 @@ void HandleModuleConfiguration()
for (byte j = 0; j < GPIO_SENSOR_END; j++) { for (byte j = 0; j < GPIO_SENSOR_END; j++) {
if (!GetUsedInModule(j, cmodule.gp.io)) { if (!GetUsedInModule(j, cmodule.gp.io)) {
snprintf_P(stemp, sizeof(stemp), kSensors[j]); snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SCRIPT_MODULE2, j, j, GetTextIndexed(stemp, sizeof(stemp), j, kSensorNames));
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SCRIPT_MODULE2, j, j, stemp);
page += mqtt_data; page += mqtt_data;
} }
} }

View File

@ -203,7 +203,7 @@ void DhtInit()
pinMode(Dht[i].pin, INPUT_PULLUP); pinMode(Dht[i].pin, INPUT_PULLUP);
Dht[i].lastreadtime = 0; Dht[i].lastreadtime = 0;
Dht[i].lastresult = 0; Dht[i].lastresult = 0;
strcpy_P(Dht[i].stype, kSensors[Dht[i].type]); GetTextIndexed(Dht[i].stype, sizeof(Dht[i].stype), Dht[i].type, kSensorNames);
if (dht_sensors > 1) { if (dht_sensors > 1) {
snprintf_P(Dht[i].stype, sizeof(Dht[i].stype), PSTR("%s-%02d"), Dht[i].stype, Dht[i].pin); snprintf_P(Dht[i].stype, sizeof(Dht[i].stype), PSTR("%s-%02d"), Dht[i].stype, Dht[i].pin);
} }