void logger_stop() { if (!logger_active()) return; if (fc.logger_state == LOGGER_WAIT_FOR_GPS) { char text[32]; strcpy_P(text, PSTR("No GPS fix during flight!")); logger_comment(text); } fc.logger_state = LOGGER_IDLE; switch (config.logger.format) { case(LOGGER_IGC): igc_stop(); break; case(LOGGER_KML): kml_stop(); break; case(LOGGER_RAW): raw_step(); break; } }
void logger_comment(char * text) { if (!logger_active()) return; switch (config.logger.format) { case(LOGGER_IGC): igc_comment(text); break; case(LOGGER_KML): kml_comment(text); break; case(LOGGER_RAW): DEBUG("%s\n", text); break; } }
void gui_set_logger_action(uint8_t index) { switch(index) { case(0): config.logger.enabled = !config.logger.enabled; eeprom_busy_wait(); eeprom_update_byte(&config_ee.logger.enabled, config.logger.enabled); break; case(1): if (logger_active()) { gui_showmessage_P(PSTR("Cannot change\nin flight!")); return; } config.logger.format = (config.logger.format + 1) % NUMBER_OF_FORMATS; eeprom_busy_wait(); eeprom_update_byte(&config_ee.logger.format, config.logger.format); break; case(2): gui_switch_task(GUI_SET_AUTOSTART); break; case(3): gui_text_conf((char *)config.logger.pilot, LOG_TEXT_LEN, gui_set_logger_pilot_cb); gui_switch_task(GUI_TEXT); break; case(4): gui_text_conf((char *)config.logger.glider_type, LOG_TEXT_LEN, gui_set_logger_glider_type_cb); gui_switch_task(GUI_TEXT); break; case(5): gui_text_conf((char *)config.logger.glider_id, LOG_TEXT_LEN, gui_set_logger_glider_id_cb); gui_switch_task(GUI_TEXT); break; } }
void logger_step() { if (!logger_active()) return; if (logger_next > task_get_ms_tick()) return; if (!fc.baro_valid) return; //RAW is running as fast as it can! if (config.logger.format != LOGGER_RAW) { if (fc.gps_data.new_sample) { logger_next = task_get_ms_tick() + 1000; fc.gps_data.new_sample = false; } } switch (config.logger.format) { case(LOGGER_IGC): igc_step(); break; case(LOGGER_KML): kml_step(); break; case(LOGGER_RAW): raw_step(); break; } }
void fc_step() { //using fake data #ifdef FAKE_ENABLE return; #endif gps_step(); bt_step(); protocol_step(); logger_step(); wind_step(); //logger always enabled if (config.autostart.flags & AUTOSTART_ALWAYS_ENABLED) { if (fc.vario.valid && fc.flight.state == FLIGHT_WAIT) { fc_takeoff(); } } else { //auto start // baro valid, waiting to take off or landed, and enabled auto start if (fc.vario.valid && (fc.flight.state == FLIGHT_WAIT || fc.flight.state == FLIGHT_LAND) && config.autostart.start_sensititvity > 0) { if (abs(fc.altitude1 - fc.flight.autostart_altitude) > config.autostart.start_sensititvity) { fc_takeoff(); } else { uint32_t t = task_get_ms_tick(); if(t < fc.flight.autostart_timer) { assert(0); DEBUG("old %lu\n", fc.flight.autostart_timer); DEBUG("act %lu\n", t); } //reset wait timer if (t - fc.flight.autostart_timer > (uint32_t)config.autostart.timeout * 1000ul) { fc.flight.autostart_timer = t; fc.flight.autostart_altitude = fc.altitude1; } } } //auto land // flying and auto land enabled if (fc.flight.state == FLIGHT_FLIGHT && config.autostart.land_sensititvity > 0) { if (abs(fc.altitude1 - fc.flight.autostart_altitude) < config.autostart.land_sensititvity) { uint32_t tick = task_get_ms_tick(); if (tick < fc.flight.autostart_timer) { assert(0); DEBUG("TT %lu\n", tick); DEBUG("AT %lu\n", fc.flight.autostart_timer); } else if (tick - fc.flight.autostart_timer > (uint32_t)config.autostart.timeout * 1000ul) { //reduce timeout from flight time fc.flight.timer += (uint32_t)config.autostart.timeout * 1000ul; gui_reset_timeout(); fc_landing(); } } else { fc.flight.autostart_altitude = fc.altitude1; fc.flight.autostart_timer = task_get_ms_tick(); } } } //gps time sync if ((config.system.time_flags & TIME_SYNC) && fc.gps_data.fix_cnt == GPS_FIX_TIME_SYNC) { if (config.gui.menu_audio_flags & CFG_AUDIO_MENU_GPS) seq_start(&gps_ready, config.gui.alert_volume); fc_sync_gps_time(); fc.gps_data.fix_cnt++; } //glide ratio //when you have GPS, baro and speed is higher than 2km/h and you are sinking <= -0.01 if (fc.gps_data.valid && fc.vario.valid && fc.gps_data.groud_speed > FC_GLIDE_MIN_KNOTS && fc.vario.avg <= FC_GLIDE_MIN_SINK) { float spd_m = fc.gps_data.groud_speed * FC_KNOTS_TO_MPS; fc.glide_ratio = spd_m / abs(fc.vario.avg); fc.glide_ratio_valid = true; } else { fc.glide_ratio_valid = false; } //flight logger if (config.logger.enabled) { if (fc.flight.state == FLIGHT_FLIGHT && !logger_active() && time_is_set() && !logger_error()) { logger_start(); } } //flight statistic if (fc.flight.state == FLIGHT_FLIGHT) { int16_t t_vario = fc.vario.avg * 100; if (fc.altitude1 > fc.flight.stats.max_alt) fc.flight.stats.max_alt = fc.altitude1; if (fc.altitude1 < fc.flight.stats.min_alt) fc.flight.stats.min_alt = fc.altitude1; if (t_vario > fc.flight.stats.max_climb) fc.flight.stats.max_climb = t_vario; if (t_vario < fc.flight.stats.max_sink) fc.flight.stats.max_sink = t_vario; } }