diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index eb4b5b098..d226d1fa7 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -29,6 +29,12 @@ void setup() { 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 lastActive = millis(); // mark last active time since boot @@ -42,6 +48,7 @@ void setup() { #endif if (!radio_init()) { + MESH_DEBUG_PRINTLN("Radio init failed!"); halt(); } diff --git a/variants/heltec_t114/platformio.ini b/variants/heltec_t114/platformio.ini index 20f5e8fec..b985030f7 100644 --- a/variants/heltec_t114/platformio.ini +++ b/variants/heltec_t114/platformio.ini @@ -6,6 +6,7 @@ extends = nrf52_base board = heltec_t114 board_build.ldscript = boards/nrf52840_s140_v6.ld build_flags = ${nrf52_base.build_flags} + ${sensor_base.build_flags} -I lib/nrf52/s140_nrf52_6.1.1_API/include -I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52 -I variants/heltec_t114 @@ -28,20 +29,20 @@ build_flags = ${nrf52_base.build_flags} -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_CURRENT_LIMIT=140 -D SX126X_RX_BOOSTED_GAIN=1 - -D DISPLAY_CLASS=NullDisplayDriver - -D ST7789 -D PIN_GPS_RX=39 -D PIN_GPS_TX=37 -D PIN_GPS_EN=21 -D PIN_GPS_RESET=38 -D PIN_GPS_RESET_ACTIVE=LOW + -D ENV_PIN_SDA=PIN_WIRE1_SDA + -D ENV_PIN_SCL=PIN_WIRE1_SCL build_src_filter = ${nrf52_base.build_src_filter} + + + +<../variants/heltec_t114> lib_deps = ${nrf52_base.lib_deps} - stevemarple/MicroNMEA @ ^2.0.6 - adafruit/Adafruit GFX Library @ ^1.12.1 + ${sensor_base.lib_deps} debug_tool = jlink upload_protocol = nrfutil @@ -100,6 +101,7 @@ board_upload.maximum_size = 712704 build_flags = ${Heltec_t114.build_flags} -I examples/companion_radio/ui-new + -D DISPLAY_CLASS=NullDisplayDriver -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 @@ -122,6 +124,7 @@ board_upload.maximum_size = 712704 build_flags = ${Heltec_t114.build_flags} -I examples/companion_radio/ui-new + -D DISPLAY_CLASS=NullDisplayDriver -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 ; -D BLE_PIN_CODE=123456 @@ -144,6 +147,7 @@ extends = Heltec_t114 board = heltec_t114 board_build.ldscript = boards/nrf52840_s140_v6.ld build_flags = ${Heltec_t114.build_flags} + -D ST7789 -D HELTEC_T114_WITH_DISPLAY -D DISPLAY_CLASS=ST7789Display build_src_filter = ${Heltec_t114.build_src_filter} @@ -153,6 +157,7 @@ build_src_filter = ${Heltec_t114.build_src_filter} + lib_deps = ${Heltec_t114.lib_deps} + adafruit/Adafruit SSD1306 @ ^2.5.13 debug_tool = jlink upload_protocol = nrfutil diff --git a/variants/heltec_t114/target.cpp b/variants/heltec_t114/target.cpp index c3341103a..cd280ddab 100644 --- a/variants/heltec_t114/target.cpp +++ b/variants/heltec_t114/target.cpp @@ -1,28 +1,46 @@ -#include #include "target.h" + +#include #include + +#ifdef ENV_INCLUDE_GPS #include +#endif 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); +#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); VolatileRTCClock fallback_clock; AutoDiscoverRTCClock rtc_clock(fallback_clock); -MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock); -T114SensorManager sensors = T114SensorManager(nmea); + +#if ENV_INCLUDE_GPS +#include +MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1); +EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea); +#else +EnvironmentSensorManager sensors; +#endif #ifdef DISPLAY_CLASS - DISPLAY_CLASS display; - MomentaryButton user_btn(PIN_USER_BTN, 1000, true); +DISPLAY_CLASS display; +MomentaryButton user_btn(PIN_USER_BTN, 1000, true); #endif bool radio_init() { rtc_clock.begin(Wire); +#if defined(P_LORA_SCLK) return radio.std_init(&SPI); +#else + return radio.std_init(); +#endif } uint32_t radio_get_rng_seed() { @@ -42,92 +60,5 @@ void radio_set_tx_power(uint8_t dbm) { mesh::LocalIdentity radio_new_identity() { RadioNoiseListener rng(radio); - return mesh::LocalIdentity(&rng); // create new random identity -} - -void T114SensorManager::start_gps() { - if (!gps_active) { - gps_active = true; - _location->begin(); - } -} - -void T114SensorManager::stop_gps() { - if (gps_active) { - gps_active = false; - _location->stop(); - } -} - -bool T114SensorManager::begin() { - Serial1.begin(9600); - - // Try to detect if GPS is physically connected to determine if we should expose the setting - pinMode(GPS_EN, OUTPUT); - digitalWrite(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(GPS_EN, LOW); // Power off GPS until the setting is changed - - return true; -} - -bool T114SensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) { - if (requester_permissions & TELEM_PERM_LOCATION) { // does requester have permission? - telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude); - } - return true; -} - -void T114SensorManager::loop() { - static long next_gps_update = 0; - - _location->loop(); - - if (millis() > next_gps_update) { - if (_location->isValid()) { - node_lat = ((double)_location->getLatitude())/1000000.; - node_lon = ((double)_location->getLongitude())/1000000.; - node_altitude = ((double)_location->getAltitude()) / 1000.0; - MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon); - } - next_gps_update = millis() + 1000; - } -} - -int T114SensorManager::getNumSettings() const { - return gps_detected ? 1 : 0; // only show GPS setting if GPS is detected -} - -const char* T114SensorManager::getSettingName(int i) const { - return (gps_detected && i == 0) ? "gps" : NULL; -} - -const char* T114SensorManager::getSettingValue(int i) const { - if (gps_detected && i == 0) { - return gps_active ? "1" : "0"; - } - return NULL; -} - -bool T114SensorManager::setSettingValue(const char* name, const char* value) { - if (gps_detected && strcmp(name, "gps") == 0) { - if (strcmp(value, "0") == 0) { - stop_gps(); - } else { - start_gps(); - } - return true; - } - return false; // not supported + return mesh::LocalIdentity(&rng); // create new random identity } diff --git a/variants/heltec_t114/target.h b/variants/heltec_t114/target.h index 6306cd699..94f990ecc 100644 --- a/variants/heltec_t114/target.h +++ b/variants/heltec_t114/target.h @@ -2,11 +2,11 @@ #define RADIOLIB_STATIC_ONLY 1 #include -#include #include -#include #include -#include +#include +#include +#include #include #ifdef DISPLAY_CLASS @@ -18,33 +18,14 @@ #endif #endif -class T114SensorManager : public SensorManager { - bool gps_active = false; - bool gps_detected = false; - LocationProvider* _location; - - void start_gps(); - void stop_gps(); -public: - T114SensorManager(LocationProvider &location): _location(&location) { } - bool begin() override; - bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override; - void loop() override; - LocationProvider* getLocationProvider() override { return gps_detected ? _location : NULL; } - 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; -}; - extern T114Board board; extern WRAPPER_CLASS radio_driver; extern AutoDiscoverRTCClock rtc_clock; -extern T114SensorManager sensors; +extern EnvironmentSensorManager sensors; #ifdef DISPLAY_CLASS - extern DISPLAY_CLASS display; - extern MomentaryButton user_btn; +extern DISPLAY_CLASS display; +extern MomentaryButton user_btn; #endif bool radio_init(); diff --git a/variants/heltec_t114/variant.h b/variants/heltec_t114/variant.h index aa7f40222..bfb4484d1 100644 --- a/variants/heltec_t114/variant.h +++ b/variants/heltec_t114/variant.h @@ -14,7 +14,7 @@ #define USE_LFXO // 32.768 kHz crystal oscillator #define VARIANT_MCK (64000000ul) -#define WIRE_INTERFACES_COUNT (1) +#define WIRE_INTERFACES_COUNT (2) //////////////////////////////////////////////////////////////////////////////// // Power @@ -58,8 +58,11 @@ //////////////////////////////////////////////////////////////////////////////// // I2C pin definition -#define PIN_WIRE_SDA (26) // P0.26 -#define PIN_WIRE_SCL (27) // P0.27 +#define PIN_WIRE_SDA (26) // P0.26 +#define PIN_WIRE_SCL (27) // P0.27 + +#define PIN_WIRE1_SDA (7) // P0.8 +#define PIN_WIRE1_SCL (8) // P0.7 //////////////////////////////////////////////////////////////////////////////// // SPI pin definition