From 4b16cda03a26ac6c957ef04cf514430f9fa7fb2c Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Wed, 28 May 2025 23:31:31 +1000 Subject: [PATCH] * RAK4632 targets, now requiring ENV_INCLUDE_GPS to enable GPS --- variants/rak4631/platformio.ini | 23 +++++++++++++++++++++++ variants/rak4631/target.cpp | 27 +++++++++++---------------- variants/rak4631/target.h | 17 +++++++++++++---- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index 54fd063a..c7f1fa53 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -97,6 +97,29 @@ lib_deps = ${rak4631.lib_deps} densaugeo/base64 @ ~1.4.0 +[env:RAK_4631_GPS_companion_radio_ble] +extends = rak4631 +build_flags = + ${rak4631.build_flags} + -D DISPLAY_CLASS=SSD1306Display + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=8 + -D BLE_PIN_CODE=123456 + -D BLE_DEBUG_LOGGING=1 + -D OFFLINE_QUEUE_SIZE=256 + -D ENV_INCLUDE_GPS=1 +; -D ENABLE_PRIVATE_KEY_IMPORT=1 +; -D ENABLE_PRIVATE_KEY_EXPORT=1 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${rak4631.build_src_filter} + + + + + +<../examples/companion_radio> +lib_deps = + ${rak4631.lib_deps} + densaugeo/base64 @ ~1.4.0 + [env:RAK_4631_terminal_chat] extends = rak4631 build_flags = diff --git a/variants/rak4631/target.cpp b/variants/rak4631/target.cpp index 1f55dac1..daadd044 100644 --- a/variants/rak4631/target.cpp +++ b/variants/rak4631/target.cpp @@ -11,8 +11,13 @@ WRAPPER_CLASS radio_driver(radio, board); VolatileRTCClock fallback_clock; AutoDiscoverRTCClock rtc_clock(fallback_clock); + +#if ENV_INCLUDE_GPS MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Wire); RAK4631SensorManager sensors = RAK4631SensorManager(nmea); +#else +RAK4631SensorManager sensors; +#endif #ifdef DISPLAY_CLASS DISPLAY_CLASS display; @@ -68,22 +73,6 @@ void scanDevices(TwoWire *w) } #endif -static bool readStringUntil(Stream& s, char dest[], size_t max_len, char term, unsigned int timeout_millis) { - unsigned long timeout = millis() + timeout_millis; - char *dp = dest; - while (millis() < timeout && dp - dest < max_len - 1) { - if (s.available()) { - char c = s.read(); - if (c == term) break; - *dp++ = c; // append to dest[] - } else { - delay(1); - } - } - *dp = 0; // null terminator - return millis() < timeout; // false, if timed out -} - bool radio_init() { rtc_clock.begin(Wire); @@ -132,6 +121,7 @@ void radio_set_tx_power(uint8_t dbm) { radio.setOutputPower(dbm); } +#if ENV_INCLUDE_GPS void RAK4631SensorManager::start_gps() { //function currently not used @@ -187,6 +177,7 @@ bool RAK4631SensorManager::gpsIsAwake(uint32_t ioPin){ //digitalWrite(ioPin,pinInitialState); //reset the IO pin to initial state return false; } +#endif bool RAK4631SensorManager::begin() { @@ -194,6 +185,7 @@ bool RAK4631SensorManager::begin() { scanDevices(&Wire); #endif +#if ENV_INCLUDE_GPS //search for the correct IO standby pin depending on socket used if(gpsIsAwake(P_GPS_STANDBY_A)){ MESH_DEBUG_PRINTLN("GPS is on socket A"); @@ -213,8 +205,10 @@ bool RAK4631SensorManager::begin() { //Now that GPS is found and set up, set to sleep for initial state stop_gps(); +#endif } +#if ENV_INCLUDE_GPS bool RAK4631SensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) { if (requester_permissions & TELEM_PERM_LOCATION && gps_active) { // does requester have permission? telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude); @@ -261,6 +255,7 @@ bool RAK4631SensorManager::setSettingValue(const char* name, const char* value) } return false; // not supported } +#endif mesh::LocalIdentity radio_new_identity() { RadioNoiseListener rng(radio); diff --git a/variants/rak4631/target.h b/variants/rak4631/target.h index 7ae3e914..3e6db0aa 100644 --- a/variants/rak4631/target.h +++ b/variants/rak4631/target.h @@ -7,8 +7,10 @@ #include #include #include -#include -#include +#if ENV_INCLUDE_GPS + #include + #include +#endif #ifdef DISPLAY_CLASS #include #endif @@ -16,6 +18,7 @@ #define _BV(x) (1 << x) class RAK4631SensorManager: public SensorManager { + #if ENV_INCLUDE_GPS bool gps_active = false; bool gps_present = false; LocationProvider * _nmea; @@ -27,17 +30,23 @@ class RAK4631SensorManager: public SensorManager { void sleep_gps(); void wake_gps(); bool gpsIsAwake(uint32_t ioPin); + #endif public: + #if ENV_INCLUDE_GPS RAK4631SensorManager(LocationProvider &nmea): _nmea(&nmea) { } - bool begin() override; + bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override; void loop() override; int getNumSettings() const override; const char* getSettingName(int i) const override; const char* getSettingValue(int i) const override; bool setSettingValue(const char* name, const char* value) override; - }; + #else + RAK4631SensorManager() { } + #endif + bool begin() override; +}; extern RAK4631Board board; extern WRAPPER_CLASS radio_driver;