Merge pull request #216 from Professr/issue#162

Use spare TBeam GPIO for an alternate middle button - Issue#162
This commit is contained in:
Kevin Hester 2020-06-23 15:42:19 -07:00 committed by GitHub
commit 58dbc3c702
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 22 deletions

View File

@ -67,7 +67,7 @@ debug_tool = jlink
lib_deps = lib_deps =
https://github.com/meshtastic/esp8266-oled-ssd1306.git ; ESP8266_SSD1306 https://github.com/meshtastic/esp8266-oled-ssd1306.git ; ESP8266_SSD1306
SPI SPI
; 1260 ; OneButton - not used yet 1260 ; OneButton library for non-blocking button debounce
1202 ; CRC32, explicitly needed because dependency is missing in the ble ota update lib 1202 ; CRC32, explicitly needed because dependency is missing in the ble ota update lib
Wire ; explicitly needed here because the AXP202 library forgets to add it Wire ; explicitly needed here because the AXP202 library forgets to add it
https://github.com/meshtastic/arduino-fsm.git https://github.com/meshtastic/arduino-fsm.git
@ -98,6 +98,7 @@ board = ttgo-t-beam
lib_deps = lib_deps =
${env.lib_deps} ${env.lib_deps}
https://github.com/meshtastic/AXP202X_Library.git https://github.com/meshtastic/AXP202X_Library.git
build_flags = build_flags =
${esp32_base.build_flags} -D TBEAM_V10 ${esp32_base.build_flags} -D TBEAM_V10

View File

@ -144,7 +144,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define I2C_SDA 21 #define I2C_SDA 21
#define I2C_SCL 22 #define I2C_SCL 22
#define BUTTON_PIN 38 #define BUTTON_PIN 38 // The middle button GPIO on the T-Beam
#define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed
#ifndef USE_JTAG #ifndef USE_JTAG
#define RESET_GPIO 14 #define RESET_GPIO 14

View File

@ -38,6 +38,7 @@
#include "screen.h" #include "screen.h"
#include "sleep.h" #include "sleep.h"
#include <Wire.h> #include <Wire.h>
#include <OneButton.h>
// #include <driver/rtc_io.h> // #include <driver/rtc_io.h>
#ifndef NO_ESP32 #ifndef NO_ESP32
@ -125,6 +126,17 @@ static uint32_t ledBlinker()
Periodic ledPeriodic(ledBlinker); Periodic ledPeriodic(ledBlinker);
// Prepare for button presses
#ifdef BUTTON_PIN
OneButton userButton;
#endif
#ifdef BUTTON_PIN_ALT
OneButton userButtonAlt;
#endif
void userButtonPressed() {
powerFSM.trigger(EVENT_PRESS);
}
#ifndef NO_ESP32 #ifndef NO_ESP32
void initWifi() void initWifi()
{ {
@ -183,8 +195,12 @@ void setup()
// Buttons & LED // Buttons & LED
#ifdef BUTTON_PIN #ifdef BUTTON_PIN
pinMode(BUTTON_PIN, INPUT_PULLUP); userButton = OneButton(BUTTON_PIN, true, true);
digitalWrite(BUTTON_PIN, 1); userButton.attachClick(userButtonPressed);
#endif
#ifdef BUTTON_PIN_ALT
userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true);
userButtonAlt.attachClick(userButtonPressed);
#endif #endif
#ifdef LED_PIN #ifdef LED_PIN
pinMode(LED_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT);
@ -322,24 +338,10 @@ void loop()
#endif #endif
#ifdef BUTTON_PIN #ifdef BUTTON_PIN
// if user presses button for more than 3 secs, discard our network prefs and reboot (FIXME, use a debounce lib instead of userButton.tick();
// this boilerplate) #endif
static bool wasPressed = false; #ifdef BUTTON_PIN_ALT
userButtonAlt.tick();
if (!digitalRead(BUTTON_PIN)) {
if (!wasPressed) { // just started a new press
DEBUG_MSG("pressing\n");
// doLightSleep();
// esp_pm_dump_locks(stdout); // FIXME, do this someplace better
wasPressed = true;
powerFSM.trigger(EVENT_PRESS);
}
} else if (wasPressed) {
// we just did a release
wasPressed = false;
}
#endif #endif
// Show boot screen for first 3 seconds, then switch to normal operation. // Show boot screen for first 3 seconds, then switch to normal operation.