Skip to content

Commit 1a41da6

Browse files
authored
Merge pull request #700 from fdlamotte/techo_env_sensors
techo: use EnvironmentSensor to get BME280 data
2 parents 637891b + 76711f5 commit 1a41da6

File tree

3 files changed

+18
-96
lines changed

3 files changed

+18
-96
lines changed

variants/techo/platformio.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,21 @@ build_flags = ${nrf52840_techo.build_flags}
2222
-D SX126X_CURRENT_LIMIT=140
2323
-D SX126X_RX_BOOSTED_GAIN=1
2424
-D P_LORA_TX_LED=LED_GREEN
25+
-D DISABLE_DIAGNOSTIC_OUTPUT
26+
-D ENV_INCLUDE_GPS=1
27+
-D ENV_INCLUDE_BME280=1
28+
-D GPS_BAUD_RATE=9600
29+
-D PIN_GPS_EN=GPS_EN
30+
-D TELEM_BME280_ADDRESS=0x77
2531
build_src_filter = ${nrf52840_techo.build_src_filter}
2632
+<helpers/*.cpp>
2733
+<helpers/nrf52/TechoBoard.cpp>
34+
+<helpers/sensors/EnvironmentSensorManager.cpp>
2835
+<../variants/techo>
2936
lib_deps =
3037
${nrf52840_techo.lib_deps}
3138
stevemarple/MicroNMEA @ ^2.0.6
39+
adafruit/Adafruit BME280 Library @ ^2.3.0
3240
debug_tool = jlink
3341
upload_protocol = nrfutil
3442

variants/techo/target.cpp

Lines changed: 8 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ WRAPPER_CLASS radio_driver(radio, board);
1111

1212
VolatileRTCClock fallback_clock;
1313
AutoDiscoverRTCClock rtc_clock(fallback_clock);
14-
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
15-
TechoSensorManager sensors = TechoSensorManager(nmea);
14+
15+
#ifdef ENV_INCLUDE_GPS
16+
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
17+
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
18+
#else
19+
EnvironmentSensorManager sensors = EnvironmentSensorManager();
20+
#endif
21+
1622

1723
#ifdef DISPLAY_CLASS
1824
DISPLAY_CLASS display;
@@ -45,79 +51,3 @@ mesh::LocalIdentity radio_new_identity() {
4551
return mesh::LocalIdentity(&rng); // create new random identity
4652
}
4753

48-
void TechoSensorManager::start_gps() {
49-
if (!gps_active) {
50-
gps_active = true;
51-
_location->begin();
52-
}
53-
}
54-
55-
void TechoSensorManager::stop_gps() {
56-
if (gps_active) {
57-
gps_active = false;
58-
_location->stop();
59-
}
60-
}
61-
62-
bool TechoSensorManager::begin() {
63-
Serial1.begin(9600);
64-
65-
// GPS enabled pin
66-
pinMode(GPS_EN, OUTPUT);
67-
68-
return true;
69-
}
70-
71-
bool TechoSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) {
72-
if (requester_permissions & TELEM_PERM_LOCATION) { // does requester have permission?
73-
telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude);
74-
}
75-
return true;
76-
}
77-
78-
void TechoSensorManager::loop() {
79-
static long next_gps_update = 0;
80-
81-
if (!gps_active) {
82-
return; // GPS is not active, skip further processing
83-
}
84-
85-
_location->loop();
86-
87-
if (millis() > next_gps_update) {
88-
if (_location->isValid()) {
89-
node_lat = ((double)_location->getLatitude())/1000000.;
90-
node_lon = ((double)_location->getLongitude())/1000000.;
91-
node_altitude = ((double)_location->getAltitude()) / 1000.0;
92-
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
93-
}
94-
next_gps_update = millis() + 1000;
95-
}
96-
}
97-
98-
int TechoSensorManager::getNumSettings() const {
99-
return 1; // always show GPS setting
100-
}
101-
102-
const char* TechoSensorManager::getSettingName(int i) const {
103-
return (i == 0) ? "gps" : NULL;
104-
}
105-
106-
const char* TechoSensorManager::getSettingValue(int i) const {
107-
if (i == 0) {
108-
return gps_active ? "1" : "0";
109-
}
110-
return NULL;
111-
}
112-
113-
bool TechoSensorManager::setSettingValue(const char* name, const char* value) {
114-
if (strcmp(name, "gps") == 0) {
115-
if (strcmp(value, "0") == 0) {
116-
stop_gps();
117-
} else {
118-
start_gps();
119-
}
120-
return true;
121-
}
122-
return false; // not supported
123-
}

variants/techo/target.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,17 @@
77
#include <helpers/radiolib/CustomSX1262Wrapper.h>
88
#include <helpers/AutoDiscoverRTCClock.h>
99
#include <helpers/SensorManager.h>
10+
#include <helpers/sensors/EnvironmentSensorManager.h>
1011
#include <helpers/sensors/LocationProvider.h>
1112
#ifdef DISPLAY_CLASS
1213
#include <helpers/ui/GxEPDDisplay.h>
1314
#include <helpers/ui/MomentaryButton.h>
1415
#endif
1516

16-
class TechoSensorManager : public SensorManager {
17-
bool gps_active = false;
18-
LocationProvider* _location;
19-
20-
void start_gps();
21-
void stop_gps();
22-
public:
23-
TechoSensorManager(LocationProvider &location): _location(&location) { }
24-
bool begin() override;
25-
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override;
26-
void loop() override;
27-
int getNumSettings() const override;
28-
const char* getSettingName(int i) const override;
29-
const char* getSettingValue(int i) const override;
30-
bool setSettingValue(const char* name, const char* value) override;
31-
};
32-
3317
extern TechoBoard board;
3418
extern WRAPPER_CLASS radio_driver;
3519
extern AutoDiscoverRTCClock rtc_clock;
36-
extern TechoSensorManager sensors;
20+
extern EnvironmentSensorManager sensors;
3721

3822
#ifdef DISPLAY_CLASS
3923
extern DISPLAY_CLASS display;

0 commit comments

Comments
 (0)