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; }