Skip to content

Commit 4aa58ad

Browse files
authored
Merge pull request #811 from fdlamotte/tracker_l1_environment_sensors
Tracker l1: environment sensors
2 parents 4579a1b + 611d61b commit 4aa58ad

File tree

6 files changed

+30
-134
lines changed

6 files changed

+30
-134
lines changed

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static Adafruit_INA260 INA260;
7070
#define TELEM_INA226_SHUNT_VALUE 0.100
7171
#define TELEM_INA226_MAX_AMP 0.8
7272
#include <INA226.h>
73-
static INA226 INA226(TELEM_INA226_ADDRESS);
73+
static INA226 INA226(TELEM_INA226_ADDRESS, TELEM_WIRE);
7474
#endif
7575

7676
#if ENV_INCLUDE_MLX90614
@@ -108,7 +108,13 @@ bool EnvironmentSensorManager::begin() {
108108
#endif
109109

110110
#if ENV_PIN_SDA && ENV_PIN_SCL
111+
#ifdef NRF52_PLATFORM
112+
Wire1.setPins(ENV_PIN_SDA, ENV_PIN_SCL);
113+
Wire1.setClock(100000);
114+
Wire1.begin();
115+
#else
111116
Wire1.begin(ENV_PIN_SDA, ENV_PIN_SCL, 100000);
117+
#endif
112118
MESH_DEBUG_PRINTLN("Second I2C initialized on pins SDA: %d SCL: %d", ENV_PIN_SDA, ENV_PIN_SCL);
113119
#endif
114120

variants/wio-tracker-l1-eink/platformio.ini

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ extends = nrf52_base
33
board = seeed-wio-tracker-l1
44
board_build.ldscript = boards/nrf52840_s140_v7.ld
55
build_flags = ${nrf52_base.build_flags}
6+
${sensor_base.build_flags}
67
-I lib/nrf52/s140_nrf52_7.3.0_API/include
78
-I lib/nrf52/s140_nrf52_7.3.0_API/include/nrf52
89
-I variants/wio-tracker-l1
@@ -22,18 +23,19 @@ build_flags = ${nrf52_base.build_flags}
2223
-D DISPLAY_ROTATION=1
2324
-D DISABLE_DIAGNOSTIC_OUTPUT
2425
-D AUTO_OFF_MILLIS=0
26+
-D GPS_BAUD_RATE=9600
27+
-D ENV_PIN_SDA=PIN_WIRE1_SDA
28+
-D ENV_PIN_SCL=PIN_WIRE1_SCL
2529
build_src_filter = ${nrf52_base.build_src_filter}
2630
+<WioTrackerL1Board.cpp>
2731
+<../variants/wio-tracker-l1>
2832
+<helpers/ui/GxEPDDisplay.cpp>
2933
+<helpers/sensors>
3034
lib_deps= ${nrf52_base.lib_deps}
31-
adafruit/Adafruit SH110X @ ^2.1.13
35+
${sensor_base.lib_deps}
3236
adafruit/Adafruit GFX Library @ ^1.12.1
33-
stevemarple/MicroNMEA @ ^2.0.6
3437
zinggjm/GxEPD2 @ 1.6.2
3538
bakercp/CRC32 @ ^2.0.0
36-
adafruit/Adafruit BME280 Library @ ^2.3.0
3739

3840
[env:WioTrackerL1Eink_companion_radio_ble]
3941
extends = WioTrackerL1Eink
@@ -51,7 +53,7 @@ build_flags = ${WioTrackerL1Eink.build_flags}
5153
-D QSPIFLASH=1
5254
; -D MESH_PACKET_LOGGING=1
5355
; -D MESH_DEBUG=1
54-
-D UI_RECENT_LIST_SIZE=9
56+
-D UI_RECENT_LIST_SIZE=6
5557
-D UI_SENSORS_PAGE=1
5658
build_src_filter = ${WioTrackerL1Eink.build_src_filter}
5759
+<helpers/nrf52/SerialBLEInterface.cpp>

variants/wio-tracker-l1/platformio.ini

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ extends = nrf52_base
33
board = seeed-wio-tracker-l1
44
board_build.ldscript = boards/nrf52840_s140_v7.ld
55
build_flags = ${nrf52_base.build_flags}
6+
${sensor_base.build_flags}
67
-I lib/nrf52/s140_nrf52_7.3.0_API/include
78
-I lib/nrf52/s140_nrf52_7.3.0_API/include/nrf52
89
-I variants/wio-tracker-l1
@@ -13,16 +14,18 @@ build_flags = ${nrf52_base.build_flags}
1314
-D SX126X_CURRENT_LIMIT=140
1415
-D SX126X_RX_BOOSTED_GAIN=1
1516
-D PIN_OLED_RESET=-1
16-
; -D MESH_DEBUG=1
17+
-D GPS_BAUD_RATE=9600
18+
-D ENV_PIN_SDA=PIN_WIRE1_SDA
19+
-D ENV_PIN_SCL=PIN_WIRE1_SCL
1720
build_src_filter = ${nrf52_base.build_src_filter}
1821
+<WioTrackerL1Board.cpp>
1922
+<../variants/wio-tracker-l1>
2023
+<helpers/ui/SH1106Display.cpp>
2124
+<helpers/sensors>
2225
lib_deps= ${nrf52_base.lib_deps}
26+
${sensor_base.lib_deps}
2327
adafruit/Adafruit SH110X @ ^2.1.13
2428
adafruit/Adafruit GFX Library @ ^1.12.1
25-
stevemarple/MicroNMEA @ ^2.0.6
2629

2730
[env:WioTrackerL1_Repeater]
2831
extends = WioTrackerL1

variants/wio-tracker-l1/target.cpp

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

1212
VolatileRTCClock fallback_clock;
1313
AutoDiscoverRTCClock rtc_clock(fallback_clock);
14-
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
15-
WioTrackerL1SensorManager sensors = WioTrackerL1SensorManager(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
1621

1722
#ifdef DISPLAY_CLASS
1823
DISPLAY_CLASS display;
@@ -42,107 +47,6 @@ void radio_set_tx_power(uint8_t dbm) {
4247
radio.setOutputPower(dbm);
4348
}
4449

45-
void WioTrackerL1SensorManager::start_gps()
46-
{
47-
if (!gps_active)
48-
{
49-
MESH_DEBUG_PRINTLN("starting GPS");
50-
digitalWrite(PIN_GPS_STANDBY, HIGH);
51-
gps_active = true;
52-
}
53-
}
54-
55-
void WioTrackerL1SensorManager::stop_gps()
56-
{
57-
if (gps_active)
58-
{
59-
MESH_DEBUG_PRINTLN("stopping GPS");
60-
digitalWrite(PIN_GPS_STANDBY, LOW);
61-
gps_active = false;
62-
}
63-
}
64-
65-
bool WioTrackerL1SensorManager::begin()
66-
{
67-
Serial1.setPins(PIN_GPS_TX, PIN_GPS_RX); // be sure to tx into rx and rx into tx
68-
Serial1.begin(GPS_BAUDRATE);
69-
70-
pinMode(PIN_GPS_STANDBY, OUTPUT);
71-
digitalWrite(PIN_GPS_STANDBY, HIGH); // Wake GPS from standby
72-
delay(500);
73-
74-
// We'll consider GPS detected if we see any data on Serial1
75-
if (Serial1.available() > 0)
76-
{
77-
MESH_DEBUG_PRINTLN("GPS detected");
78-
}
79-
else
80-
{
81-
MESH_DEBUG_PRINTLN("No GPS detected");
82-
}
83-
digitalWrite(PIN_GPS_STANDBY, LOW); // Put GPS back into standby mode
84-
return true;
85-
}
86-
87-
bool WioTrackerL1SensorManager::querySensors(uint8_t requester_permissions, CayenneLPP &telemetry)
88-
{
89-
if (requester_permissions & TELEM_PERM_LOCATION)
90-
{ // does requester have permission?
91-
telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude);
92-
}
93-
return true;
94-
}
95-
96-
void WioTrackerL1SensorManager::loop()
97-
{
98-
static long next_gps_update = 0;
99-
_location->loop();
100-
if (millis() > next_gps_update && gps_active) // don't bother if gps position is not enabled
101-
{
102-
if (_location->isValid())
103-
{
104-
node_lat = ((double)_location->getLatitude()) / 1000000.;
105-
node_lon = ((double)_location->getLongitude()) / 1000000.;
106-
node_altitude = ((double)_location->getAltitude()) / 1000.0;
107-
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon);
108-
}
109-
next_gps_update = millis() + (1000 * 60); // after initial update, only check every minute TODO: should be configurable
110-
}
111-
}
112-
113-
int WioTrackerL1SensorManager::getNumSettings() const { return 1; } // just one supported: "gps" (power switch)
114-
115-
const char *WioTrackerL1SensorManager::getSettingName(int i) const
116-
{
117-
return i == 0 ? "gps" : NULL;
118-
}
119-
120-
const char *WioTrackerL1SensorManager::getSettingValue(int i) const
121-
{
122-
if (i == 0)
123-
{
124-
return gps_active ? "1" : "0";
125-
}
126-
return NULL;
127-
}
128-
129-
bool WioTrackerL1SensorManager::setSettingValue(const char *name, const char *value)
130-
{
131-
if (strcmp(name, "gps") == 0)
132-
{
133-
if (strcmp(value, "0") == 0)
134-
{
135-
stop_gps();
136-
}
137-
else
138-
{
139-
start_gps();
140-
}
141-
return true;
142-
}
143-
return false; // not supported
144-
}
145-
14650
mesh::LocalIdentity radio_new_identity() {
14751
RadioNoiseListener rng(radio);
14852
return mesh::LocalIdentity(&rng); // create new random identity

variants/wio-tracker-l1/target.h

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <helpers/radiolib/CustomSX1262Wrapper.h>
88
#include <helpers/AutoDiscoverRTCClock.h>
99
#include <helpers/ArduinoHelpers.h>
10+
#include <helpers/sensors/EnvironmentSensorManager.h>
1011
#ifdef DISPLAY_CLASS
1112
#if defined(WIO_TRACKER_L1_EINK)
1213
#include <helpers/ui/GxEPDDisplay.h>
@@ -17,30 +18,10 @@
1718
#endif
1819
#include <helpers/sensors/EnvironmentSensorManager.h>
1920

20-
class WioTrackerL1SensorManager : public SensorManager
21-
{
22-
bool gps_active = false;
23-
LocationProvider *_location;
24-
25-
void start_gps();
26-
void stop_gps();
27-
28-
public:
29-
WioTrackerL1SensorManager(LocationProvider &location) : _location(&location) {}
30-
bool begin() override;
31-
bool querySensors(uint8_t requester_permissions, CayenneLPP &telemetry) override;
32-
void loop() override;
33-
int getNumSettings() const override;
34-
const char *getSettingName(int i) const override;
35-
const char *getSettingValue(int i) const override;
36-
bool setSettingValue(const char *name, const char *value) override;
37-
};
38-
39-
4021
extern WioTrackerL1Board board;
4122
extern WRAPPER_CLASS radio_driver;
4223
extern AutoDiscoverRTCClock rtc_clock;
43-
extern WioTrackerL1SensorManager sensors;
24+
extern EnvironmentSensorManager sensors;
4425
#ifdef DISPLAY_CLASS
4526
extern DISPLAY_CLASS display;
4627
extern MomentaryButton user_btn;

variants/wio-tracker-l1/variant.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@
7878

7979
#define PIN_WIRE_SDA (14)
8080
#define PIN_WIRE_SCL (15)
81-
#define PIN_WIRE1_SDA (17)
82-
#define PIN_WIRE1_SCL (18)
81+
#define PIN_WIRE1_SDA (18)
82+
#define PIN_WIRE1_SCL (17)
8383
#define I2C_NO_RESCAN
8484
#define DISPLAY_ADDRESS 0x3D // SH1106 OLED I2C address
8585

@@ -88,7 +88,7 @@
8888
#define PIN_GPS_TX PIN_SERIAL1_RX
8989
#define PIN_GPS_RX PIN_SERIAL1_TX
9090
#define PIN_GPS_STANDBY (0)
91-
#define PIN_GPS_EN (18)
91+
#define PIN_GPS_EN (PIN_GPS_STANDBY)
9292

9393
// QSPI Pins
9494
#define PIN_QSPI_SCK (19)

0 commit comments

Comments
 (0)