@@ -56,12 +56,13 @@ enum RingBufferConsumers
56
56
RBC_TCP_SERVER,
57
57
RBC_SD_CARD,
58
58
RBC_UDP_SERVER,
59
+ RBC_USB_SERIAL,
59
60
// Insert new consumers here
60
61
RBC_MAX
61
62
};
62
63
63
64
const char *const ringBufferConsumer[] = {
64
- " Bluetooth" , " TCP Client" , " TCP Server" , " SD Card" , " UDP Server" ,
65
+ " Bluetooth" , " TCP Client" , " TCP Server" , " SD Card" , " UDP Server" , " USB Serial " ,
65
66
};
66
67
67
68
const int ringBufferConsumerEntries = sizeof (ringBufferConsumer) / sizeof (ringBufferConsumer[0 ]);
@@ -101,6 +102,7 @@ unsigned long lastGnssSend; // Timestamp of the last time we sent RTCM to GNSS
101
102
// Ring buffer tails
102
103
static RING_BUFFER_OFFSET btRingBufferTail; // BT Tail advances as it is sent over BT
103
104
static RING_BUFFER_OFFSET sdRingBufferTail; // SD Tail advances as it is recorded to SD
105
+ static RING_BUFFER_OFFSET usbRingBufferTail; // USB Tail advances as it is sent over USB serial
104
106
105
107
// Ring buffer offsets
106
108
static uint16_t rbOffsetHead;
@@ -898,6 +900,58 @@ void handleGnssDataTask(void *e)
898
900
}
899
901
}
900
902
903
+ // ----------------------------------------------------------------------
904
+ // Send data over USB serial
905
+ // ----------------------------------------------------------------------
906
+
907
+ startMillis = millis ();
908
+
909
+ // Determine USB serial connection state
910
+ if (!forwardGnssDataToUsbSerial)
911
+ // Discard the data
912
+ usbRingBufferTail = dataHead;
913
+ else
914
+ {
915
+ // Determine the amount of USB serial data in the buffer
916
+ bytesToSend = dataHead - usbRingBufferTail;
917
+ if (bytesToSend < 0 )
918
+ bytesToSend += settings.gnssHandlerBufferSize ;
919
+ if (bytesToSend > 0 )
920
+ {
921
+ // Reduce bytes to send if we have more to send then the end of
922
+ // the buffer, we'll wrap next loop
923
+ if ((usbRingBufferTail + bytesToSend) > settings.gnssHandlerBufferSize )
924
+ bytesToSend = settings.gnssHandlerBufferSize - usbRingBufferTail;
925
+
926
+ // Send data over USB serial to the PC
927
+ bytesToSend = systemWriteGnssDataToUsbSerial (&ringBuffer[usbRingBufferTail], bytesToSend);
928
+
929
+ // Account for the data that was sent
930
+ if (bytesToSend > 0 )
931
+ {
932
+ // Account for the sent or dropped data
933
+ usbRingBufferTail += bytesToSend;
934
+ if (usbRingBufferTail >= settings.gnssHandlerBufferSize )
935
+ usbRingBufferTail -= settings.gnssHandlerBufferSize ;
936
+
937
+ // Remember the maximum transfer time
938
+ deltaMillis = millis () - startMillis;
939
+ if (maxMillis[RBC_USB_SERIAL] < deltaMillis)
940
+ maxMillis[RBC_USB_SERIAL] = deltaMillis;
941
+ }
942
+
943
+ // Determine the amount of data that remains in the buffer
944
+ bytesToSend = dataHead - usbRingBufferTail;
945
+ if (bytesToSend < 0 )
946
+ bytesToSend += settings.gnssHandlerBufferSize ;
947
+ if (usedSpace < bytesToSend)
948
+ {
949
+ usedSpace = bytesToSend;
950
+ slowConsumer = " USB Serial" ;
951
+ }
952
+ }
953
+ }
954
+
901
955
// ----------------------------------------------------------------------
902
956
// Send data to the network clients
903
957
// ----------------------------------------------------------------------
@@ -1150,9 +1204,6 @@ void tickerBluetoothLedUpdate()
1150
1204
void tickerGnssLedUpdate ()
1151
1205
{
1152
1206
static uint8_t ledCallCounter = 0 ; // Used to calculate a 50% or 10% on rate for blinking
1153
- // static int gnssFadeLevel = 0; // Used to fade LED when needed
1154
- // static int gnssPwmFadeAmount = 255 / gnssTaskUpdatesHz; // Fade in/out with 20 steps, as limited by the ticker
1155
- // rate of 20Hz
1156
1207
1157
1208
ledCallCounter++;
1158
1209
ledCallCounter %= gnssTaskUpdatesHz; // Wrap to X calls per 1 second
@@ -1161,61 +1212,15 @@ void tickerGnssLedUpdate()
1161
1212
{
1162
1213
// Update the GNSS LED according to our state
1163
1214
1164
- // Solid once RTK Fix is achieved
1165
- if (gnssIsRTKFix () == true )
1215
+ // Solid once RTK Fix is achieved, or PPP converges
1216
+ if (gnssIsRTKFix () == true || gnssIsPppConverged () )
1166
1217
{
1167
1218
ledcWrite (ledGnssChannel, 255 );
1168
1219
}
1169
1220
else
1170
1221
{
1171
1222
ledcWrite (ledGnssChannel, 0 );
1172
1223
}
1173
-
1174
- // // Solid during tilt corrected RTK fix
1175
- // if (tiltIsCorrecting() == true)
1176
- // {
1177
- // ledcWrite(ledGnssChannel, 255);
1178
- // }
1179
- // else
1180
- // {
1181
- // ledcWrite(ledGnssChannel, 0);
1182
- // }
1183
-
1184
- // Fade on/off during RTK Fix
1185
- // else if (gnssIsRTKFix() == true)
1186
- // {
1187
- // // Fade in/out the GNSS LED during RTK Fix
1188
- // gnssFadeLevel += gnssPwmFadeAmount;
1189
- // if (gnssFadeLevel <= 0 || gnssFadeLevel >= 255)
1190
- // gnssPwmFadeAmount *= -1;
1191
-
1192
- // if (gnssFadeLevel > 255)
1193
- // gnssFadeLevel = 255;
1194
- // if (gnssFadeLevel < 0)
1195
- // gnssFadeLevel = 0;
1196
-
1197
- // ledcWrite(ledGnssChannel, gnssFadeLevel);
1198
- // }
1199
-
1200
- // // Blink 2Hz 50% during RTK float
1201
- // else if (gnssIsRTKFloat() == true)
1202
- // {
1203
- // if (ledCallCounter <= (gnssTaskUpdatesHz / 2))
1204
- // ledcWrite(ledGnssChannel, 255);
1205
- // else
1206
- // ledcWrite(ledGnssChannel, 0);
1207
- // }
1208
-
1209
- // // Blink a short PPS when GNSS 3D fixed
1210
- // else if (gnssIsFixed() == true)
1211
- // {
1212
- // if (ledCallCounter == (gnssTaskUpdatesHz / 10))
1213
- // {
1214
- // ledcWrite(ledGnssChannel, 255);
1215
- // }
1216
- // else
1217
- // ledcWrite(ledGnssChannel, 0);
1218
- // }
1219
1224
}
1220
1225
}
1221
1226
@@ -1384,7 +1389,7 @@ void buttonCheckTask(void *e)
1384
1389
// The user button only exits tilt mode
1385
1390
if ((singleTap || doubleTap) && (tiltIsCorrecting () == true ))
1386
1391
{
1387
- tiltStop ();
1392
+ tiltRequestStop (); // Don't force the hardware off here as it may be in use in another task
1388
1393
}
1389
1394
1390
1395
else if (doubleTap)
0 commit comments