bool LoadEEPROM() { FILINFO fno; if (f_stat("UPDATE.EE", &fno) == FR_OK) { DEBUG("EE update found.\n"); FIL * ee_file; ee_file = new FIL; f_open(ee_file, "UPDATE.EE", FA_READ); uint16_t rd = 0; byte4 tmp; f_read(ee_file, tmp.uint8, sizeof(tmp), &rd); if (tmp.uint32 != BUILD_NUMBER) { gui_showmessage_P(PSTR("UPDATE.EE is not\ncompatibile!")); DEBUG("Rejecting update file %lu != %lu\n", tmp.uint32, BUILD_NUMBER); delete ee_file; return false; } //rewind the file f_lseek(ee_file, 0); DEBUG("tell = %d\n", f_tell(ee_file)); for (uint16_t i = 0; i < fno.fsize; i += rd) { uint8_t buf[256]; f_read(ee_file, buf, sizeof(buf), &rd); DEBUG("tell = %d\n", f_tell(ee_file)); DEBUG(" %d / %d\n", i + rd, fno.fsize); eeprom_busy_wait(); eeprom_update_block(buf, (uint8_t *)(APP_INFO_EE_offset + i), rd); } gui_showmessage_P(PSTR("UPDATE.EE\napplied.")); delete ee_file; return true; } return false; }
void gui_set_advanced_action(uint8_t index) { switch(index) { case(0): config.connectivity.usb_mode = !config.connectivity.usb_mode; eeprom_busy_wait(); eeprom_update_byte(&config_ee.connectivity.usb_mode, config.connectivity.usb_mode); break; case(1): config.connectivity.uart_function = (config.connectivity.uart_function + 1) % NUMBER_OF_UART_FORWARD; eeprom_busy_wait(); eeprom_update_byte(&config_ee.connectivity.uart_function, config.connectivity.uart_function); uart_stop(); uart_init(); break; case(2): if (!storage_card_in()) { gui_showmessage_P(PSTR("No SD card!")); return; } gui_dialog_set_P(PSTR("Warning"), PSTR("This will erase\nall data from SD\ncard! Continue?"), GUI_STYLE_YESNO, gui_set_advanced_format_cb); gui_switch_task(GUI_DIALOG); break; case(3): gui_switch_task(GUI_SET_CALIB); 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 (fc.logger_state == FLIGHT_LAND) { 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; } }
void logger_start() { if (!config.logger.enabled) return; logger_next_flight(); if (!storage_ready()) { gui_showmessage_P(PSTR("SD card error!")); fc.logger_state = LOGGER_ERROR; return; } uint8_t sec; uint8_t min; uint8_t hour; uint8_t day; uint8_t wday; uint8_t month; uint16_t year; datetime_from_epoch(time_get_utc(), &sec, &min, &hour, &day, &wday, &month, &year); char path[128]; //base dir sprintf_P(path, PSTR("%S"), LOG_DIR); f_mkdir(path); //year sprintf_P(path, PSTR("%S/%04d"), LOG_DIR, year); f_mkdir(path); //month sprintf_P(path, PSTR("%S/%04d/%02d"), LOG_DIR, year, month); f_mkdir(path); //day sprintf_P(path, PSTR("%S/%04d/%02d/%02d"), LOG_DIR, year, month, day); f_mkdir(path); switch (config.logger.format) { case(LOGGER_IGC): fc.logger_state = igc_start(path); break; case(LOGGER_KML): fc.logger_state = kml_start(path); break; case(LOGGER_RAW): fc.logger_state = raw_start(path); break; } }
bool gui_format_sd() { gui_showmessage_P(PSTR("Formating...")); gui_force_loop(); ewdt_reset(); uint8_t ret = f_mkfs("", 0, 0); assert(ret == RES_OK); DEBUG("ret = %u\n", ret); if (ret == RES_OK) { gui_showmessage_P(PSTR("Done!")); return true; } else { char tmp[16]; sprintf_P(tmp, PSTR("Error: %02u"), ret); gui_showmessage(tmp); return false; } }
void fc_sync_gps_time() { if (time_get_local() == (fc.gps_data.utc_time + config.system.time_zone * 1800ul)) return; DEBUG("Syncing time\n"); DEBUG(" local %lu\n", time_get_local()); DEBUG(" gps + tz %lu\n", fc.gps_data.utc_time + config.system.time_zone * 1800ul); time_set_utc(fc.gps_data.utc_time); gui_showmessage_P(PSTR("GPS Time set")); time_set_flags(); }
void gui_set_system_action(uint8_t index) { switch(index) { case(0): gui_switch_task(GUI_SET_TIME); break; case(1): gui_switch_task(GUI_SET_DISPLAY); break; case(2): gui_switch_task(GUI_SET_AUDIO); break; case(3): config.connectivity.usb_mode = !config.connectivity.usb_mode; eeprom_busy_wait(); eeprom_update_byte(&config_ee.connectivity.usb_mode, config.connectivity.usb_mode); break; case(4): gui_value_conf_P(PSTR("Auto power-off"), GUI_VAL_NUMBER_DISABLE, PSTR("%0.0f min"), config.system.auto_power_off, 0, 120, 1, gui_set_system_auto_power_off_cb); gui_switch_task(GUI_SET_VAL); break; case(5): config.connectivity.uart_function = (config.connectivity.uart_function + 1) % NUMBER_OF_UART_FORWARD; eeprom_busy_wait(); eeprom_update_byte(&config_ee.connectivity.uart_function, config.connectivity.uart_function); uart_stop(); uart_init(); break; case(6): if (!storage_card_in()) { gui_showmessage_P(PSTR("No SD card!")); return; } gui_dialog_set_P(PSTR("Warning"), PSTR("This will erase\nall data from SD\ncard! Continue?"), GUI_STYLE_OKCANCEL, gui_set_system_format_cb); gui_switch_task(GUI_DIALOG); break; } }
void gui_set_vario_action(uint8_t index) { switch(index) { case(0): gui_value_conf_P(PSTR("Lift threshold"), GUI_VAL_NUMBER, PSTR("%0.1f m/s"), fc.audio_lift / 100.0, fc.audio_sink / 100.0, 2, 0.1, gui_set_vario_lift_cb); gui_switch_task(GUI_SET_VAL); break; case(1): gui_value_conf_P(PSTR("Sink threshold"), GUI_VAL_NUMBER, PSTR("%0.1f m/s"), fc.audio_sink / 100.0, -10, fc.audio_lift / 100.0, 0.1, gui_set_vario_sink_cb); gui_switch_task(GUI_SET_VAL); break; case(2): gui_showmessage_P(PSTR("Not implemented")); break; case(3): fc.audio_fluid = !fc.audio_fluid; eeprom_busy_wait(); eeprom_update_byte(&config.audio_profile.fluid, fc.audio_fluid); break; case(4): gui_value_conf_P(PSTR("Digital vario int."), GUI_VAL_NUMBER, PSTR("%0.1f sec"), set_vario_digital, 0, 30, 0.1, gui_set_vario_dig_int_cb); gui_switch_task(GUI_SET_VAL); break; case(5): gui_value_conf_P(PSTR("Average vario int."), GUI_VAL_NUMBER, PSTR("%0.1f sec"), set_vario_avg, 0, 90, 0.1, gui_set_vario_avg_int_cb); gui_switch_task(GUI_SET_VAL); break; case(6): fc.vario_flags ^= VARIO_UNITS_I; eeprom_busy_wait(); eeprom_update_byte(&config.vario.flags, fc.vario_flags); 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 (fc.logger_state == 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 fc_takeoff() { if (!fc.vario.valid) return; gui_showmessage_P(PSTR("Take off")); fc.flight.state = FLIGHT_FLIGHT; fc.flight.timer = task_get_ms_tick(); //reset timer and altitude for autoland fc.flight.autostart_altitude = fc.altitude1; fc.flight.autostart_timer = task_get_ms_tick(); //reset battery info timer fc_log_battery_next = 0; //zero altimeters at take off for (uint8_t i = 0; i < NUMBER_OF_ALTIMETERS; i++) { if (config.altitude.altimeter[i].flags & ALT_AUTO_ZERO) fc_zero_alt(i + 1); } }
void bt_irqh(uint8_t type, uint8_t * buf) { uint8_t old_type; switch(type) { case(BT_IRQ_INIT): DEBUG("BT_MOD_STATE_INIT\n"); bt_module_state = BT_MOD_STATE_INIT; break; case(BT_IRQ_INIT_OK): DEBUG("BT_MOD_STATE_OK\n"); bt_module_state = BT_MOD_STATE_OK; bt_autodetect = false; break; case(BT_IRQ_DEINIT): DEBUG("BT_MOD_STATE_OFF\n"); bt_module_state = BT_MOD_STATE_OFF; bt_device_connected = false; break; case(BT_IRQ_CONNECTED): DEBUG("BT_IRQ_CONNECTED\n"); gui_showmessage_P(PSTR("Bluetooth\nconnected")); bt_device_connected = true; break; case(BT_IRQ_DISCONNECTED): DEBUG("BT_IRQ_DISCONNECTED\n"); gui_showmessage_P(PSTR("Bluetooth\ndisconnected")); bt_device_connected = false; bt_output.Clear(); break; case(BT_IRQ_RESET): DEBUG("BT_IRQ_RESET\n"); bt_device_connected = false; break; case(BT_IRQ_INIT_FAIL): DEBUG("BT_IRQ_INIT_FAIL!\n"); if (bt_autodetect) { old_type = bt_module_type; bt_module_deinit(); bt_module_type = BT_UNKNOWN; _delay_ms(500); BT_UART_PWR_ON; if (old_type == BT_PAN1322) { bt_module_type = BT_PAN1026; bt_pan1026_init(); } if (old_type == BT_PAN1026) { bt_module_type = BT_PAN1322; bt_pan1322_init(); } } else { // gui_showmessage_P(PSTR("Bluetooth\nInit failed!")); } break; } }
void fc_sync_gps_time() { time_set_actual(fc.gps_data.utc_time + (fc.time_zone * 3600ul) / 2); gui_showmessage_P(PSTR("GPS Time set")); }
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; } }