Fix prep for Buttons V2

Fix prep for Buttons V2 for ESP32 (#8177)
This commit is contained in:
Theo Arends 2020-04-14 17:18:34 +02:00
parent 1de275c82b
commit fe63ddbd20
3 changed files with 330 additions and 320 deletions

View File

@ -1243,11 +1243,11 @@ void SettingsDelta(void)
Settings.ex_serial_config = TS_SERIAL_8N1;
}
if (Settings.version < 0x07010204) {
if (Settings.flag3.mqtt_buttons == 1) {
strlcpy(Settings.ex_cors_domain, CORS_ENABLED_ALL, sizeof(Settings.ex_cors_domain));
} else {
Settings.ex_cors_domain[0] = 0;
}
if (Settings.flag3.mqtt_buttons == 1) {
strlcpy(Settings.ex_cors_domain, CORS_ENABLED_ALL, sizeof(Settings.ex_cors_domain));
} else {
Settings.ex_cors_domain[0] = 0;
}
}
if (Settings.version < 0x07010205) {
Settings.seriallog_level = Settings.ex_seriallog_level; // 09E -> 452

View File

@ -24,6 +24,7 @@
\*********************************************************************************************/
#define MAX_BUTTON_COMMANDS 5 // Max number of button commands supported
const char kCommands[] PROGMEM =
D_CMND_WIFICONFIG " 2|" D_CMND_WIFICONFIG " 2|" D_CMND_WIFICONFIG " 2|" D_CMND_RESTART " 1|" D_CMND_UPGRADE " 1";

View File

@ -17,14 +17,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define BUTTON_V2
//#define BUTTON_V2
#ifdef BUTTON_V2
/*********************************************************************************************\
* Button support
\*********************************************************************************************/
#define MAX_BUTTON_COMMANDS 3 // Max number of button commands supported
#define MAX_RELAY_BUTTON1 4 // Max number of relay controlled by button1
#define MAX_BUTTON_COMMANDS_V2 3 // Max number of button commands supported
#define MAX_RELAY_BUTTON1 4 // Max number of relay controlled by button1
const char kCommands[] PROGMEM =
D_CMND_WIFICONFIG " 2|" D_CMND_RESTART " 1|" D_CMND_UPGRADE " 1";
@ -127,6 +127,7 @@ void ButtonHandler(void)
uint8_t button = NOT_PRESSED;
uint8_t button_present = 0;
#ifdef ESP8266
if (!button_index && ((SONOFF_DUAL == my_module_type) || (CH4 == my_module_type))) {
button_present = 1;
if (Button.dual_code) {
@ -139,7 +140,9 @@ void ButtonHandler(void)
Button.dual_code = 0;
}
}
else if (pin[GPIO_KEY1 +button_index] < 99) {
else
#endif // ESP8266
if (pin[GPIO_KEY1 +button_index] < 99) {
button_present = 1;
button = (digitalRead(pin[GPIO_KEY1 +button_index]) != bitRead(Button.inverted_mask, button_index));
}
@ -161,6 +164,7 @@ void ButtonHandler(void)
if (XdrvCall(FUNC_BUTTON_PRESSED)) {
// Serviced
}
#ifdef ESP8266
else if (SONOFF_4CHPRO == my_module_type) {
if (Button.hold_timer[button_index]) { Button.hold_timer[button_index]--; }
@ -180,7 +184,9 @@ void ButtonHandler(void)
}
}
} else {
}
#endif // ESP8266
else {
if ((PRESSED == button) && (NOT_PRESSED == Button.last_state[button_index])) {
@ -231,12 +237,15 @@ void ButtonHandler(void)
if (Button.window_timer[button_index]) {
Button.window_timer[button_index]--;
} else {
if (!restart_flag && !Button.hold_timer[button_index] && (Button.press_counter[button_index] > 0) && (Button.press_counter[button_index] < MAX_BUTTON_COMMANDS +6)) {
if (!restart_flag && !Button.hold_timer[button_index] && (Button.press_counter[button_index] > 0) && (Button.press_counter[button_index] < MAX_BUTTON_COMMANDS_V2 +6)) {
bool single_press = false;
if (Button.press_counter[button_index] < 3) { // Single or Double press
#ifdef ESP8266
if ((SONOFF_DUAL_R2 == my_module_type) || (SONOFF_DUAL == my_module_type) || (CH4 == my_module_type)) {
single_press = true;
} else {
} else
#endif // ESP8266
{
single_press = (Settings.flag.button_swap +1 == Button.press_counter[button_index]); // SetOption11 (0)
if ((1 == Button.present) && (2 == devices_present)) { // Single Button with two devices only
if (Settings.flag.button_swap) { // SetOption11 (0)