Files
MeshCore/variants/thinknode_m4/ThinkNodeM4Board.h
T
9d52b1fd68 Add saved LED controls across supported boards
Add get leds and set leds on|off for Companion, repeater, room server and
sensor builds. Preserve the setting across reboots and cover GPIO, RGB,
Bluetooth, notification and expander indicators without changing radio
amplifier controls or screen backlights.

RAK Companions blink while advertising and keep the Bluetooth LED off once
connected, including late timer callbacks.

Adapted from meshcore-dev/MeshCore#3605 and #2694.
Validated with host regressions and firmware builds for SenseCAP Solar,
RAK4631, T096, Heltec V4, T-Beam, Xiao S3, Pico W and Wio E5 Mini.

Co-authored-by: R0ck <develop@hectospark.co.uk>
Co-authored-by: Nick Dunklee <nick@dunklee.org>
2026-10-20 08:59:39 -07:00

81 lines
2.0 KiB
C++

#pragma once
#include <Arduino.h>
#include <MeshCore.h>
#include <helpers/NRF52Board.h>
class ThinkNodeM4Board : public NRF52BoardDCDC {
protected:
#if NRF52_POWER_MANAGEMENT
void initiateShutdown(uint8_t reason) override;
#endif
uint8_t btn_prev_state;
HardwareSerial * battery_serial;
uint16_t bat_level_mv = 0;
uint8_t bat_level_percent =0;
public:
ThinkNodeM4Board() : NRF52Board("THINKNODE_M4_OTA"), battery_serial(&Serial2) {}
void begin();
uint16_t getBattMilliVolts() override;
#ifdef P_LORA_TX_LED
void applyLedPolicy() override {
NRF52Board::applyLedPolicy();
if (!mesh::leds::enabled()) digitalWrite(P_LORA_TX_LED, !LED_STATE_ON);
}
void onBeforeTransmit() override {
if (mesh::leds::enabled()) digitalWrite(P_LORA_TX_LED, LED_STATE_ON); // turn TX LED on
}
void onAfterTransmit() override {
digitalWrite(P_LORA_TX_LED, !LED_STATE_ON); // turn TX LED off
}
#endif
const char* getManufacturerName() const override {
return "Elecrow ThinkNode M4";
}
int buttonStateChanged() {
#ifdef BUTTON_PIN
uint8_t v = digitalRead(BUTTON_PIN);
if (v != btn_prev_state) {
btn_prev_state = v;
return (v == USER_BTN_PRESSED) ? 1 : -1;
}
#endif
return 0;
}
void shutdownPeripherals() override {
// shutdown common peripherals
NRF52Board::shutdownPeripherals();
#ifdef LED_STATUS
if (mesh::leds::enabled()) digitalWrite(LED_STATUS, HIGH);
#endif
#ifdef BUTTON_PIN
while(!digitalRead(BUTTON_PIN));
#endif
#ifdef LED_STATUS
digitalWrite(LED_STATUS, LOW);
#endif
digitalWrite(LED_BAT1, LOW);
digitalWrite(LED_BAT2, LOW);
digitalWrite(LED_BAT3, LOW);
digitalWrite(LED_BAT4, LOW);
digitalWrite(LED_STATUS, LOW);
digitalWrite(LED_PIN, LOW);
digitalWrite(PIN_PWR_EN, LOW);
digitalWrite(I2C_POWER, !I2C_POWER_ACTIVE);
digitalWrite(PIN_GPS_POWER, !GPS_POWER_ACTIVE);
#ifdef BUTTON_PIN
nrf_gpio_cfg_sense_input(BUTTON_PIN, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);
#endif
}
};