@@ -11,8 +11,13 @@ WRAPPER_CLASS radio_driver(radio, board);
1111
1212VolatileRTCClock fallback_clock;
1313AutoDiscoverRTCClock 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-
14650mesh::LocalIdentity radio_new_identity () {
14751 RadioNoiseListener rng (radio);
14852 return mesh::LocalIdentity (&rng); // create new random identity
0 commit comments