Skip to content

Commit

Permalink
Merge pull request #117 from optorres/fix-warnings-2
Browse files Browse the repository at this point in the history
Fix boolean deprecation and -Wdouble-promotion warnings
  • Loading branch information
drak7 authored Feb 25, 2020
2 parents 8738b30 + a0cf6d8 commit c65c00a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 39 deletions.
28 changes: 14 additions & 14 deletions src/NMEA_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ void Adafruit_GPS::newDataValue(nmea_index_t idx, nmea_float_t v) {

// update the smoothed verion
if (isCompoundAngle(idx)) { // angle with sin/cos component recording
newDataValue((nmea_index_t)(idx + 1), sin(v / RAD_TO_DEG));
newDataValue((nmea_index_t)(idx + 2), cos(v / RAD_TO_DEG));
newDataValue((nmea_index_t)(idx + 1), sin(v / (nmea_float_t)RAD_TO_DEG));
newDataValue((nmea_index_t)(idx + 2), cos(v / (nmea_float_t)RAD_TO_DEG));
}
// weighting factor for smoothing depends on delta t / tau
nmea_float_t w =
min((nmea_float_t)1.0,
(nmea_float_t)(millis() - val[idx].lastUpdate) / val[idx].response);
// default smoothing
val[idx].smoothed = (1.0 - w) * val[idx].smoothed + w * v;
val[idx].smoothed = (1.0f - w) * val[idx].smoothed + w * v;
// special smoothing for some angle types
if (val[idx].type == NMEA_COMPASS_ANGLE_SIN)
val[idx].smoothed =
Expand Down Expand Up @@ -403,7 +403,7 @@ nmea_history_t *Adafruit_GPS::initHistory(nmea_index_t idx, nmea_float_t scale,
}
if (val[idx].hist != NULL) {
val[idx].hist->n = historyN;
if (scale > 0.0)
if (scale > 0.0f)
val[idx].hist->scale = scale;
val[idx].hist->offset = offset;
if (historyInterval > 0)
Expand Down Expand Up @@ -517,18 +517,18 @@ bool Adafruit_GPS::isCompoundAngle(nmea_index_t idx) {
*/
/**************************************************************************/
nmea_float_t Adafruit_GPS::boatAngle(nmea_float_t s, nmea_float_t c) {
nmea_float_t sAng =
asin(s) * RAD_TO_DEG; // put the sin angle in -90 to 90 range
// put the sin angle in -90 to 90 range
nmea_float_t sAng = asin(s) * (nmea_float_t)RAD_TO_DEG;
while (sAng < -90)
sAng += 180.;
sAng += 180.0f;
while (sAng > 90)
sAng -= 180.;
nmea_float_t cAng =
acos(c) * RAD_TO_DEG; // put the cos angle in 0 to 180 range
sAng -= 180.0f;
// put the cos angle in 0 to 180 range
nmea_float_t cAng = acos(c) * (nmea_float_t)RAD_TO_DEG;
while (cAng < 0)
cAng += 180.;
cAng += 180.0f;
while (cAng > 180)
cAng -= 180.;
cAng -= 180.0f;
// Pick the most accurate representation and translate
if (cAng < 45)
return sAng; // Close hauled
Expand Down Expand Up @@ -561,9 +561,9 @@ nmea_float_t Adafruit_GPS::compassAngle(nmea_float_t s, nmea_float_t c) {
nmea_float_t ang = boatAngle(s, c);
if (ang < 5000) { // if reasonable range
while (ang < 0)
ang += 360.; // round up
ang += 360.0f; // round up
while (ang > 360)
ang -= 360.; // round down
ang -= 360.0f; // round down
}
return ang;
}
Expand Down
52 changes: 27 additions & 25 deletions src/NMEA_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,17 @@ bool Adafruit_GPS::parse(char *nmea) {
// feet, metres, fathoms below transducer coerced to water depth from
// surface in metres
if (!isEmpty(p))
newDataValue(NMEA_DEPTH, atof(p) * 0.3048 + depthToTransducer);
newDataValue(NMEA_DEPTH,
(nmea_float_t)atof(p) * 0.3048f + depthToTransducer);
p = strchr(p, ',') + 1;
p = strchr(p, ',') + 1;
if (!isEmpty(p))
newDataValue(NMEA_DEPTH, atof(p) + depthToTransducer);
newDataValue(NMEA_DEPTH, (nmea_float_t)atof(p) + depthToTransducer);
p = strchr(p, ',') + 1;
p = strchr(p, ',') + 1;
if (!isEmpty(p))
newDataValue(NMEA_DEPTH, atof(p) * 6 * 0.3048 + depthToTransducer);
newDataValue(NMEA_DEPTH,
(nmea_float_t)atof(p) * 6 * 0.3048f + depthToTransducer);

} else if (!strcmp(thisSentence, "DPT")) { //*****************************DPT
// from Actisense NGW-1
Expand Down Expand Up @@ -233,7 +235,7 @@ bool Adafruit_GPS::parse(char *nmea) {
u = *p;
p = strchr(p, ',') + 1;
if (u != 'C') {
T = (T - 32) / 1.8;
T = (T - 32) / 1.8f;
u = 'C';
} // coerce to C
if (T < 1000)
Expand All @@ -247,7 +249,7 @@ bool Adafruit_GPS::parse(char *nmea) {
u = *p;
p = strchr(p, ',') + 1;
if (u != 'C') {
T = (T - 32) / 1.8;
T = (T - 32) / 1.8f;
u = 'C';
}
if (T < 1000)
Expand All @@ -264,7 +266,7 @@ bool Adafruit_GPS::parse(char *nmea) {
if (!isEmpty(p))
u = *p; // last before checksum
if (u != 'C') {
T = (T - 32) / 1.8;
T = (T - 32) / 1.8f;
u = 'C';
}
if (T < 1000)
Expand Down Expand Up @@ -296,24 +298,24 @@ bool Adafruit_GPS::parse(char *nmea) {
if (!isEmpty(p))
stat = *p; // last before checksum
if (units == 'K') {
spd /= 1.6;
spd /= 1.6f;
units = 'M';
}
if (units == 'M') {
spd *= 5280. / 6000.;
spd *= 5280.0f / 6000.0f;
units = 'N';
}
if (ang > 180.)
ang -= 360.;
if (ang > 180.0f)
ang -= 360.0f;
if (ref == 'R') {
if (ang < 1000. && stat == 'A')
if (ang < 1000.0f && stat == 'A')
newDataValue(NMEA_AWA, ang);
if (spd < 1000. && stat == 'A')
if (spd < 1000.0f && stat == 'A')
newDataValue(NMEA_AWS, spd);
} else {
if (ang < 1000. && stat == 'A')
if (ang < 1000.0f && stat == 'A')
newDataValue(NMEA_TWA, ang);
if (spd < 1000. && stat == 'A')
if (spd < 1000.0f && stat == 'A')
newDataValue(NMEA_TWS, spd);
}

Expand Down Expand Up @@ -343,9 +345,9 @@ bool Adafruit_GPS::parse(char *nmea) {
if (!isEmpty(p))
xteDir = *p;
p = strchr(p, ',') + 1;
if (xte < 10000. && xteDir != 'X') {
if (xte < 10000.0f && xteDir != 'X') {
if (xteDir == 'L')
xte *= -1.;
xte *= -1.0f;
newDataValue(NMEA_XTE, xte);
}
if (!isEmpty(p))
Expand Down Expand Up @@ -452,7 +454,7 @@ bool Adafruit_GPS::parse(char *nmea) {
p = strchr(p, ',') + 1;
if (!isEmpty(p))
vmg = atof(p) * 0.3048 * 3600. / 6000.; // skip units
if (vmg < 1000.)
if (vmg < 1000.0f)
newDataValue(NMEA_VMG, vmg);
} else if (!strcmp(thisSentence, "VTG")) { //*****************************VTG
// from Actisense NGW-1 from SH CP150C
Expand All @@ -470,7 +472,7 @@ bool Adafruit_GPS::parse(char *nmea) {
p = strchr(p, ',') + 1;
if (ref == 'L')
ang *= -1;
if (ang < 1000.)
if (ang < 1000.0f)
newDataValue(NMEA_AWA, ang);
nmea_float_t ws = 0.0;
char units = 'X';
Expand All @@ -492,15 +494,15 @@ bool Adafruit_GPS::parse(char *nmea) {
if (!isEmpty(p))
units = *p; // last before checksum
if (units == 'M') {
ws *= 3.6;
ws *= 3.6f;
units = 'K';
} // convert m/s to km/h
if (units == 'K') {
ws /= 1.6;
ws /= 1.6f;
units = 'M';
} // convert km/h to miles / h
if (units == 'M') {
ws *= 5280. / 6000.;
ws *= 5280.0f / 6000.0f;
units = 'N';
} // convert miles / hr to knots
if (units == 'N')
Expand All @@ -523,9 +525,9 @@ bool Adafruit_GPS::parse(char *nmea) {
if (!isEmpty(p))
xteDir = *p;
p = strchr(p, ',') + 1;
if (xte < 10000. && xteDir != 'X') {
if (xte < 10000.0f && xteDir != 'X') {
if (xteDir == 'L')
xte *= -1.;
xte *= -1.0f;
newDataValue(NMEA_XTE, xte);
} // skip units

Expand Down Expand Up @@ -555,7 +557,7 @@ bool Adafruit_GPS::parse(char *nmea) {
@return True if well formed, false if it has problems
*/
/**************************************************************************/
boolean Adafruit_GPS::check(char *nmea) {
bool Adafruit_GPS::check(char *nmea) {
thisCheck = 0; // new check
*thisSentence = *thisSource = 0;
if (*nmea != '$' && *nmea != '!')
Expand Down Expand Up @@ -799,7 +801,7 @@ bool Adafruit_GPS::parseTime(char *p) {
@return True if we parsed it, false if it has invalid data
*/
/**************************************************************************/
boolean Adafruit_GPS::parseFix(char *p) {
bool Adafruit_GPS::parseFix(char *p) {
if (!isEmpty(p)) {
if (p[0] == 'A') {
fix = true;
Expand Down

2 comments on commit c65c00a

@siddacious
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drak7 Limor has asked me to defer to you about when to release this and the rest of these changes:
1.4.1...master

Anything I can do to help get it out the door?

@drak7
Copy link
Contributor Author

@drak7 drak7 commented on c65c00a May 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't run into any issues so it looks like it's ready to go. Quite a lot in this one so I'll bump it to 1.5.0.

Please sign in to comment.