Merge pull request #3 from adam2872/revert-2-RAK4631-user-button

Revert "RAK4631 analogue user button on input 31"
This commit is contained in:
adam2872
2025-05-14 22:05:23 +01:00
committed by GitHub
3 changed files with 29 additions and 43 deletions

View File

@@ -209,24 +209,15 @@ void UITask::userLedHandler() {
} }
void UITask::buttonHandler() { void UITask::buttonHandler() {
#ifdef PIN_USER_BTN || PIN_USER_BTN_ANA #ifdef PIN_USER_BTN
static int prev_btn_state = !USER_BTN_PRESSED; static int prev_btn_state = !USER_BTN_PRESSED;
static int prev_btn_state_ana = !USER_BTN_PRESSED;
static unsigned long btn_state_change_time = 0; static unsigned long btn_state_change_time = 0;
static unsigned long next_read = 0; static unsigned long next_read = 0;
int cur_time = millis(); int cur_time = millis();
if (cur_time >= next_read) { if (cur_time >= next_read) {
int btn_state = 0; int btn_state = digitalRead(PIN_USER_BTN);
int btn_state_ana = 0; if (btn_state != prev_btn_state) {
#ifdef PIN_USER_BTN if (btn_state == USER_BTN_PRESSED) { // pressed?
btn_state = digitalRead(PIN_USER_BTN);
#endif
#ifdef PIN_USER_BTN_ANA
btn_state_ana = (analogRead(PIN_USER_BTN_ANA) < 20); // analogRead returns a value hopefully below 20 when button is pressed.
#endif
//Serial.println(analogRead(PIN_USER_BTN_ANA));
if (btn_state != prev_btn_state || btn_state_ana != prev_btn_state_ana) { // check for either digital or analogue button change of state
if (btn_state == USER_BTN_PRESSED || btn_state_ana == USER_BTN_PRESSED) { // pressed?
if (_display != NULL) { if (_display != NULL) {
if (_display->isOn()) { if (_display->isOn()) {
clearMsgPreview(); clearMsgPreview();
@@ -247,7 +238,6 @@ void UITask::buttonHandler() {
} }
btn_state_change_time = millis(); btn_state_change_time = millis();
prev_btn_state = btn_state; prev_btn_state = btn_state;
prev_btn_state_ana = btn_state_ana;
} }
next_read = millis() + 100; // 10 reads per second next_read = millis() + 100; // 10 reads per second
} }

View File

@@ -25,9 +25,6 @@ void RAK4631Board::begin() {
#ifdef PIN_USER_BTN #ifdef PIN_USER_BTN
pinMode(PIN_USER_BTN, INPUT_PULLUP); pinMode(PIN_USER_BTN, INPUT_PULLUP);
#endif #endif
#ifdef PIN_USER_BTN_ANA
pinMode(PIN_USER_BTN_ANA, INPUT_PULLUP);
#endif
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL) #if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL); Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);

View File

@@ -7,7 +7,6 @@ build_flags = ${nrf52840_base.build_flags}
-I variants/rak4631 -I variants/rak4631
-D RAK_4631 -D RAK_4631
-D PIN_USER_BTN=9 -D PIN_USER_BTN=9
-D PIN_USER_BTN_ANA=31
-D PIN_BOARD_SCL=14 -D PIN_BOARD_SCL=14
-D PIN_BOARD_SDA=13 -D PIN_BOARD_SDA=13
-D PIN_OLED_RESET=-1 -D PIN_OLED_RESET=-1