Add Speed conversion to kmph

This commit is contained in:
Sanyog Nevase Nevase 2024-11-30 16:14:15 +05:30
parent c16e5fa816
commit 15cb6ad7ad
1 changed files with 7 additions and 2 deletions

9
main.c
View File

@ -88,6 +88,7 @@ void nmea_sentence_process(const char *nmea_sentence)
{ {
uint8_t i = 0; uint8_t i = 0;
uint8_t field_number = 0; uint8_t field_number = 0;
float speed_knots = 0.0;
float speed_kmh = 0.0; float speed_kmh = 0.0;
uint8_t field_index = 0; uint8_t field_index = 0;
@ -100,7 +101,9 @@ void nmea_sentence_process(const char *nmea_sentence)
if (nmea_sentence[i] == ',') if (nmea_sentence[i] == ',')
{ {
if (field_number == 7) // Speed in knots (field 7) if (field_number == 7) // Speed in knots (field 7)
{ speed_kmh = atof(nmea_sentence + i - field_index); {
speed_knots = atof(nmea_sentence + i - field_index);
speed_kmh = speed_knots * 1.852;
control_leds_based_on_speed(speed_kmh); control_leds_based_on_speed(speed_kmh);
} }
field_number++; field_number++;
@ -124,7 +127,9 @@ void nmea_sentence_process(const char *nmea_sentence)
{ {
if (field_number == 6) if (field_number == 6)
{ {
speed_kmh = atof(nmea_sentence + i - field_index); speed_knots = atof(nmea_sentence + i - field_index);
speed_kmh = speed_knots * 1.852;
control_leds_based_on_speed(speed_kmh); control_leds_based_on_speed(speed_kmh);
} }
field_number++; field_number++;