void fc_step() { gps_step(); bt_step(); if ((fc.time_flags & TIME_SYNC) && fc.gps_data.fix_cnt == GPS_FIX_TIME_SYNC) { fc_sync_gps_time(); } }
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; } }
void gui_set_gps_action(uint8_t index) { uint8_t tmp; switch(index) { case(0): config.system.use_gps = !config.system.use_gps; eeprom_busy_wait(); eeprom_update_byte(&config_ee.system.use_gps, config.system.use_gps); if (config.system.use_gps) gps_start(); else gps_stop(); break; case(1): if (!config.system.use_gps) gui_showmessage_P(PSTR("Enable GPS first")); else gui_switch_task(GUI_SET_GPS_DETAIL); break; case(2): if (config.system.use_gps) { if (fc.gps_data.fix_cnt > GPS_FIX_TIME_SYNC) fc_sync_gps_time(); else gui_showmessage_P(PSTR("Wait for GPS")); } else gui_showmessage_P(PSTR("Enable GPS first")); break; case(3): if (config.system.use_gps) { if (fc.gps_data.fix_cnt > GPS_FIX_TIME_SYNC) fc_sync_gps_time(); else gui_showmessage_P(PSTR("Wait for GPS")); } else gui_showmessage_P(PSTR("Enable GPS first")); break; case(4): tmp = (config.system.gps_format_flags & GPS_SPD_MASK) >> 0; tmp = (tmp + 1) % 4; config.system.gps_format_flags = (config.system.gps_format_flags & ~GPS_SPD_MASK) | (tmp << 0); eeprom_busy_wait(); eeprom_update_byte(&config_ee.system.gps_format_flags, config.system.gps_format_flags); break; case(5): tmp = (config.system.gps_format_flags & GPS_FORMAT_MASK) >> 2; tmp = (tmp + 1) % 3; config.system.gps_format_flags = (config.system.gps_format_flags & ~GPS_FORMAT_MASK) | (tmp << 2); eeprom_busy_wait(); eeprom_update_byte(&config_ee.system.gps_format_flags, config.system.gps_format_flags); break; } }