Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions examples/simple_repeater/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ static char ethernet_command[160];
// For power saving
unsigned long POWERSAVING_FIRSTSLEEP_SECS = 120; // The first sleep (if enabled) from boot

#if defined(PIN_USER_BTN) && defined(_SEEED_SENSECAP_SOLAR_H_)
#if defined(PIN_USER_BTN) && (defined(_SEEED_SENSECAP_SOLAR_H_) || defined(THINKNODE_M6))
static unsigned long userBtnDownAt = 0;
#if defined(THINKNODE_M6)
#define USER_BTN_HOLD_OFF_MILLIS 5000 // matches Elecrow's stock firmware UX
#else
#define USER_BTN_HOLD_OFF_MILLIS 1500
#endif
#endif

void setup() {
Serial.begin(115200);
Expand Down Expand Up @@ -170,13 +174,22 @@ void loop() {
}
#endif

#if defined(PIN_USER_BTN) && defined(_SEEED_SENSECAP_SOLAR_H_) && !defined(DISPLAY_CLASS)
// Hold the user button to power off the SenseCAP Solar repeater.
#if defined(PIN_USER_BTN) && (defined(_SEEED_SENSECAP_SOLAR_H_) || defined(THINKNODE_M6)) && !defined(DISPLAY_CLASS)
// Hold the user button to power off the repeater.
int btnState = digitalRead(PIN_USER_BTN);
if (btnState == LOW) {
if (userBtnDownAt == 0) {
userBtnDownAt = millis();
} else if ((unsigned long)(millis() - userBtnDownAt) >= USER_BTN_HOLD_OFF_MILLIS) {
#if defined(THINKNODE_M6) && defined(PIN_LED_RED)
// blink the power LED a few times to confirm the hold was registered
for (int i = 0; i < 3; i++) {
digitalWrite(PIN_LED_RED, HIGH);
delay(150);
digitalWrite(PIN_LED_RED, LOW);
delay(150);
}
#endif
Serial.println("Powering off...");
board.powerOff(); // does not return
}
Expand Down
29 changes: 29 additions & 0 deletions examples/simple_room_server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ static char command[MAX_POST_TEXT_LEN+1];
static char ethernet_command[MAX_POST_TEXT_LEN+1];
#endif

#if defined(PIN_USER_BTN) && defined(THINKNODE_M6)
static unsigned long userBtnDownAt = 0;
#define USER_BTN_HOLD_OFF_MILLIS 5000 // matches Elecrow's stock firmware UX
#endif

void setup() {
Serial.begin(115200);
delay(1000);
Expand Down Expand Up @@ -148,6 +153,30 @@ void loop() {
}
#endif

#if defined(PIN_USER_BTN) && defined(THINKNODE_M6) && !defined(DISPLAY_CLASS)
// Hold the user button to power off the room server.
int btnState = digitalRead(PIN_USER_BTN);
if (btnState == LOW) {
if (userBtnDownAt == 0) {
userBtnDownAt = millis();
} else if ((unsigned long)(millis() - userBtnDownAt) >= USER_BTN_HOLD_OFF_MILLIS) {
#ifdef PIN_LED_RED
// blink the power LED a few times to confirm the hold was registered
for (int i = 0; i < 3; i++) {
digitalWrite(PIN_LED_RED, HIGH);
delay(150);
digitalWrite(PIN_LED_RED, LOW);
delay(150);
}
#endif
Serial.println("Powering off...");
board.powerOff(); // does not return
}
} else {
userBtnDownAt = 0;
}
#endif

the_mesh.loop();
sensors.loop();
#ifdef DISPLAY_CLASS
Expand Down
14 changes: 14 additions & 0 deletions variants/thinknode_m6/ThinkNodeM6Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ void ThinkNodeM6Board::begin() {
digitalWrite(P_LORA_TX_LED, LOW);
#endif

#ifdef PIN_USER_BTN
pinMode(PIN_USER_BTN, INPUT_PULLUP);
#endif

#ifdef PIN_LED_RED
// blink the power LED a few times to confirm power-on/wake
for (int i = 0; i < 3; i++) {
digitalWrite(PIN_LED_RED, HIGH);
delay(150);
digitalWrite(PIN_LED_RED, LOW);
delay(150);
}
#endif

delay(10); // give sx1262 some time to power up
}

Expand Down
6 changes: 6 additions & 0 deletions variants/thinknode_m6/ThinkNodeM6Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class ThinkNodeM6Board : public NRF52BoardDCDC {
digitalWrite(P_LORA_TX_LED, LOW);
#endif

#ifdef PIN_USER_BTN
while (digitalRead(PIN_USER_BTN) == LOW); // wait for release, avoid instant re-trigger
// keep pull-up enabled in system-off so the wake line doesn't float low
nrf_gpio_cfg_sense_input(digitalPinToInterrupt(g_ADigitalPinMap[PIN_USER_BTN]), NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
#endif

// power off board
NRF52Board::powerOff();
}
Expand Down