Browse Source
Merge pull request #289 from adam2872/RAK4631-user-button
Implement user button on RAK4631 using analogue pin 31 (same as MT)
pull/329/head
ripplebiz
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
43 additions and
29 deletions
-
examples/companion_radio/UITask.cpp
-
src/helpers/nrf52/RAK4631Board.cpp
-
variants/rak4631/platformio.ini
|
|
|
@ -232,15 +232,23 @@ void UITask::userLedHandler() { |
|
|
|
} |
|
|
|
|
|
|
|
void UITask::buttonHandler() { |
|
|
|
#ifdef PIN_USER_BTN |
|
|
|
#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA) |
|
|
|
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 next_read = 0; |
|
|
|
int cur_time = millis(); |
|
|
|
if (cur_time >= next_read) { |
|
|
|
int btn_state = digitalRead(PIN_USER_BTN); |
|
|
|
if (btn_state != prev_btn_state) { |
|
|
|
if (btn_state == USER_BTN_PRESSED) { // pressed?
|
|
|
|
int btn_state = 0; |
|
|
|
int btn_state_ana = 0; |
|
|
|
#ifdef PIN_USER_BTN |
|
|
|
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 |
|
|
|
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->isOn()) { |
|
|
|
clearMsgPreview(); |
|
|
|
@ -261,11 +269,12 @@ void UITask::buttonHandler() { |
|
|
|
} |
|
|
|
btn_state_change_time = millis(); |
|
|
|
prev_btn_state = btn_state; |
|
|
|
prev_btn_state_ana = btn_state_ana; |
|
|
|
} |
|
|
|
next_read = millis() + 100; // 10 reads per second
|
|
|
|
} |
|
|
|
#endif |
|
|
|
} |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
void UITask::loop() { |
|
|
|
buttonHandler(); |
|
|
|
|
|
|
|
@ -26,6 +26,10 @@ void RAK4631Board::begin() { |
|
|
|
pinMode(PIN_USER_BTN, INPUT_PULLUP); |
|
|
|
#endif |
|
|
|
|
|
|
|
#ifdef PIN_USER_BTN_ANA |
|
|
|
pinMode(PIN_USER_BTN_ANA, INPUT_PULLUP); |
|
|
|
#endif |
|
|
|
|
|
|
|
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL) |
|
|
|
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL); |
|
|
|
#endif |
|
|
|
|
|
|
|
@ -7,6 +7,7 @@ build_flags = ${nrf52840_base.build_flags} |
|
|
|
-I variants/rak4631 |
|
|
|
-D RAK_4631 |
|
|
|
-D PIN_USER_BTN=9 |
|
|
|
-D PIN_USER_BTN_ANA=31 |
|
|
|
-D PIN_BOARD_SCL=14 |
|
|
|
-D PIN_BOARD_SDA=13 |
|
|
|
-D PIN_OLED_RESET=-1 |
|
|
|
|