@@ -56,12 +56,13 @@ enum RingBufferConsumers
5656 RBC_TCP_SERVER,
5757 RBC_SD_CARD,
5858 RBC_UDP_SERVER,
59+ RBC_USB_SERIAL,
5960 // Insert new consumers here
6061 RBC_MAX
6162};
6263
6364const 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 " ,
6566};
6667
6768const int ringBufferConsumerEntries = sizeof (ringBufferConsumer) / sizeof (ringBufferConsumer[0 ]);
@@ -101,6 +102,7 @@ unsigned long lastGnssSend; // Timestamp of the last time we sent RTCM to GNSS
101102// Ring buffer tails
102103static RING_BUFFER_OFFSET btRingBufferTail; // BT Tail advances as it is sent over BT
103104static 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
104106
105107// Ring buffer offsets
106108static uint16_t rbOffsetHead;
@@ -898,6 +900,58 @@ void handleGnssDataTask(void *e)
898900 }
899901 }
900902
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+
901955 // ----------------------------------------------------------------------
902956 // Send data to the network clients
903957 // ----------------------------------------------------------------------
@@ -1150,9 +1204,6 @@ void tickerBluetoothLedUpdate()
11501204void tickerGnssLedUpdate ()
11511205{
11521206 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
11561207
11571208 ledCallCounter++;
11581209 ledCallCounter %= gnssTaskUpdatesHz; // Wrap to X calls per 1 second
@@ -1161,61 +1212,15 @@ void tickerGnssLedUpdate()
11611212 {
11621213 // Update the GNSS LED according to our state
11631214
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 () )
11661217 {
11671218 ledcWrite (ledGnssChannel, 255 );
11681219 }
11691220 else
11701221 {
11711222 ledcWrite (ledGnssChannel, 0 );
11721223 }
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- // }
12191224 }
12201225}
12211226
@@ -1384,7 +1389,7 @@ void buttonCheckTask(void *e)
13841389 // The user button only exits tilt mode
13851390 if ((singleTap || doubleTap) && (tiltIsCorrecting () == true ))
13861391 {
1387- tiltStop ();
1392+ tiltRequestStop (); // Don't force the hardware off here as it may be in use in another task
13881393 }
13891394
13901395 else if (doubleTap)
0 commit comments