- if (state->flight_pres < min_pres)
- min_pres = state->flight_pres;
- if (state->flight_accel < min_accel)
- min_accel = state->flight_accel;
- altitude = aoview_pres_to_altitude(state->flight_pres) - aoview_pres_to_altitude(pad_pres);
- accel = (pad_accel - state->flight_accel) / 27.0;
- velocity = state->flight_vel / 2700.0;
- max_accel = (pad_accel - min_accel) / 27.0;
- ticks = state->tick - prev_tick;
- temp = ((state->temp / 32767.0 * 3.3) - 0.5) / 0.01;
- battery = (state->batt / 32767.0 * 5.0);
- drogue_sense = (state->drogue / 32767.0 * 15.0);
- main_sense = (state->main / 32767.0 * 15.0);
-
- prev_accel = accel;
- prev_tick = state->tick;
+ state->ascent = FALSE;
+ for (i = 0; ascent_states[i]; i++)
+ if (!strcmp(state->state, ascent_states[i]))
+ state->ascent = TRUE;
+
+ /* Only look at accelerometer data on the way up */
+ if (state->ascent && state->acceleration > state->max_acceleration)
+ state->max_acceleration = state->acceleration;
+ if (state->ascent && state->speed > state->max_speed)
+ state->max_speed = state->speed;
+
+ if (state->height > state->max_height)
+ state->max_height = state->height;
+ aoview_great_circle(state->pad_lat, state->pad_lon, state->lat, state->lon,
+ &state->distance, &state->bearing);
+ if (state->npad) {
+ state->gps_height = state->alt - state->pad_alt;
+ } else {
+ state->gps_height = 0;
+ }
+}
+
+void
+aoview_state_speak(struct aostate *state)
+{
+ static char last_state[32];
+ int i;
+ gboolean report = FALSE;
+ int this_tick;
+ static int last_tick;
+ static int last_altitude;
+ int this_altitude;
+
+ if (strcmp(state->state, last_state)) {
+ aoview_voice_speak("%s\n", state->state);
+ if (!strcmp(state->state, "drogue"))
+ aoview_voice_speak("apogee %d meters\n",
+ (int) state->max_height);
+ report = TRUE;
+ strcpy(last_state, state->state);
+ }
+ this_altitude = aoview_pres_to_altitude(state->flight_pres) - aoview_pres_to_altitude(state->ground_pres);
+ this_tick = state->tick;
+ while (this_tick < last_tick)
+ this_tick += 65536;
+ if (strcmp(state->state, "pad") != 0) {
+ if (this_altitude / 1000 != last_altitude / 1000)
+ report = TRUE;
+ if (this_tick - last_tick >= 10 * 100)
+ report = TRUE;
+ }
+ if (report) {
+ aoview_voice_speak("%d meters\n",
+ this_altitude);
+ if (state->ascent)
+ aoview_voice_speak("%d meters per second\n",
+ state->flight_vel / 2700);
+ last_tick = state->tick;
+ last_altitude = this_altitude;
+ }
+}
+
+void
+aoview_state_notify(struct aostate *state)
+{
+ aoview_state_derive(state);