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

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

View File

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