Skip to content

Commit 5cb26b9

Browse files
committed
Refactor Heltec T114 sensor management
1 parent f0aa12f commit 5cb26b9

5 files changed

Lines changed: 48 additions & 59 deletions

File tree

examples/simple_repeater/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ void setup() {
2929

3030
board.begin();
3131

32+
#if defined(MESH_DEBUG) && defined(NRF52_PLATFORM)
33+
// give some extra time for serial to settle so
34+
// boot debug messages can be seen on terminal
35+
delay(5000);
36+
#endif
37+
3238
// For power saving
3339
lastActive = millis(); // mark last active time since boot
3440

@@ -42,6 +48,7 @@ void setup() {
4248
#endif
4349

4450
if (!radio_init()) {
51+
MESH_DEBUG_PRINTLN("Radio init failed!");
4552
halt();
4653
}
4754

variants/heltec_t114/platformio.ini

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,20 @@ build_flags = ${nrf52_base.build_flags}
2929
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
3030
-D SX126X_CURRENT_LIMIT=140
3131
-D SX126X_RX_BOOSTED_GAIN=1
32-
-D DISPLAY_CLASS=NullDisplayDriver
33-
-D ST7789
3432
-D PIN_GPS_RX=39
3533
-D PIN_GPS_TX=37
3634
-D PIN_GPS_EN=21
3735
-D PIN_GPS_RESET=38
3836
-D PIN_GPS_RESET_ACTIVE=LOW
39-
-D PIN_BOARD_SDA=16
40-
-D PIN_BOARD_SCL=13
37+
-D ENV_PIN_SDA=PIN_WIRE1_SDA
38+
-D ENV_PIN_SCL=PIN_WIRE1_SCL
4139
build_src_filter = ${nrf52_base.build_src_filter}
4240
+<helpers/*.cpp>
4341
+<helpers/sensors>
4442
+<../variants/heltec_t114>
4543
lib_deps =
4644
${nrf52_base.lib_deps}
4745
${sensor_base.lib_deps}
48-
stevemarple/MicroNMEA @ ^2.0.6
49-
adafruit/Adafruit GFX Library @ ^1.12.1
5046
debug_tool = jlink
5147
upload_protocol = nrfutil
5248

@@ -105,6 +101,7 @@ board_upload.maximum_size = 712704
105101
build_flags =
106102
${Heltec_t114.build_flags}
107103
-I examples/companion_radio/ui-new
104+
-D DISPLAY_CLASS=NullDisplayDriver
108105
-D MAX_CONTACTS=350
109106
-D MAX_GROUP_CHANNELS=40
110107
-D BLE_PIN_CODE=123456
@@ -127,6 +124,7 @@ board_upload.maximum_size = 712704
127124
build_flags =
128125
${Heltec_t114.build_flags}
129126
-I examples/companion_radio/ui-new
127+
-D DISPLAY_CLASS=NullDisplayDriver
130128
-D MAX_CONTACTS=350
131129
-D MAX_GROUP_CHANNELS=40
132130
; -D BLE_PIN_CODE=123456
@@ -149,6 +147,7 @@ extends = Heltec_t114
149147
board = heltec_t114
150148
board_build.ldscript = boards/nrf52840_s140_v6.ld
151149
build_flags = ${Heltec_t114.build_flags}
150+
-D ST7789
152151
-D HELTEC_T114_WITH_DISPLAY
153152
-D DISPLAY_CLASS=ST7789Display
154153
build_src_filter = ${Heltec_t114.build_src_filter}
@@ -158,6 +157,7 @@ build_src_filter = ${Heltec_t114.build_src_filter}
158157
+<helpers/ui/OLEDDisplayFonts.cpp>
159158
lib_deps =
160159
${Heltec_t114.lib_deps}
160+
adafruit/Adafruit SSD1306 @ ^2.5.13
161161
debug_tool = jlink
162162
upload_protocol = nrfutil
163163

variants/heltec_t114/target.cpp

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,46 @@
1-
#include <Arduino.h>
21
#include "target.h"
2+
3+
#include <Arduino.h>
34
#include <helpers/ArduinoHelpers.h>
5+
6+
#ifdef ENV_INCLUDE_GPS
47
#include <helpers/sensors/MicroNMEALocationProvider.h>
8+
#endif
59

610
T114Board board;
711

12+
#if defined(P_LORA_SCLK)
813
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
14+
#else
15+
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY);
16+
#endif
917

1018
WRAPPER_CLASS radio_driver(radio, board);
1119

1220
VolatileRTCClock fallback_clock;
1321
AutoDiscoverRTCClock rtc_clock(fallback_clock);
14-
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
15-
T114SensorManager sensors = T114SensorManager(nmea);
22+
23+
#if ENV_INCLUDE_GPS
24+
#include <helpers/sensors/MicroNMEALocationProvider.h>
25+
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
26+
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
27+
#else
28+
EnvironmentSensorManager sensors;
29+
#endif
1630

1731
#ifdef DISPLAY_CLASS
18-
DISPLAY_CLASS display;
19-
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
32+
DISPLAY_CLASS display;
33+
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
2034
#endif
2135

2236
bool radio_init() {
2337
rtc_clock.begin(Wire);
2438

39+
#if defined(P_LORA_SCLK)
2540
return radio.std_init(&SPI);
41+
#else
42+
return radio.std_init();
43+
#endif
2644
}
2745

2846
uint32_t radio_get_rng_seed() {
@@ -42,37 +60,5 @@ void radio_set_tx_power(uint8_t dbm) {
4260

4361
mesh::LocalIdentity radio_new_identity() {
4462
RadioNoiseListener rng(radio);
45-
return mesh::LocalIdentity(&rng); // create new random identity
46-
}
47-
48-
bool T114SensorManager::begin() {
49-
Serial1.begin(9600);
50-
51-
// Try to detect if GPS is physically connected to determine if we should expose the setting
52-
pinMode(PIN_GPS_EN, OUTPUT);
53-
digitalWrite(PIN_GPS_EN, HIGH); // Power on GPS
54-
55-
// Give GPS a moment to power up and send data
56-
delay(1500);
57-
58-
// We'll consider GPS detected if we see any data on Serial1
59-
gps_detected = (Serial1.available() > 0);
60-
61-
if (gps_detected) {
62-
MESH_DEBUG_PRINTLN("GPS detected");
63-
} else {
64-
MESH_DEBUG_PRINTLN("No GPS detected");
65-
}
66-
digitalWrite(PIN_GPS_EN, LOW); // Power off GPS until the setting is changed
67-
68-
return EnvironmentSensorManager::begin();
69-
}
70-
71-
bool T114SensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) {
72-
EnvironmentSensorManager::querySensors(requester_permissions, telemetry);
73-
74-
if (requester_permissions & TELEM_PERM_LOCATION) { // does requester have permission?
75-
telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude);
76-
}
77-
return true;
63+
return mesh::LocalIdentity(&rng); // create new random identity
7864
}

variants/heltec_t114/target.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
#define RADIOLIB_STATIC_ONLY 1
44
#include <RadioLib.h>
5-
#include <helpers/radiolib/RadioLibWrappers.h>
65
#include <T114Board.h>
7-
#include <helpers/radiolib/CustomSX1262Wrapper.h>
86
#include <helpers/AutoDiscoverRTCClock.h>
7+
#include <helpers/radiolib/CustomSX1262Wrapper.h>
8+
#include <helpers/radiolib/RadioLibWrappers.h>
99
#include <helpers/sensors/EnvironmentSensorManager.h>
1010
#include <helpers/sensors/LocationProvider.h>
1111

@@ -18,21 +18,14 @@
1818
#endif
1919
#endif
2020

21-
class T114SensorManager : public EnvironmentSensorManager {
22-
public:
23-
T114SensorManager(LocationProvider &location): EnvironmentSensorManager(location) { }
24-
bool begin() override;
25-
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override;
26-
};
27-
2821
extern T114Board board;
2922
extern WRAPPER_CLASS radio_driver;
3023
extern AutoDiscoverRTCClock rtc_clock;
31-
extern T114SensorManager sensors;
24+
extern EnvironmentSensorManager sensors;
3225

3326
#ifdef DISPLAY_CLASS
34-
extern DISPLAY_CLASS display;
35-
extern MomentaryButton user_btn;
27+
extern DISPLAY_CLASS display;
28+
extern MomentaryButton user_btn;
3629
#endif
3730

3831
bool radio_init();

variants/heltec_t114/variant.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define USE_LFXO // 32.768 kHz crystal oscillator
1515
#define VARIANT_MCK (64000000ul)
1616

17-
#define WIRE_INTERFACES_COUNT (1)
17+
#define WIRE_INTERFACES_COUNT (2)
1818

1919
////////////////////////////////////////////////////////////////////////////////
2020
// Power
@@ -58,8 +58,11 @@
5858
////////////////////////////////////////////////////////////////////////////////
5959
// I2C pin definition
6060

61-
#define PIN_WIRE_SDA (26) // P0.26
62-
#define PIN_WIRE_SCL (27) // P0.27
61+
#define PIN_WIRE_SDA (26) // P0.26
62+
#define PIN_WIRE_SCL (27) // P0.27
63+
64+
#define PIN_WIRE1_SDA (7) // P0.8
65+
#define PIN_WIRE1_SCL (8) // P0.7
6366

6467
////////////////////////////////////////////////////////////////////////////////
6568
// SPI pin definition

0 commit comments

Comments
 (0)