From 14654b4d32d3adad98a195ce5031d3db2e5dbe8b Mon Sep 17 00:00:00 2001 From: richonguzman Date: Thu, 14 Nov 2024 12:41:21 -0300 Subject: [PATCH] ready for testing --- src/LoRa_APRS_Tracker.cpp | 5 ++++- src/button_utils.h | 2 ++ src/joystick_utils.cpp | 34 +++++++++++++++++++++++++++++----- src/joystick_utils.h | 1 + src/keyboard_utils.cpp | 18 +++++++++++++++--- src/msg_utils.cpp | 4 ++-- 6 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/LoRa_APRS_Tracker.cpp b/src/LoRa_APRS_Tracker.cpp index 3f2841e..0612805 100644 --- a/src/LoRa_APRS_Tracker.cpp +++ b/src/LoRa_APRS_Tracker.cpp @@ -55,7 +55,7 @@ TinyGPSPlus gps; BluetoothSerial SerialBT; #endif -String versionDate = "2024.11.13"; +String versionDate = "2024.11.14"; uint8_t myBeaconsIndex = 0; int myBeaconsSize = Config.beacons.size(); @@ -186,6 +186,9 @@ void loop() { Utils::checkDisplayEcoMode(); KEYBOARD_Utils::read(); + #ifdef HAS_JOYSTICK + JOYSTICK_Utils::loop(); + #endif ReceivedLoRaPacket packet = LoRa_Utils::receivePacket(); diff --git a/src/button_utils.h b/src/button_utils.h index 97eabd5..39197f8 100644 --- a/src/button_utils.h +++ b/src/button_utils.h @@ -5,6 +5,8 @@ namespace BUTTON_Utils { + void longPress(); + void loop(); void setup(); diff --git a/src/joystick_utils.cpp b/src/joystick_utils.cpp index 5f59a92..dbef764 100644 --- a/src/joystick_utils.cpp +++ b/src/joystick_utils.cpp @@ -1,14 +1,19 @@ #include "joystick_utils.h" #include "keyboard_utils.h" #include "boards_pinout.h" +#include "button_utils.h" -extern int menuDisplay; +extern int menuDisplay; + +bool exitJoystickInterrupt = false; + +typedef void (*DirectionFunc)(); #ifdef HAS_JOYSTICK namespace JOYSTICK_Utils { - int debounceDelay = 300; + int debounceDelay = 400; uint32_t lastInterruptTime = 0; bool checkLastJoystickInterrupTime() { @@ -20,14 +25,33 @@ extern int menuDisplay; } } - void IRAM_ATTR joystickHandler(void (*directionFunc)()) { - if (checkLastJoystickInterrupTime() && menuDisplay != 0) directionFunc(); + bool checkMenuDisplayToExitInterrupt(int menu) { + if (menu == 10 || menu == 120 || menu == 200 || menu == 210 || menu == 51 || menu == 50100 || menu == 50111) { + return true; // read / delete/ callsignIndex / loraIndex / readW / readW / delete + } else { + return false; + } + } + + void loop() { // for running process with SPIFFS outside interrupt + if (checkMenuDisplayToExitInterrupt(menuDisplay) && exitJoystickInterrupt) BUTTON_Utils::longPress(); + } + + void IRAM_ATTR joystickHandler(DirectionFunc directionFunc) { + if (checkLastJoystickInterrupTime() && menuDisplay != 0) { + if (checkMenuDisplayToExitInterrupt(menuDisplay) && directionFunc == BUTTON_Utils::longPress) { + exitJoystickInterrupt = true; + } else { + exitJoystickInterrupt = false; + directionFunc(); + } + } } void IRAM_ATTR joystickUp() { joystickHandler(KEYBOARD_Utils::upArrow); } void IRAM_ATTR joystickDown() { joystickHandler(KEYBOARD_Utils::downArrow); } void IRAM_ATTR joystickLeft() { joystickHandler(KEYBOARD_Utils::leftArrow); } - void IRAM_ATTR joystickRight() { joystickHandler(KEYBOARD_Utils::rightArrow); } + void IRAM_ATTR joystickRight() { joystickHandler(BUTTON_Utils::longPress); } void setup() { pinMode(JOYSTICK_CENTER, INPUT_PULLUP); diff --git a/src/joystick_utils.h b/src/joystick_utils.h index 4407504..0bea3d2 100644 --- a/src/joystick_utils.h +++ b/src/joystick_utils.h @@ -5,6 +5,7 @@ namespace JOYSTICK_Utils { + void loop(); void setup(); } diff --git a/src/keyboard_utils.cpp b/src/keyboard_utils.cpp index a1a2e0d..2bc07d6 100644 --- a/src/keyboard_utils.cpp +++ b/src/keyboard_utils.cpp @@ -283,7 +283,11 @@ namespace KEYBOARD_Utils { } else if (menuDisplay == 10) { MSG_Utils::loadMessagesFromMemory(0); if (MSG_Utils::warnNoAPRSMessages()) { - menuDisplay = 10; + #ifdef HAS_JOYSTICK + menuDisplay = 11; + #else + menuDisplay = 10; + #endif } else { menuDisplay = 100; } @@ -355,7 +359,11 @@ namespace KEYBOARD_Utils { } else if (menuDisplay == 51) { MSG_Utils::loadMessagesFromMemory(1); if (MSG_Utils::warnNoWLNKMails()) { - menuDisplay = 51; + #ifdef HAS_JOYSTICK + menuDisplay = 50; + #else + menuDisplay = 51; + #endif } else { menuDisplay = 50101; } @@ -387,7 +395,11 @@ namespace KEYBOARD_Utils { displayShow("___INFO___", "", " ALL MAILS DELETED!", 2000); MSG_Utils::loadNumMessages(); if (winlinkStatus == 0) { - menuDisplay = 52; + #ifdef HAS_JOYSTICK + menuDisplay = 50; + #else + menuDisplay = 52; + #endif } else { menuDisplay = 50110; } diff --git a/src/msg_utils.cpp b/src/msg_utils.cpp index fc7821c..f7aa978 100644 --- a/src/msg_utils.cpp +++ b/src/msg_utils.cpp @@ -166,8 +166,8 @@ namespace MSG_Utils { loadedWLNKMails.push_back(fileToRead.readStringUntil('\n')); } fileToRead.close(); - } - } + } + } } void ledNotification() {