@@ -11,8 +11,14 @@ WRAPPER_CLASS radio_driver(radio, board);
1111
1212VolatileRTCClock fallback_clock;
1313AutoDiscoverRTCClock 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- }
0 commit comments