From e33657eb75ec0f70cb7b958de9aef55bb9af8068 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Mon, 9 Nov 2020 19:47:31 -0800 Subject: [PATCH 1/6] Toggle GPIO2 to HIGH when transmitting a packet out the LORA radio. --- src/configuration.h | 4 ++++ src/main.cpp | 7 +++++++ src/mesh/RadioLibInterface.cpp | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/src/configuration.h b/src/configuration.h index 5e8964d2..3fadf9a6 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -162,6 +162,10 @@ along with this program. If not, see . // This string must exactly match the case used in release file names or the android updater won't work #define HW_VENDOR "tbeam" +// Jm's TXRX Deduplexer +#define RADIO_TXRX 2 + + // #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep #define I2C_SDA 21 diff --git a/src/main.cpp b/src/main.cpp index 0f24e1bc..99a19755 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -233,6 +233,13 @@ RadioInterface *rIf = NULL; void setup() { + +// Jm's TXRX Deduplexer +// if 0 - receive +// 1 - transmit +pinMode(RADIO_TXRX, OUTPUT); +digitalWrite(RADIO_TXRX, 0); + #ifdef USE_SEGGER SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_TRIM); #endif diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 41d000d6..7d5aa10b 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -247,6 +247,8 @@ void RadioLibInterface::completeSending() txGood++; printPacket("Completed sending", sendingPacket); + digitalWrite(RADIO_TXRX, 0); + // We are done sending that packet, release it packetPool.release(sendingPacket); sendingPacket = NULL; @@ -309,6 +311,8 @@ void RadioLibInterface::handleReceiveInterrupt() /** start an immediate transmit */ void RadioLibInterface::startSend(MeshPacket *txp) { + digitalWrite(RADIO_TXRX, 1); + printPacket("Starting low level send", txp); setStandby(); // Cancel any already in process receives From f60922af34927d1a5d12e62f8d7869588ba772dc Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sun, 22 Nov 2020 15:42:36 -0800 Subject: [PATCH 2/6] Accidently checked in my rf deduplexer --- src/configuration.h | 4 ---- src/main.cpp | 6 ------ 2 files changed, 10 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index 08956678..ed851ed8 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -162,10 +162,6 @@ along with this program. If not, see . // This string must exactly match the case used in release file names or the android updater won't work #define HW_VENDOR "tbeam" -// Jm's TXRX Deduplexer -#define RADIO_TXRX 2 - - // #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep #define I2C_SDA 21 diff --git a/src/main.cpp b/src/main.cpp index 84ea99c0..acef3b67 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -245,12 +245,6 @@ void setup() SEGGER_RTT_ConfigUpBuffer(SEGGER_STDOUT_CH, NULL, NULL, 1024, SEGGER_RTT_MODE_NO_BLOCK_TRIM); #endif -// Jm's TXRX Deduplexer -// if 0 - receive -// 1 - transmit -pinMode(RADIO_TXRX, OUTPUT); -digitalWrite(RADIO_TXRX, 0); - #ifdef USE_SEGGER SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_TRIM); #endif From 3ab9d2a50e2cf1b68e87b956761009274e4779f6 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sun, 22 Nov 2020 16:24:22 -0800 Subject: [PATCH 3/6] Removing stuff I accidently checked in for the duplexer --- src/mesh/RadioLibInterface.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 069403ad..9a5ec536 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -197,8 +197,6 @@ void RadioLibInterface::completeSending() txGood++; printPacket("Completed sending", p); - digitalWrite(RADIO_TXRX, 0); - // We are done sending that packet, release it packetPool.release(p); // DEBUG_MSG("Done with send\n"); @@ -256,12 +254,10 @@ void RadioLibInterface::handleReceiveInterrupt() } } } - + /** start an immediate transmit */ void RadioLibInterface::startSend(MeshPacket *txp) { - digitalWrite(RADIO_TXRX, 1); - printPacket("Starting low level send", txp); setStandby(); // Cancel any already in process receives From 2bd40b7053b4c6ca11c29238416520f069eb1480 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sun, 22 Nov 2020 18:50:14 -0800 Subject: [PATCH 4/6] Add support for the power button #528 --- src/Power.cpp | 5 +++++ src/main.cpp | 54 +++++++++++++++++++++++++++++++++++++++------------ src/power.h | 1 + 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index ae51e803..93e3096d 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -134,6 +134,11 @@ bool Power::setup() return found; } +void Power::shutdown() { + DEBUG_MSG("Shutting down\n"); + axp.shutdown(); +} + /// Reads power status to powerStatus singleton. // // TODO(girts): move this and other axp stuff to power.h/power.cpp. diff --git a/src/main.cpp b/src/main.cpp index acef3b67..228f2b3e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -167,29 +167,35 @@ class ButtonThread : public OSThread #endif public: + static uint32_t longPressTime; + // callback returns the period for the next callback invocation (or 0 if we should no longer be called) ButtonThread() : OSThread("Button") { #ifdef BUTTON_PIN userButton = OneButton(BUTTON_PIN, true, true); #ifdef INPUT_PULLUP_SENSE - // Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did + // Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did pinMode(BUTTON_PIN, INPUT_PULLUP_SENSE); #endif userButton.attachClick(userButtonPressed); userButton.attachDuringLongPress(userButtonPressedLong); userButton.attachDoubleClick(userButtonDoublePressed); + userButton.attachLongPressStart(userButtonPressedLongStart); + userButton.attachLongPressStop(userButtonPressedLongStop); wakeOnIrq(BUTTON_PIN, FALLING); #endif #ifdef BUTTON_PIN_ALT userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true); #ifdef INPUT_PULLUP_SENSE - // Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did + // Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did pinMode(BUTTON_PIN_ALT, INPUT_PULLUP_SENSE); -#endif +#endif userButtonAlt.attachClick(userButtonPressed); userButtonAlt.attachDuringLongPress(userButtonPressedLong); userButtonAlt.attachDoubleClick(userButtonDoublePressed); + userButtonAlt.attachLongPressStart(userButtonPressedLongStart); + userButtonAlt.attachLongPressStop(userButtonPressedLongStop); wakeOnIrq(BUTTON_PIN_ALT, FALLING); #endif } @@ -209,7 +215,7 @@ class ButtonThread : public OSThread canSleep &= userButtonAlt.isIdle(); #endif // if (!canSleep) DEBUG_MSG("Supressing sleep!\n"); - //else DEBUG_MSG("sleep ok\n"); + // else DEBUG_MSG("sleep ok\n"); return 5; } @@ -222,20 +228,44 @@ class ButtonThread : public OSThread } static void userButtonPressedLong() { - DEBUG_MSG("Long press!\n"); + // DEBUG_MSG("Long press!\n"); screen->adjustBrightness(); - } - - static void userButtonDoublePressed() -{ -#ifndef NO_ESP32 - disablePin(); + + // If user button is held down for 10 seconds, shutdown the device. + if (millis() - longPressTime > 10 * 1000) { +#ifdef AXP192_SLAVE_ADDRESS + if (axp192_found == true) { + power->shutdown(); + } #endif -} + } else { + //DEBUG_MSG("Long press %u\n", (millis() - longPressTime)); + } + } + + static void userButtonDoublePressed() + { +#ifndef NO_ESP32 + disablePin(); +#endif + } + + static void userButtonPressedLongStart() + { + DEBUG_MSG("Long press start!\n"); + longPressTime = millis(); + } + + static void userButtonPressedLongStop() + { + DEBUG_MSG("Long press stop!\n"); + longPressTime = 0; + } }; static Periodic *ledPeriodic; static OSThread *powerFSMthread, *buttonThread; +uint32_t ButtonThread::longPressTime = 0; RadioInterface *rIf = NULL; diff --git a/src/power.h b/src/power.h index 8b75834a..815e2267 100644 --- a/src/power.h +++ b/src/power.h @@ -23,6 +23,7 @@ class Power : private concurrency::OSThread Power(); + void shutdown(); void readPowerStatus(); virtual bool setup(); virtual int32_t runOnce(); From 9801a62d2dc1f722f49013ac57c14385498c7ed2 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sun, 22 Nov 2020 19:01:48 -0800 Subject: [PATCH 5/6] Fix for CI on other boards. --- src/Power.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Power.cpp b/src/Power.cpp index 93e3096d..4e30c828 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -134,9 +134,12 @@ bool Power::setup() return found; } -void Power::shutdown() { +void Power::shutdown() +{ +#ifdef AXP192_SLAVE_ADDRESS DEBUG_MSG("Shutting down\n"); axp.shutdown(); +#endif } /// Reads power status to powerStatus singleton. From 817c99e09ccdd9e47ace7e967a6ed2ef02da7a16 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sun, 22 Nov 2020 19:12:11 -0800 Subject: [PATCH 6/6] trying to fix it again --- src/Power.cpp | 2 +- src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index 4e30c828..ba908e3f 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -136,7 +136,7 @@ bool Power::setup() void Power::shutdown() { -#ifdef AXP192_SLAVE_ADDRESS +#ifdef TBEAM_V10 DEBUG_MSG("Shutting down\n"); axp.shutdown(); #endif diff --git a/src/main.cpp b/src/main.cpp index 228f2b3e..4c0af7f7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -233,7 +233,7 @@ class ButtonThread : public OSThread // If user button is held down for 10 seconds, shutdown the device. if (millis() - longPressTime > 10 * 1000) { -#ifdef AXP192_SLAVE_ADDRESS +#ifdef TBEAM_V10 if (axp192_found == true) { power->shutdown(); }