void PROTOCOL_Init(u8 force) { if(! force && (proto_state & PROTO_MODULEDLG)) return; PROTOCOL_DeInit(); PROTOCOL_Load(0); proto_state = PROTO_INIT; if (! force && PROTOCOL_CheckSafe()) { return; } proto_state |= PROTO_READY; if(Model.protocol == PROTOCOL_NONE || ! PROTOCOL_LOADED) CLOCK_StopTimer(); else PROTO_Cmds(PROTOCMD_INIT); }
static void calibrate_sticks(void) { // bug fix: should turn of safety dialog during calibrating, or it might fail when stick is not calibrated and safety setting is on PAGE_DisableSafetyDialog(1); PROTOCOL_DeInit(); PAGE_SetModal(1); PAGE_RemoveAllObjects(); PAGE_SetActionCB(_action_cb_calibrate); snprintf(tempstring, sizeof(tempstring), "%s", _tr("Center all \nsticks and knobs\nthen press ENT")); GUI_CreateLabelBox(&guic->msg, 1, 10, LCD_WIDTH -1, LCD_HEIGHT - 10, LCD_HEIGHT > 70? &NARROW_FONT:&DEFAULT_FONT, NULL, NULL, tempstring); memcpy(cp->calibration, Transmitter.calibration, sizeof(cp->calibration)); while(1) { CLOCK_ResetWatchdog(); if(PWR_CheckPowerSwitch()) PWR_Shutdown(); if(priority_ready & (1 << MEDIUM_PRIORITY)) { BUTTON_Handler(); priority_ready &= ~(1 << MEDIUM_PRIORITY); } if(priority_ready & (1 << LOW_PRIORITY)) { //Only sample every 100msec GUI_RefreshScreen(); priority_ready = 0; } for (u8 i = 0; i < INP_HAS_CALIBRATION; i++) { s32 value = CHAN_ReadRawInput(i + 1); if (value > Transmitter.calibration[i].max) Transmitter.calibration[i].max = value; else if (value < Transmitter.calibration[i].min) Transmitter.calibration[i].min = value; } if (calibrate_state == CALI_SUCCESSEXIT || calibrate_state == CALI_EXIT) break; } if (calibrate_state == CALI_EXIT) memcpy(Transmitter.calibration, cp->calibration, sizeof(cp->calibration)); PAGE_SetActionCB(NULL); PROTOCOL_Init(0); PAGE_TxConfigureInit(-1); // should be -1 so that devo10 can get back to previous item selection PAGE_DisableSafetyDialog(0); }
void PAGE_CalibInit(int page) { (void)page; PROTOCOL_DeInit(); PAGE_SetActionCB(_action_cb_calibrate); snprintf(tempstring, sizeof(tempstring), "%s", _tr("Center all \nsticks and knobs\nthen press ENT")); GUI_CreateLabelBox(&guic->msg, 1, CALIB_Y, 0, 0, LCD_HEIGHT > 70? &NARROW_FONT:&DEFAULT_FONT, NULL, NULL, tempstring); memcpy(cp->calibration, Transmitter.calibration, sizeof(cp->calibration)); while(1) { CLOCK_ResetWatchdog(); if(PWR_CheckPowerSwitch()) PWR_Shutdown(); if(priority_ready & (1 << MEDIUM_PRIORITY)) { BUTTON_Handler(); priority_ready &= ~(1 << MEDIUM_PRIORITY); } if(priority_ready & (1 << LOW_PRIORITY)) { //Only sample every 100msec GUI_RefreshScreen(); priority_ready = 0; } for (u8 i = 0; i < INP_HAS_CALIBRATION; i++) { s32 value = CHAN_ReadRawInput(i + 1); if (value > Transmitter.calibration[i].max) Transmitter.calibration[i].max = value; else if (value < Transmitter.calibration[i].min) Transmitter.calibration[i].min = value; } if (calibrate_state == CALI_SUCCESSEXIT || calibrate_state == CALI_EXIT) break; } if (calibrate_state == CALI_EXIT) memcpy(Transmitter.calibration, cp->calibration, sizeof(cp->calibration)); PAGE_Pop(); // PAGE_SetActionCB(NULL); // PROTOCOL_Init(0); // PAGE_SetModal(0); // //cp->enable = CALIB_NONE; // PAGE_ChangeByID(PAGEID_TXCFG, 0); }
static void okcancel_cb(guiObject_t *obj, const void *data) { int msg = (long)data; (void)obj; if (msg == LOAD_MODEL + 1) { /* Load Model */ if (mp->selected != CONFIG_GetCurrentModel()) { // don't do that if model didn't change CONFIG_SaveModelIfNeeded(); PROTOCOL_DeInit(); CONFIG_ReadModel(mp->selected); CONFIG_SaveTxIfNeeded(); //Save here to ensure in case of crash we restart on the right model /* Need to recalculate channels to see if we're in a safe state */ MIXER_Init(); MIXER_CalcChannels(); PROTOCOL_Init(0); } } else if (msg == SAVE_MODEL + 1) { /* Save Model */ CONFIG_WriteModel(mp->selected); CONFIG_ReadModel(mp->selected); //Reload the model after saving to switch (for future saves) } else if (msg == LOAD_TEMPLATE + 1) { /* Load Template */ get_idx_filename(tempstring, "template", ".ini", mp->selected-1, ""); CONFIG_ReadTemplate(tempstring); } else if (msg == LOAD_ICON + 1) { if (mp->selected == 1) Model.icon[0] = 0; else strcpy(Model.icon, mp->iconstr); } else if (msg == LOAD_LAYOUT + 1) { /* Load Layout */ if (mp->selected > mp->file_state) { sprintf(tempstring, "models/model%d.ini", mp->selected - mp->file_state); } else { get_idx_filename(tempstring, "layout", ".ini", mp->selected-1, "layout/"); } CONFIG_ReadLayout(tempstring); } PAGE_SetModal(0); PAGE_RemoveAllObjects(); mp->return_page(-1); // -1 for devo10 means return to the focus of previous page, which is important so that users don't need to scroll down from the 1st item }
static const char *protoselect_cb(guiObject_t *obj, int dir, void *data) { (void)data; (void)obj; u8 changed; enum Protocols new_protocol; new_protocol = GUI_TextSelectHelper(Model.protocol, PROTOCOL_NONE, PROTOCOL_COUNT-1, dir, 1, 1, &changed); if (changed) { const u8 *oldmap = ProtocolChannelMap[Model.protocol]; // DeInit() the old protocol (Model.protocol unchanged) PROTOCOL_DeInit(); // Load() the new protocol Model.protocol = new_protocol; PROTOCOL_Load(1); TELEMETRY_SetTypeByProtocol(Model.protocol); Model.num_channels = PROTOCOL_DefaultNumChannels(); if (! PROTOCOL_HasPowerAmp(Model.protocol)) Model.tx_power = TXPOWER_150mW; else Model.tx_power = mp->last_txpower; memset(Model.proto_opts, 0, sizeof(Model.proto_opts)); guiObject_t *obj = _get_obj(ITEM_NUMCHAN, 0); if (obj) GUI_Redraw(obj); obj = _get_obj(ITEM_TXPOWER, 0); if (obj) GUI_Redraw(obj); if (Model.mixer_mode == MIXER_STANDARD) STDMIXER_SetChannelOrderByProtocol(); else RemapChannelsForProtocol(oldmap); configure_bind_button(); } GUI_TextSelectEnablePress((guiTextSelect_t *)obj, PROTOCOL_GetOptions() ? 1 : 0); if (Model.protocol == 0) return _tr("None"); if(PROTOCOL_HasModule(Model.protocol)) return ProtocolNames[Model.protocol]; sprintf(tempstring, "*%s", ProtocolNames[Model.protocol]); return tempstring; }