diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 80a9af330d83..10a0699c7d61 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,5 +1,7 @@ /* 5.10.0a * Add (experimental) support for sensor SHT3x + * Change ADS1115 default voltage range from +/-2V to +/-4V (#1289) + * Add multipress support and more user configurable options to Sonoff Dual R2 (#1291) * * 5.10.0 20171201 * Upgrade library ArduinoJson to 5.11.2 diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 3bb680aa242e..ec33d9ee37b5 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -1925,7 +1925,7 @@ void ButtonHandler() snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_BUTTON " " D_CODE " %04X"), dual_button_code); AddLog(LOG_LEVEL_DEBUG); button = PRESSED; - if (0xF500 == dual_button_code) { // Button hold + if (0xF500 == dual_button_code) { // Button hold holdbutton[i] = (Settings.param[P_HOLD_TIME] * (STATES / 10)) -1; } dual_button_code = 0; @@ -1952,28 +1952,28 @@ void ButtonHandler() if ((NOT_PRESSED == button) && (PRESSED == lastbutton[i])) { snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_BUTTON " %d " D_LEVEL_01), i +1); AddLog(LOG_LEVEL_DEBUG); - if (!holdbutton[i]) { // Do not allow within 1 second + if (!holdbutton[i]) { // Do not allow within 1 second button_pressed = true; } } if (button_pressed) { - if (!send_button_power(0, i +1, 2)) { // Execute Toggle command via MQTT if ButtonTopic is set - ExecuteCommandPower(i +1, 2); // Execute Toggle command internally + if (!send_button_power(0, i +1, 2)) { // Execute Toggle command via MQTT if ButtonTopic is set + ExecuteCommandPower(i +1, 2); // Execute Toggle command internally } } } else { if ((PRESSED == button) && (NOT_PRESSED == lastbutton[i])) { - if (Settings.flag.button_single) { // Allow only single button press for immediate action + if (Settings.flag.button_single) { // Allow only single button press for immediate action snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_BUTTON " %d " D_IMMEDIATE), i +1); AddLog(LOG_LEVEL_DEBUG); - if (!send_button_power(0, i +1, 2)) { // Execute Toggle command via MQTT if ButtonTopic is set - ExecuteCommandPower(i +1, 2); // Execute Toggle command internally + if (!send_button_power(0, i +1, 2)) { // Execute Toggle command via MQTT if ButtonTopic is set + ExecuteCommandPower(i +1, 2); // Execute Toggle command internally } } else { multipress[i] = (multiwindow[i]) ? multipress[i] +1 : 1; snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_BUTTON " %d " D_MULTI_PRESS " %d"), i +1, multipress[i]); AddLog(LOG_LEVEL_DEBUG); - multiwindow[i] = STATES /2; // 0.5 second multi press window + multiwindow[i] = STATES /2; // 0.5 second multi press window } blinks = 201; } @@ -1982,33 +1982,33 @@ void ButtonHandler() holdbutton[i] = 0; } else { holdbutton[i]++; - if (Settings.flag.button_single) { // Allow only single button press for immediate action + if (Settings.flag.button_single) { // Allow only single button press for immediate action if (holdbutton[i] == Settings.param[P_HOLD_TIME] * (STATES / 10) * 4) { // Button hold for four times longer // Settings.flag.button_single = 0; snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_SETOPTION "13 0")); // Disable single press only ExecuteCommand(scmnd); } } else { - if (holdbutton[i] == Settings.param[P_HOLD_TIME] * (STATES / 10)) { // Button hold + if (holdbutton[i] == Settings.param[P_HOLD_TIME] * (STATES / 10)) { // Button hold multipress[i] = 0; - if (!Settings.flag.button_restrict) { // No button restriction + if (!Settings.flag.button_restrict) { // No button restriction snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_RESET " 1")); ExecuteCommand(scmnd); } else { - send_button_power(0, i +1, 3); // Execute Hold command via MQTT if ButtonTopic is set + send_button_power(0, i +1, 3); // Execute Hold command via MQTT if ButtonTopic is set } } } } - if (!Settings.flag.button_single) { // Allow multi-press + if (!Settings.flag.button_single) { // Allow multi-press if (multiwindow[i]) { multiwindow[i]--; } else { if (!restart_flag && !holdbutton[i] && (multipress[i] > 0) && (multipress[i] < MAX_BUTTON_COMMANDS +3)) { boolean single_press = false; - if (multipress[i] < 3) { // Single or Double press - if ((SONOFF_DUAL == Settings.module) || (CH4 == Settings.module)) { + if (multipress[i] < 3) { // Single or Double press + if ((SONOFF_DUAL_R2 == Settings.module) || (SONOFF_DUAL == Settings.module) || (CH4 == Settings.module)) { single_press = true; } else { single_press = (Settings.flag.button_swap +1 == multipress[i]); @@ -2018,13 +2018,13 @@ void ButtonHandler() if (single_press && send_button_power(0, i + multipress[i], 2)) { // Execute Toggle command via MQTT if ButtonTopic is set // Success } else { - if (multipress[i] < 3) { // Single or Double press - if (WifiState()) { // WPSconfig, Smartconfig or Wifimanager active + if (multipress[i] < 3) { // Single or Double press + if (WifiState()) { // WPSconfig, Smartconfig or Wifimanager active restart_flag = 1; } else { ExecuteCommandPower(i + multipress[i], 2); // Execute Toggle command internally } - } else { // 3 - 7 press + } else { // 3 - 7 press if (!Settings.flag.button_restrict) { snprintf_P(scmnd, sizeof(scmnd), kCommands[multipress[i] -3]); ExecuteCommand(scmnd); diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index e7e1d6cbb4de..89384d938d22 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -765,15 +765,15 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { 0, 0 }, { "Sonoff Dual R2", // Sonoff Dual R2 (ESP8285) - GPIO_SWT1, // GPIO00 Button 1 on header + GPIO_USER, // GPIO00 Button 0 on header (0 = On, 1 = Off) GPIO_USER, // GPIO01 Serial RXD and Optional sensor 0, GPIO_USER, // GPIO03 Serial TXD and Optional sensor 0, GPIO_REL2, // GPIO05 Relay 2 (0 = Off, 1 = On) 0, 0, 0, // Flash connection - GPIO_SWT2, // GPIO09 Button 2 on header - GPIO_KEY1, // GPIO10 Button 3 on casing + GPIO_USER, // GPIO09 Button 1 on header (0 = On, 1 = Off) + GPIO_KEY1, // GPIO10 Button on casing 0, // Flash connection GPIO_REL1, // GPIO12 Relay 1 (0 = Off, 1 = On) GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off) diff --git a/sonoff/xsns_12_ads1115.ino b/sonoff/xsns_12_ads1115.ino index ffe5c5eca592..411d9a4b3e70 100644 --- a/sonoff/xsns_12_ads1115.ino +++ b/sonoff/xsns_12_ads1115.ino @@ -33,19 +33,19 @@ * ADS1115 * ------- * ADS1115_REG_CONFIG_PGA_6_144V // 2/3x gain +/- 6.144V 1 bit = 0.1875mV - * ADS1115_REG_CONFIG_PGA_4_096V // 1x gain +/- 4.096V 1 bit = 0.125mV - * ADS1115_REG_CONFIG_PGA_2_048V // 2x gain +/- 2.048V 1 bit = 0.0625mV (default) + * ADS1115_REG_CONFIG_PGA_4_096V // 1x gain +/- 4.096V 1 bit = 0.125mV (default) + * ADS1115_REG_CONFIG_PGA_2_048V // 2x gain +/- 2.048V 1 bit = 0.0625mV * ADS1115_REG_CONFIG_PGA_1_024V // 4x gain +/- 1.024V 1 bit = 0.03125mV * ADS1115_REG_CONFIG_PGA_0_512V // 8x gain +/- 0.512V 1 bit = 0.015625mV * ADS1115_REG_CONFIG_PGA_0_256V // 16x gain +/- 0.256V 1 bit = 0.0078125mV \*********************************************************************************************/ -#define ADS1115_ADDRESS_ADDR_GND 0x48 // address pin low (GND) -#define ADS1115_ADDRESS_ADDR_VDD 0x49 // address pin high (VCC) -#define ADS1115_ADDRESS_ADDR_SDA 0x4A // address pin tied to SDA pin -#define ADS1115_ADDRESS_ADDR_SCL 0x4B // address pin tied to SCL pin +#define ADS1115_ADDRESS_ADDR_GND 0x48 // address pin low (GND) +#define ADS1115_ADDRESS_ADDR_VDD 0x49 // address pin high (VCC) +#define ADS1115_ADDRESS_ADDR_SDA 0x4A // address pin tied to SDA pin +#define ADS1115_ADDRESS_ADDR_SCL 0x4B // address pin tied to SCL pin -#define ADS1115_CONVERSIONDELAY (8) // CONVERSION DELAY (in mS) +#define ADS1115_CONVERSIONDELAY (8) // CONVERSION DELAY (in mS) /*====================================================================== POINTER REGISTER @@ -126,7 +126,7 @@ void Ads1115StartComparator(uint8_t channel, uint16_t mode) uint16_t config = mode | ADS1115_REG_CONFIG_CQUE_NONE | // Comparator enabled and asserts on 1 match ADS1115_REG_CONFIG_CLAT_NONLAT | // Non Latching mode - ADS1115_REG_CONFIG_PGA_2_048V | // ADC Input voltage range (Gain) + ADS1115_REG_CONFIG_PGA_4_096V | // ADC Input voltage range (Gain) ADS1115_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val) ADS1115_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val) ADS1115_REG_CONFIG_DR_6000SPS; // 6000 samples per second diff --git a/sonoff/xsns_12_ads1115_i2cdev.ino b/sonoff/xsns_12_ads1115_i2cdev.ino index 10def543c0bb..08db3cc63f3d 100644 --- a/sonoff/xsns_12_ads1115_i2cdev.ino +++ b/sonoff/xsns_12_ads1115_i2cdev.ino @@ -84,7 +84,7 @@ void Ads1115Detect() ADS1115 adc0(ads1115_address); if (adc0.testConnection()) { adc0.initialize(); - adc0.setGain(ADS1115_PGA_2P048); // Set the gain (PGA) +/-4.096V + adc0.setGain(ADS1115_PGA_4P096); // Set the gain (PGA) +/-4.096V adc0.setRate(ADS1115_RATE_860); adc0.setMode(ADS1115_MODE_CONTINUOUS); ads1115_type = 1; diff --git a/sonoff/xsns_14_sht3x.ino b/sonoff/xsns_14_sht3x.ino index bd8cd981d3d7..6b38cf661ec7 100644 --- a/sonoff/xsns_14_sht3x.ino +++ b/sonoff/xsns_14_sht3x.ino @@ -1,7 +1,7 @@ /* - xsns_15SHT3X.ino - WeMos SHT30 Shield + xsns_14_sht3x.ino - SHT3X temperature and humidity sensor support for Sonoff-Tasmota - Copyright (C) 2017 Palich2000 + Copyright (C) 2017 Theo Arends 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 @@ -20,10 +20,11 @@ #ifdef USE_I2C #ifdef USE_SHT3X /*********************************************************************************************\ - * WeMos SHT30 Shield - * https://wiki.wemos.cc/products:d1_mini_shields:sht30_shield + * SHT3X - Temperature and Humidy * - * https://github.com/wemos/WEMOS_SHT3x_Arduino_Library + * Required library: none but based on Adafruit Industries SHT31 library + * + * I2C Address: 0x44 or 0x45 \*********************************************************************************************/ #define SHT3X_ADDR_GND 0x44 // address pin low (GND)