Fix boolean deprecation and -Wdouble-promotion warnings

This commit is contained in:
Owen Torres 2020-02-23 18:31:37 -05:00
parent 96625de7d3
commit e3caa7d491
2 changed files with 37 additions and 37 deletions

View File

@ -54,15 +54,15 @@ void Adafruit_GPS::newDataValue(nmea_index_t idx, nmea_float_t v) {
// update the smoothed verion // update the smoothed verion
if (isCompoundAngle(idx)) { // angle with sin/cos component recording 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 + 1), sin(v / (nmea_float_t)RAD_TO_DEG));
newDataValue((nmea_index_t)(idx + 2), cos(v / 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 // weighting factor for smoothing depends on delta t / tau
nmea_float_t w = nmea_float_t w =
min((nmea_float_t)1.0, min((nmea_float_t)1.0,
((nmea_float_t)millis() - val[idx].lastUpdate) / val[idx].response); ((nmea_float_t)millis() - val[idx].lastUpdate) / val[idx].response);
// default smoothing // 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 // special smoothing for some angle types
if (val[idx].type == NMEA_COMPASS_ANGLE_SIN) if (val[idx].type == NMEA_COMPASS_ANGLE_SIN)
val[idx].smoothed = val[idx].smoothed =
@ -403,7 +403,7 @@ nmea_history_t *Adafruit_GPS::initHistory(nmea_index_t idx, nmea_float_t scale,
} }
if (val[idx].hist != NULL) { if (val[idx].hist != NULL) {
val[idx].hist->n = historyN; val[idx].hist->n = historyN;
if (scale > 0.0) if (scale > 0.0f)
val[idx].hist->scale = scale; val[idx].hist->scale = scale;
val[idx].hist->offset = offset; val[idx].hist->offset = offset;
if (historyInterval > 0) if (historyInterval > 0)
@ -518,17 +518,17 @@ 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 Adafruit_GPS::boatAngle(nmea_float_t s, nmea_float_t c) {
nmea_float_t sAng = nmea_float_t sAng =
asin(s) * RAD_TO_DEG; // put the sin angle in -90 to 90 range asin(s) * (nmea_float_t)RAD_TO_DEG; // put the sin angle in -90 to 90 range
while (sAng < -90) while (sAng < -90)
sAng += 180.; sAng += 180.0f;
while (sAng > 90) while (sAng > 90)
sAng -= 180.; sAng -= 180.0f;
nmea_float_t cAng = nmea_float_t cAng =
acos(c) * RAD_TO_DEG; // put the cos angle in 0 to 180 range acos(c) * (nmea_float_t)RAD_TO_DEG; // put the cos angle in 0 to 180 range
while (cAng < 0) while (cAng < 0)
cAng += 180.; cAng += 180.0f;
while (cAng > 180) while (cAng > 180)
cAng -= 180.; cAng -= 180.0f;
// Pick the most accurate representation and translate // Pick the most accurate representation and translate
if (cAng < 45) if (cAng < 45)
return sAng; // Close hauled return sAng; // Close hauled
@ -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); nmea_float_t ang = boatAngle(s, c);
if (ang < 5000) { // if reasonable range if (ang < 5000) { // if reasonable range
while (ang < 0) while (ang < 0)
ang += 360.; // round up ang += 360.0f; // round up
while (ang > 360) while (ang > 360)
ang -= 360.; // round down ang -= 360.0f; // round down
} }
return ang; return ang;
} }

View File

@ -184,15 +184,15 @@ bool Adafruit_GPS::parse(char *nmea) {
// feet, metres, fathoms below transducer coerced to water depth from // feet, metres, fathoms below transducer coerced to water depth from
// surface in metres // surface in metres
if (!isEmpty(p)) 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;
p = strchr(p, ',') + 1; p = strchr(p, ',') + 1;
if (!isEmpty(p)) 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;
p = strchr(p, ',') + 1; p = strchr(p, ',') + 1;
if (!isEmpty(p)) 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 } else if (!strcmp(thisSentence, "DPT")) { //*****************************DPT
// from Actisense NGW-1 // from Actisense NGW-1
@ -233,7 +233,7 @@ bool Adafruit_GPS::parse(char *nmea) {
u = *p; u = *p;
p = strchr(p, ',') + 1; p = strchr(p, ',') + 1;
if (u != 'C') { if (u != 'C') {
T = (T - 32) / 1.8; T = (T - 32) / 1.8f;
u = 'C'; u = 'C';
} // coerce to C } // coerce to C
if (T < 1000) if (T < 1000)
@ -247,7 +247,7 @@ bool Adafruit_GPS::parse(char *nmea) {
u = *p; u = *p;
p = strchr(p, ',') + 1; p = strchr(p, ',') + 1;
if (u != 'C') { if (u != 'C') {
T = (T - 32) / 1.8; T = (T - 32) / 1.8f;
u = 'C'; u = 'C';
} }
if (T < 1000) if (T < 1000)
@ -264,7 +264,7 @@ bool Adafruit_GPS::parse(char *nmea) {
if (!isEmpty(p)) if (!isEmpty(p))
u = *p; // last before checksum u = *p; // last before checksum
if (u != 'C') { if (u != 'C') {
T = (T - 32) / 1.8; T = (T - 32) / 1.8f;
u = 'C'; u = 'C';
} }
if (T < 1000) if (T < 1000)
@ -296,24 +296,24 @@ bool Adafruit_GPS::parse(char *nmea) {
if (!isEmpty(p)) if (!isEmpty(p))
stat = *p; // last before checksum stat = *p; // last before checksum
if (units == 'K') { if (units == 'K') {
spd /= 1.6; spd /= 1.6f;
units = 'M'; units = 'M';
} }
if (units == 'M') { if (units == 'M') {
spd *= 5280. / 6000.; spd *= 5280.0f / 6000.0f;
units = 'N'; units = 'N';
} }
if (ang > 180.) if (ang > 180.0f)
ang -= 360.; ang -= 360.0f;
if (ref == 'R') { if (ref == 'R') {
if (ang < 1000. && stat == 'A') if (ang < 1000.0f && stat == 'A')
newDataValue(NMEA_AWA, ang); newDataValue(NMEA_AWA, ang);
if (spd < 1000. && stat == 'A') if (spd < 1000.0f && stat == 'A')
newDataValue(NMEA_AWS, spd); newDataValue(NMEA_AWS, spd);
} else { } else {
if (ang < 1000. && stat == 'A') if (ang < 1000.0f && stat == 'A')
newDataValue(NMEA_TWA, ang); newDataValue(NMEA_TWA, ang);
if (spd < 1000. && stat == 'A') if (spd < 1000.0f && stat == 'A')
newDataValue(NMEA_TWS, spd); newDataValue(NMEA_TWS, spd);
} }
@ -343,9 +343,9 @@ bool Adafruit_GPS::parse(char *nmea) {
if (!isEmpty(p)) if (!isEmpty(p))
xteDir = *p; xteDir = *p;
p = strchr(p, ',') + 1; p = strchr(p, ',') + 1;
if (xte < 10000. && xteDir != 'X') { if (xte < 10000.0f && xteDir != 'X') {
if (xteDir == 'L') if (xteDir == 'L')
xte *= -1.; xte *= -1.0f;
newDataValue(NMEA_XTE, xte); newDataValue(NMEA_XTE, xte);
} }
if (!isEmpty(p)) if (!isEmpty(p))
@ -452,7 +452,7 @@ bool Adafruit_GPS::parse(char *nmea) {
p = strchr(p, ',') + 1; p = strchr(p, ',') + 1;
if (!isEmpty(p)) if (!isEmpty(p))
vmg = atof(p) * 0.3048 * 3600. / 6000.; // skip units vmg = atof(p) * 0.3048 * 3600. / 6000.; // skip units
if (vmg < 1000.) if (vmg < 1000.0f)
newDataValue(NMEA_VMG, vmg); newDataValue(NMEA_VMG, vmg);
} else if (!strcmp(thisSentence, "VTG")) { //*****************************VTG } else if (!strcmp(thisSentence, "VTG")) { //*****************************VTG
// from Actisense NGW-1 from SH CP150C // from Actisense NGW-1 from SH CP150C
@ -470,7 +470,7 @@ bool Adafruit_GPS::parse(char *nmea) {
p = strchr(p, ',') + 1; p = strchr(p, ',') + 1;
if (ref == 'L') if (ref == 'L')
ang *= -1; ang *= -1;
if (ang < 1000.) if (ang < 1000.0f)
newDataValue(NMEA_AWA, ang); newDataValue(NMEA_AWA, ang);
nmea_float_t ws = 0.0; nmea_float_t ws = 0.0;
char units = 'X'; char units = 'X';
@ -492,15 +492,15 @@ bool Adafruit_GPS::parse(char *nmea) {
if (!isEmpty(p)) if (!isEmpty(p))
units = *p; // last before checksum units = *p; // last before checksum
if (units == 'M') { if (units == 'M') {
ws *= 3.6; ws *= 3.6f;
units = 'K'; units = 'K';
} // convert m/s to km/h } // convert m/s to km/h
if (units == 'K') { if (units == 'K') {
ws /= 1.6; ws /= 1.6f;
units = 'M'; units = 'M';
} // convert km/h to miles / h } // convert km/h to miles / h
if (units == 'M') { if (units == 'M') {
ws *= 5280. / 6000.; ws *= 5280.0f / 6000.0f;
units = 'N'; units = 'N';
} // convert miles / hr to knots } // convert miles / hr to knots
if (units == 'N') if (units == 'N')
@ -523,9 +523,9 @@ bool Adafruit_GPS::parse(char *nmea) {
if (!isEmpty(p)) if (!isEmpty(p))
xteDir = *p; xteDir = *p;
p = strchr(p, ',') + 1; p = strchr(p, ',') + 1;
if (xte < 10000. && xteDir != 'X') { if (xte < 10000.0f && xteDir != 'X') {
if (xteDir == 'L') if (xteDir == 'L')
xte *= -1.; xte *= -1.0f;
newDataValue(NMEA_XTE, xte); newDataValue(NMEA_XTE, xte);
} // skip units } // skip units
@ -555,7 +555,7 @@ bool Adafruit_GPS::parse(char *nmea) {
@return True if well formed, false if it has problems @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 thisCheck = 0; // new check
*thisSentence = *thisSource = 0; *thisSentence = *thisSource = 0;
if (*nmea != '$' && *nmea != '!') if (*nmea != '$' && *nmea != '!')
@ -799,7 +799,7 @@ bool Adafruit_GPS::parseTime(char *p) {
@return True if we parsed it, false if it has invalid data @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 (!isEmpty(p)) {
if (p[0] == 'A') { if (p[0] == 'A') {
fix = true; fix = true;