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
610T114Board board;
711
12+ #if defined(P_LORA_SCLK)
813RADIO_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
1018WRAPPER_CLASS radio_driver (radio, board);
1119
1220VolatileRTCClock fallback_clock;
1321AutoDiscoverRTCClock 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
2236bool 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
2846uint32_t radio_get_rng_seed () {
@@ -42,92 +60,5 @@ void radio_set_tx_power(uint8_t dbm) {
4260
4361mesh::LocalIdentity radio_new_identity () {
4462 RadioNoiseListener rng (radio);
45- return mesh::LocalIdentity (&rng); // create new random identity
46- }
47-
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-
62- bool T114SensorManager::begin () {
63- Serial1.begin (9600 );
64-
65- // 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
68-
69- // Give GPS a moment to power up and send data
70- delay (1500 );
71-
72- // We'll consider GPS detected if we see any data on Serial1
73- gps_detected = (Serial1.available () > 0 );
74-
75- if (gps_detected) {
76- MESH_DEBUG_PRINTLN (" GPS detected" );
77- } else {
78- MESH_DEBUG_PRINTLN (" No GPS detected" );
79- }
80- digitalWrite (GPS_EN , LOW ); // Power off GPS until the setting is changed
81-
82- return true ;
83- }
84-
85- bool T114SensorManager::querySensors (uint8_t requester_permissions, CayenneLPP& telemetry) {
86- if (requester_permissions & TELEM_PERM_LOCATION ) { // does requester have permission?
87- telemetry.addGPS (TELEM_CHANNEL_SELF , node_lat, node_lon, node_altitude);
88- }
89- return true ;
90- }
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
63+ return mesh::LocalIdentity (&rng); // create new random identity
13364}
0 commit comments