20
20
GPSHardware::GPSHardware () {
21
21
_iface_type = GPS_IFACE_NONE;
22
22
_driver_type = GPS_DRV_NONE;
23
+ _nmea_baud_rate = DEFAULT_MTK_NMEA_BAUD_RATE;
24
+ _nmea_update_rate = DEFAULT_MTK_NMEA_UPDATE_RATE;
23
25
}
24
26
25
27
/* !
@@ -96,22 +98,36 @@ bool GPSHardware::Handle_GPSConfig(wippersnapper_gps_GPSConfig *gps_config) {
96
98
bool GPSHardware::SetInterface (HardwareSerial *serial) {
97
99
if (serial == nullptr )
98
100
return false ;
99
- // Set the hardware serial interface
101
+ // Configure the hardware serial interface
100
102
_hw_serial = serial;
101
103
_iface_type = GPS_IFACE_UART_HW;
102
104
return true ;
103
105
}
104
106
107
+ /* !
108
+ * @brief Sets a TwoWire (I2C) interface for the GPS controller.
109
+ * @param wire
110
+ * Points to a TwoWire instance.
111
+ * @returns True if the interface was set successfully, False otherwise.
112
+ */
113
+ bool GPSHardware::SetInterface (TwoWire *wire) {
114
+ if (wire == nullptr )
115
+ return false ;
116
+ // Configure the I2C interface
117
+ _wire = wire;
118
+ _iface_type = GPS_IFACE_I2C;
119
+ return true ;
120
+ }
121
+
105
122
/* !
106
123
* @brief Attempts to initialize the GPS device based on the configured
107
124
* interface type.
108
125
* @returns True if the GPS device was initialized successfully, False
109
126
* otherwise.
110
127
*/
111
128
bool GPSHardware::begin () {
112
- // Validate if the interface type is set
113
129
if (_iface_type == GPS_IFACE_NONE) {
114
- WS_DEBUG_PRINTLN (" [gps] ERROR: No interface type configured!" );
130
+ WS_DEBUG_PRINTLN (" [gps] ERROR: No interface configured for GPS !" );
115
131
return false ;
116
132
}
117
133
@@ -120,9 +136,8 @@ bool GPSHardware::begin() {
120
136
WS_DEBUG_PRINTLN (" [gps] ERROR: Failed to query GPS module type!" );
121
137
return false ;
122
138
}
139
+ WS_DEBUG_PRINTLN (" [gps] Module detected, ready for commands!" );
123
140
124
- WS_DEBUG_PRINTLN (
125
- " [gps] GPS module type detected successfully and ready for commands!" );
126
141
return true ;
127
142
}
128
143
@@ -132,32 +147,48 @@ bool GPSHardware::begin() {
132
147
* @returns True if the driver type was detected successfully, False otherwise.
133
148
*/
134
149
bool GPSHardware::QueryModuleType () {
135
- // Validate if the interface is set
136
- if (_iface_type == GPS_IFACE_NONE) {
137
- WS_DEBUG_PRINTLN (" [gps] ERROR: No interface configured for GPS!" );
138
- return false ;
139
- }
140
150
WS_DEBUG_PRINTLN (" [gps] Attempting to detect GPS module type..." );
141
151
142
- // Try to detect MediaTek GPS module
143
- if (DetectMediatek ()) {
144
- WS_DEBUG_PRINTLN (" [gps] Using MediaTek GPS driver!" );
145
- return true ;
146
- }
147
-
148
- WS_DEBUG_PRINTLN (" [gps] Failed to detect MTK GPS, attempting to detect "
149
- " u-blox GPS module..." );
150
- // TODO: Implement u-blox detection here
151
- // if (DetectUblox()) {
152
- // return true;
153
- // }
152
+ if (_iface_type == GPS_IFACE_UART_HW) {
153
+ // Try to detect MediaTek GPS module
154
+ if (DetectMediatek ()) {
155
+ WS_DEBUG_PRINTLN (" [gps] Using MediaTek GPS driver!" );
156
+ return true ;
157
+ }
154
158
155
- WS_DEBUG_PRINTLN (" [gps] ERROR: Failed to detect GPS driver type, attempting "
156
- " to use generic driver!" );
157
- // TODO: Implement generic NMEA GPS driver detection
159
+ WS_DEBUG_PRINTLN (" [gps] Failed to detect MTK GPS, attempting to detect "
160
+ " u-blox GPS module..." );
161
+ // TODO: Implement u-blox detection here
162
+ // if (DetectUblox()) {
163
+ // return true;
164
+ // }
165
+
166
+ WS_DEBUG_PRINTLN (
167
+ " [gps] ERROR: Failed to detect GPS driver type, attempting "
168
+ " to use generic driver!" );
169
+ // TODO: Implement generic NMEA GPS driver detection
170
+
171
+ // No responses from the GPS module over the defined iface, so we bail out
172
+ WS_DEBUG_PRINTLN (" [gps] ERROR: No GPS driver type detected!" );
173
+ } else if (_iface_type == GPS_IFACE_I2C) {
174
+ if (_addr == PA1010D_I2C_ADDRESS) {
175
+ WS_DEBUG_PRINT (" [gps] Attempting to use PA1010D driver..." );
176
+ // Attempt to use Adafruit_GPS I2c interface
177
+ _ada_gps = new Adafruit_GPS (_hw_serial);
178
+ if (!_ada_gps->begin (_addr)) {
179
+ WS_DEBUG_PRINTLN (" [gps] ERROR: Failed to initialize Mediatek!" );
180
+ return false ;
181
+ }
182
+ WS_DEBUG_PRINTLN (" ok!" );
183
+ _driver_type = GPS_DRV_MTK;
184
+ return true ;
185
+ } else {
186
+ WS_DEBUG_PRINTLN (
187
+ " [gps] ERROR: Only PA1010D i2c module is supported at this time!" );
188
+ return false ;
189
+ }
190
+ }
158
191
159
- // No responses from the GPS module over the defined iface, so we bail out
160
- WS_DEBUG_PRINTLN (" [gps] ERROR: No GPS driver type detected!" );
161
192
return false ;
162
193
}
163
194
@@ -212,17 +243,12 @@ bool GPSHardware::DetectMediatek() {
212
243
}
213
244
214
245
// Attempt to use Adafruit_GPS
215
- if (_ada_gps != nullptr ) {
216
- delete _ada_gps; // Clean up previous instance if it exists
217
- }
218
246
_ada_gps = new Adafruit_GPS (_hw_serial);
219
247
if (!_ada_gps->begin (_hw_serial->baudRate ())) {
220
248
WS_DEBUG_PRINTLN (" [gps] ERROR: Failed to initialize Mediatek!" );
221
249
return false ;
222
250
}
223
251
_driver_type = GPS_DRV_MTK;
224
- _nmea_baud_rate = DEFAULT_MTK_NMEA_BAUD_RATE;
225
- _nmea_update_rate = DEFAULT_MTK_NMEA_UPDATE_RATE;
226
252
return true ;
227
253
}
228
254
@@ -313,6 +339,13 @@ void GPSHardware::SetNmeaBaudRate(int nmea_baud_rate) {
313
339
*/
314
340
int GPSHardware::GetNmeaBaudRate () { return _nmea_baud_rate; }
315
341
342
+ /* !
343
+ * @brief Sets the I2C address for a GPS.
344
+ * @param i2c_address
345
+ * The I2C address to set for the GPS device.
346
+ */
347
+ void GPSHardware::SetI2CAddress (uint32_t i2c_address) { _addr = i2c_address; }
348
+
316
349
/* !
317
350
* @brief Sets the last time the GPS hardware was polled.
318
351
* @param kat_prv
0 commit comments