diff options
author | Keith Packard <keithp@keithp.com> | 2013-04-09 00:28:05 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2013-04-09 00:30:36 -0700 |
commit | 398c02b945a58634c8932f07df2c2be8438da7d1 (patch) | |
tree | 2741e99555d58e9509271da719d039516e16819f /altoslib/AltosState.java | |
parent | 08eb1e3e1abb1aa4f5ea92b781a2ff8f480006c5 (diff) |
altoslib/altosui: Carry receiver status around in AltosListenerState
This moves the crc_errors into the new structure and adds a receiver
battery voltage value there as well. Now the receiver status can be
monitored separately from the flight status. That also means that code
receiving state updates should be prepared to accept missing listener
or flight state values.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosState.java')
-rw-r--r-- | altoslib/AltosState.java | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/altoslib/AltosState.java b/altoslib/AltosState.java index 8a3bbd4c..f1bcb1c1 100644 --- a/altoslib/AltosState.java +++ b/altoslib/AltosState.java @@ -155,30 +155,41 @@ public class AltosState { /* compute barometric speed */ double height_change = height - prev_state.height; + + double prev_baro_speed = prev_state.baro_speed; + if (prev_baro_speed == AltosRecord.MISSING) + prev_baro_speed = 0; + if (time_change > 0) - baro_speed = (prev_state.baro_speed * 3 + (height_change / time_change)) / 4.0; + baro_speed = (prev_baro_speed * 3 + (height_change / time_change)) / 4.0; else baro_speed = prev_state.baro_speed; + double prev_accel_speed = prev_state.accel_speed; + + if (prev_accel_speed == AltosRecord.MISSING) + prev_accel_speed = 0; + if (acceleration == AltosRecord.MISSING) { /* Fill in mising acceleration value */ accel_speed = baro_speed; - if (time_change > 0) - acceleration = (accel_speed - prev_state.accel_speed) / time_change; + + if (time_change > 0 && accel_speed != AltosRecord.MISSING) + acceleration = (accel_speed - prev_accel_speed) / time_change; else acceleration = prev_state.acceleration; } else { /* compute accelerometer speed */ - accel_speed = prev_state.accel_speed + acceleration * time_change; + accel_speed = prev_accel_speed + acceleration * time_change; } } - } else { npad = 0; ngps = 0; gps = null; baro_speed = AltosRecord.MISSING; accel_speed = AltosRecord.MISSING; + pad_alt = AltosRecord.MISSING; max_baro_speed = 0; max_accel_speed = 0; max_height = 0; |