u64 PROTOCOL_CheckSafe() { int i; volatile s32 *raw = MIXER_GetInputs(); u64 unsafe = 0; for(i = 0; i < NUM_SOURCES + 1; i++) { if (! Model.safety[i]) continue; int ch; if (i == 0) { //Auto mode (choose 'THR' channel (or CH3) ch = PROTOCOL_MapChannel(INP_THROTTLE, NUM_INPUTS + 2); } else { ch = i-1; } s32 val = RANGE_TO_PCT((ch < NUM_INPUTS) ? raw[ch+1] : MIXER_GetChannel(ch - (NUM_INPUTS), APPLY_SAFETY)); if (Model.safety[i] == SAFE_MIN && val > -99) unsafe |= 1ULL << i; else if (Model.safety[i] == SAFE_ZERO && (val < -1 || val > 1)) unsafe |= 1ULL << i; else if (Model.safety[i] == SAFE_MAX && val < 99) unsafe |= 1ULL << i; } return unsafe; }
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 PAGE_ChantestEvent() { int i; if(cp->type == MONITOR_BUTTONTEST) { _handle_button_test(); return; } volatile s16 *raw = MIXER_GetInputs(); for(i = 0; i < cp->num_bars; i++) { int j = _get_input_idx(i); int v = RANGE_TO_PCT(cp->type ? raw[j+1] : Channels[j]); if (v != cp->pctvalue[i]) { guiObject_t *obj = _get_obj(i, ITEM_GRAPH); if (obj) { GUI_Redraw(obj); GUI_Redraw(_get_obj(i, ITEM_VALUE)); } cp->pctvalue[i] = v; } } }
void PAGE_ChantestEvent() { if(cp->type == MONITOR_BUTTONTEST) { _handle_button_test(); return; } volatile s32 *raw = MIXER_GetInputs(); for(int i = 0; i < cp->num_bars; i++) { int ch = get_channel_idx(cur_row * NUM_BARS_PER_ROW + i); int v = RANGE_TO_PCT((ch >= NUM_INPUTS && ch < NUM_INPUTS + NUM_OUT_CHANNELS) ? Channels[ch - NUM_INPUTS] : raw[ch + 1]); if (v != cp->pctvalue[i]) { guiObject_t *obj = _get_obj(i, ITEM_VALUE); if (obj) { GUI_Redraw(obj); GUI_Redraw(_get_obj(i, ITEM_GRAPH)); } cp->pctvalue[i] = v; } } }
void PAGE_MainEvent() { int i; if (PAGE_GetModal()) { #if HAS_TELEMETRY if(pagemem.modal_page == 2) { PAGE_TelemtestEvent(); } #endif return; } volatile s32 *raw = MIXER_GetInputs(); for(i = 0; i < NUM_ELEMS; i++) { if (! ELEM_USED(pc->elem[i])) break; if (! OBJ_IS_USED(&gui->elem[i])) continue; int src = pc->elem[i].src; int type = ELEM_TYPE(pc->elem[i]); switch(type) { case ELEM_VTRIM: case ELEM_HTRIM: { int value = *(MIXER_GetTrim(src-1)); if (mp->elem[i] != value) { mp->elem[i] = value; GUI_Redraw(&gui->elem[i].bar); } break; } case ELEM_SMALLBOX: case ELEM_BIGBOX: { s32 val = get_boxval(src); #if HAS_RTC if (src <= NUM_RTC) { if (mp->elem[i] != val) { mp->elem[i] = val; GUI_Redraw(&gui->elem[i].box); } } else #endif if (src - NUM_RTC <= NUM_TIMERS) { //Timer if ((val >= 0 && mp->elem[i] < 0) || (val < 0 && mp->elem[i] >= 0)) { GUI_SetLabelDesc(&gui->elem[i].box, get_box_font(type == ELEM_BIGBOX ? 0 : 2, val < 0)); mp->elem[i] = val; GUI_Redraw(&gui->elem[i].box); } else if (mp->elem[i] / 1000 != val /1000) { mp->elem[i] = val; GUI_Redraw(&gui->elem[i].box); } } else if (src - NUM_RTC - NUM_TIMERS <= NUM_TELEM) { //Telem int alarm = TELEMETRY_HasAlarm(src - NUM_RTC - NUM_TIMERS); if (alarm || ! TELEMETRY_IsUpdated(0xff)) { GUI_SetLabelDesc(&gui->elem[i].box, get_box_font(type == ELEM_BIGBOX ? 0 : 2, 1)); } else if(mp->elem[i] != val) { GUI_SetLabelDesc(&gui->elem[i].box, get_box_font(type == ELEM_BIGBOX ? 0 : 2, 0)); mp->elem[i] = val; GUI_Redraw(&gui->elem[i].box); } } else if (mp->elem[i] != val) { //Source mp->elem[i] = val; GUI_Redraw(&gui->elem[i].box); } break; } case ELEM_BAR: { s32 chan = MIXER_GetChannel(src-1, APPLY_SAFETY); if (mp->elem[i] != chan) { mp->elem[i] = chan; GUI_Redraw(&gui->elem[i].bar); } break; } case ELEM_TOGGLE: { src = MIXER_SRC(src); int idx = -1; if(src) { if (src > INP_HAS_CALIBRATION && src < INP_LAST) { //switch for (int j = 0; j < 3; j++) { // Assume switch 0/1/2 are in order if(ELEM_ICO(pc->elem[i], j) && raw[src+j] > 0) { idx = ELEM_ICO(pc->elem[i], j); break; } } } else { //Non switch int sw = raw[src] > 0 ? 1 : 0; if (ELEM_ICO(pc->elem[i], sw)) { idx = ELEM_ICO(pc->elem[i], sw); } } } if (idx != -1) { #ifdef HAS_CHAR_ICONS gui->elem[i].box.cb_data = (void *)(long)idx; #else struct ImageMap img; img = TGLICO_GetImage(idx); GUI_ChangeImage(&gui->elem[i].img, img.file, img.x_off, img.y_off); #endif GUI_SetHidden((guiObject_t *)&gui->elem[i], 0); } else { GUI_SetHidden((guiObject_t *)&gui->elem[i], 1); } } break; case ELEM_BATTERY: _check_voltage(&gui->elem[i].box); break; } } if(HAS_TOUCH) //FIXME: Hack to let 320x240 GUI continue to work _check_voltage(NULL); #if HAS_RTC if(Display.flags & SHOW_TIME) { u32 time = RTC_GetValue() / 60; if(mp->time != time) { mp->time = time; GUI_Redraw(&gui->time); } } #endif }
void TIMER_Update() { unsigned i; unsigned chan_val = 0; u32 t = CLOCK_getms(); if (PROTOCOL_WaitingForSafe()) return; if( Transmitter.power_alarm > 0 ) TIMER_Power(); for (i = 0; i < NUM_TIMERS; i++) { if (Model.timer[i].src) { s16 val; if (MIXER_SRC(Model.timer[i].src) <= NUM_INPUTS) { volatile s16 *raw = MIXER_GetInputs(); val = raw[MIXER_SRC(Model.timer[i].src)]; } else { val = MIXER_GetChannel(Model.timer[i].src - NUM_INPUTS - 1, APPLY_SAFETY); } if (MIXER_SRC_IS_INV(Model.timer[i].src)) val = -val; if (Model.timer[i].type == TIMER_STOPWATCH_PROP || Model.timer[i].type == TIMER_COUNTDOWN_PROP) { chan_val = RANGE_TO_PCT(abs(val)); if (chan_val > 100) chan_val = 100; } else { unsigned new_state = (val - CHAN_MIN_VALUE > (CHAN_MAX_VALUE - CHAN_MIN_VALUE) / 20) ? 1 : 0; if (new_state != timer_state[i]) { if (new_state) last_time[i] = t; timer_state[i] = new_state; } } } if (timer_state[i]) { s32 delta = t - last_time[i]; if (Model.timer[i].type == TIMER_STOPWATCH_PROP || Model.timer[i].type == TIMER_COUNTDOWN_PROP) { delta = delta * chan_val / 100; } if (Model.timer[i].type == TIMER_PERMANENT) { timer_val[i] += delta; if( timer_val[i] >= 359999900) // Reset when 99h59mn59sec timer_val[i] = 0 ; Model.timer[i].val = timer_val[i]; } else if (Model.timer[i].type == TIMER_STOPWATCH || Model.timer[i].type == TIMER_STOPWATCH_PROP) { timer_val[i] += delta; } else { s32 warn_time; // start to beep for each prealert_interval at the last prealert_time(seconds) if (Transmitter.countdown_timer_settings.prealert_time != 0 && Transmitter.countdown_timer_settings.prealert_interval != 0 && timer_val[i] > Transmitter.countdown_timer_settings.prealert_interval && timer_val[i] < (s32)Transmitter.countdown_timer_settings.prealert_time + 1000) { // give extra 1seconds warn_time = ((timer_val[i] / Transmitter.countdown_timer_settings.prealert_interval) * Transmitter.countdown_timer_settings.prealert_interval); if (timer_val[i] > warn_time && (timer_val[i] - delta) <= warn_time) { MUSIC_Play(MUSIC_TIMER_WARNING); } } // Beep once for each timeup_interval past 0 if (timer_val[i] < 0 && Transmitter.countdown_timer_settings.timeup_interval != 0) { warn_time = ((timer_val[i] - Transmitter.countdown_timer_settings.timeup_interval) / Transmitter.countdown_timer_settings.timeup_interval) * Transmitter.countdown_timer_settings.timeup_interval; if (timer_val[i] > warn_time && (timer_val[i] - delta) <= warn_time) { MUSIC_Play(MUSIC_ALARM1 + i); } } if (timer_val[i] >= 0 && timer_val[i] < delta) { MUSIC_Play(MUSIC_ALARM1 + i); } timer_val[i] -= delta; } last_time[i] = t; } if (Model.timer[i].resetsrc) { s16 val; if (MIXER_SRC(Model.timer[i].resetsrc) <= NUM_INPUTS) { volatile s16 *raw = MIXER_GetInputs(); val = raw[MIXER_SRC(Model.timer[i].resetsrc)]; } else { val = MIXER_GetChannel(Model.timer[i].resetsrc - NUM_INPUTS - 1, APPLY_SAFETY); } if (MIXER_SRC_IS_INV(Model.timer[i].resetsrc)) val = -val; if (val - CHAN_MIN_VALUE > (CHAN_MAX_VALUE - CHAN_MIN_VALUE) / 20) { TIMER_Reset(i); } } } }