aboutsummaryrefslogtreecommitdiff
path: root/altimeter.c
diff options
context:
space:
mode:
authorDavid Phillips <david@yeah.nah.nz>2020-12-20 22:22:17 +1300
committerDavid Phillips <david@yeah.nah.nz>2020-12-20 22:22:17 +1300
commit75154ebdfbbfe7a04d21d910254058a757d2eef6 (patch)
treea4b2276da1b23a88fb15c434a2aaa7d6939c79b0 /altimeter.c
parent74dbe89a7574ccfc0238c9ec4f55ac4fd9d40949 (diff)
downloadaltimeter-75154ebdfbbfe7a04d21d910254058a757d2eef6.tar.xz
Use float-enabled printf implementation
I hadn't realised there is a float-enabled printf implementation in AVR libc, so let's use that instead of our own hack.
Diffstat (limited to 'altimeter.c')
-rw-r--r--altimeter.c19
1 files changed, 4 insertions, 15 deletions
diff --git a/altimeter.c b/altimeter.c
index 429976c..acaa95e 100644
--- a/altimeter.c
+++ b/altimeter.c
@@ -24,7 +24,6 @@
ISR(TIMER1_COMPA_vect)
{
PORTD ^= 1 << 5;
- int tcnt1_start = TCNT1;
static volatile float setting = 1040.21; /* FIXME volatile for gdb hacks */
static float last_height = 0;
float pressure = 0;
@@ -46,36 +45,26 @@ ISR(TIMER1_COMPA_vect)
char line[LCD_WIDTH+1];
/* line 1 */
- int alt_m_int;
- float alt_m_float;
- split_float(height_m, &alt_m_int, &alt_m_float);
- snprintf(line, sizeof(line), "%d.%d m %c%d m/s", alt_m_int, (int)(round(alt_m_float*10)), rate_sym, abs(rate_m_s));
+ snprintf(line, sizeof(line), "%.1f m %c%d m/s", height_m, rate_sym, abs(rate_m_s));
blank_to_eol(line, sizeof(line));
display_set_cursor(0, 0);
display_write(line);
/* line 2 */
- int pressure_hpa_int;
- float pressure_hpa_float;
- split_float(pressure, &pressure_hpa_int, &pressure_hpa_float);
- snprintf(line, sizeof(line), "%d.%d hPa", pressure_hpa_int, (int)(round(pressure_hpa_float*100)));
+ snprintf(line, sizeof(line), "%.2f hPa", pressure);
blank_to_eol(line, sizeof(line));
display_set_cursor(0, 1);
display_write(line);
/* line 3 */
- int setting_hpa_int;
- float setting_hpa_float;
- split_float(setting, &setting_hpa_int, &setting_hpa_float);
- snprintf(line, sizeof(line), "SET %d.%d hPa", setting_hpa_int, (int)(round(setting_hpa_float*100)));
+ snprintf(line, sizeof(line), "SET %.2f hPa", setting);
blank_to_eol(line, sizeof(line));
display_set_cursor(0, 2);
display_write(line);
- int tcnt1_end = TCNT1;
/* line 4 */
- snprintf(line, sizeof(line), "TCNT1 delta %u", tcnt1_end - tcnt1_start);
+ snprintf(line, sizeof(line), "%.1f ""\xdf""C", 12.3f);
blank_to_eol(line, sizeof(line));
display_set_cursor(0, 3);
display_write(line);