From 7c857b0feb5178595301040d8b25a1fc808c9a50 Mon Sep 17 00:00:00 2001 From: Luis Teixeira Date: Wed, 4 Dec 2019 22:51:21 +0000 Subject: [PATCH 01/13] 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 5de4b7a1dd20..65f9887a3c4a 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 a98087a189fb..15e880600886 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 46bafdef6d0c..27987acf0930 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 554711cad877..61359226b321 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 9ca979b45c62..3f66214951c7 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 55c01b71de76..8f1ba2862fed 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 fe86400450a9..f0a5ba87d0a2 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 64a1125c6442..e6511eb047ce 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/13] 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 61359226b321..a3f5fd63eeb7 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/13] 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 4bc5feebd029..10f13b786ef6 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 8800368a3c41..639a0a1843a0 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 c50de823f1c1..75bf51435320 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 4fe47ae6deef..0583c17e8561 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 014d822a9be0..7f1ac36d6ab7 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 4704c49e7391..446485462f4b 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 69387ceca2ce..1c9eed40a03b 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 58f85eb229b3..f34b2cbb302f 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 3029f37dac93..5de100fee58e 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 c6236a05fde2..65c045f3f3b1 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 da20ff1d79a8..541b9bdc6130 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 7a631f95f0eb..dbb7339d303b 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 2eb81f294597..77451415299b 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 5ff9bff50799..cd734a575d26 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 57ec74f8ad32..0accdc4072bf 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 aee8fd25d139..30de42797cff 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 78612dace6c4..cea928af7027 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 f16d66648b21..890c40b9ca53 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 2c8610400833..178497a88a83 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 e5ef8926a939..5862f4b5bfa8 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/13] 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 53ebba456cbb..18f25042b83e 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 f9cf5b0e3be0..2a89ba8aa150 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 a62c6d191cd3..40cbb5ce4c87 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 c881e5db11a7..43db864307e9 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 961dd1091cd0..906442f9e8fd 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 7cf0fff75991..119ec70e46cd 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 000000000000..7cfb9873e141 --- /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 fe80630cc5c2..232cebc07cf7 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -178,7 +178,7 @@ "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/13] More intermediate changes and troubleshooting. --- tasmota/support_features.ino | 9 +- tasmota/xsns_92_hdc1080.ino | 178 +++++++++++++++++++++-------------- 2 files changed, 111 insertions(+), 76 deletions(-) diff --git a/tasmota/support_features.ino b/tasmota/support_features.ino index 906442f9e8fd..213219621996 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 7cfb9873e141..24a714055f63 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_CONV_TIME 15 // Assume 6.50 + 6.35 ms + x of conversion delay for this device +#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 + +// 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 I2cRead16(HDC1080_ADDR, HDC_REG_DEV_ID); +} - return deviceID; +/** + * 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,57 +153,71 @@ 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. + * Runs the heater in order to reduce the accumulated + * offset when the sensor is exposed for long periods + * at high humidity levels. * - * RST = 1 -> software reset + * HEAT = 0 -> heater off + * HEAT = 1 -> heater on * */ -void HdcReset(void) { +void HdcHeater(uint8_t heater) { 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: + // bits 13 of the configuration register contains the HEAT flag + // so we set it according to the value of the heater argument: - current |= 0x8000; + current = (current | 0xDFFF) | ((uint16_t) (heater << 13)); I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); +} - delay(15); // Not sure how long it takes to reset. Assuming 15ms +/** + * Overwrites the configuration register with the provided config + */ +void HdcConfig(uint16_t config) { + I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, config); } /** - * Runs the heater in order to reduce the accumulated - * offset when the sensor is exposed for long periods - * at high humidity levels. + * Performs a soft reset on the device. * - * HEAT = 0 -> heater off - * HEAT = 1 -> heater on + * RST = 1 -> software reset * */ -void HdcHeater(uint8_t heater) { +void HdcReset(void) { 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: + // bit 15 of the configuration register contains the RST flag + // so we set it to 1: - current &= (uint16_t) ((heater << 13) | 0xDFFF); + current |= 0x8000; I2cWrite16(HDC1080_ADDR, HDC_REG_CONFIG, current); + + delay(30); // Not sure how long it takes to reset. Assuming 15ms } -void HdcInit(void) -{ + +/** + * 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); - if (hdc_humidity > 100) { hdc_humidity = 100.0; } + //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/13] 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 24a714055f63..d1a5175b0173 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]; - - 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: + uint8_t sensor_data[4]; + uint16_t temp_data = 0; + uint16_t rh_data = 0; - Wire.beginTransmission(HDC1080_ADDR); - Wire.write(HDC_REG_TEMP); + status = HdcReadBuffer(HDC1080_ADDR, HDC_REG_TEMP, sensor_data, 4); - if (Wire.endTransmission() != 0) { // In case of error - AddLog_P(LOG_LEVEL_DEBUG, PSTR("HdcRead: failed to write to device for performing acquisition.")); + temp_data = (uint16_t) ((sensor_data[0] << 8) | sensor_data[1]); + rh_data = (uint16_t) ((sensor_data[2] << 8) | sensor_data[3]); - 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) (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]); + // read the temperature from the first 16 bits of the result - hdc_humidity = HDC1080_RH_MULT * (float) (sensor_data); + hdc_temperature = ConvertTemp(HDC1080_TEMP_MULT * (float) (temp_data) - HDC1080_TEMP_OFFSET); - //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/13] 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 d1a5175b0173..1e045c9a8026 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/13] 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 1e045c9a8026..f5cd385b1b6b 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/13] 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 09485cff662c..f36f379775e5 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 589e74a90f56..9323c9174e4a 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 d663724b707d..6303708de234 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 7f59a6b16243..8cf6d8def6b6 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 ddd34c944846..4a59d87b805d 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 c10378d94a81..e28e153e9bdf 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 dde47b382b79..69c91c6935e5 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 243ae74c3658..8b71a8067b26 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 87614e04fae3..09a803be6176 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 280a617f7864..551d81014013 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 d52b9de02954..e23c86757cd8 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 5c015f09b691..ddc815de5971 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 624bef70f865..46e29e1fda9d 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 a7fa58199383..2a75d6f46799 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 9d6daa244f98..f1b8fdbc5489 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 d7260ca6a406..36188994dfa7 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 ed3fe87bed0e..5690f9209160 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 58505249805b..b7bd30f2519a 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 58ea66d3b677..483633ae1093 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 e92a9584bf69..62990d5aad1d 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 45a5621af8db..fbeb0f7825cf 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 3e7e108bc303..95ba593587dd 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 c7416df0efbc..b2ebcddd5ab7 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/13] 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 2a89ba8aa150..7c1e4d772ee5 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 213219621996..0dd97f76fa97 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/13] 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} | 107 ++++++++++++++---- tools/decode-status.py | 2 +- 5 files changed, 89 insertions(+), 28 deletions(-) rename tasmota/{xsns_92_hdc1080.ino => xsns_65_hdc1080.ino} (73%) diff --git a/I2CDEVICES.md b/I2CDEVICES.md index 7c1e4d772ee5..75c0a1a9a479 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 0dd97f76fa97..410ae7bee5b7 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 119ec70e46cd..dea6b1ca36ea 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 f5cd385b1b6b..8e5538b9d0f5 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(); - - delay(HDC1080_CONV_TIME); +int8_t HdcTransactionOpen(uint8_t addr, uint8_t reg) { + Wire.beginTransmission((uint8_t) addr); + Wire.write((uint8_t) reg); + return Wire.endTransmission(); +} - 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,19 +199,21 @@ 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; - temp_data = (uint16_t) ((sensor_data[0] << 8) | sensor_data[1]); - rh_data = (uint16_t) ((sensor_data[2] << 8) | sensor_data[3]); + status = HdcTransactionClose(HDC1080_ADDR, sensor_data, 4); - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("HdcRead: temperature raw data: 0x%04x; humidity raw data: 0x%04x"), temp_data, rh_data); - - if(status != 0) { + 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); + // read the temperature from the first 16 bits of the result hdc_temperature = ConvertTemp(HDC1080_TEMP_MULT * (float) (temp_data) - HDC1080_TEMP_OFFSET); @@ -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 232cebc07cf7..c9ba04f6d4a1 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -178,7 +178,7 @@ "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 2441acdc023484529e38fef6f6c383690d557690 Mon Sep 17 00:00:00 2001 From: Luis Teixeira Date: Fri, 13 Mar 2020 22:40:33 +0000 Subject: [PATCH 12/13] 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 8e5538b9d0f5..74de683838cf 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 13/13] 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 c9ba04f6d4a1..fe80630cc5c2 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -178,7 +178,7 @@ "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",