Skip to content

Commit 28375c8

Browse files
authored
Merge branch 'master' into showscroller-q3
2 parents 54f631d + 3788fbb commit 28375c8

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
jsvObjectIterator is now safe even if not called on something iterable
4040
X.on now always allocates an array - tidies up code (fix #2559)
4141
Bangle.js: E.showMenu no longer sends the internal `l` menu object as argument when running the callback function.
42+
Bangle.js2: GPS request RMC packet automatically (so GPS speed/time work even without AGPS) (fix #2354)
43+
Bangle.js2: GPS now detects binary CASIC packets and splits them into their own GPS-raw event
4244
Bangle.js2: Pass the modified touch event on through both E.showScroller and E.showMenu (to enable more complex interaction with menus).
4345

4446
2v24 : Bangle.js2: Add 'Bangle.touchRd()', 'Bangle.touchWr()'

libs/banglejs/jswrap_bangle.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ JshI2CInfo i2cHRM;
587587
#define PRESSURE_I2C &i2cPressure
588588
#define HRM_I2C &i2cHRM
589589
#define GPS_UART EV_SERIAL1
590+
#define GPS_CASIC 1 // handle decoding of 'CASIC' packets from the GPS
590591
#define HEARTRATE 1
591592

592593
bool pressureBMP280Enabled = false;
@@ -4658,7 +4659,7 @@ bool jswrap_banglejs_idle() {
46584659
bool jswrap_banglejs_gps_character(char ch) {
46594660
#ifdef GPS_PIN_RX
46604661
// if too many chars, roll over since it's probably because we skipped a newline
4661-
// or messed the message length
4662+
// or messed up the message length
46624663
if (gpsLineLength >= sizeof(gpsLine)) {
46634664
#ifdef GPS_UBLOX
46644665
if (inComingUbloxProtocol == UBLOX_PROTOCOL_UBX &&
@@ -4689,6 +4690,21 @@ bool jswrap_banglejs_gps_character(char ch) {
46894690
}
46904691
#endif // GPS_UBLOX
46914692
gpsLine[gpsLineLength++] = ch;
4693+
#ifdef GPS_CASIC
4694+
if (gpsLineLength>2 && gpsLine[0]==0xBA && gpsLine[1]==0xCE) {
4695+
if (gpsLineLength<4) return true; // not enough data for length
4696+
int len = gpsLine[2] | (gpsLine[3] << 8);
4697+
// 4 class, 5 = msg
4698+
// 4 byte checksum on end
4699+
if (gpsLineLength>=len+10) { // packet end!
4700+
memcpy(gpsLastLine, gpsLine, gpsLineLength);
4701+
gpsLastLineLength = gpsLineLength;
4702+
bangleTasks |= JSBT_GPS_DATA_LINE;
4703+
gpsClearLine();
4704+
}
4705+
return true;
4706+
}
4707+
#endif
46924708
if (
46934709
#ifdef GPS_UBLOX
46944710
inComingUbloxProtocol == UBLOX_PROTOCOL_NMEA &&
@@ -4707,8 +4723,20 @@ bool jswrap_banglejs_gps_character(char ch) {
47074723
if (gpsLineLength > 2 && gpsLineLength <= NMEA_MAX_SIZE && gpsLine[gpsLineLength - 2] =='\r') {
47084724
gpsLine[gpsLineLength - 2] = 0; // just overwriting \r\n
47094725
gpsLine[gpsLineLength - 1] = 0;
4710-
if (nmea_decode(&gpsFix, (char *)gpsLine))
4726+
if (nmea_decode(&gpsFix, (char *)gpsLine)) {
47114727
bangleTasks |= JSBT_GPS_DATA;
4728+
#ifdef BANGLEJS_Q3
4729+
if (gpsFix.packetCount == 1) { // first packet
4730+
// https://github.com/espruino/Espruino/issues/2354 - on newer Bangle.js, speed/time may not be reported
4731+
// as there's no RMC packet by default. If we detect this in 1st packet send a command to fix it
4732+
if ((gpsFix.packetsParsed & NMEA_RMC)==0) {
4733+
jshTransmitPrintf(GPS_UART,"$PCAS03,1,0,0,1,1,0,0,0*03\r\n");
4734+
}
4735+
}
4736+
#endif
4737+
// reset what packets we think we got
4738+
gpsFix.packetsParsed = NMEA_NONE;
4739+
}
47124740
if (bangleTasks & (JSBT_GPS_DATA_PARTIAL|JSBT_GPS_DATA_LINE)) {
47134741
// we were already waiting to post data, so lets not overwrite it
47144742
bangleTasks |= JSBT_GPS_DATA_OVERFLOW;

libs/misc/nmea.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ bool nmea_decode(NMEAFixInfo *gpsFix, const char *nmeaLine) {
5151
if (nmea[0]=='$' && nmea[1]=='G') {
5252
if (nmea[3]=='R' && nmea[4]=='M' && nmea[5]=='C') {
5353
// $GNRMC,161945.00,A,5139.11397,N,00116.07202,W,1.530,,190919,,,A*7E
54+
gpsFix->packetsParsed |= NMEA_RMC;
5455
nmea = nmea_next_comma(nmea)+1;
5556
nextComma = nmea_next_comma(nmea);
5657
// time
@@ -87,6 +88,7 @@ bool nmea_decode(NMEAFixInfo *gpsFix, const char *nmeaLine) {
8788
}
8889
if (nmea[3]=='G' && nmea[4]=='G' && nmea[5]=='A') {
8990
// $GNGGA,161945.00,5139.11397,N,00116.07202,W,1,06,1.29,71.1,M,47.0,M,,*64
91+
gpsFix->packetsParsed |= NMEA_GGA;
9092
nmea = nmea_next_comma(nmea)+1;
9193
nextComma = nmea_next_comma(nmea);
9294
// time
@@ -118,6 +120,7 @@ bool nmea_decode(NMEAFixInfo *gpsFix, const char *nmeaLine) {
118120
}
119121
if (nmea[3]=='G' && nmea[4]=='S' && nmea[5]=='V') {
120122
// loads of cool data about what satellites we have and signal strength...
123+
gpsFix->packetsParsed |= NMEA_GSV;
121124
thisIsGSV = true;
122125
}
123126
}
@@ -159,13 +162,17 @@ bool nmea_decode(NMEAFixInfo *gpsFix, const char *nmeaLine) {
159162
// Complete set of data received
160163
createGPSEvent = true;
161164
}
162-
if (gpsFix->lastWasGGA && thisIsGGA) { // We got two GGAs - we can do this if
165+
if (gpsFix->lastWasGGA && thisIsGGA) { // We got two GGAs - we can do this if
163166
// Complete set of data received
164167
createGPSEvent = true;
165168
}
166169
// update info we had last
167170
gpsFix->lastWasGSV = thisIsGSV;
168171
gpsFix->lastWasGGA = thisIsGGA;
172+
if (createGPSEvent) {
173+
if (gpsFix->packetCount < 255)
174+
gpsFix->packetCount++;
175+
}
169176
return createGPSEvent;
170177
}
171178

libs/misc/nmea.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414

1515
#include "jsvar.h"
1616

17+
typedef enum {
18+
NMEA_NONE = 0,
19+
NMEA_RMC = 1,
20+
NMEA_GGA = 2,
21+
NMEA_GSV = 4,
22+
} NMEAFixPackets;
23+
1724
typedef struct {
25+
NMEAFixPackets packetsParsed; // which types of packet have been received?
26+
uint8_t packetCount; // number of packets received
1827
double lat,lon,alt;
1928
double speed; // speed in km/h
2029
double course; // angle of travel in degrees

0 commit comments

Comments
 (0)