Skip to content

Commit f0aa12f

Browse files
committed
Merge remote-tracking branch 'pikolin/T114_sensors' into 2026/t114-sensors
2 parents 2360259 + 2239307 commit f0aa12f

3 files changed

Lines changed: 14 additions & 76 deletions

File tree

variants/heltec_t114/platformio.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extends = nrf52_base
66
board = heltec_t114
77
board_build.ldscript = boards/nrf52840_s140_v6.ld
88
build_flags = ${nrf52_base.build_flags}
9+
${sensor_base.build_flags}
910
-I lib/nrf52/s140_nrf52_6.1.1_API/include
1011
-I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52
1112
-I variants/heltec_t114
@@ -35,11 +36,15 @@ build_flags = ${nrf52_base.build_flags}
3536
-D PIN_GPS_EN=21
3637
-D PIN_GPS_RESET=38
3738
-D PIN_GPS_RESET_ACTIVE=LOW
39+
-D PIN_BOARD_SDA=16
40+
-D PIN_BOARD_SCL=13
3841
build_src_filter = ${nrf52_base.build_src_filter}
3942
+<helpers/*.cpp>
43+
+<helpers/sensors>
4044
+<../variants/heltec_t114>
4145
lib_deps =
4246
${nrf52_base.lib_deps}
47+
${sensor_base.lib_deps}
4348
stevemarple/MicroNMEA @ ^2.0.6
4449
adafruit/Adafruit GFX Library @ ^1.12.1
4550
debug_tool = jlink

variants/heltec_t114/target.cpp

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,12 @@ mesh::LocalIdentity radio_new_identity() {
4545
return mesh::LocalIdentity(&rng); // create new random identity
4646
}
4747

48-
void T114SensorManager::start_gps() {
49-
if (!gps_active) {
50-
gps_active = true;
51-
_location->begin();
52-
}
53-
}
54-
55-
void T114SensorManager::stop_gps() {
56-
if (gps_active) {
57-
gps_active = false;
58-
_location->stop();
59-
}
60-
}
61-
6248
bool T114SensorManager::begin() {
6349
Serial1.begin(9600);
6450

6551
// Try to detect if GPS is physically connected to determine if we should expose the setting
66-
pinMode(GPS_EN, OUTPUT);
67-
digitalWrite(GPS_EN, HIGH); // Power on GPS
52+
pinMode(PIN_GPS_EN, OUTPUT);
53+
digitalWrite(PIN_GPS_EN, HIGH); // Power on GPS
6854

6955
// Give GPS a moment to power up and send data
7056
delay(1500);
@@ -77,57 +63,16 @@ bool T114SensorManager::begin() {
7763
} else {
7864
MESH_DEBUG_PRINTLN("No GPS detected");
7965
}
80-
digitalWrite(GPS_EN, LOW); // Power off GPS until the setting is changed
66+
digitalWrite(PIN_GPS_EN, LOW); // Power off GPS until the setting is changed
8167

82-
return true;
68+
return EnvironmentSensorManager::begin();
8369
}
8470

8571
bool T114SensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) {
72+
EnvironmentSensorManager::querySensors(requester_permissions, telemetry);
73+
8674
if (requester_permissions & TELEM_PERM_LOCATION) { // does requester have permission?
8775
telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude);
8876
}
8977
return true;
9078
}
91-
92-
void T114SensorManager::loop() {
93-
static long next_gps_update = 0;
94-
95-
_location->loop();
96-
97-
if (millis() > next_gps_update) {
98-
if (_location->isValid()) {
99-
node_lat = ((double)_location->getLatitude())/1000000.;
100-
node_lon = ((double)_location->getLongitude())/1000000.;
101-
node_altitude = ((double)_location->getAltitude()) / 1000.0;
102-
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
103-
}
104-
next_gps_update = millis() + 1000;
105-
}
106-
}
107-
108-
int T114SensorManager::getNumSettings() const {
109-
return gps_detected ? 1 : 0; // only show GPS setting if GPS is detected
110-
}
111-
112-
const char* T114SensorManager::getSettingName(int i) const {
113-
return (gps_detected && i == 0) ? "gps" : NULL;
114-
}
115-
116-
const char* T114SensorManager::getSettingValue(int i) const {
117-
if (gps_detected && i == 0) {
118-
return gps_active ? "1" : "0";
119-
}
120-
return NULL;
121-
}
122-
123-
bool T114SensorManager::setSettingValue(const char* name, const char* value) {
124-
if (gps_detected && strcmp(name, "gps") == 0) {
125-
if (strcmp(value, "0") == 0) {
126-
stop_gps();
127-
} else {
128-
start_gps();
129-
}
130-
return true;
131-
}
132-
return false; // not supported
133-
}

variants/heltec_t114/target.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <T114Board.h>
77
#include <helpers/radiolib/CustomSX1262Wrapper.h>
88
#include <helpers/AutoDiscoverRTCClock.h>
9-
#include <helpers/SensorManager.h>
9+
#include <helpers/sensors/EnvironmentSensorManager.h>
1010
#include <helpers/sensors/LocationProvider.h>
1111

1212
#ifdef DISPLAY_CLASS
@@ -18,23 +18,11 @@
1818
#endif
1919
#endif
2020

21-
class T114SensorManager : public SensorManager {
22-
bool gps_active = false;
23-
bool gps_detected = false;
24-
LocationProvider* _location;
25-
26-
void start_gps();
27-
void stop_gps();
21+
class T114SensorManager : public EnvironmentSensorManager {
2822
public:
29-
T114SensorManager(LocationProvider &location): _location(&location) { }
23+
T114SensorManager(LocationProvider &location): EnvironmentSensorManager(location) { }
3024
bool begin() override;
3125
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override;
32-
void loop() override;
33-
LocationProvider* getLocationProvider() override { return gps_detected ? _location : NULL; }
34-
int getNumSettings() const override;
35-
const char* getSettingName(int i) const override;
36-
const char* getSettingValue(int i) const override;
37-
bool setSettingValue(const char* name, const char* value) override;
3826
};
3927

4028
extern T114Board board;

0 commit comments

Comments
 (0)