mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Refactor Heltec T114 sensor management
This commit is contained in:
parent
f0aa12faac
commit
5cb26b91f6
5 changed files with 48 additions and 59 deletions
|
|
@ -29,6 +29,12 @@ void setup() {
|
||||||
|
|
||||||
board.begin();
|
board.begin();
|
||||||
|
|
||||||
|
#if defined(MESH_DEBUG) && defined(NRF52_PLATFORM)
|
||||||
|
// give some extra time for serial to settle so
|
||||||
|
// boot debug messages can be seen on terminal
|
||||||
|
delay(5000);
|
||||||
|
#endif
|
||||||
|
|
||||||
// For power saving
|
// For power saving
|
||||||
lastActive = millis(); // mark last active time since boot
|
lastActive = millis(); // mark last active time since boot
|
||||||
|
|
||||||
|
|
@ -42,6 +48,7 @@ void setup() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!radio_init()) {
|
if (!radio_init()) {
|
||||||
|
MESH_DEBUG_PRINTLN("Radio init failed!");
|
||||||
halt();
|
halt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,15 +29,13 @@ build_flags = ${nrf52_base.build_flags}
|
||||||
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
|
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
|
||||||
-D SX126X_CURRENT_LIMIT=140
|
-D SX126X_CURRENT_LIMIT=140
|
||||||
-D SX126X_RX_BOOSTED_GAIN=1
|
-D SX126X_RX_BOOSTED_GAIN=1
|
||||||
-D DISPLAY_CLASS=NullDisplayDriver
|
|
||||||
-D ST7789
|
|
||||||
-D PIN_GPS_RX=39
|
-D PIN_GPS_RX=39
|
||||||
-D PIN_GPS_TX=37
|
-D PIN_GPS_TX=37
|
||||||
-D PIN_GPS_EN=21
|
-D PIN_GPS_EN=21
|
||||||
-D PIN_GPS_RESET=38
|
-D PIN_GPS_RESET=38
|
||||||
-D PIN_GPS_RESET_ACTIVE=LOW
|
-D PIN_GPS_RESET_ACTIVE=LOW
|
||||||
-D PIN_BOARD_SDA=16
|
-D ENV_PIN_SDA=PIN_WIRE1_SDA
|
||||||
-D PIN_BOARD_SCL=13
|
-D ENV_PIN_SCL=PIN_WIRE1_SCL
|
||||||
build_src_filter = ${nrf52_base.build_src_filter}
|
build_src_filter = ${nrf52_base.build_src_filter}
|
||||||
+<helpers/*.cpp>
|
+<helpers/*.cpp>
|
||||||
+<helpers/sensors>
|
+<helpers/sensors>
|
||||||
|
|
@ -45,8 +43,6 @@ build_src_filter = ${nrf52_base.build_src_filter}
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${nrf52_base.lib_deps}
|
${nrf52_base.lib_deps}
|
||||||
${sensor_base.lib_deps}
|
${sensor_base.lib_deps}
|
||||||
stevemarple/MicroNMEA @ ^2.0.6
|
|
||||||
adafruit/Adafruit GFX Library @ ^1.12.1
|
|
||||||
debug_tool = jlink
|
debug_tool = jlink
|
||||||
upload_protocol = nrfutil
|
upload_protocol = nrfutil
|
||||||
|
|
||||||
|
|
@ -105,6 +101,7 @@ board_upload.maximum_size = 712704
|
||||||
build_flags =
|
build_flags =
|
||||||
${Heltec_t114.build_flags}
|
${Heltec_t114.build_flags}
|
||||||
-I examples/companion_radio/ui-new
|
-I examples/companion_radio/ui-new
|
||||||
|
-D DISPLAY_CLASS=NullDisplayDriver
|
||||||
-D MAX_CONTACTS=350
|
-D MAX_CONTACTS=350
|
||||||
-D MAX_GROUP_CHANNELS=40
|
-D MAX_GROUP_CHANNELS=40
|
||||||
-D BLE_PIN_CODE=123456
|
-D BLE_PIN_CODE=123456
|
||||||
|
|
@ -127,6 +124,7 @@ board_upload.maximum_size = 712704
|
||||||
build_flags =
|
build_flags =
|
||||||
${Heltec_t114.build_flags}
|
${Heltec_t114.build_flags}
|
||||||
-I examples/companion_radio/ui-new
|
-I examples/companion_radio/ui-new
|
||||||
|
-D DISPLAY_CLASS=NullDisplayDriver
|
||||||
-D MAX_CONTACTS=350
|
-D MAX_CONTACTS=350
|
||||||
-D MAX_GROUP_CHANNELS=40
|
-D MAX_GROUP_CHANNELS=40
|
||||||
; -D BLE_PIN_CODE=123456
|
; -D BLE_PIN_CODE=123456
|
||||||
|
|
@ -149,6 +147,7 @@ extends = Heltec_t114
|
||||||
board = heltec_t114
|
board = heltec_t114
|
||||||
board_build.ldscript = boards/nrf52840_s140_v6.ld
|
board_build.ldscript = boards/nrf52840_s140_v6.ld
|
||||||
build_flags = ${Heltec_t114.build_flags}
|
build_flags = ${Heltec_t114.build_flags}
|
||||||
|
-D ST7789
|
||||||
-D HELTEC_T114_WITH_DISPLAY
|
-D HELTEC_T114_WITH_DISPLAY
|
||||||
-D DISPLAY_CLASS=ST7789Display
|
-D DISPLAY_CLASS=ST7789Display
|
||||||
build_src_filter = ${Heltec_t114.build_src_filter}
|
build_src_filter = ${Heltec_t114.build_src_filter}
|
||||||
|
|
@ -158,6 +157,7 @@ build_src_filter = ${Heltec_t114.build_src_filter}
|
||||||
+<helpers/ui/OLEDDisplayFonts.cpp>
|
+<helpers/ui/OLEDDisplayFonts.cpp>
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${Heltec_t114.lib_deps}
|
${Heltec_t114.lib_deps}
|
||||||
|
adafruit/Adafruit SSD1306 @ ^2.5.13
|
||||||
debug_tool = jlink
|
debug_tool = jlink
|
||||||
upload_protocol = nrfutil
|
upload_protocol = nrfutil
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,46 @@
|
||||||
#include <Arduino.h>
|
|
||||||
#include "target.h"
|
#include "target.h"
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
#include <helpers/ArduinoHelpers.h>
|
#include <helpers/ArduinoHelpers.h>
|
||||||
|
|
||||||
|
#ifdef ENV_INCLUDE_GPS
|
||||||
#include <helpers/sensors/MicroNMEALocationProvider.h>
|
#include <helpers/sensors/MicroNMEALocationProvider.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
T114Board board;
|
T114Board board;
|
||||||
|
|
||||||
|
#if defined(P_LORA_SCLK)
|
||||||
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
|
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
|
||||||
|
#else
|
||||||
|
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY);
|
||||||
|
#endif
|
||||||
|
|
||||||
WRAPPER_CLASS radio_driver(radio, board);
|
WRAPPER_CLASS radio_driver(radio, board);
|
||||||
|
|
||||||
VolatileRTCClock fallback_clock;
|
VolatileRTCClock fallback_clock;
|
||||||
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
||||||
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
|
|
||||||
T114SensorManager sensors = T114SensorManager(nmea);
|
#if ENV_INCLUDE_GPS
|
||||||
|
#include <helpers/sensors/MicroNMEALocationProvider.h>
|
||||||
|
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
|
||||||
|
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
|
||||||
|
#else
|
||||||
|
EnvironmentSensorManager sensors;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
DISPLAY_CLASS display;
|
DISPLAY_CLASS display;
|
||||||
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
|
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool radio_init() {
|
bool radio_init() {
|
||||||
rtc_clock.begin(Wire);
|
rtc_clock.begin(Wire);
|
||||||
|
|
||||||
|
#if defined(P_LORA_SCLK)
|
||||||
return radio.std_init(&SPI);
|
return radio.std_init(&SPI);
|
||||||
|
#else
|
||||||
|
return radio.std_init();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t radio_get_rng_seed() {
|
uint32_t radio_get_rng_seed() {
|
||||||
|
|
@ -42,37 +60,5 @@ void radio_set_tx_power(uint8_t dbm) {
|
||||||
|
|
||||||
mesh::LocalIdentity radio_new_identity() {
|
mesh::LocalIdentity radio_new_identity() {
|
||||||
RadioNoiseListener rng(radio);
|
RadioNoiseListener rng(radio);
|
||||||
return mesh::LocalIdentity(&rng); // create new random identity
|
return mesh::LocalIdentity(&rng); // create new random identity
|
||||||
}
|
|
||||||
|
|
||||||
bool T114SensorManager::begin() {
|
|
||||||
Serial1.begin(9600);
|
|
||||||
|
|
||||||
// Try to detect if GPS is physically connected to determine if we should expose the setting
|
|
||||||
pinMode(PIN_GPS_EN, OUTPUT);
|
|
||||||
digitalWrite(PIN_GPS_EN, HIGH); // Power on GPS
|
|
||||||
|
|
||||||
// Give GPS a moment to power up and send data
|
|
||||||
delay(1500);
|
|
||||||
|
|
||||||
// We'll consider GPS detected if we see any data on Serial1
|
|
||||||
gps_detected = (Serial1.available() > 0);
|
|
||||||
|
|
||||||
if (gps_detected) {
|
|
||||||
MESH_DEBUG_PRINTLN("GPS detected");
|
|
||||||
} else {
|
|
||||||
MESH_DEBUG_PRINTLN("No GPS detected");
|
|
||||||
}
|
|
||||||
digitalWrite(PIN_GPS_EN, LOW); // Power off GPS until the setting is changed
|
|
||||||
|
|
||||||
return EnvironmentSensorManager::begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool T114SensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) {
|
|
||||||
EnvironmentSensorManager::querySensors(requester_permissions, telemetry);
|
|
||||||
|
|
||||||
if (requester_permissions & TELEM_PERM_LOCATION) { // does requester have permission?
|
|
||||||
telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
#define RADIOLIB_STATIC_ONLY 1
|
#define RADIOLIB_STATIC_ONLY 1
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
#include <helpers/radiolib/RadioLibWrappers.h>
|
|
||||||
#include <T114Board.h>
|
#include <T114Board.h>
|
||||||
#include <helpers/radiolib/CustomSX1262Wrapper.h>
|
|
||||||
#include <helpers/AutoDiscoverRTCClock.h>
|
#include <helpers/AutoDiscoverRTCClock.h>
|
||||||
|
#include <helpers/radiolib/CustomSX1262Wrapper.h>
|
||||||
|
#include <helpers/radiolib/RadioLibWrappers.h>
|
||||||
#include <helpers/sensors/EnvironmentSensorManager.h>
|
#include <helpers/sensors/EnvironmentSensorManager.h>
|
||||||
#include <helpers/sensors/LocationProvider.h>
|
#include <helpers/sensors/LocationProvider.h>
|
||||||
|
|
||||||
|
|
@ -18,21 +18,14 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class T114SensorManager : public EnvironmentSensorManager {
|
|
||||||
public:
|
|
||||||
T114SensorManager(LocationProvider &location): EnvironmentSensorManager(location) { }
|
|
||||||
bool begin() override;
|
|
||||||
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern T114Board board;
|
extern T114Board board;
|
||||||
extern WRAPPER_CLASS radio_driver;
|
extern WRAPPER_CLASS radio_driver;
|
||||||
extern AutoDiscoverRTCClock rtc_clock;
|
extern AutoDiscoverRTCClock rtc_clock;
|
||||||
extern T114SensorManager sensors;
|
extern EnvironmentSensorManager sensors;
|
||||||
|
|
||||||
#ifdef DISPLAY_CLASS
|
#ifdef DISPLAY_CLASS
|
||||||
extern DISPLAY_CLASS display;
|
extern DISPLAY_CLASS display;
|
||||||
extern MomentaryButton user_btn;
|
extern MomentaryButton user_btn;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool radio_init();
|
bool radio_init();
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
#define USE_LFXO // 32.768 kHz crystal oscillator
|
#define USE_LFXO // 32.768 kHz crystal oscillator
|
||||||
#define VARIANT_MCK (64000000ul)
|
#define VARIANT_MCK (64000000ul)
|
||||||
|
|
||||||
#define WIRE_INTERFACES_COUNT (1)
|
#define WIRE_INTERFACES_COUNT (2)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Power
|
// Power
|
||||||
|
|
@ -58,8 +58,11 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// I2C pin definition
|
// I2C pin definition
|
||||||
|
|
||||||
#define PIN_WIRE_SDA (26) // P0.26
|
#define PIN_WIRE_SDA (26) // P0.26
|
||||||
#define PIN_WIRE_SCL (27) // P0.27
|
#define PIN_WIRE_SCL (27) // P0.27
|
||||||
|
|
||||||
|
#define PIN_WIRE1_SDA (7) // P0.8
|
||||||
|
#define PIN_WIRE1_SCL (8) // P0.7
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// SPI pin definition
|
// SPI pin definition
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue