From 7c857b0feb5178595301040d8b25a1fc808c9a50 Mon Sep 17 00:00:00 2001 From: Luis Teixeira Date: Wed, 4 Dec 2019 22:51:21 +0000 Subject: [PATCH 01/17] Added the command SerialConfig with the capability of changing the data bits/parity/stop bits setting in the hardware serial port. --- tasmota/i18n.h | 1 + tasmota/language/en-GB.h | 1 + tasmota/language/pt-PT.h | 1 + tasmota/settings.h | 22 ++++++++++++- tasmota/settings.ino | 35 +++++++++++++++++++-- tasmota/support.ino | 62 ++++++++++++++++++++++++++++++++++--- tasmota/support_command.ino | 50 ++++++++++++++++++++++++------ tasmota/tasmota.ino | 4 ++- 8 files changed, 158 insertions(+), 18 deletions(-) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 5de4b7a1d..65f9887a3 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -284,6 +284,7 @@ #define D_CMND_I2CDRIVER "I2CDriver" #define D_CMND_SERIALSEND "SerialSend" #define D_CMND_SERIALDELIMITER "SerialDelimiter" +#define D_CMND_SERIALCONFIG "SerialConfig" #define D_CMND_BAUDRATE "Baudrate" #define D_CMND_TEMPLATE "Template" #define D_JSON_NAME "NAME" diff --git a/tasmota/language/en-GB.h b/tasmota/language/en-GB.h index a98087a18..15e880600 100644 --- a/tasmota/language/en-GB.h +++ b/tasmota/language/en-GB.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog logging re-enabled" #define D_SET_BAUDRATE_TO "Set Baudrate to" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Received Topic" #define D_DATA_SIZE "Data Size" #define D_ANALOG_INPUT "Analog" diff --git a/tasmota/language/pt-PT.h b/tasmota/language/pt-PT.h index 46bafdef6..27987acf0 100644 --- a/tasmota/language/pt-PT.h +++ b/tasmota/language/pt-PT.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Registro do Syslog reativado" #define D_SET_BAUDRATE_TO "Ajuste da velocidade para" +#define D_SET_SERIAL_CONFIG_TO "Ajuste do modo da porta série" #define D_RECEIVED_TOPIC "Topico Recebido" #define D_DATA_SIZE "Tamanho de Dados" #define D_ANALOG_INPUT "Entrada Analógica" diff --git a/tasmota/settings.h b/tasmota/settings.h index 554711cad..61359226b 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -231,6 +231,26 @@ typedef struct { const uint8_t MAX_TUYA_FUNCTIONS = 16; +/** + * Structure used for holding the hardware serial port settings. + * + * Description of the fields: + * + * baudrate - the baud rate multiplier, which can range from 0 - 15360 (multiply by 300 to obtain the actual baud rate) + * mode - encodes a selection of the main serial port settings. + * + * The mode field can take the following values: + * + * 0 - 7N1 (7 data bits / no parity / 1 stop bit) + * 1 - 7E1 (7 data bits / even parity / 1 stop bit) + * 2 - 8N1 (8 data bits / no parity / 1 stop bit) + * 3 - 8E1 (8 data bits / even parity / 1 stop bit) + */ +typedef struct { + uint16_t baudrate; // the baud rate multiplier, which can range from 0 - 15360 (multiply by 300 to obtain the actual baud rate) + uint8_t mode; // encodes a selection of the main serial port settings: 8E1, 8N1, 7E1 and 7N1 +} SerialCfg; + /* struct SYSCFG { unsigned long cfg_holder; // 000 Pre v6 header @@ -397,7 +417,7 @@ struct SYSCFG { uint8_t web_color[18][3]; // 73E uint16_t display_width; // 774 uint16_t display_height; // 776 - uint16_t baudrate; // 778 + uint16_t serial_config; // 778 - 11 MSB's define the baud rate; 5 LSB's define the serial config (e.g. 8N1). Maps to the SerialCfg struct. uint16_t sbaudrate; // 77A EnergyUsage energy_usage; // 77C // uint32_t drivers[3]; // 794 - 6.5.0.12 replaced by below three entries diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 9ca979b45..3f6621495 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -670,8 +670,13 @@ void SettingsDefaultSet2(void) // for (uint32_t i = 1; i < MAX_PULSETIMERS; i++) { Settings.pulse_timer[i] = 0; } // Serial - Settings.baudrate = APP_BAUDRATE / 300; + + SerialCfg config = SettingToSerialCfg(Settings.serial_config); + config.baudrate = APP_BAUDRATE / 300; + Settings.serial_config = SerialCfgToSetting(config); + Settings.sbaudrate = SOFT_BAUDRATE / 300; + //Settings.serial_config = SERIAL_8N1; Settings.serial_delimiter = 0xff; Settings.seriallog_level = SERIAL_LOG_LEVEL; @@ -1059,7 +1064,10 @@ void SettingsDelta(void) } } if (Settings.version < 0x06060009) { - Settings.baudrate = Settings.ex_baudrate * 4; + SerialCfg config = SettingToSerialCfg(Settings.serial_config); + config.baudrate = Settings.ex_baudrate * 4; + Settings.serial_config = SerialCfgToSetting(config); + Settings.sbaudrate = Settings.ex_sbaudrate * 4; } if (Settings.version < 0x0606000A) { @@ -1160,3 +1168,26 @@ void SettingsDelta(void) SettingsSave(1); } } + +/* Performs the bitwise operations needed for translating the serial port settings 16-bit word + to the SerialCfg struct: */ +SerialCfg SettingToSerialCfg(uint16_t setting) +{ + SerialCfg serial_config; + + serial_config.baudrate = (uint16_t) (setting >> 2) & 0x3FFF; + serial_config.mode = (uint8_t) (setting) & 0x3; + + return serial_config; +} + +/* Performs the bitwise operations needed for translating from the SerialCfg struct + to the serial port settings 16-bit word: */ +uint16_t SerialCfgToSetting(SerialCfg serial_config) +{ + uint16_t setting; + + setting = (uint16_t) ((uint16_t) (serial_config.baudrate << 2 & 0xFFFC)) | (serial_config.mode & 0x3); + + return setting; +} diff --git a/tasmota/support.ino b/tasmota/support.ino index 55c01b71d..8f1ba2862 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -738,16 +738,42 @@ int GetStateNumber(char *state_text) return state_number; } -void SetSerialBaudrate(int baudrate) +void SetSerialConfig(uint8_t mode) { - Settings.baudrate = baudrate / 300; + SerialCfg config = SettingToSerialCfg(Settings.serial_config); + config.mode = mode; + Settings.serial_config = SerialCfgToSetting(config); + + SerialConfig hardware_serial_config = ConvertSettingByteToSerialConfig(mode); + + if (seriallog_level) { + AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_SET_SERIAL_CONFIG_TO " %d"), mode); + } + + delay(100); + Serial.flush(); + + Serial.begin(Serial.baudRate(), hardware_serial_config); + delay(10); + Serial.println(); +} + +void SetSerialBaudrate(uint32_t baudrate) +{ + SerialCfg config = SettingToSerialCfg(Settings.serial_config); + config.baudrate = ((baudrate / 300) & 0x3FFF); + Settings.serial_config = SerialCfgToSetting(config); + + SerialConfig hardware_serial_config = ConvertSettingByteToSerialConfig(config.mode); + if (Serial.baudRate() != baudrate) { if (seriallog_level) { AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION D_SET_BAUDRATE_TO " %d"), baudrate); } delay(100); Serial.flush(); - Serial.begin(baudrate, serial_config); + + Serial.begin(baudrate, hardware_serial_config); delay(10); Serial.println(); } @@ -759,7 +785,10 @@ void ClaimSerial(void) AddLog_P(LOG_LEVEL_INFO, PSTR("SNS: Hardware Serial")); SetSeriallog(LOG_LEVEL_NONE); baudrate = Serial.baudRate(); - Settings.baudrate = baudrate / 300; + + SerialCfg config = SettingToSerialCfg(Settings.serial_config); + config.baudrate = baudrate / 300; + Settings.serial_config = SerialCfgToSetting(config); } void SerialSendRaw(char *codes) @@ -1647,3 +1676,28 @@ void AddLogMissed(char *sensor, uint32_t misses) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SNS: %s missed %d"), sensor, SENSOR_MAX_MISS - misses); } + +SerialConfig ConvertSettingByteToSerialConfig(uint8_t setting_byte) +{ + SerialConfig hardware_serial_config; + + switch(setting_byte) { + case 0: + hardware_serial_config = SERIAL_7N1; + break; + case 1: + hardware_serial_config = SERIAL_7E1; + break; + case 2: + hardware_serial_config = SERIAL_8N1; + break; + case 3: + hardware_serial_config = SERIAL_8E1; + break; + default: + hardware_serial_config = SERIAL_8N1; + break; + } + + return hardware_serial_config; +} \ No newline at end of file diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index fe8640045..f0a5ba87d 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -23,10 +23,10 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix D_CMND_SETOPTION "|" D_CMND_TEMPERATURE_RESOLUTION "|" D_CMND_HUMIDITY_RESOLUTION "|" D_CMND_PRESSURE_RESOLUTION "|" D_CMND_POWER_RESOLUTION "|" D_CMND_VOLTAGE_RESOLUTION "|" D_CMND_FREQUENCY_RESOLUTION "|" D_CMND_CURRENT_RESOLUTION "|" D_CMND_ENERGY_RESOLUTION "|" D_CMND_WEIGHT_RESOLUTION "|" D_CMND_MODULE "|" D_CMND_MODULES "|" D_CMND_GPIO "|" D_CMND_GPIOS "|" D_CMND_TEMPLATE "|" D_CMND_PWM "|" D_CMND_PWMFREQUENCY "|" D_CMND_PWMRANGE "|" - D_CMND_BUTTONDEBOUNCE "|" D_CMND_SWITCHDEBOUNCE "|" D_CMND_SYSLOG "|" D_CMND_LOGHOST "|" D_CMND_LOGPORT "|" D_CMND_SERIALSEND "|" D_CMND_BAUDRATE "|" - D_CMND_SERIALDELIMITER "|" D_CMND_IPADDRESS "|" D_CMND_NTPSERVER "|" D_CMND_AP "|" D_CMND_SSID "|" D_CMND_PASSWORD "|" D_CMND_HOSTNAME "|" D_CMND_WIFICONFIG "|" - D_CMND_FRIENDLYNAME "|" D_CMND_SWITCHMODE "|" D_CMND_INTERLOCK "|" D_CMND_TELEPERIOD "|" D_CMND_RESET "|" D_CMND_TIME "|" D_CMND_TIMEZONE "|" D_CMND_TIMESTD "|" - D_CMND_TIMEDST "|" D_CMND_ALTITUDE "|" D_CMND_LEDPOWER "|" D_CMND_LEDSTATE "|" D_CMND_LEDMASK "|" D_CMND_WIFIPOWER "|" D_CMND_TEMPOFFSET "|" + D_CMND_BUTTONDEBOUNCE "|" D_CMND_SWITCHDEBOUNCE "|" D_CMND_SYSLOG "|" D_CMND_LOGHOST "|" D_CMND_LOGPORT "|" D_CMND_SERIALSEND "|" D_CMND_SERIALCONFIG "|" + D_CMND_BAUDRATE "|" D_CMND_SERIALDELIMITER "|" D_CMND_IPADDRESS "|" D_CMND_NTPSERVER "|" D_CMND_AP "|" D_CMND_SSID "|" D_CMND_PASSWORD "|" D_CMND_HOSTNAME "|" + D_CMND_WIFICONFIG "|" D_CMND_FRIENDLYNAME "|" D_CMND_SWITCHMODE "|" D_CMND_INTERLOCK "|" D_CMND_TELEPERIOD "|" D_CMND_RESET "|" D_CMND_TIME "|" D_CMND_TIMEZONE "|" + D_CMND_TIMESTD "|" D_CMND_TIMEDST "|" D_CMND_ALTITUDE "|" D_CMND_LEDPOWER "|" D_CMND_LEDSTATE "|" D_CMND_LEDMASK "|" D_CMND_WIFIPOWER "|" D_CMND_TEMPOFFSET "|" #ifdef USE_I2C D_CMND_I2CSCAN "|" D_CMND_I2CDRIVER "|" #endif @@ -38,7 +38,7 @@ void (* const TasmotaCommand[])(void) PROGMEM = { &CmndSetoption, &CmndTemperatureResolution, &CmndHumidityResolution, &CmndPressureResolution, &CmndPowerResolution, &CmndVoltageResolution, &CmndFrequencyResolution, &CmndCurrentResolution, &CmndEnergyResolution, &CmndWeightResolution, &CmndModule, &CmndModules, &CmndGpio, &CmndGpios, &CmndTemplate, &CmndPwm, &CmndPwmfrequency, &CmndPwmrange, - &CmndButtonDebounce, &CmndSwitchDebounce, &CmndSyslog, &CmndLoghost, &CmndLogport, &CmndSerialSend, &CmndBaudrate, + &CmndButtonDebounce, &CmndSwitchDebounce, &CmndSyslog, &CmndLoghost, &CmndLogport, &CmndSerialSend, &CmndSerialConfig, &CmndBaudrate, &CmndSerialDelimiter, &CmndIpAddress, &CmndNtpServer, &CmndAp, &CmndSsid, &CmndPassword, &CmndHostname, &CmndWifiConfig, &CmndFriendlyname, &CmndSwitchMode, &CmndInterlock, &CmndTeleperiod, &CmndReset, &CmndTime, &CmndTimezone, &CmndTimeStd, &CmndTimeDst, &CmndAltitude, &CmndLedPower, &CmndLedState, &CmndLedMask, &CmndWifiPower, &CmndTempOffset, @@ -1072,14 +1072,44 @@ void CmndSwitchDebounce(void) ResponseCmndNumber(Settings.switch_debounce); } +/** + * Changes the Serial port number of bits, parity and stop bits. + * For the time being this command only has effect on the hardware + * serial port (GPIO1 and GPIO3) + * + * Meaning of the values: + * + * 0 - 7N1 (7 data bits / no parity / 1 stop bit) + * 1 - 7E1 (7 data bits / even parity / 1 stop bit) + * 2 - 8N1 (8 data bits / no parity / 1 stop bit) + * 3 - 8E1 (8 data bits / even parity / 1 stop bit) + * + */ + +void CmndSerialConfig(void) +{ + // a frugal validation to check if the provided serial port mode is valid: + + if (XdrvMailbox.payload >= 0 && XdrvMailbox.payload <= 3) { + uint8_t mode = (uint8_t) (XdrvMailbox.payload & 3); + + SetSerialConfig(mode); + } + + SerialCfg config = SettingToSerialCfg(Settings.serial_config); + + ResponseCmndNumber(config.mode); +} + void CmndBaudrate(void) { - if (XdrvMailbox.payload >= 300) { - XdrvMailbox.payload /= 300; // Make it a valid baudrate - baudrate = (XdrvMailbox.payload & 0xFFFF) * 300; - SetSerialBaudrate(baudrate); + if (XdrvMailbox.payload >= 300) { + SetSerialBaudrate(XdrvMailbox.payload); } - ResponseCmndNumber(Settings.baudrate * 300); + + SerialCfg config = SettingToSerialCfg(Settings.serial_config); + + ResponseCmndNumber(config.baudrate * 300); } void CmndSerialSend(void) diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 64a1125c6..e6511eb04 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -1535,7 +1535,9 @@ void setup(void) XdrvCall(FUNC_SETTINGS_OVERRIDE); } - baudrate = Settings.baudrate * 300; + SerialCfg config = SettingToSerialCfg(Settings.serial_config); + + baudrate = config.baudrate * 300; // mdns_delayed_start = Settings.param[P_MDNS_DELAYED_START]; seriallog_level = Settings.seriallog_level; seriallog_timer = SERIALLOG_TIMER; From 83f9c7b588f64d74e3d3fec09eb5dd5f9538bfc5 Mon Sep 17 00:00:00 2001 From: Luis Teixeira Date: Wed, 4 Dec 2019 23:03:52 +0000 Subject: [PATCH 02/17] Fixed comment (bits for each field) --- tasmota/settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index 61359226b..a3f5fd63e 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -417,7 +417,7 @@ struct SYSCFG { uint8_t web_color[18][3]; // 73E uint16_t display_width; // 774 uint16_t display_height; // 776 - uint16_t serial_config; // 778 - 11 MSB's define the baud rate; 5 LSB's define the serial config (e.g. 8N1). Maps to the SerialCfg struct. + uint16_t serial_config; // 778 - 14 MSB's define the baud rate; 2 LSB's define the serial config (e.g. 8N1). Maps to the SerialCfg struct. uint16_t sbaudrate; // 77A EnergyUsage energy_usage; // 77C // uint32_t drivers[3]; // 794 - 6.5.0.12 replaced by below three entries From 871fd1f60db02209218037589def86294d3e835c Mon Sep 17 00:00:00 2001 From: Luis Teixeira Date: Thu, 5 Dec 2019 01:18:59 +0000 Subject: [PATCH 03/17] Added the new text field D_SET_SERIAL_CONFIG_TO (used in the logs) to the internationalized resource files. --- tasmota/language/bg-BG.h | 1 + tasmota/language/cs-CZ.h | 1 + tasmota/language/de-DE.h | 1 + tasmota/language/el-GR.h | 1 + tasmota/language/es-ES.h | 1 + tasmota/language/fr-FR.h | 1 + tasmota/language/he-HE.h | 1 + tasmota/language/hu-HU.h | 1 + tasmota/language/it-IT.h | 1 + tasmota/language/ko-KO.h | 1 + tasmota/language/nl-NL.h | 1 + tasmota/language/pl-PL.h | 1 + tasmota/language/pt-BR.h | 1 + tasmota/language/ru-RU.h | 1 + tasmota/language/sk-SK.h | 1 + tasmota/language/sv-SE.h | 1 + tasmota/language/tr-TR.h | 1 + tasmota/language/uk-UK.h | 1 + tasmota/language/zh-CN.h | 1 + tasmota/language/zh-TW.h | 1 + 20 files changed, 20 insertions(+) diff --git a/tasmota/language/bg-BG.h b/tasmota/language/bg-BG.h index 4bc5feebd..10f13b786 100644 --- a/tasmota/language/bg-BG.h +++ b/tasmota/language/bg-BG.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Системният лог активиран" #define D_SET_BAUDRATE_TO "Задаване скорост на предаване (Baudrate)" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Получен топик" #define D_DATA_SIZE "Размер на данните" #define D_ANALOG_INPUT "Аналогов вход" diff --git a/tasmota/language/cs-CZ.h b/tasmota/language/cs-CZ.h index 8800368a3..639a0a184 100644 --- a/tasmota/language/cs-CZ.h +++ b/tasmota/language/cs-CZ.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Obnoven zápis do Syslog" #define D_SET_BAUDRATE_TO "Nastavení rychlosti přenosu na" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Přijatý topic" #define D_DATA_SIZE "Velikost dat" #define D_ANALOG_INPUT "Analogový vstup" diff --git a/tasmota/language/de-DE.h b/tasmota/language/de-DE.h index c50de823f..75bf51435 100644 --- a/tasmota/language/de-DE.h +++ b/tasmota/language/de-DE.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog-Logging aktiviert" #define D_SET_BAUDRATE_TO "Setze Baudrate auf" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "empfangenes topic" #define D_DATA_SIZE "Datengröße" #define D_ANALOG_INPUT "Analog" diff --git a/tasmota/language/el-GR.h b/tasmota/language/el-GR.h index 4fe47ae6d..0583c17e8 100644 --- a/tasmota/language/el-GR.h +++ b/tasmota/language/el-GR.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Η καταγραφή Syslog επαναενεργοποιήθηκε" #define D_SET_BAUDRATE_TO "Ορισμός Baudrate σε" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Received Topic" #define D_DATA_SIZE "Μέγεθος δεδομένων" #define D_ANALOG_INPUT "Αναλογικό" diff --git a/tasmota/language/es-ES.h b/tasmota/language/es-ES.h index 014d822a9..7f1ac36d6 100644 --- a/tasmota/language/es-ES.h +++ b/tasmota/language/es-ES.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog re-habilitado" #define D_SET_BAUDRATE_TO "Baudrate a" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Topic Recibido" #define D_DATA_SIZE "Tamaño de Datos" #define D_ANALOG_INPUT "Entrada Analógica" diff --git a/tasmota/language/fr-FR.h b/tasmota/language/fr-FR.h index 4704c49e7..446485462 100644 --- a/tasmota/language/fr-FR.h +++ b/tasmota/language/fr-FR.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Jounalisation SysLog réactivée" #define D_SET_BAUDRATE_TO "Définir le débit à" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Topic reçu" // Terme MQTT #define D_DATA_SIZE "Taille données" #define D_ANALOG_INPUT "Analogique" diff --git a/tasmota/language/he-HE.h b/tasmota/language/he-HE.h index 69387ceca..1c9eed40a 100644 --- a/tasmota/language/he-HE.h +++ b/tasmota/language/he-HE.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "הופעל מחדש Syslog רישום" #define D_SET_BAUDRATE_TO "הגדר קצב שידור ל" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Topic התקבל" #define D_DATA_SIZE "גודל נתונים" #define D_ANALOG_INPUT "אנלוגי" diff --git a/tasmota/language/hu-HU.h b/tasmota/language/hu-HU.h index 58f85eb22..f34b2cbb3 100644 --- a/tasmota/language/hu-HU.h +++ b/tasmota/language/hu-HU.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog logolás újraengedélyezve" #define D_SET_BAUDRATE_TO "Baudrate beállítása" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Érkezett topic" #define D_DATA_SIZE "Adatméret" #define D_ANALOG_INPUT "Analóg" diff --git a/tasmota/language/it-IT.h b/tasmota/language/it-IT.h index 3029f37da..5de100fee 100644 --- a/tasmota/language/it-IT.h +++ b/tasmota/language/it-IT.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog ri-abilitato" #define D_SET_BAUDRATE_TO "Baudrate impostato a" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Topic Ricevuto" #define D_DATA_SIZE "Dimensione Dati" #define D_ANALOG_INPUT "Ingresso Analogico" diff --git a/tasmota/language/ko-KO.h b/tasmota/language/ko-KO.h index c6236a05f..65c045f3f 100644 --- a/tasmota/language/ko-KO.h +++ b/tasmota/language/ko-KO.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog log 다시 사용" #define D_SET_BAUDRATE_TO "Set Baudrate to" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Received Topic" #define D_DATA_SIZE "데이터 용량" #define D_ANALOG_INPUT "아날로그" diff --git a/tasmota/language/nl-NL.h b/tasmota/language/nl-NL.h index da20ff1d7..541b9bdc6 100644 --- a/tasmota/language/nl-NL.h +++ b/tasmota/language/nl-NL.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog logging weer ingeschakeld" #define D_SET_BAUDRATE_TO "Zet baudrate op" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Ontvangen topic" #define D_DATA_SIZE "Data lengte" #define D_ANALOG_INPUT "Analoog" diff --git a/tasmota/language/pl-PL.h b/tasmota/language/pl-PL.h index 7a631f95f..dbb7339d3 100644 --- a/tasmota/language/pl-PL.h +++ b/tasmota/language/pl-PL.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Wznowiono zapis do Syslog" #define D_SET_BAUDRATE_TO "Ustaw szybkość transmisji na" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Otrzymany temat" #define D_DATA_SIZE "Wielkość danych" #define D_ANALOG_INPUT "Wejście analogowe" diff --git a/tasmota/language/pt-BR.h b/tasmota/language/pt-BR.h index 2eb81f294..774514152 100644 --- a/tasmota/language/pt-BR.h +++ b/tasmota/language/pt-BR.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Registro do Syslog reativado" #define D_SET_BAUDRATE_TO "Ajuste da velocidade para" +#define D_SET_SERIAL_CONFIG_TO "Ajuste do modo da porta série" #define D_RECEIVED_TOPIC "Tópico recebido" #define D_DATA_SIZE "Tamanho de dados" #define D_ANALOG_INPUT "Entrada analógica" diff --git a/tasmota/language/ru-RU.h b/tasmota/language/ru-RU.h index 5ff9bff50..cd734a575 100644 --- a/tasmota/language/ru-RU.h +++ b/tasmota/language/ru-RU.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog logging включен" #define D_SET_BAUDRATE_TO "Установить скорость передачи (Baudrate)" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Полученный Топик" #define D_DATA_SIZE "Размер данных" #define D_ANALOG_INPUT "Аналоговый вход" diff --git a/tasmota/language/sk-SK.h b/tasmota/language/sk-SK.h index 57ec74f8a..0accdc407 100644 --- a/tasmota/language/sk-SK.h +++ b/tasmota/language/sk-SK.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Obnovený zápis do Syslog" #define D_SET_BAUDRATE_TO "Nastaviť rýchlosti prenosu na" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Prijatý topic" #define D_DATA_SIZE "Veľkosť dát" #define D_ANALOG_INPUT "Analógový vstup" diff --git a/tasmota/language/sv-SE.h b/tasmota/language/sv-SE.h index aee8fd25d..30de42797 100644 --- a/tasmota/language/sv-SE.h +++ b/tasmota/language/sv-SE.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog återaktiverad" #define D_SET_BAUDRATE_TO "Ange Baudrate till" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Mottaget ämne" #define D_DATA_SIZE "Datastorlek" #define D_ANALOG_INPUT "Analog" diff --git a/tasmota/language/tr-TR.h b/tasmota/language/tr-TR.h index 78612dace..cea928af7 100644 --- a/tasmota/language/tr-TR.h +++ b/tasmota/language/tr-TR.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Sistem loglaması tekrar aktif" #define D_SET_BAUDRATE_TO "Baud hızını şu şekilde değiştir" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Alınan Başlık" #define D_DATA_SIZE "Veri Büyüklüğü" #define D_ANALOG_INPUT "Analog" diff --git a/tasmota/language/uk-UK.h b/tasmota/language/uk-UK.h index f16d66648..890c40b9c 100644 --- a/tasmota/language/uk-UK.h +++ b/tasmota/language/uk-UK.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog журнал увімкнений" #define D_SET_BAUDRATE_TO "Встановити швидкість передачі (Baudrate)" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Отриманий Топік" #define D_DATA_SIZE "Розмір даних" #define D_ANALOG_INPUT "Напруга" diff --git a/tasmota/language/zh-CN.h b/tasmota/language/zh-CN.h index 2c8610400..178497a88 100644 --- a/tasmota/language/zh-CN.h +++ b/tasmota/language/zh-CN.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog 日志已开启" #define D_SET_BAUDRATE_TO "设置波特率为:" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "接收到的主题:" #define D_DATA_SIZE "数据大小:" #define D_ANALOG_INPUT "Analog" diff --git a/tasmota/language/zh-TW.h b/tasmota/language/zh-TW.h index e5ef8926a..5862f4b5b 100644 --- a/tasmota/language/zh-TW.h +++ b/tasmota/language/zh-TW.h @@ -190,6 +190,7 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog 日誌已開啟" #define D_SET_BAUDRATE_TO "設置波特率為:" +#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "接收到的主題:" #define D_DATA_SIZE "數據大小:" #define D_ANALOG_INPUT "Analog" From 39088654739c2e42dee504508f3d6bf8462d5682 Mon Sep 17 00:00:00 2001 From: Luis Teixeira Date: Sun, 8 Mar 2020 20:54:28 +0000 Subject: [PATCH 04/17] Added the hdc1080 device driver. --- BUILDS.md | 1 + I2CDEVICES.md | 1 + tasmota/my_user_config.h | 2 + tasmota/support_command.ino | 29 --- tasmota/support_features.ino | 4 + tasmota/tasmota_post.h | 3 + tasmota/xsns_92_hdc1080.ino | 358 +++++++++++++++++++++++++++++++++++ tools/decode-status.py | 2 +- 8 files changed, 370 insertions(+), 30 deletions(-) create mode 100644 tasmota/xsns_92_hdc1080.ino diff --git a/BUILDS.md b/BUILDS.md index 53ebba456..18f25042b 100644 --- a/BUILDS.md +++ b/BUILDS.md @@ -113,6 +113,7 @@ | USE_DHT12 | - | - | - | - | x | - | - | | USE_DS1624 | - | - | - | - | x | - | - | | USE_AHT1x | - | - | - | - | - | - | - | +| USE_HDC1080 | - | - | - | - | - | - | - | | USE_WEMOS_MOTOR_V1 | - | - | - | - | x | - | - | | | | | | | | | | | Feature or Sensor | minimal | lite | tasmota | knx | sensors | ir | display | Remarks diff --git a/I2CDEVICES.md b/I2CDEVICES.md index f9cf5b0e3..2a89ba8aa 100644 --- a/I2CDEVICES.md +++ b/I2CDEVICES.md @@ -66,3 +66,4 @@ Index | Define | Driver | Device | Address(es) | Description 42 | USE_DS1624 | xsns_59 | DS1624 | 0x48 - 0x4F | Temperature sensor 43 | USE_AHT1x | xsns_63 | AHT10/15 | 0x38 | Temperature and humidity sensor 44 | USE_WEMOS_MOTOR_V1 | xdrv_34 | | 0x2D - 0x30 | WEMOS motor shield v1.0.0 (6612FNG) + 92 | USE_HDC1080 | xsns_92 | HDC1080 | 0x40 | Digital Humidity Sensor with Temperature Sensor diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index a62c6d191..40cbb5ce4 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -494,6 +494,8 @@ // #define USE_DS1624 // [I2cDriver42] Enable DS1624, DS1621 temperature sensor (I2C addresses 0x48 - 0x4F) (+1k2 code) // #define USE_AHT1x // [I2cDriver43] Enable AHT10/15 humidity and temperature sensor (I2C address 0x38) (+0k8 code) // #define USE_WEMOS_MOTOR_V1 // [I2cDriver44] Enable Wemos motor driver V1 (I2C addresses 0x2D - 0x30) (+0k7 code) +// #define USE_HDC1080 // [I2cDriver92] Enable HDC1080 temperature/humidity sensor + // #define WEMOS_MOTOR_V1_ADDR 0x30 // Default I2C address 0x30 // #define WEMOS_MOTOR_V1_FREQ 1000 // Default frequency diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index c881e5db1..43db86430 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -1113,35 +1113,6 @@ void CmndSwitchDebounce(void) ResponseCmndNumber(Settings.switch_debounce); } -/** - * Changes the Serial port number of bits, parity and stop bits. - * For the time being this command only has effect on the hardware - * serial port (GPIO1 and GPIO3) - * - * Meaning of the values: - * - * 0 - 7N1 (7 data bits / no parity / 1 stop bit) - * 1 - 7E1 (7 data bits / even parity / 1 stop bit) - * 2 - 8N1 (8 data bits / no parity / 1 stop bit) - * 3 - 8E1 (8 data bits / even parity / 1 stop bit) - * - */ - -void CmndSerialConfig(void) -{ - // a frugal validation to check if the provided serial port mode is valid: - - if (XdrvMailbox.payload >= 0 && XdrvMailbox.payload <= 3) { - uint8_t mode = (uint8_t) (XdrvMailbox.payload & 3); - - SetSerialConfig(mode); - } - - SerialCfg config = SettingToSerialCfg(Settings.serial_config); - - ResponseCmndNumber(config.mode); -} - void CmndBaudrate(void) { if (XdrvMailbox.payload >= 300) { diff --git a/tasmota/support_features.ino b/tasmota/support_features.ino index 961dd1091..906442f9e 100644 --- a/tasmota/support_features.ino +++ b/tasmota/support_features.ino @@ -257,6 +257,10 @@ void GetFeatures(void) #ifdef USE_HTU feature_sns1 |= 0x00000200; // xsns_08_htu21.ino #endif +// TODO not sure if is the correct feature setting for this sensor: +#ifdef USE_HDC1080 + feature_sns1 |= 0x00000200; // xsns_92_hdc1080.ino +#endif #ifdef USE_BMP feature_sns1 |= 0x00000400; // xsns_09_bmp.ino #endif diff --git a/tasmota/tasmota_post.h b/tasmota/tasmota_post.h index 7cf0fff75..119ec70e4 100644 --- a/tasmota/tasmota_post.h +++ b/tasmota/tasmota_post.h @@ -182,6 +182,9 @@ extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack #define USE_DHT12 // Add I2C code for DHT12 temperature and humidity sensor (+0k7 code) #define USE_DS1624 // Add I2C code for DS1624, DS1621 sensor //#define USE_AHT1x // Enable AHT10/15 humidity and temperature sensor (I2C address 0x38) (+0k8 code) +#define USE_HDC1080 // Enable HDC1080 temperature/humidity sensor + + #define USE_WEMOS_MOTOR_V1 // Enable Wemos motor driver V1 (I2C addresses 0x2D - 0x30) (+0k7 code) #define WEMOS_MOTOR_V1_ADDR 0x30 // Default I2C address 0x30 #define WEMOS_MOTOR_V1_FREQ 1000 // Default frequency diff --git a/tasmota/xsns_92_hdc1080.ino b/tasmota/xsns_92_hdc1080.ino new file mode 100644 index 000000000..7cfb9873e --- /dev/null +++ b/tasmota/xsns_92_hdc1080.ino @@ -0,0 +1,358 @@ +/* + xsns_92_hdc1080.ino - Texas Instruments HDC1080 temperature and humidity sensor support for Tasmota + + Copyright (C) 2020 Luis Teixeira + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_I2C +#ifdef USE_HDC1080 +/*********************************************************************************************\ + * HDC1080 - Temperature and Humidy sensor + * + * Source: Luis Teixeira + * + * I2C Address: 0x40 +\*********************************************************************************************/ + +#define XSNS_92 92 +#define XI2C_92 92 // See I2CDEVICES.md + +#define HDC1080_ADDR 0x40 + +// Registers: + +#define HDC_REG_TEMP 0x00 // Temperature register +#define HDC_REG_RH 0x01 // Humidity register +#define HDC_REG_CONFIG 0x02 // Configuration register +#define HDC_REG_SERIAL1 0xFB // First 2 bytes of the serial ID +#define HDC_REG_SERIAL2 0xFC // Mid 2 bytes of the serial ID +#define HDC_REG_SERIAL3 0xFD // Last bits of the serial ID +#define HDC_REG_MAN_ID 0xFE // Manufacturer ID +#define HDC_REG_DEV_ID 0xFF // Device ID + +// Expected constant values of some of the registers: + +#define HDC1080_MAN_ID 0x5449 // Manufacturer ID (Texas Instruments) +#define HDC1080_DEV_ID 0x1050 // Device ID (valid for the HDC1080) + +// Possible values for the configuration register fields: + +#define HDC1080_HEAT_OFF 0x00 +#define HDC1080_HEAT_ON 0x01 +#define HDC1080_ACQ_SEQ_ON 1 +#define HDC1080_ACQ_SEQ_OFF 0 +#define HDC1080_MEAS_RES_14 0x00 +#define HDC1080_MEAS_RES_11 0x01 +#define HDC1080_MEAS_RES_8 0x02 + +#define HDC1080_CONV_TIME 15 // Assume 6.50 + 6.35 ms + x of conversion delay for this device +#define HDC1080_TEMP_MULT 0.0025177 +#define HDC1080_RH_MULT 0.0025177 +#define HDC1080_TEMP_OFFSET 40 + +const char kHdcTypes[] PROGMEM = "HDC1080"; + +uint8_t hdc_address; +uint8_t hdc_type = 0; + +float hdc_temperature = 0; +float hdc_humidity = 0; +uint8_t hdc_valid = 0; +char hdc_types[1]; + +/** + * Reads the device ID register. + * + */ +uint16_t HdcReadDeviceId(void) { + uint16_t deviceID = 0; + + deviceID = I2cRead16(HDC1080_ADDR, HDC_REG_DEV_ID); + + return deviceID; +} + +/** + * Configures the acquisition mode of the sensor. The + * HDC1080 supports the acquisition of temperature + * and humidity in a single I2C transaction. + * + * MODE = 0 -> Temperature or Humidity is acquired. + * MODE = 1 -> Temperature and Humidity are acquired in sequence, Temperature first + * + */ +void HdcSetAcqMode(bool mode) { + uint16_t current = I2cRead16(HDC1080_ADDR, HDC_REG_CONFIG); + + // bit 12 of the register contains the MODE field + // so we shift our value to that position and + // apply the bit mask to preserve the remaining bits + // of the register: + + current &= (uint16_t) ((mode << 12) | 0xEFFF); + + I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); +} + +/** + * Configures the temperature sampling resolution of the sensor. + * + * This particular device provides two options: + * + * TRES = 0 -> 14 bit resolution + * TRES = 1 -> 11 bit resolution + * + */ +void HdcSetTemperatureResolution(uint8_t resolution) { + uint16_t current = I2cRead16(HDC1080_ADDR, HDC_REG_CONFIG); + + // bit 10 of the register contains the TRES field + // so we shift our value to that position and + // apply the bit mask to preserve the remaining bits + // of the register: + + current &= (uint16_t) ((resolution << 10) | 0xFBFF); + + I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); +} + +/** + * Configures the humidity sampling resolution of the sensor. + * + * This particular device provides three options: + * + * HRES = 0 -> 14 bit resolution + * HRES = 1 -> 11 bit resolution + * HRES = 2 -> 8 bit resolution + * + */ +void HdcSetHumidityResolution(uint8_t resolution) { + uint16_t current = I2cRead16(HDC1080_ADDR, HDC_REG_CONFIG); + + // bits 9:8 of the register contain the HRES field + // so we shift our value to that position and + // apply the bit mask to preserve the remaining bits + // of the register: + + current &= (uint16_t) ((resolution << 8) | 0xFCFF); + + I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); +} + +/** + * Performs a soft reset on the device. + * + * RST = 1 -> software reset + * + */ +void HdcReset(void) { + uint16_t current = I2cRead16(HDC1080_ADDR, HDC_REG_CONFIG); + + // bits 9:8 of the register contain the RST flag + // so we set it to 1: + + current |= 0x8000; + + I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); + + delay(15); // Not sure how long it takes to reset. Assuming 15ms +} + +/** + * Runs the heater in order to reduce the accumulated + * offset when the sensor is exposed for long periods + * at high humidity levels. + * + * HEAT = 0 -> heater off + * HEAT = 1 -> heater on + * + */ +void HdcHeater(uint8_t heater) { + uint16_t current = I2cRead16(HDC1080_ADDR, HDC_REG_CONFIG); + + // bits 13 of the register contain the HEAT flag + // so we set it according to the value of the heater argument: + + current &= (uint16_t) ((heater << 13) | 0xDFFF); + + I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); +} + +void HdcInit(void) +{ + HdcReset(); + HdcHeater(HDC1080_HEAT_OFF); + HdcSetAcqMode(HDC1080_ACQ_SEQ_ON); + HdcSetTemperatureResolution(HDC1080_MEAS_RES_14); + HdcSetHumidityResolution(HDC1080_MEAS_RES_14); +} + +/** + * Performs a temperature and humidity measurement, and calls + * the conversion function providing the results in the correct + * unit according to the device settings. + * + */ +bool HdcRead(void) { + int8_t status = 0; + uint16_t sensor_data[2]; + + // In this sensor we must start by performing a write to the + // temperature register. This signals the sensor to begin a + // measurement: + + // TODO initialize the measurement mode and + // read both registers in a single transaction: + + Wire.beginTransmission(HDC1080_ADDR); + Wire.write(HDC_REG_TEMP); + + if (Wire.endTransmission() != 0) { // In case of error + AddLog_P(LOG_LEVEL_DEBUG, PSTR("HdcRead: failed to write to device for performing acquisition.")); + + return false; + } + + delay(HDC1080_CONV_TIME); // Sensor time at max resolution + + // reads the temperature and humidity in a single transaction: + + status = I2cReadBuffer(HDC1080_ADDR, HDC_REG_TEMP, (uint8_t*) sensor_data, 4); + + if(status != 0) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: failed to read HDC_REG_TEMP. Status = %d"), status); + + return false; + } + + // read the temperature from the first 16 bits of the result + + hdc_temperature = ConvertTemp(HDC1080_TEMP_MULT * (float) (sensor_data[0]) - HDC1080_TEMP_OFFSET); + + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: temperature successfully converted. Value = %f"), hdc_temperature); + + // read the humidity from the last 16 bits of the result + + hdc_humidity = HDC1080_RH_MULT * (float) (sensor_data[1]); + + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: humidity successfully converted. Value = %f"), hdc_humidity); + + if (hdc_humidity > 100) { hdc_humidity = 100.0; } + + if (hdc_humidity < 0) { hdc_humidity = 0.01; } + + ConvertHumidity(hdc_humidity); // Set global humidity + + hdc_valid = SENSOR_MAX_MISS; + + return true; +} + +/********************************************************************************************/ + +void HdcDetect(void) +{ + hdc_address = HDC1080_ADDR; + + if (I2cActive(hdc_address)) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcDetect: Address = 0x%02X already in use."), hdc_address); + + return; + } + + hdc_type = HdcReadDeviceId(); + + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcDetect: detected device with id = 0x%04X"), hdc_type); + + if (hdc_type == HDC1080_DEV_ID) { + HdcInit(); + GetTextIndexed(hdc_types, sizeof(hdc_types), 0, kHdcTypes); + I2cSetActiveFound(hdc_address, hdc_types); + } +} + +void HdcEverySecond(void) { + if (uptime &1) { // Every 2 seconds + if (!HdcRead()) { + AddLogMissed(hdc_types, hdc_valid); + } + } +} + +void HdcShow(bool json) { + if (hdc_valid) { + char temperature[33]; + + dtostrfd(hdc_temperature, Settings.flag2.temperature_resolution, temperature); + char humidity[33]; + dtostrfd(hdc_humidity, Settings.flag2.humidity_resolution, humidity); + + if (json) { + ResponseAppend_P(JSON_SNS_TEMPHUM, hdc_type, temperature, humidity); +#ifdef USE_DOMOTICZ + if (0 == tele_period) { + DomoticzTempHumSensor(temperature, humidity); + } +#endif // USE_DOMOTICZ +#ifdef USE_KNX + if (0 == tele_period) { + KnxSensor(KNX_TEMPERATURE, hdc_temperature); + KnxSensor(KNX_HUMIDITY, hdc_humidity); + } +#endif // USE_KNX +#ifdef USE_WEBSERVER + } else { + WSContentSend_PD(HTTP_SNS_TEMP, hdc_types, temperature, TempUnit()); + WSContentSend_PD(HTTP_SNS_HUM, hdc_types, humidity); +#endif // USE_WEBSERVER + } + } +} + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +bool Xsns92(uint8_t function) +{ + if (!I2cEnabled(XI2C_92)) { return false; } + + bool result = false; + + if (FUNC_INIT == function) { + HdcDetect(); + } + else if (hdc_type) { + switch (function) { + case FUNC_EVERY_SECOND: + HdcEverySecond(); + break; + case FUNC_JSON_APPEND: + HdcShow(1); + break; +#ifdef USE_WEBSERVER + case FUNC_WEB_SENSOR: + HdcShow(0); + break; +#endif // USE_WEBSERVER + } + } + return result; +} + +#endif // USE_HDC1080 +#endif // USE_I2C + diff --git a/tools/decode-status.py b/tools/decode-status.py index fe80630cc..232cebc07 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -178,7 +178,7 @@ a_features = [[ "USE_INA219","USE_SHT3X","USE_MHZ19","USE_TSL2561", "USE_SENSEAIR","USE_PMS5003","USE_MGS","USE_NOVA_SDS", "USE_SGP30","USE_SR04","USE_SDM120","USE_SI1145", - "USE_SDM630","USE_LM75AD","USE_APDS9960","USE_TM1638" + "USE_SDM630","USE_LM75AD","USE_APDS9960","USE_TM1638", "USE_HDC1080" ],[ "USE_MCP230xx","USE_MPR121","USE_CCS811","USE_MPU6050", "USE_MCP230xx_OUTPUT","USE_MCP230xx_DISPLAYOUTPUT","USE_HLW8012","USE_CSE7766", From cb2cc9bbb182335408ce4655afc6476d65867759 Mon Sep 17 00:00:00 2001 From: Luis Teixeira Date: Mon, 9 Mar 2020 23:02:03 +0000 Subject: [PATCH 05/17] More intermediate changes and troubleshooting. --- tasmota/support_features.ino | 9 +- tasmota/xsns_92_hdc1080.ino | 188 +++++++++++++++++++++-------------- 2 files changed, 116 insertions(+), 81 deletions(-) diff --git a/tasmota/support_features.ino b/tasmota/support_features.ino index 906442f9e..213219621 100644 --- a/tasmota/support_features.ino +++ b/tasmota/support_features.ino @@ -257,10 +257,6 @@ void GetFeatures(void) #ifdef USE_HTU feature_sns1 |= 0x00000200; // xsns_08_htu21.ino #endif -// TODO not sure if is the correct feature setting for this sensor: -#ifdef USE_HDC1080 - feature_sns1 |= 0x00000200; // xsns_92_hdc1080.ino -#endif #ifdef USE_BMP feature_sns1 |= 0x00000400; // xsns_09_bmp.ino #endif @@ -327,7 +323,10 @@ void GetFeatures(void) #ifdef USE_TM1638 feature_sns1 |= 0x80000000; // xsns_28_tm1638.ino #endif - +// TODO not sure if is the correct feature setting for this sensor: +#ifdef USE_HDC1080 + feature_sns1 |= 0x00000200; // xsns_92_hdc1080.ino +#endif /*********************************************************************************************/ feature_sns2 = 0x00000000; diff --git a/tasmota/xsns_92_hdc1080.ino b/tasmota/xsns_92_hdc1080.ino index 7cfb9873e..24a714055 100644 --- a/tasmota/xsns_92_hdc1080.ino +++ b/tasmota/xsns_92_hdc1080.ino @@ -50,41 +50,47 @@ // Possible values for the configuration register fields: -#define HDC1080_HEAT_OFF 0x00 -#define HDC1080_HEAT_ON 0x01 -#define HDC1080_ACQ_SEQ_ON 1 -#define HDC1080_ACQ_SEQ_OFF 0 -#define HDC1080_MEAS_RES_14 0x00 -#define HDC1080_MEAS_RES_11 0x01 -#define HDC1080_MEAS_RES_8 0x02 +#define HDC1080_RST_ON 0x8000 +#define HDC1080_HEAT_ON 0x2000 +#define HDC1080_MODE_ON 0x1000 // acquision mode (temperature + humidity) +#define HDC1080_TRES_11 0x400 +#define HDC1080_HRES_11 0x100 +#define HDC1080_HRES_8 0x80 -#define HDC1080_CONV_TIME 15 // Assume 6.50 + 6.35 ms + x of conversion delay for this device +// Constants: + +#define HDC1080_CONV_TIME 25 // Assume 6.50 + 6.35 ms + x of conversion delay for this device #define HDC1080_TEMP_MULT 0.0025177 #define HDC1080_RH_MULT 0.0025177 -#define HDC1080_TEMP_OFFSET 40 - -const char kHdcTypes[] PROGMEM = "HDC1080"; +#define HDC1080_TEMP_OFFSET 40.0 +const char* hdc_type_name = "HDC1080"; uint8_t hdc_address; -uint8_t hdc_type = 0; +uint16_t hdc_manufacturer_id = 0; +uint16_t hdc_device_id = 0; + +float hdc_temperature = 0.0; +float hdc_humidity = 0.0; -float hdc_temperature = 0; -float hdc_humidity = 0; uint8_t hdc_valid = 0; -char hdc_types[1]; /** * Reads the device ID register. * */ uint16_t HdcReadDeviceId(void) { - uint16_t deviceID = 0; - - deviceID = I2cRead16(HDC1080_ADDR, HDC_REG_DEV_ID); - - return deviceID; + return I2cRead16(HDC1080_ADDR, HDC_REG_DEV_ID); } +/** + * Reads the manufacturer ID register. + * + */ +uint16_t HdcReadManufacturerId(void) { + return I2cRead16(HDC1080_ADDR, HDC_REG_MAN_ID); +} + + /** * Configures the acquisition mode of the sensor. The * HDC1080 supports the acquisition of temperature @@ -94,7 +100,7 @@ uint16_t HdcReadDeviceId(void) { * MODE = 1 -> Temperature and Humidity are acquired in sequence, Temperature first * */ -void HdcSetAcqMode(bool mode) { +void HdcSetAcqMode(uint8_t mode) { uint16_t current = I2cRead16(HDC1080_ADDR, HDC_REG_CONFIG); // bit 12 of the register contains the MODE field @@ -102,7 +108,7 @@ void HdcSetAcqMode(bool mode) { // apply the bit mask to preserve the remaining bits // of the register: - current &= (uint16_t) ((mode << 12) | 0xEFFF); + current = (current & 0xEFFF) | ((uint16_t) (mode << 12)); I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); } @@ -124,7 +130,7 @@ void HdcSetTemperatureResolution(uint8_t resolution) { // apply the bit mask to preserve the remaining bits // of the register: - current &= (uint16_t) ((resolution << 10) | 0xFBFF); + current = (current & 0xFBFF) | ((uint16_t) (resolution << 10)); I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); } @@ -147,30 +153,11 @@ void HdcSetHumidityResolution(uint8_t resolution) { // apply the bit mask to preserve the remaining bits // of the register: - current &= (uint16_t) ((resolution << 8) | 0xFCFF); + current = (current & 0xFCFF) | ((uint16_t) (resolution << 8)); I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); } -/** - * Performs a soft reset on the device. - * - * RST = 1 -> software reset - * - */ -void HdcReset(void) { - uint16_t current = I2cRead16(HDC1080_ADDR, HDC_REG_CONFIG); - - // bits 9:8 of the register contain the RST flag - // so we set it to 1: - - current |= 0x8000; - - I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); - - delay(15); // Not sure how long it takes to reset. Assuming 15ms -} - /** * Runs the heater in order to reduce the accumulated * offset when the sensor is exposed for long periods @@ -183,21 +170,54 @@ void HdcReset(void) { void HdcHeater(uint8_t heater) { uint16_t current = I2cRead16(HDC1080_ADDR, HDC_REG_CONFIG); - // bits 13 of the register contain the HEAT flag + // bits 13 of the configuration register contains the HEAT flag // so we set it according to the value of the heater argument: - current &= (uint16_t) ((heater << 13) | 0xDFFF); + current = (current | 0xDFFF) | ((uint16_t) (heater << 13)); I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); } -void HdcInit(void) -{ +/** + * Overwrites the configuration register with the provided config + */ +void HdcConfig(uint16_t config) { + I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, config); +} + +/** + * Performs a soft reset on the device. + * + * RST = 1 -> software reset + * + */ +void HdcReset(void) { + uint16_t current = I2cRead16(HDC1080_ADDR, HDC_REG_CONFIG); + + // bit 15 of the configuration register contains the RST flag + // so we set it to 1: + + current |= 0x8000; + + I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); + + delay(30); // Not sure how long it takes to reset. Assuming 15ms +} + + +/** + * The various initialization steps for this sensor. + * + */ +void HdcInit(void) { HdcReset(); - HdcHeater(HDC1080_HEAT_OFF); - HdcSetAcqMode(HDC1080_ACQ_SEQ_ON); - HdcSetTemperatureResolution(HDC1080_MEAS_RES_14); - HdcSetHumidityResolution(HDC1080_MEAS_RES_14); + //HdcHeater(HDC1080_HEAT_OFF); + //HdcSetAcqMode(HDC1080_ACQ_SEQ_ON); + //HdcSetAcqMode(HDC1080_ACQ_SEQ_OFF); + //HdcSetTemperatureResolution(HDC1080_MEAS_RES_14); + //HdcSetHumidityResolution(HDC1080_MEAS_RES_14); + + HdcConfig(0); } /** @@ -208,15 +228,14 @@ void HdcInit(void) */ bool HdcRead(void) { int8_t status = 0; - uint16_t sensor_data[2]; + //uint16_t sensor_data[2]; + + uint16_t sensor_data = 0; // In this sensor we must start by performing a write to the // temperature register. This signals the sensor to begin a // measurement: - // TODO initialize the measurement mode and - // read both registers in a single transaction: - Wire.beginTransmission(HDC1080_ADDR); Wire.write(HDC_REG_TEMP); @@ -226,32 +245,46 @@ bool HdcRead(void) { return false; } - delay(HDC1080_CONV_TIME); // Sensor time at max resolution + delay(HDC1080_CONV_TIME); // Apply sensor conversion time at max resolution // reads the temperature and humidity in a single transaction: - status = I2cReadBuffer(HDC1080_ADDR, HDC_REG_TEMP, (uint8_t*) sensor_data, 4); + //status = I2cReadBuffer(HDC1080_ADDR, HDC_REG_TEMP, (uint8_t*) sensor_data, 4); + sensor_data = I2cRead16(HDC1080_ADDR, HDC_REG_TEMP); + + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: temperature raw data: 0x%04x"), sensor_data); + + // status = I2cReadBuffer(HDC1080_ADDR, HDC_REG_TEMP, (uint8_t*) &sensor_data, 2); + +/* if(status != 0) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: failed to read HDC_REG_TEMP. Status = %d"), status); return false; } - +*/ // read the temperature from the first 16 bits of the result - hdc_temperature = ConvertTemp(HDC1080_TEMP_MULT * (float) (sensor_data[0]) - HDC1080_TEMP_OFFSET); + //hdc_temperature = ConvertTemp(HDC1080_TEMP_MULT * (float) (sensor_data[0]) - HDC1080_TEMP_OFFSET); - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: temperature successfully converted. Value = %f"), hdc_temperature); + hdc_temperature = ConvertTemp(HDC1080_TEMP_MULT * (float) (sensor_data) - HDC1080_TEMP_OFFSET); + + //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: temperature successfully converted. Value = %f"), hdc_temperature); // read the humidity from the last 16 bits of the result - hdc_humidity = HDC1080_RH_MULT * (float) (sensor_data[1]); + sensor_data = I2cRead16(HDC1080_ADDR, HDC_REG_RH); - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: humidity successfully converted. Value = %f"), hdc_humidity); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: humidity raw data: 0x%04x"), sensor_data); + + //hdc_humidity = HDC1080_RH_MULT * (float) (sensor_data[1]); + + hdc_humidity = HDC1080_RH_MULT * (float) (sensor_data); + + //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: humidity successfully converted. Value = %f"), hdc_humidity); if (hdc_humidity > 100) { hdc_humidity = 100.0; } - if (hdc_humidity < 0) { hdc_humidity = 0.01; } ConvertHumidity(hdc_humidity); // Set global humidity @@ -263,8 +296,7 @@ bool HdcRead(void) { /********************************************************************************************/ -void HdcDetect(void) -{ +void HdcDetect(void) { hdc_address = HDC1080_ADDR; if (I2cActive(hdc_address)) { @@ -273,21 +305,21 @@ void HdcDetect(void) return; } - hdc_type = HdcReadDeviceId(); + hdc_manufacturer_id = HdcReadManufacturerId(); + hdc_device_id = HdcReadDeviceId(); - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcDetect: detected device with id = 0x%04X"), hdc_type); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcDetect: detected device with manufacturerId = 0x%04X and deviceId = 0x%04X"), hdc_manufacturer_id, hdc_device_id); - if (hdc_type == HDC1080_DEV_ID) { + if (hdc_device_id == HDC1080_DEV_ID) { HdcInit(); - GetTextIndexed(hdc_types, sizeof(hdc_types), 0, kHdcTypes); - I2cSetActiveFound(hdc_address, hdc_types); + I2cSetActiveFound(hdc_address, hdc_type_name); } } void HdcEverySecond(void) { if (uptime &1) { // Every 2 seconds if (!HdcRead()) { - AddLogMissed(hdc_types, hdc_valid); + AddLogMissed((char*) hdc_type_name, hdc_valid); } } } @@ -301,7 +333,7 @@ void HdcShow(bool json) { dtostrfd(hdc_humidity, Settings.flag2.humidity_resolution, humidity); if (json) { - ResponseAppend_P(JSON_SNS_TEMPHUM, hdc_type, temperature, humidity); + ResponseAppend_P(JSON_SNS_TEMPHUM, hdc_device_id, temperature, humidity); #ifdef USE_DOMOTICZ if (0 == tele_period) { DomoticzTempHumSensor(temperature, humidity); @@ -315,8 +347,8 @@ void HdcShow(bool json) { #endif // USE_KNX #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TEMP, hdc_types, temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, hdc_types, humidity); + WSContentSend_PD(HTTP_SNS_TEMP, hdc_type_name, temperature, TempUnit()); + WSContentSend_PD(HTTP_SNS_HUM, hdc_type_name, humidity); #endif // USE_WEBSERVER } } @@ -328,14 +360,18 @@ void HdcShow(bool json) { bool Xsns92(uint8_t function) { - if (!I2cEnabled(XI2C_92)) { return false; } + if (!I2cEnabled(XI2C_92)) { + AddLog_P(LOG_LEVEL_DEBUG, PSTR("Xsns92: I2C driver not enabled for this device.")); + + return false; + } bool result = false; if (FUNC_INIT == function) { HdcDetect(); } - else if (hdc_type) { + else if (hdc_device_id) { switch (function) { case FUNC_EVERY_SECOND: HdcEverySecond(); From 2a06a6bc5a1949fd92a578dd55d6f2819c37fa2e Mon Sep 17 00:00:00 2001 From: Luis Teixeira Date: Tue, 10 Mar 2020 00:15:42 +0000 Subject: [PATCH 06/17] Fixed issue when reading temperature and humidity in the same transaction. --- tasmota/xsns_92_hdc1080.ino | 192 ++++++++---------------------------- 1 file changed, 43 insertions(+), 149 deletions(-) diff --git a/tasmota/xsns_92_hdc1080.ino b/tasmota/xsns_92_hdc1080.ino index 24a714055..d1a5175b0 100644 --- a/tasmota/xsns_92_hdc1080.ino +++ b/tasmota/xsns_92_hdc1080.ino @@ -59,13 +59,13 @@ // Constants: -#define HDC1080_CONV_TIME 25 // Assume 6.50 + 6.35 ms + x of conversion delay for this device +#define HDC1080_CONV_TIME 50 // Assume 6.50 + 6.35 ms + x of conversion delay for this device #define HDC1080_TEMP_MULT 0.0025177 #define HDC1080_RH_MULT 0.0025177 #define HDC1080_TEMP_OFFSET 40.0 -const char* hdc_type_name = "HDC1080"; -uint8_t hdc_address; + +char* hdc_type_name = "HDC1080"; uint16_t hdc_manufacturer_id = 0; uint16_t hdc_device_id = 0; @@ -90,94 +90,6 @@ uint16_t HdcReadManufacturerId(void) { return I2cRead16(HDC1080_ADDR, HDC_REG_MAN_ID); } - -/** - * Configures the acquisition mode of the sensor. The - * HDC1080 supports the acquisition of temperature - * and humidity in a single I2C transaction. - * - * MODE = 0 -> Temperature or Humidity is acquired. - * MODE = 1 -> Temperature and Humidity are acquired in sequence, Temperature first - * - */ -void HdcSetAcqMode(uint8_t mode) { - uint16_t current = I2cRead16(HDC1080_ADDR, HDC_REG_CONFIG); - - // bit 12 of the register contains the MODE field - // so we shift our value to that position and - // apply the bit mask to preserve the remaining bits - // of the register: - - current = (current & 0xEFFF) | ((uint16_t) (mode << 12)); - - I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); -} - -/** - * Configures the temperature sampling resolution of the sensor. - * - * This particular device provides two options: - * - * TRES = 0 -> 14 bit resolution - * TRES = 1 -> 11 bit resolution - * - */ -void HdcSetTemperatureResolution(uint8_t resolution) { - uint16_t current = I2cRead16(HDC1080_ADDR, HDC_REG_CONFIG); - - // bit 10 of the register contains the TRES field - // so we shift our value to that position and - // apply the bit mask to preserve the remaining bits - // of the register: - - current = (current & 0xFBFF) | ((uint16_t) (resolution << 10)); - - I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); -} - -/** - * Configures the humidity sampling resolution of the sensor. - * - * This particular device provides three options: - * - * HRES = 0 -> 14 bit resolution - * HRES = 1 -> 11 bit resolution - * HRES = 2 -> 8 bit resolution - * - */ -void HdcSetHumidityResolution(uint8_t resolution) { - uint16_t current = I2cRead16(HDC1080_ADDR, HDC_REG_CONFIG); - - // bits 9:8 of the register contain the HRES field - // so we shift our value to that position and - // apply the bit mask to preserve the remaining bits - // of the register: - - current = (current & 0xFCFF) | ((uint16_t) (resolution << 8)); - - I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); -} - -/** - * Runs the heater in order to reduce the accumulated - * offset when the sensor is exposed for long periods - * at high humidity levels. - * - * HEAT = 0 -> heater off - * HEAT = 1 -> heater on - * - */ -void HdcHeater(uint8_t heater) { - uint16_t current = I2cRead16(HDC1080_ADDR, HDC_REG_CONFIG); - - // bits 13 of the configuration register contains the HEAT flag - // so we set it according to the value of the heater argument: - - current = (current | 0xDFFF) | ((uint16_t) (heater << 13)); - - I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); -} - /** * Overwrites the configuration register with the provided config */ @@ -201,9 +113,32 @@ void HdcReset(void) { I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); - delay(30); // Not sure how long it takes to reset. Assuming 15ms + delay(HDC1080_CONV_TIME); // Not sure how long it takes to reset. Assuming this value. } +/** + * Performs the single transaction read of the HDC1080, providing the + * adequate delay for the acquisition. + * + */ +int8_t HdcReadBuffer(uint8_t addr, uint8_t reg, uint8_t *reg_data, uint16_t len) { + Wire.beginTransmission((uint8_t)addr); + Wire.write((uint8_t)reg); + Wire.endTransmission(); + + delay(HDC1080_CONV_TIME); + + if (len != Wire.requestFrom((uint8_t)addr, (uint8_t)len)) { + return 1; + } + + while (len--) { + *reg_data = (uint8_t)Wire.read(); + reg_data++; + } + + return 0; +} /** * The various initialization steps for this sensor. @@ -211,13 +146,7 @@ void HdcReset(void) { */ void HdcInit(void) { HdcReset(); - //HdcHeater(HDC1080_HEAT_OFF); - //HdcSetAcqMode(HDC1080_ACQ_SEQ_ON); - //HdcSetAcqMode(HDC1080_ACQ_SEQ_OFF); - //HdcSetTemperatureResolution(HDC1080_MEAS_RES_14); - //HdcSetHumidityResolution(HDC1080_MEAS_RES_14); - - HdcConfig(0); + HdcConfig(HDC1080_MODE_ON); } /** @@ -228,61 +157,28 @@ void HdcInit(void) { */ bool HdcRead(void) { int8_t status = 0; - //uint16_t sensor_data[2]; + uint8_t sensor_data[4]; + uint16_t temp_data = 0; + uint16_t rh_data = 0; - uint16_t sensor_data = 0; + status = HdcReadBuffer(HDC1080_ADDR, HDC_REG_TEMP, sensor_data, 4); - // In this sensor we must start by performing a write to the - // temperature register. This signals the sensor to begin a - // measurement: + temp_data = (uint16_t) ((sensor_data[0] << 8) | sensor_data[1]); + rh_data = (uint16_t) ((sensor_data[2] << 8) | sensor_data[3]); - Wire.beginTransmission(HDC1080_ADDR); - Wire.write(HDC_REG_TEMP); - - if (Wire.endTransmission() != 0) { // In case of error - AddLog_P(LOG_LEVEL_DEBUG, PSTR("HdcRead: failed to write to device for performing acquisition.")); - - return false; - } - - delay(HDC1080_CONV_TIME); // Apply sensor conversion time at max resolution - - // reads the temperature and humidity in a single transaction: - - //status = I2cReadBuffer(HDC1080_ADDR, HDC_REG_TEMP, (uint8_t*) sensor_data, 4); - - sensor_data = I2cRead16(HDC1080_ADDR, HDC_REG_TEMP); - - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: temperature raw data: 0x%04x"), sensor_data); - - // status = I2cReadBuffer(HDC1080_ADDR, HDC_REG_TEMP, (uint8_t*) &sensor_data, 2); - -/* + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: temperature raw data: 0x%04x; humidity raw data: 0x%04x"), temp_data, rh_data); + if(status != 0) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: failed to read HDC_REG_TEMP. Status = %d"), status); return false; } -*/ + // read the temperature from the first 16 bits of the result - //hdc_temperature = ConvertTemp(HDC1080_TEMP_MULT * (float) (sensor_data[0]) - HDC1080_TEMP_OFFSET); + hdc_temperature = ConvertTemp(HDC1080_TEMP_MULT * (float) (temp_data) - HDC1080_TEMP_OFFSET); - hdc_temperature = ConvertTemp(HDC1080_TEMP_MULT * (float) (sensor_data) - HDC1080_TEMP_OFFSET); - - //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: temperature successfully converted. Value = %f"), hdc_temperature); - - // read the humidity from the last 16 bits of the result - - sensor_data = I2cRead16(HDC1080_ADDR, HDC_REG_RH); - - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: humidity raw data: 0x%04x"), sensor_data); - - //hdc_humidity = HDC1080_RH_MULT * (float) (sensor_data[1]); - - hdc_humidity = HDC1080_RH_MULT * (float) (sensor_data); - - //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: humidity successfully converted. Value = %f"), hdc_humidity); + hdc_humidity = HDC1080_RH_MULT * (float) (rh_data); if (hdc_humidity > 100) { hdc_humidity = 100.0; } if (hdc_humidity < 0) { hdc_humidity = 0.01; } @@ -297,10 +193,8 @@ bool HdcRead(void) { /********************************************************************************************/ void HdcDetect(void) { - hdc_address = HDC1080_ADDR; - - if (I2cActive(hdc_address)) { - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcDetect: Address = 0x%02X already in use."), hdc_address); + if (I2cActive(HDC1080_ADDR)) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcDetect: Address = 0x%02X already in use."), HDC1080_ADDR); return; } @@ -312,14 +206,14 @@ void HdcDetect(void) { if (hdc_device_id == HDC1080_DEV_ID) { HdcInit(); - I2cSetActiveFound(hdc_address, hdc_type_name); + I2cSetActiveFound(HDC1080_ADDR, hdc_type_name); } } void HdcEverySecond(void) { if (uptime &1) { // Every 2 seconds if (!HdcRead()) { - AddLogMissed((char*) hdc_type_name, hdc_valid); + AddLogMissed(hdc_type_name, hdc_valid); } } } From e9d201a2c3af9d34aa62fd258d9806e008467683 Mon Sep 17 00:00:00 2001 From: Luis Teixeira Date: Tue, 10 Mar 2020 00:26:24 +0000 Subject: [PATCH 07/17] Fixed issue during the call to ResponseAppend_P (was passing a primitive instead of pointer to the expected string) --- tasmota/xsns_92_hdc1080.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/xsns_92_hdc1080.ino b/tasmota/xsns_92_hdc1080.ino index d1a5175b0..1e045c9a8 100644 --- a/tasmota/xsns_92_hdc1080.ino +++ b/tasmota/xsns_92_hdc1080.ino @@ -227,7 +227,7 @@ void HdcShow(bool json) { dtostrfd(hdc_humidity, Settings.flag2.humidity_resolution, humidity); if (json) { - ResponseAppend_P(JSON_SNS_TEMPHUM, hdc_device_id, temperature, humidity); + ResponseAppend_P(JSON_SNS_TEMPHUM, hdc_type_name, temperature, humidity); #ifdef USE_DOMOTICZ if (0 == tele_period) { DomoticzTempHumSensor(temperature, humidity); From 725b9898c5309c1738c429b76b9a57d351301ee5 Mon Sep 17 00:00:00 2001 From: Luis Teixeira Date: Tue, 10 Mar 2020 22:53:49 +0000 Subject: [PATCH 08/17] Added cast to properly deal with the AddLogMissed function prototype. --- tasmota/xsns_92_hdc1080.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasmota/xsns_92_hdc1080.ino b/tasmota/xsns_92_hdc1080.ino index 1e045c9a8..f5cd385b1 100644 --- a/tasmota/xsns_92_hdc1080.ino +++ b/tasmota/xsns_92_hdc1080.ino @@ -65,7 +65,7 @@ #define HDC1080_TEMP_OFFSET 40.0 -char* hdc_type_name = "HDC1080"; +const char* hdc_type_name = "HDC1080"; uint16_t hdc_manufacturer_id = 0; uint16_t hdc_device_id = 0; @@ -213,7 +213,7 @@ void HdcDetect(void) { void HdcEverySecond(void) { if (uptime &1) { // Every 2 seconds if (!HdcRead()) { - AddLogMissed(hdc_type_name, hdc_valid); + AddLogMissed((char*) hdc_type_name, hdc_valid); } } } From 78a608dd449f349cae56f15c5554892954bd0c15 Mon Sep 17 00:00:00 2001 From: Luis Teixeira Date: Tue, 10 Mar 2020 23:01:51 +0000 Subject: [PATCH 09/17] Synched with resources from original repo --- tasmota/i18n.h | 1 - tasmota/language/bg-BG.h | 1 - tasmota/language/cs-CZ.h | 1 - tasmota/language/de-DE.h | 1 - tasmota/language/el-GR.h | 1 - tasmota/language/en-GB.h | 1 - tasmota/language/es-ES.h | 1 - tasmota/language/fr-FR.h | 1 - tasmota/language/he-HE.h | 1 - tasmota/language/hu-HU.h | 1 - tasmota/language/it-IT.h | 1 - tasmota/language/ko-KO.h | 1 - tasmota/language/nl-NL.h | 1 - tasmota/language/pl-PL.h | 1 - tasmota/language/pt-BR.h | 1 - tasmota/language/pt-PT.h | 1 - tasmota/language/ru-RU.h | 1 - tasmota/language/sk-SK.h | 1 - tasmota/language/sv-SE.h | 1 - tasmota/language/tr-TR.h | 1 - tasmota/language/uk-UA.h | 1 - tasmota/language/zh-CN.h | 1 - tasmota/language/zh-TW.h | 1 - 23 files changed, 23 deletions(-) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 09485cff6..f36f37977 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -295,7 +295,6 @@ #define D_CMND_DEVGROUP_SHARE "DevGroupShare" #define D_CMND_SERIALSEND "SerialSend" #define D_CMND_SERIALDELIMITER "SerialDelimiter" -#define D_CMND_SERIALCONFIG "SerialConfig" #define D_CMND_BAUDRATE "Baudrate" #define D_CMND_SERIALCONFIG "SerialConfig" #define D_CMND_TEMPLATE "Template" diff --git a/tasmota/language/bg-BG.h b/tasmota/language/bg-BG.h index 589e74a90..9323c9174 100644 --- a/tasmota/language/bg-BG.h +++ b/tasmota/language/bg-BG.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Системният лог активиран" #define D_SET_BAUDRATE_TO "Задаване скорост на предаване (Baudrate)" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Получен топик" #define D_DATA_SIZE "Размер на данните" #define D_ANALOG_INPUT "Аналогов вход" diff --git a/tasmota/language/cs-CZ.h b/tasmota/language/cs-CZ.h index d663724b7..6303708de 100644 --- a/tasmota/language/cs-CZ.h +++ b/tasmota/language/cs-CZ.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Obnoven zápis do Syslog" #define D_SET_BAUDRATE_TO "Nastavení rychlosti přenosu na" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Přijatý topic" #define D_DATA_SIZE "Velikost dat" #define D_ANALOG_INPUT "Analogový vstup" diff --git a/tasmota/language/de-DE.h b/tasmota/language/de-DE.h index 7f59a6b16..8cf6d8def 100644 --- a/tasmota/language/de-DE.h +++ b/tasmota/language/de-DE.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog-Logging aktiviert" #define D_SET_BAUDRATE_TO "Setze Baudrate auf" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "empfangenes topic" #define D_DATA_SIZE "Datengröße" #define D_ANALOG_INPUT "Analog" diff --git a/tasmota/language/el-GR.h b/tasmota/language/el-GR.h index ddd34c944..4a59d87b8 100644 --- a/tasmota/language/el-GR.h +++ b/tasmota/language/el-GR.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Η καταγραφή Syslog επαναενεργοποιήθηκε" #define D_SET_BAUDRATE_TO "Ορισμός Baudrate σε" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Received Topic" #define D_DATA_SIZE "Μέγεθος δεδομένων" #define D_ANALOG_INPUT "Αναλογικό" diff --git a/tasmota/language/en-GB.h b/tasmota/language/en-GB.h index c10378d94..e28e153e9 100644 --- a/tasmota/language/en-GB.h +++ b/tasmota/language/en-GB.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog logging re-enabled" #define D_SET_BAUDRATE_TO "Set Baudrate to" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Received Topic" #define D_DATA_SIZE "Data Size" #define D_ANALOG_INPUT "Analog" diff --git a/tasmota/language/es-ES.h b/tasmota/language/es-ES.h index dde47b382..69c91c693 100644 --- a/tasmota/language/es-ES.h +++ b/tasmota/language/es-ES.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog re-habilitado" #define D_SET_BAUDRATE_TO "Baudrate a" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Topic Recibido" #define D_DATA_SIZE "Tamaño de Datos" #define D_ANALOG_INPUT "Entrada Analógica" diff --git a/tasmota/language/fr-FR.h b/tasmota/language/fr-FR.h index 243ae74c3..8b71a8067 100644 --- a/tasmota/language/fr-FR.h +++ b/tasmota/language/fr-FR.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Jounalisation SysLog réactivée" #define D_SET_BAUDRATE_TO "Définir le débit à" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Topic reçu" // Terme MQTT #define D_DATA_SIZE "Taille données" #define D_ANALOG_INPUT "Analogique" diff --git a/tasmota/language/he-HE.h b/tasmota/language/he-HE.h index 87614e04f..09a803be6 100644 --- a/tasmota/language/he-HE.h +++ b/tasmota/language/he-HE.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "הופעל מחדש Syslog רישום" #define D_SET_BAUDRATE_TO "הגדר קצב שידור ל" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Topic התקבל" #define D_DATA_SIZE "גודל נתונים" #define D_ANALOG_INPUT "אנלוגי" diff --git a/tasmota/language/hu-HU.h b/tasmota/language/hu-HU.h index 280a617f7..551d81014 100644 --- a/tasmota/language/hu-HU.h +++ b/tasmota/language/hu-HU.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog logolás újraengedélyezve" #define D_SET_BAUDRATE_TO "Baudrate beállítása" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Érkezett topic" #define D_DATA_SIZE "Adatméret" #define D_ANALOG_INPUT "Analóg" diff --git a/tasmota/language/it-IT.h b/tasmota/language/it-IT.h index d52b9de02..e23c86757 100644 --- a/tasmota/language/it-IT.h +++ b/tasmota/language/it-IT.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog ri-abilitato" #define D_SET_BAUDRATE_TO "Baudrate impostato a" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Topic Ricevuto" #define D_DATA_SIZE "Dimensione Dati" #define D_ANALOG_INPUT "Ingresso Analogico" diff --git a/tasmota/language/ko-KO.h b/tasmota/language/ko-KO.h index 5c015f09b..ddc815de5 100644 --- a/tasmota/language/ko-KO.h +++ b/tasmota/language/ko-KO.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog log 다시 사용" #define D_SET_BAUDRATE_TO "Set Baudrate to" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Received Topic" #define D_DATA_SIZE "데이터 용량" #define D_ANALOG_INPUT "아날로그" diff --git a/tasmota/language/nl-NL.h b/tasmota/language/nl-NL.h index 624bef70f..46e29e1fd 100644 --- a/tasmota/language/nl-NL.h +++ b/tasmota/language/nl-NL.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog logging weer ingeschakeld" #define D_SET_BAUDRATE_TO "Zet baudrate op" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Ontvangen topic" #define D_DATA_SIZE "Data lengte" #define D_ANALOG_INPUT "Analoog" diff --git a/tasmota/language/pl-PL.h b/tasmota/language/pl-PL.h index a7fa58199..2a75d6f46 100644 --- a/tasmota/language/pl-PL.h +++ b/tasmota/language/pl-PL.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Wznowiono zapis do Syslog" #define D_SET_BAUDRATE_TO "Ustaw szybkość transmisji na" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Otrzymany temat" #define D_DATA_SIZE "Wielkość danych" #define D_ANALOG_INPUT "Wejście analogowe" diff --git a/tasmota/language/pt-BR.h b/tasmota/language/pt-BR.h index 9d6daa244..f1b8fdbc5 100644 --- a/tasmota/language/pt-BR.h +++ b/tasmota/language/pt-BR.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Registro do Syslog reativado" #define D_SET_BAUDRATE_TO "Ajuste da velocidade para" -#define D_SET_SERIAL_CONFIG_TO "Ajuste do modo da porta série" #define D_RECEIVED_TOPIC "Tópico recebido" #define D_DATA_SIZE "Tamanho de dados" #define D_ANALOG_INPUT "Entrada analógica" diff --git a/tasmota/language/pt-PT.h b/tasmota/language/pt-PT.h index d7260ca6a..36188994d 100644 --- a/tasmota/language/pt-PT.h +++ b/tasmota/language/pt-PT.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Registro do Syslog reativado" #define D_SET_BAUDRATE_TO "Ajuste da velocidade para" -#define D_SET_SERIAL_CONFIG_TO "Ajuste do modo da porta série" #define D_RECEIVED_TOPIC "Topico Recebido" #define D_DATA_SIZE "Tamanho de Dados" #define D_ANALOG_INPUT "Entrada Analógica" diff --git a/tasmota/language/ru-RU.h b/tasmota/language/ru-RU.h index ed3fe87be..5690f9209 100644 --- a/tasmota/language/ru-RU.h +++ b/tasmota/language/ru-RU.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog logging включен" #define D_SET_BAUDRATE_TO "Установить скорость передачи (Baudrate)" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Полученный Топик" #define D_DATA_SIZE "Размер данных" #define D_ANALOG_INPUT "Аналоговый вход" diff --git a/tasmota/language/sk-SK.h b/tasmota/language/sk-SK.h index 585052498..b7bd30f25 100644 --- a/tasmota/language/sk-SK.h +++ b/tasmota/language/sk-SK.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Obnovený zápis do Syslog" #define D_SET_BAUDRATE_TO "Nastaviť rýchlosti prenosu na" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Prijatý topic" #define D_DATA_SIZE "Veľkosť dát" #define D_ANALOG_INPUT "Analógový vstup" diff --git a/tasmota/language/sv-SE.h b/tasmota/language/sv-SE.h index 58ea66d3b..483633ae1 100644 --- a/tasmota/language/sv-SE.h +++ b/tasmota/language/sv-SE.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog återaktiverad" #define D_SET_BAUDRATE_TO "Ange Baudrate till" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Mottaget ämne" #define D_DATA_SIZE "Datastorlek" #define D_ANALOG_INPUT "Analog" diff --git a/tasmota/language/tr-TR.h b/tasmota/language/tr-TR.h index e92a9584b..62990d5aa 100644 --- a/tasmota/language/tr-TR.h +++ b/tasmota/language/tr-TR.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Sistem loglaması tekrar aktif" #define D_SET_BAUDRATE_TO "Baud hızını şu şekilde değiştir" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Alınan Başlık" #define D_DATA_SIZE "Veri Büyüklüğü" #define D_ANALOG_INPUT "Analog" diff --git a/tasmota/language/uk-UA.h b/tasmota/language/uk-UA.h index 45a5621af..fbeb0f782 100644 --- a/tasmota/language/uk-UA.h +++ b/tasmota/language/uk-UA.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog журнал увімкнений" #define D_SET_BAUDRATE_TO "Встановити швидкість передачі (Baudrate)" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "Отриманий Топік" #define D_DATA_SIZE "Розмір даних" #define D_ANALOG_INPUT "Аналоговий вхід" diff --git a/tasmota/language/zh-CN.h b/tasmota/language/zh-CN.h index 3e7e108bc..95ba59358 100644 --- a/tasmota/language/zh-CN.h +++ b/tasmota/language/zh-CN.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog 日志已开启" #define D_SET_BAUDRATE_TO "设置波特率为:" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "接收到的主题:" #define D_DATA_SIZE "数据大小:" #define D_ANALOG_INPUT "Analog" diff --git a/tasmota/language/zh-TW.h b/tasmota/language/zh-TW.h index c7416df0e..b2ebcddd5 100644 --- a/tasmota/language/zh-TW.h +++ b/tasmota/language/zh-TW.h @@ -194,7 +194,6 @@ #define D_SYSLOG_LOGGING_REENABLED "Syslog 日誌已開啟" #define D_SET_BAUDRATE_TO "設置波特率為:" -#define D_SET_SERIAL_CONFIG_TO "Set serial port mode to" #define D_RECEIVED_TOPIC "接收到的主題:" #define D_DATA_SIZE "數據大小:" #define D_ANALOG_INPUT "Analog" From 292698123bfada13d37f491ccf7cf970f47a1772 Mon Sep 17 00:00:00 2001 From: Luis Teixeira Date: Tue, 10 Mar 2020 23:33:09 +0000 Subject: [PATCH 10/17] Minor correction to the description. Slightly simplified declaration of the sensor in the support_features.ino. --- I2CDEVICES.md | 2 +- tasmota/support_features.ino | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/I2CDEVICES.md b/I2CDEVICES.md index 2a89ba8aa..7c1e4d772 100644 --- a/I2CDEVICES.md +++ b/I2CDEVICES.md @@ -66,4 +66,4 @@ Index | Define | Driver | Device | Address(es) | Description 42 | USE_DS1624 | xsns_59 | DS1624 | 0x48 - 0x4F | Temperature sensor 43 | USE_AHT1x | xsns_63 | AHT10/15 | 0x38 | Temperature and humidity sensor 44 | USE_WEMOS_MOTOR_V1 | xdrv_34 | | 0x2D - 0x30 | WEMOS motor shield v1.0.0 (6612FNG) - 92 | USE_HDC1080 | xsns_92 | HDC1080 | 0x40 | Digital Humidity Sensor with Temperature Sensor + 92 | USE_HDC1080 | xsns_92 | HDC1080 | 0x40 | Temperature and Humidity sensor diff --git a/tasmota/support_features.ino b/tasmota/support_features.ino index 213219621..0dd97f76f 100644 --- a/tasmota/support_features.ino +++ b/tasmota/support_features.ino @@ -254,8 +254,8 @@ void GetFeatures(void) #ifdef USE_SHT feature_sns1 |= 0x00000100; // xsns_07_sht1x.ino #endif -#ifdef USE_HTU - feature_sns1 |= 0x00000200; // xsns_08_htu21.ino +#if defined(USE_HTU) || defined(USE_HDC1080) + feature_sns1 |= 0x00000200; // xsns_08_htu21.ino or xsns_92_hdc1080.ino #endif #ifdef USE_BMP feature_sns1 |= 0x00000400; // xsns_09_bmp.ino @@ -323,10 +323,6 @@ void GetFeatures(void) #ifdef USE_TM1638 feature_sns1 |= 0x80000000; // xsns_28_tm1638.ino #endif -// TODO not sure if is the correct feature setting for this sensor: -#ifdef USE_HDC1080 - feature_sns1 |= 0x00000200; // xsns_92_hdc1080.ino -#endif /*********************************************************************************************/ feature_sns2 = 0x00000000; From b758699e39e9f1ee88f006b021d1fd2b249499e1 Mon Sep 17 00:00:00 2001 From: Luis Teixeira Date: Fri, 13 Mar 2020 00:46:25 +0000 Subject: [PATCH 11/17] Some corrections based on feedback from the project leads contributors. Improved runtime impact by replacing the sleep between the I2C operations with separate code triggered by timer events. --- I2CDEVICES.md | 2 +- tasmota/support_features.ino | 4 +- tasmota/tasmota_post.h | 2 +- ...sns_92_hdc1080.ino => xsns_65_hdc1080.ino} | 109 ++++++++++++++---- tools/decode-status.py | 2 +- 5 files changed, 90 insertions(+), 29 deletions(-) rename tasmota/{xsns_92_hdc1080.ino => xsns_65_hdc1080.ino} (73%) diff --git a/I2CDEVICES.md b/I2CDEVICES.md index 7c1e4d772..75c0a1a9a 100644 --- a/I2CDEVICES.md +++ b/I2CDEVICES.md @@ -66,4 +66,4 @@ Index | Define | Driver | Device | Address(es) | Description 42 | USE_DS1624 | xsns_59 | DS1624 | 0x48 - 0x4F | Temperature sensor 43 | USE_AHT1x | xsns_63 | AHT10/15 | 0x38 | Temperature and humidity sensor 44 | USE_WEMOS_MOTOR_V1 | xdrv_34 | | 0x2D - 0x30 | WEMOS motor shield v1.0.0 (6612FNG) - 92 | USE_HDC1080 | xsns_92 | HDC1080 | 0x40 | Temperature and Humidity sensor + 45 | USE_HDC1080 | xsns_65 | HDC1080 | 0x40 | Temperature and Humidity sensor diff --git a/tasmota/support_features.ino b/tasmota/support_features.ino index 0dd97f76f..410ae7bee 100644 --- a/tasmota/support_features.ino +++ b/tasmota/support_features.ino @@ -254,8 +254,8 @@ void GetFeatures(void) #ifdef USE_SHT feature_sns1 |= 0x00000100; // xsns_07_sht1x.ino #endif -#if defined(USE_HTU) || defined(USE_HDC1080) - feature_sns1 |= 0x00000200; // xsns_08_htu21.ino or xsns_92_hdc1080.ino +#ifdef USE_HTU + feature_sns1 |= 0x00000200; // xsns_08_htu21.ino #endif #ifdef USE_BMP feature_sns1 |= 0x00000400; // xsns_09_bmp.ino diff --git a/tasmota/tasmota_post.h b/tasmota/tasmota_post.h index 119ec70e4..dea6b1ca3 100644 --- a/tasmota/tasmota_post.h +++ b/tasmota/tasmota_post.h @@ -182,7 +182,7 @@ extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack #define USE_DHT12 // Add I2C code for DHT12 temperature and humidity sensor (+0k7 code) #define USE_DS1624 // Add I2C code for DS1624, DS1621 sensor //#define USE_AHT1x // Enable AHT10/15 humidity and temperature sensor (I2C address 0x38) (+0k8 code) -#define USE_HDC1080 // Enable HDC1080 temperature/humidity sensor +//#define USE_HDC1080 // Enable HDC1080 temperature/humidity sensor #define USE_WEMOS_MOTOR_V1 // Enable Wemos motor driver V1 (I2C addresses 0x2D - 0x30) (+0k7 code) diff --git a/tasmota/xsns_92_hdc1080.ino b/tasmota/xsns_65_hdc1080.ino similarity index 73% rename from tasmota/xsns_92_hdc1080.ino rename to tasmota/xsns_65_hdc1080.ino index f5cd385b1..8e5538b9d 100644 --- a/tasmota/xsns_92_hdc1080.ino +++ b/tasmota/xsns_65_hdc1080.ino @@ -19,6 +19,7 @@ #ifdef USE_I2C #ifdef USE_HDC1080 + /*********************************************************************************************\ * HDC1080 - Temperature and Humidy sensor * @@ -27,8 +28,8 @@ * I2C Address: 0x40 \*********************************************************************************************/ -#define XSNS_92 92 -#define XI2C_92 92 // See I2CDEVICES.md +#define XSNS_65 65 +#define XI2C_45 45 // See I2CDEVICES.md #define HDC1080_ADDR 0x40 @@ -59,7 +60,7 @@ // Constants: -#define HDC1080_CONV_TIME 50 // Assume 6.50 + 6.35 ms + x of conversion delay for this device +#define HDC1080_CONV_TIME 80 // Assume 6.50 + 6.35 ms + x of conversion delay for this device #define HDC1080_TEMP_MULT 0.0025177 #define HDC1080_RH_MULT 0.0025177 #define HDC1080_TEMP_OFFSET 40.0 @@ -74,6 +75,9 @@ float hdc_humidity = 0.0; uint8_t hdc_valid = 0; +bool is_reading = false; +uint32_t timer = millis() + HDC1080_CONV_TIME; + /** * Reads the device ID register. * @@ -117,18 +121,32 @@ void HdcReset(void) { } /** - * Performs the single transaction read of the HDC1080, providing the - * adequate delay for the acquisition. + * Performs the write portion of the HDC1080 sensor transaction. This + * action of writing to a register signals the beginning of the operation + * (e.g. data acquisition). * + * addr: the address of the I2C device we are talking to. + * reg: the register where we are writing to. + * + * returns: 0 if the transmission was successfully completed, != 0 otherwise. */ -int8_t HdcReadBuffer(uint8_t addr, uint8_t reg, uint8_t *reg_data, uint16_t len) { - Wire.beginTransmission((uint8_t)addr); - Wire.write((uint8_t)reg); - Wire.endTransmission(); +int8_t HdcTransactionOpen(uint8_t addr, uint8_t reg) { + Wire.beginTransmission((uint8_t) addr); + Wire.write((uint8_t) reg); + return Wire.endTransmission(); +} - delay(HDC1080_CONV_TIME); - - if (len != Wire.requestFrom((uint8_t)addr, (uint8_t)len)) { +/** + * Performs the read portion of the HDC1080 sensor transaction. + * + * addr: the address of the I2C device we are talking to. + * reg_data: the pointer to the memory location where we will place the bytes that were read from the device + * len: the number of bytes we expect to read + * + * returns: if the read operation was successful. != 0 otherwise. + */ +int8_t HdcTransactionClose(uint8_t addr, uint8_t *reg_data, uint16_t len) { + if (len != Wire.requestFrom((uint8_t) addr, (uint8_t) len)) { return 1; } @@ -149,11 +167,31 @@ void HdcInit(void) { HdcConfig(HDC1080_MODE_ON); } +/** + * Triggers the single transaction read of the T/RH sensor. + * + */ +bool HdcTriggerRead(void) { + int8_t status = HdcTransactionOpen(HDC1080_ADDR, HDC_REG_TEMP); + + if(status) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcTriggerRead: failed to open the transaction for HDC_REG_TEMP. Status = %d"), status); + + return false; + } + + is_reading = true; + + return true; +} + /** * Performs a temperature and humidity measurement, and calls * the conversion function providing the results in the correct * unit according to the device settings. * + * returns: false if something failed during the read process. + * */ bool HdcRead(void) { int8_t status = 0; @@ -161,18 +199,20 @@ bool HdcRead(void) { uint16_t temp_data = 0; uint16_t rh_data = 0; - status = HdcReadBuffer(HDC1080_ADDR, HDC_REG_TEMP, sensor_data, 4); + is_reading = false; + + status = HdcTransactionClose(HDC1080_ADDR, sensor_data, 4); + + if(status) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: failed to read HDC_REG_TEMP. Status = %d"), status); + + return false; + } temp_data = (uint16_t) ((sensor_data[0] << 8) | sensor_data[1]); rh_data = (uint16_t) ((sensor_data[2] << 8) | sensor_data[3]); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: temperature raw data: 0x%04x; humidity raw data: 0x%04x"), temp_data, rh_data); - - if(status != 0) { - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: failed to read HDC_REG_TEMP. Status = %d"), status); - - return false; - } // read the temperature from the first 16 bits of the result @@ -190,7 +230,10 @@ bool HdcRead(void) { return true; } -/********************************************************************************************/ +/** + * Performs the detection of the HTC1080 sensor. + * + */ void HdcDetect(void) { if (I2cActive(HDC1080_ADDR)) { @@ -210,14 +253,24 @@ void HdcDetect(void) { } } +/** + * As the name suggests, this function is called every second + * for performing driver related logic. + * + */ void HdcEverySecond(void) { if (uptime &1) { // Every 2 seconds - if (!HdcRead()) { + if (!HdcTriggerRead()) { AddLogMissed((char*) hdc_type_name, hdc_valid); } } } +/** + * Tasmota boilerplate for presenting the sensor data in the web UI, JSON for + * the MQTT messages, and so on. + * + */ void HdcShow(bool json) { if (hdc_valid) { char temperature[33]; @@ -252,10 +305,10 @@ void HdcShow(bool json) { * Interface \*********************************************************************************************/ -bool Xsns92(uint8_t function) +bool Xsns65(uint8_t function) { - if (!I2cEnabled(XI2C_92)) { - AddLog_P(LOG_LEVEL_DEBUG, PSTR("Xsns92: I2C driver not enabled for this device.")); + if (!I2cEnabled(XI2C_45)) { + AddLog_P(LOG_LEVEL_DEBUG, PSTR("Xsns65: I2C driver not enabled for this device.")); return false; } @@ -267,6 +320,14 @@ bool Xsns92(uint8_t function) } else if (hdc_device_id) { switch (function) { + case FUNC_EVERY_50_MSECOND: + if(is_reading && TimeReached(timer)) { + if(!HdcRead()) { + AddLogMissed((char*) hdc_type_name, hdc_valid); + } + timer = millis() + HDC1080_CONV_TIME; + } + break; case FUNC_EVERY_SECOND: HdcEverySecond(); break; diff --git a/tools/decode-status.py b/tools/decode-status.py index 232cebc07..c9ba04f6d 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -178,7 +178,7 @@ a_features = [[ "USE_INA219","USE_SHT3X","USE_MHZ19","USE_TSL2561", "USE_SENSEAIR","USE_PMS5003","USE_MGS","USE_NOVA_SDS", "USE_SGP30","USE_SR04","USE_SDM120","USE_SI1145", - "USE_SDM630","USE_LM75AD","USE_APDS9960","USE_TM1638", "USE_HDC1080" + "USE_SDM630","USE_LM75AD","USE_APDS9960","USE_TM1638", ],[ "USE_MCP230xx","USE_MPR121","USE_CCS811","USE_MPU6050", "USE_MCP230xx_OUTPUT","USE_MCP230xx_DISPLAYOUTPUT","USE_HLW8012","USE_CSE7766", From 50d63f867808daf453d644d7035a59771f792d1a Mon Sep 17 00:00:00 2001 From: Paul C Diem Date: Fri, 13 Mar 2020 16:53:27 -0500 Subject: [PATCH 12/17] Only set power for devices included in updates --- tasmota/support_device_groups.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tasmota/support_device_groups.ino b/tasmota/support_device_groups.ino index d0844de7a..f90e07c94 100644 --- a/tasmota/support_device_groups.ino +++ b/tasmota/support_device_groups.ino @@ -333,7 +333,7 @@ void _SendDeviceGroupMessage(uint8_t device_group_index, DeviceGroupMessageType if (item > DGR_ITEM_MAX_16BIT) { value >>= 8; *message_ptr++ = value & 0xff; - *message_ptr++ = value >> 8; + *message_ptr++ = (item == DGR_ITEM_POWER ? devices_present : value >> 8); } } } @@ -590,6 +590,8 @@ void ProcessDeviceGroupMessage(char * packet, int packet_length) if (DeviceGroupItemShared(true, item)) { if (item == DGR_ITEM_POWER) { + uint8_t mask_devices = value >> 24; + if (mask_devices > devices_present) mask_devices = devices_present; for (uint32_t i = 0; i < devices_present; i++) { uint32_t mask = 1 << i; bool on = (value & mask); From 2441acdc023484529e38fef6f6c383690d557690 Mon Sep 17 00:00:00 2001 From: Luis Teixeira Date: Fri, 13 Mar 2020 22:40:33 +0000 Subject: [PATCH 13/17] Fixed the sensor read errors that were due to misplaced timer variable initializations. --- tasmota/xsns_65_hdc1080.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tasmota/xsns_65_hdc1080.ino b/tasmota/xsns_65_hdc1080.ino index 8e5538b9d..74de68383 100644 --- a/tasmota/xsns_65_hdc1080.ino +++ b/tasmota/xsns_65_hdc1080.ino @@ -60,12 +60,11 @@ // Constants: -#define HDC1080_CONV_TIME 80 // Assume 6.50 + 6.35 ms + x of conversion delay for this device +#define HDC1080_CONV_TIME 15 // Assume 6.50 + 6.35 ms + x of conversion delay for this device #define HDC1080_TEMP_MULT 0.0025177 #define HDC1080_RH_MULT 0.0025177 #define HDC1080_TEMP_OFFSET 40.0 - const char* hdc_type_name = "HDC1080"; uint16_t hdc_manufacturer_id = 0; uint16_t hdc_device_id = 0; @@ -76,7 +75,7 @@ float hdc_humidity = 0.0; uint8_t hdc_valid = 0; bool is_reading = false; -uint32_t timer = millis() + HDC1080_CONV_TIME; +uint32_t hdc_next_read; /** * Reads the device ID register. @@ -174,6 +173,8 @@ void HdcInit(void) { bool HdcTriggerRead(void) { int8_t status = HdcTransactionOpen(HDC1080_ADDR, HDC_REG_TEMP); + hdc_next_read = millis() + HDC1080_CONV_TIME; + if(status) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcTriggerRead: failed to open the transaction for HDC_REG_TEMP. Status = %d"), status); @@ -321,11 +322,10 @@ bool Xsns65(uint8_t function) else if (hdc_device_id) { switch (function) { case FUNC_EVERY_50_MSECOND: - if(is_reading && TimeReached(timer)) { + if(is_reading && TimeReached(hdc_next_read)) { if(!HdcRead()) { AddLogMissed((char*) hdc_type_name, hdc_valid); } - timer = millis() + HDC1080_CONV_TIME; } break; case FUNC_EVERY_SECOND: From a5ebdd34759dc65d4cbf5943ae686db2953653eb Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 14 Mar 2020 09:52:33 +0100 Subject: [PATCH 14/17] Update decode-status.py --- tools/decode-status.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/decode-status.py b/tools/decode-status.py index c9ba04f6d..fe80630cc 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -178,7 +178,7 @@ a_features = [[ "USE_INA219","USE_SHT3X","USE_MHZ19","USE_TSL2561", "USE_SENSEAIR","USE_PMS5003","USE_MGS","USE_NOVA_SDS", "USE_SGP30","USE_SR04","USE_SDM120","USE_SI1145", - "USE_SDM630","USE_LM75AD","USE_APDS9960","USE_TM1638", + "USE_SDM630","USE_LM75AD","USE_APDS9960","USE_TM1638" ],[ "USE_MCP230xx","USE_MPR121","USE_CCS811","USE_MPU6050", "USE_MCP230xx_OUTPUT","USE_MCP230xx_DISPLAYOUTPUT","USE_HLW8012","USE_CSE7766", From 0f157caa0532f6811c8e58a5cff3579829182167 Mon Sep 17 00:00:00 2001 From: Leonid Muravjev Date: Sat, 14 Mar 2020 13:41:57 +0300 Subject: [PATCH 15/17] switch: New mode PUSHON (13) Just turn it on, if the switch is on. Switch off by PulseTime. For a simple implementation processing of PIR sensors. --- tasmota/support_switch.ino | 5 ++++- tasmota/tasmota.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index e873ea200..e0be915e9 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -188,7 +188,7 @@ void SwitchHandler(uint8_t mode) } } -// enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, TOGGLEMULTI, FOLLOWMULTI, FOLLOWMULTI_INV, PUSHHOLDMULTI, PUSHHOLDMULTI_INV, MAX_SWITCH_OPTION}; +// enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, TOGGLEMULTI, FOLLOWMULTI, FOLLOWMULTI_INV, PUSHHOLDMULTI, PUSHHOLDMULTI_INV, PUSHON, MAX_SWITCH_OPTION}; if (button != Switch.last_state[i]) { switch (Settings.switchmode[i]) { @@ -276,6 +276,9 @@ void SwitchHandler(uint8_t mode) Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; } break; + case PUSHON: + if (PRESSED == button) switchflag = POWER_ON; // Power ON with pushbutton to Gnd + break; } Switch.last_state[i] = button; } diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 664446502..919193f09 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -233,7 +233,7 @@ enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_D enum WifiConfigOptions {WIFI_RESTART, EX_WIFI_SMARTCONFIG, WIFI_MANAGER, EX_WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL, WIFI_MANAGER_RESET_ONLY, MAX_WIFI_OPTION}; enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, TOGGLEMULTI, - FOLLOWMULTI, FOLLOWMULTI_INV, PUSHHOLDMULTI, PUSHHOLDMULTI_INV, MAX_SWITCH_OPTION}; + FOLLOWMULTI, FOLLOWMULTI_INV, PUSHHOLDMULTI, PUSHHOLDMULTI_INV, PUSHON, MAX_SWITCH_OPTION}; enum LedStateOptions {LED_OFF, LED_POWER, LED_MQTTSUB, LED_POWER_MQTTSUB, LED_MQTTPUB, LED_POWER_MQTTPUB, LED_MQTT, LED_POWER_MQTT, MAX_LED_OPTION}; From 5235ad1757ef5a584b8e71e39aed7bab9770795c Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 14 Mar 2020 12:43:02 +0100 Subject: [PATCH 16/17] Add support for HDC1080 Add support for HDC1080 Temperature and Humidity sensor by Luis Teixeira (#7888) --- RELEASENOTES.md | 1 + tasmota/CHANGELOG.md | 1 + tasmota/my_user_config.h | 3 +-- tasmota/support_features.ino | 5 +++- tasmota/tasmota_post.h | 4 +-- tasmota/xsns_65_hdc1080.ino | 50 ++++++++++++++++++------------------ tools/decode-status.py | 4 +-- 7 files changed, 35 insertions(+), 33 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 0a6e1fbcb..c318212f9 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -117,3 +117,4 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Add support for MaxBotix HRXL-MaxSonar ultrasonic range finders by Jon Little (#7814) - Add support for Romanian language translations by Augustin Marti - Add HAss Discovery support for Button and Switch triggers by Federico Leoni (#7901) +- Add support for HDC1080 Temperature and Humidity sensor by Luis Teixeira (#7888) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 11d730543..cf8694d55 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -3,6 +3,7 @@ ### 8.1.0.11 20200313 - Add HAss Discovery support for Button and Switch triggers by Federico Leoni (#7901) +- Add support for HDC1080 Temperature and Humidity sensor by Luis Teixeira (#7888) ### 8.1.0.10 20200227 diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 40cbb5ce4..a65924cdf 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -494,10 +494,9 @@ // #define USE_DS1624 // [I2cDriver42] Enable DS1624, DS1621 temperature sensor (I2C addresses 0x48 - 0x4F) (+1k2 code) // #define USE_AHT1x // [I2cDriver43] Enable AHT10/15 humidity and temperature sensor (I2C address 0x38) (+0k8 code) // #define USE_WEMOS_MOTOR_V1 // [I2cDriver44] Enable Wemos motor driver V1 (I2C addresses 0x2D - 0x30) (+0k7 code) -// #define USE_HDC1080 // [I2cDriver92] Enable HDC1080 temperature/humidity sensor - // #define WEMOS_MOTOR_V1_ADDR 0x30 // Default I2C address 0x30 // #define WEMOS_MOTOR_V1_FREQ 1000 // Default frequency +// #define USE_HDC1080 // [I2cDriver45] Enable HDC1080 temperature/humidity sensor (I2C address 0x40) (+1k5 code) // #define USE_DISPLAY // Add I2C Display Support (+2k code) #define USE_DISPLAY_MODES1TO5 // Enable display mode 1 to 5 in addition to mode 0 diff --git a/tasmota/support_features.ino b/tasmota/support_features.ino index 410ae7bee..201711e48 100644 --- a/tasmota/support_features.ino +++ b/tasmota/support_features.ino @@ -323,6 +323,7 @@ void GetFeatures(void) #ifdef USE_TM1638 feature_sns1 |= 0x80000000; // xsns_28_tm1638.ino #endif + /*********************************************************************************************/ feature_sns2 = 0x00000000; @@ -538,7 +539,9 @@ void GetFeatures(void) #ifdef USE_SONOFF_D1 feature6 |= 0x00000004; // xdrv_37_sonoff_d1.ino #endif -// feature6 |= 0x00000008; +#ifdef USE_HDC1080 + feature6 |= 0x00000008; // xsns_65_hdc1080.ino +#endif // feature6 |= 0x00000010; // feature6 |= 0x00000020; diff --git a/tasmota/tasmota_post.h b/tasmota/tasmota_post.h index dea6b1ca3..1abd371ff 100644 --- a/tasmota/tasmota_post.h +++ b/tasmota/tasmota_post.h @@ -182,12 +182,10 @@ extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack #define USE_DHT12 // Add I2C code for DHT12 temperature and humidity sensor (+0k7 code) #define USE_DS1624 // Add I2C code for DS1624, DS1621 sensor //#define USE_AHT1x // Enable AHT10/15 humidity and temperature sensor (I2C address 0x38) (+0k8 code) -//#define USE_HDC1080 // Enable HDC1080 temperature/humidity sensor - - #define USE_WEMOS_MOTOR_V1 // Enable Wemos motor driver V1 (I2C addresses 0x2D - 0x30) (+0k7 code) #define WEMOS_MOTOR_V1_ADDR 0x30 // Default I2C address 0x30 #define WEMOS_MOTOR_V1_FREQ 1000 // Default frequency +//#define USE_HDC1080 // Enable HDC1080 temperature/humidity sensor #define USE_MHZ19 // Add support for MH-Z19 CO2 sensor (+2k code) #define USE_SENSEAIR // Add support for SenseAir K30, K70 and S8 CO2 sensor (+2k3 code) diff --git a/tasmota/xsns_65_hdc1080.ino b/tasmota/xsns_65_hdc1080.ino index 74de68383..59f0f75f2 100644 --- a/tasmota/xsns_65_hdc1080.ino +++ b/tasmota/xsns_65_hdc1080.ino @@ -1,5 +1,5 @@ /* - xsns_92_hdc1080.ino - Texas Instruments HDC1080 temperature and humidity sensor support for Tasmota + xsns_65_hdc1080.ino - Texas Instruments HDC1080 temperature and humidity sensor support for Tasmota Copyright (C) 2020 Luis Teixeira @@ -79,7 +79,7 @@ uint32_t hdc_next_read; /** * Reads the device ID register. - * + * */ uint16_t HdcReadDeviceId(void) { return I2cRead16(HDC1080_ADDR, HDC_REG_DEV_ID); @@ -87,7 +87,7 @@ uint16_t HdcReadDeviceId(void) { /** * Reads the manufacturer ID register. - * + * */ uint16_t HdcReadManufacturerId(void) { return I2cRead16(HDC1080_ADDR, HDC_REG_MAN_ID); @@ -102,13 +102,13 @@ void HdcConfig(uint16_t config) { /** * Performs a soft reset on the device. - * + * * RST = 1 -> software reset - * + * */ void HdcReset(void) { uint16_t current = I2cRead16(HDC1080_ADDR, HDC_REG_CONFIG); - + // bit 15 of the configuration register contains the RST flag // so we set it to 1: @@ -120,13 +120,13 @@ void HdcReset(void) { } /** - * Performs the write portion of the HDC1080 sensor transaction. This + * Performs the write portion of the HDC1080 sensor transaction. This * action of writing to a register signals the beginning of the operation * (e.g. data acquisition). - * + * * addr: the address of the I2C device we are talking to. * reg: the register where we are writing to. - * + * * returns: 0 if the transmission was successfully completed, != 0 otherwise. */ int8_t HdcTransactionOpen(uint8_t addr, uint8_t reg) { @@ -137,11 +137,11 @@ int8_t HdcTransactionOpen(uint8_t addr, uint8_t reg) { /** * Performs the read portion of the HDC1080 sensor transaction. - * + * * addr: the address of the I2C device we are talking to. * reg_data: the pointer to the memory location where we will place the bytes that were read from the device * len: the number of bytes we expect to read - * + * * returns: if the read operation was successful. != 0 otherwise. */ int8_t HdcTransactionClose(uint8_t addr, uint8_t *reg_data, uint16_t len) { @@ -159,7 +159,7 @@ int8_t HdcTransactionClose(uint8_t addr, uint8_t *reg_data, uint16_t len) { /** * The various initialization steps for this sensor. - * + * */ void HdcInit(void) { HdcReset(); @@ -168,7 +168,7 @@ void HdcInit(void) { /** * Triggers the single transaction read of the T/RH sensor. - * + * */ bool HdcTriggerRead(void) { int8_t status = HdcTransactionOpen(HDC1080_ADDR, HDC_REG_TEMP); @@ -190,9 +190,9 @@ bool HdcTriggerRead(void) { * Performs a temperature and humidity measurement, and calls * the conversion function providing the results in the correct * unit according to the device settings. - * + * * returns: false if something failed during the read process. - * + * */ bool HdcRead(void) { int8_t status = 0; @@ -233,14 +233,14 @@ bool HdcRead(void) { /** * Performs the detection of the HTC1080 sensor. - * + * */ void HdcDetect(void) { - if (I2cActive(HDC1080_ADDR)) { - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcDetect: Address = 0x%02X already in use."), HDC1080_ADDR); + if (I2cActive(HDC1080_ADDR)) { +// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcDetect: Address = 0x%02X already in use."), HDC1080_ADDR); - return; + return; } hdc_manufacturer_id = HdcReadManufacturerId(); @@ -257,7 +257,7 @@ void HdcDetect(void) { /** * As the name suggests, this function is called every second * for performing driver related logic. - * + * */ void HdcEverySecond(void) { if (uptime &1) { // Every 2 seconds @@ -268,9 +268,9 @@ void HdcEverySecond(void) { } /** - * Tasmota boilerplate for presenting the sensor data in the web UI, JSON for + * Tasmota boilerplate for presenting the sensor data in the web UI, JSON for * the MQTT messages, and so on. - * + * */ void HdcShow(bool json) { if (hdc_valid) { @@ -308,10 +308,10 @@ void HdcShow(bool json) { bool Xsns65(uint8_t function) { - if (!I2cEnabled(XI2C_45)) { - AddLog_P(LOG_LEVEL_DEBUG, PSTR("Xsns65: I2C driver not enabled for this device.")); + if (!I2cEnabled(XI2C_45)) { +// AddLog_P(LOG_LEVEL_DEBUG, PSTR("Xsns65: I2C driver not enabled for this device.")); - return false; + return false; } bool result = false; diff --git a/tools/decode-status.py b/tools/decode-status.py index fe80630cc..25af64a97 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -198,7 +198,7 @@ a_features = [[ "USE_NRF24","USE_MIBLE","USE_HM10","USE_LE01MR", "USE_AHT1x","USE_WEMOS_MOTOR_V1","USE_DEVICE_GROUPS","USE_PWM_DIMMER" ],[ - "USE_KEELOQ","USE_HRXL","USE_SONOFF_D1","", + "USE_KEELOQ","USE_HRXL","USE_SONOFF_D1","USE_HDC1080", "","","","", "","","","", "","","","", @@ -239,7 +239,7 @@ else: obj = json.load(fp) def StartDecode(): - print ("\n*** decode-status.py v20200305 by Theo Arends and Jacek Ziolkowski ***") + print ("\n*** decode-status.py v20200314 by Theo Arends and Jacek Ziolkowski ***") # print("Decoding\n{}".format(obj)) From d043ac770d47801dc20a59066ee96e30250c54d4 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 14 Mar 2020 13:13:33 +0100 Subject: [PATCH 17/17] Refactor support_switche.ino - Add commands ``SwitchMode 13`` PushOn and ``SwitchMode 14`` PushOnInverted (#7912) - Refactor support_switche.ino --- RELEASENOTES.md | 1 + tasmota/CHANGELOG.md | 1 + tasmota/support_switch.ino | 73 ++++++++++++++++++++++++-------------- tasmota/tasmota.h | 4 +-- 4 files changed, 50 insertions(+), 29 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index c318212f9..a2757b96f 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -87,6 +87,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Add command ``ShutterButton `` to control shutter(s) by to-scho (#7403) - Add commands ``SwitchMode 8`` ToggleMulti, ``SwitchMode 9`` FollowMulti and ``SwitchMode 10`` FollowMultiInverted (#7522) - Add commands ``SwitchMode 11`` PushHoldMulti and ``SwitchMode 12`` PushHoldInverted (#7603) +- Add commands ``SwitchMode 13`` PushOn and ``SwitchMode 14`` PushOnInverted (#7912) - Add command ``Buzzer -1`` for infinite mode and command ``Buzzer -2`` for following led mode (#7623) - Add SerialConfig to ``Status 1`` - Add WifiPower to ``Status 5`` diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index cf8694d55..2c23efc42 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -4,6 +4,7 @@ - Add HAss Discovery support for Button and Switch triggers by Federico Leoni (#7901) - Add support for HDC1080 Temperature and Humidity sensor by Luis Teixeira (#7888) +- Add commands ``SwitchMode 13`` PushOn and ``SwitchMode 14`` PushOnInverted (#7912) ### 8.1.0.10 20200227 diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index e0be915e9..7acdda409 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -17,8 +17,8 @@ along with this program. If not, see . */ -#define SWITCH_V2 -#ifdef SWITCH_V2 +#define SWITCH_V3 +#ifdef SWITCH_V3 /*********************************************************************************************\ * Switch support with input filter * @@ -166,20 +166,20 @@ void SwitchHandler(uint8_t mode) switchflag = ~button &1; // Follow inverted wall switch state after hold break; case PUSHHOLDMULTI: - if (NOT_PRESSED == button){ + if (NOT_PRESSED == button) { Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 25; SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT - } - else + } else { SendKey(KEY_SWITCH, i +1, POWER_CLEAR); // Execute command via MQTT + } break; case PUSHHOLDMULTI_INV: - if (PRESSED == button){ + if (PRESSED == button) { Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 25; SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT - } - else + } else { SendKey(KEY_SWITCH, i +1, POWER_CLEAR); // Execute command via MQTT + } break; default: SendKey(KEY_SWITCH, i +1, POWER_HOLD); // Execute command via MQTT @@ -188,9 +188,7 @@ void SwitchHandler(uint8_t mode) } } -// enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, TOGGLEMULTI, FOLLOWMULTI, FOLLOWMULTI_INV, PUSHHOLDMULTI, PUSHHOLDMULTI_INV, PUSHON, MAX_SWITCH_OPTION}; - - if (button != Switch.last_state[i]) { + if (button != Switch.last_state[i]) { // This implies if ((PRESSED == button) then (NOT_PRESSED == Switch.last_state[i])) switch (Settings.switchmode[i]) { case TOGGLE: case PUSHBUTTON_TOGGLE: @@ -203,29 +201,35 @@ void SwitchHandler(uint8_t mode) switchflag = ~button &1; // Follow inverted wall switch state break; case PUSHBUTTON: - if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) { +// if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) { + if (PRESSED == button) { switchflag = POWER_TOGGLE; // Toggle with pushbutton to Gnd } break; case PUSHBUTTON_INV: - if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) { +// if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) { + if (NOT_PRESSED == button) { switchflag = POWER_TOGGLE; // Toggle with releasing pushbutton from Gnd } break; case PUSHBUTTONHOLD: - if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) { +// if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) { + if (PRESSED == button) { Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; // Start timer on button press } - if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i]) && (Switch.hold_timer[i])) { +// if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i]) && (Switch.hold_timer[i])) { + if ((NOT_PRESSED == button) && (Switch.hold_timer[i])) { Switch.hold_timer[i] = 0; // Button released and hold timer not expired : stop timer... switchflag = POWER_TOGGLE; // ...and Toggle } break; case PUSHBUTTONHOLD_INV: - if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) { +// if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) { + if (NOT_PRESSED == button) { Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; // Start timer on button press... } - if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i]) && (Switch.hold_timer[i])) { +// if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i]) && (Switch.hold_timer[i])) { + if ((PRESSED == button) && (Switch.hold_timer[i])) { Switch.hold_timer[i] = 0; // Button released and hold timer not expired : stop timer. switchflag = POWER_TOGGLE; // ...and Toggle } @@ -253,31 +257,46 @@ void SwitchHandler(uint8_t mode) } break; case PUSHHOLDMULTI: - if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) { - if(Switch.hold_timer[i]!=0) +// if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) { + if (NOT_PRESSED == button) { + if (Switch.hold_timer[i] != 0) { SendKey(KEY_SWITCH, i +1, POWER_INV); // Execute command via MQTT + } Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; } - if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) { - if(Switch.hold_timer[i] > loops_per_second * Settings.param[P_HOLD_TIME] / 25) +// if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) { + if (PRESSED == button) { + if (Switch.hold_timer[i] > loops_per_second * Settings.param[P_HOLD_TIME] / 25) { switchflag = POWER_TOGGLE; // Toggle with pushbutton + } Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; } break; case PUSHHOLDMULTI_INV: - if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) { - if(Switch.hold_timer[i]!=0) +// if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) { + if (PRESSED == button) { + if (Switch.hold_timer[i] != 0) { SendKey(KEY_SWITCH, i +1, POWER_INV); // Execute command via MQTT + } Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; } - if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) { - if(Switch.hold_timer[i] > loops_per_second * Settings.param[P_HOLD_TIME] / 25) +// if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) { + if (NOT_PRESSED == button) { + if (Switch.hold_timer[i] > loops_per_second * Settings.param[P_HOLD_TIME] / 25) { switchflag = POWER_TOGGLE; // Toggle with pushbutton + } Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; } break; case PUSHON: - if (PRESSED == button) switchflag = POWER_ON; // Power ON with pushbutton to Gnd + if (PRESSED == button) { + switchflag = POWER_ON; // Power ON with pushbutton to Gnd + } + break; + case PUSHON_INV: + if (NOT_PRESSED == button) { + switchflag = POWER_ON; // Power ON with releasing pushbutton from Gnd + } break; } Switch.last_state[i] = button; @@ -301,4 +320,4 @@ void SwitchLoop(void) } } -#endif // SWITCH_V2 +#endif // SWITCH_V3 diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 919193f09..6e9c8ac29 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -233,7 +233,7 @@ enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_D enum WifiConfigOptions {WIFI_RESTART, EX_WIFI_SMARTCONFIG, WIFI_MANAGER, EX_WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL, WIFI_MANAGER_RESET_ONLY, MAX_WIFI_OPTION}; enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, TOGGLEMULTI, - FOLLOWMULTI, FOLLOWMULTI_INV, PUSHHOLDMULTI, PUSHHOLDMULTI_INV, PUSHON, MAX_SWITCH_OPTION}; + FOLLOWMULTI, FOLLOWMULTI_INV, PUSHHOLDMULTI, PUSHHOLDMULTI_INV, PUSHON, PUSHON_INV, MAX_SWITCH_OPTION}; enum LedStateOptions {LED_OFF, LED_POWER, LED_MQTTSUB, LED_POWER_MQTTSUB, LED_MQTTPUB, LED_POWER_MQTTPUB, LED_MQTT, LED_POWER_MQTT, MAX_LED_OPTION}; @@ -317,7 +317,7 @@ enum DeviceGroupItem { DGR_ITEM_EOL, DGR_ITEM_STATUS, DGR_ITEM_LAST_16BIT, DGR_ITEM_MAX_16BIT = 127, DGR_ITEM_POWER, DGR_ITEM_DIMMER_RANGE, // Add new 32-bit items before this line - DGR_ITEM_LAST_32BIT, DGR_ITEM_MAX_32BIT = 191, + DGR_ITEM_LAST_32BIT, DGR_ITEM_MAX_32BIT = 191, // Add new string items before this line DGR_ITEM_LAST_STRING, DGR_ITEM_MAX_STRING = 223, DGR_ITEM_LIGHT_CHANNELS };