void PAGE_ShowSafetyDialog() { if (disable_safety) { return; // don't show safety dialog when calibrating } if (dialog) { u64 unsafe = PROTOCOL_CheckSafe(); if (! unsafe) { GUI_RemoveObj(dialog); dialog = NULL; PROTOCOL_Init(0); } else { safety_string_cb(NULL, NULL); u32 crc = Crc(tempstring, strlen(tempstring)); if (crc != dialogcrc) { GUI_Redraw(dialog); dialogcrc = crc; } } } else { tempstring[0] = 0; dialogcrc = 0; dialog = GUI_CreateDialog(&gui->dialog, 10 + DLG_XOFFSET, 42 + DLG_YOFFSET, 300, 188, _tr("Safety"), safety_string_cb, safety_ok_cb, dtOk, NULL); } }
static const char *safety_string_cb(guiObject_t *obj, void *data) { (void)data; int i; u32 crc = Crc(tempstring, strlen(tempstring)); if (obj && crc == dialogcrc) return tempstring; int count = 0; const s8 safeval[4] = {0, -100, 0, 100}; volatile s16 *raw = MIXER_GetInputs(); u64 unsafe = PROTOCOL_CheckSafe(); tempstring[0] = 0; for(i = 0; i < NUM_SOURCES + 1; i++) { if (! (unsafe & (1LL << i))) continue; int ch = (i == 0) ? PROTOCOL_MapChannel(INP_THROTTLE, NUM_INPUTS + 2) : i-1; s16 val = RANGE_TO_PCT((ch < NUM_INPUTS) ? raw[ch+1] : MIXER_GetChannel(ch - (NUM_INPUTS), APPLY_SAFETY)); INPUT_SourceName(tempstring + strlen(tempstring), ch + 1); int len = strlen(tempstring); snprintf(tempstring + len, sizeof(tempstring) - len, _tr(" is %d%%, safe value = %d%%\n"), val, safeval[Model.safety[i]]); if (++count >= 5) break; } return tempstring; }
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); }