void displayMenuBar(const MenuItem *menu, int index) { drawFilledRect(0, 0, LCD_W, 32, SOLID, ERASE); drawFilledRect(0, 24, LCD_W, 7, SOLID, GREY_DEFAULT); lcd_bmp(1, 0, MAINMENU_LBM); lcd_putsAtt(0, 24, menu[index].name, INVERS); lcd_rect(index*24, 0, 26, 24, SOLID, FORCE); lcd_hlineStip(0, 31, LCD_W, SOLID, FORCE); }
void drawOffsetBar(uint8_t x, uint8_t y, MixData * md) { int offset = GET_GVAR(MD_OFFSET(md), GV_RANGELARGE_NEG, GV_RANGELARGE, mixerCurrentFlightMode); int weight = GET_GVAR(MD_WEIGHT(md), GV_RANGELARGE_NEG, GV_RANGELARGE, mixerCurrentFlightMode); int barMin = offset - weight; int barMax = offset + weight; if (y > 15) { lcd_outdezAtt(x-((barMin >= 0) ? 2 : 3), y-6, barMin, TINSIZE|LEFT); lcd_outdezAtt(x+GAUGE_WIDTH+1, y-6, barMax, TINSIZE); } if (weight < 0) { barMin = -barMin; barMax = -barMax; } if (barMin < -101) barMin = -101; if (barMax > 101) barMax = 101; lcd_hlineStip(x-2, y, GAUGE_WIDTH+2, DOTTED); lcd_hlineStip(x-2, y+GAUGE_HEIGHT, GAUGE_WIDTH+2, DOTTED); lcd_vline(x-2, y+1, GAUGE_HEIGHT-1); lcd_vline(x+GAUGE_WIDTH-1, y+1, GAUGE_HEIGHT-1); if (barMin <= barMax) { int8_t right = (barMax * GAUGE_WIDTH) / 200; int8_t left = ((barMin * GAUGE_WIDTH) / 200)-1; drawFilledRect(x+GAUGE_WIDTH/2+left, y+2, right-left, GAUGE_HEIGHT-3); } lcd_vline(x+GAUGE_WIDTH/2-1, y, GAUGE_HEIGHT+1); if (barMin == -101) { for (uint8_t i=0; i<3; ++i) { lcd_plot(x+i, y+4-i); lcd_plot(x+3+i, y+4-i); } } if (barMax == 101) { for (uint8_t i=0; i<3; ++i) { lcd_plot(x+GAUGE_WIDTH-8+i, y+4-i); lcd_plot(x+GAUGE_WIDTH-5+i, y+4-i); } } }
void DrawFunction(FnFuncP fn, uint8_t offset) { lcd_vlineStip(X0-offset, 0/*TODO Y0-WCHART*/, WCHART*2, 0xee); lcd_hlineStip(X0-WCHART-offset, Y0, WCHART*2, 0xee); coord_t prev_yv = (coord_t)-1; for (int xv=-WCHART; xv<=WCHART; xv++) { coord_t yv = (LCD_H-1) - (((uint16_t)RESX + fn(xv * (RESX/WCHART))) / 2 * (LCD_H-1) / RESX); if (prev_yv != (coord_t)-1) { if (abs((int8_t)yv-prev_yv) <= 1) { lcd_plot(X0+xv-offset-1, prev_yv, FORCE); } else { uint8_t tmp = (prev_yv < yv ? 0 : 1); lcd_vline(X0+xv-offset-1, yv+tmp, prev_yv-yv); } } prev_yv = yv; } }
void menuMainView(uint8_t event) { STICK_SCROLL_DISABLE(); uint8_t view = g_eeGeneral.view; uint8_t view_base = view & 0x0f; switch(event) { case EVT_ENTRY: killEvents(KEY_EXIT); killEvents(KEY_UP); killEvents(KEY_DOWN); break; /* TODO if timer2 is OFF, it's possible to use this timer2 as in er9x... case EVT_KEY_BREAK(KEY_MENU): if (view_base == VIEW_TIMER2) { Timer2_running = !Timer2_running; AUDIO_KEYPAD_UP(); } break; */ case EVT_KEY_BREAK(KEY_RIGHT): case EVT_KEY_BREAK(KEY_LEFT): if (view_base <= VIEW_INPUTS) { #if defined(PCBSKY9X) if (view_base == VIEW_INPUTS) g_eeGeneral.view ^= ALTERNATE_VIEW; else g_eeGeneral.view = (g_eeGeneral.view + (4*ALTERNATE_VIEW) + ((event==EVT_KEY_BREAK(KEY_LEFT)) ? -ALTERNATE_VIEW : ALTERNATE_VIEW)) % (4*ALTERNATE_VIEW); #else g_eeGeneral.view ^= ALTERNATE_VIEW; #endif eeDirty(EE_GENERAL); AUDIO_KEYPAD_UP(); } break; #if defined(NAVIGATION_MENUS) case EVT_KEY_CONTEXT_MENU: killEvents(event); #if defined(CPUARM) if (modelHasNotes()) { MENU_ADD_ITEM(STR_VIEW_NOTES); } #endif #if defined(CPUARM) MENU_ADD_ITEM(STR_RESET_SUBMENU); #else MENU_ADD_ITEM(STR_RESET_TIMER1); MENU_ADD_ITEM(STR_RESET_TIMER2); #if defined(FRSKY) MENU_ADD_ITEM(STR_RESET_TELEMETRY); #endif MENU_ADD_ITEM(STR_RESET_FLIGHT); #endif MENU_ADD_ITEM(STR_STATISTICS); #if defined(CPUARM) MENU_ADD_ITEM(STR_ABOUT_US); #endif menuHandler = onMainViewMenu; break; #endif #if MENUS_LOCK != 2 /*no menus*/ case EVT_KEY_LONG(KEY_MENU):// go to last menu pushMenu(lastPopMenu()); killEvents(event); break; CASE_EVT_ROTARY_BREAK case EVT_KEY_MODEL_MENU: pushMenu(menuModelSelect); killEvents(event); break; CASE_EVT_ROTARY_LONG case EVT_KEY_GENERAL_MENU: pushMenu(menuGeneralSetup); killEvents(event); break; #endif case EVT_KEY_BREAK(KEY_UP): case EVT_KEY_BREAK(KEY_DOWN): g_eeGeneral.view = (event == EVT_KEY_BREAK(KEY_UP) ? (view_base == VIEW_COUNT-1 ? 0 : view_base+1) : (view_base == 0 ? VIEW_COUNT-1 : view_base-1)); eeDirty(EE_GENERAL); AUDIO_KEYPAD_UP(); break; case EVT_KEY_STATISTICS: chainMenu(menuStatisticsView); killEvents(event); break; case EVT_KEY_TELEMETRY: #if defined(FRSKY) if (!IS_FAI_ENABLED()) chainMenu(menuTelemetryFrsky); #elif defined(JETI) JETI_EnableRXD(); // enable JETI-Telemetry reception chainMenu(menuTelemetryJeti); #elif defined(ARDUPILOT) ARDUPILOT_EnableRXD(); // enable ArduPilot-Telemetry reception chainMenu(menuTelemetryArduPilot); #elif defined(NMEA) NMEA_EnableRXD(); // enable NMEA-Telemetry reception chainMenu(menuTelemetryNMEA); #elif defined(MAVLINK) chainMenu(menuTelemetryMavlink); #else chainMenu(menuStatisticsDebug); #endif killEvents(event); break; case EVT_KEY_FIRST(KEY_EXIT): #if defined(GVARS) && !defined(PCBSTD) if (s_gvar_timer > 0) { s_gvar_timer = 0; } #endif if (view == VIEW_TIMER2) { timerReset(1); } AUDIO_KEYPAD_UP(); break; #if !defined(NAVIGATION_MENUS) case EVT_KEY_LONG(KEY_EXIT): flightReset(); AUDIO_KEYPAD_UP(); break; #endif } { // Flight Mode Name uint8_t mode = mixerCurrentFlightMode; lcd_putsnAtt(PHASE_X, PHASE_Y, g_model.flightModeData[mode].name, sizeof(g_model.flightModeData[mode].name), ZCHAR|PHASE_FLAGS); // Model Name putsModelName(MODELNAME_X, MODELNAME_Y, g_model.header.name, g_eeGeneral.currModel, BIGSIZE); // Main Voltage (or alarm if any) displayVoltageOrAlarm(); // Timers displayTimers(); // Trims sliders displayTrims(mode); } if (view_base < VIEW_INPUTS) { // scroll bar lcd_hlineStip(38, 34, 54, DOTTED); #if defined(PCBSKY9X) lcd_hline(38 + (g_eeGeneral.view / ALTERNATE_VIEW) * 13, 34, 13, SOLID); #else lcd_hline((g_eeGeneral.view & ALTERNATE_VIEW) ? 64 : 38, 34, 26, SOLID); #endif for (uint8_t i=0; i<8; i++) { uint8_t x0,y0; #if defined(PCBSKY9X) uint8_t chan = 8*(g_eeGeneral.view / ALTERNATE_VIEW) + i; #else uint8_t chan = (g_eeGeneral.view & ALTERNATE_VIEW) ? 8+i : i; #endif int16_t val = channelOutputs[chan]; switch(view_base) { case VIEW_OUTPUTS_VALUES: x0 = (i%4*9+3)*FW/2; y0 = i/4*FH+40; #if defined(PPM_UNIT_US) lcd_outdezAtt(x0+4*FW , y0, PPM_CH_CENTER(chan)+val/2, 0); #elif defined(PPM_UNIT_PERCENT_PREC1) lcd_outdezAtt(x0+4*FW , y0, calcRESXto1000(val), PREC1); #else lcd_outdezAtt(x0+4*FW , y0, calcRESXto1000(val)/10, 0); // G: Don't like the decimal part* #endif break; case VIEW_OUTPUTS_BARS: #define WBAR2 (50/2) x0 = i<4 ? LCD_W/4+2 : LCD_W*3/4-2; y0 = 38+(i%4)*5; uint16_t lim = g_model.extendedLimits ? 640*2 : 512*2; int8_t len = (abs(val) * WBAR2 + lim/2) / lim; if(len>WBAR2) len = WBAR2; // prevent bars from going over the end - comment for debugging lcd_hlineStip(x0-WBAR2, y0, WBAR2*2+1, DOTTED); lcd_vline(x0,y0-2,5); if (val>0) x0+=1; else x0-=len; lcd_hline(x0,y0+1,len); lcd_hline(x0,y0-1,len); break; } } } else if (view_base == VIEW_INPUTS) { if (view == VIEW_INPUTS) { // Sticks + Pots doMainScreenGraphics(); // Switches for (uint8_t i=SWSRC_THR; i<=SWSRC_TRN; i++) { int8_t sw = (i == SWSRC_TRN ? (switchState(SW_ID0) ? SWSRC_ID0 : (switchState(SW_ID1) ? SWSRC_ID1 : SWSRC_ID2)) : i); uint8_t x = 2*FW-2, y = i*FH+1; if (i>=SWSRC_AIL) { x = 17*FW-1; y -= 3*FH; } putsSwitches(x, y, sw, getSwitch(i) ? INVERS : 0); } } else { #if defined(PCBMEGA2560) && defined(ROTARY_ENCODERS) for (uint8_t i=0; i<NUM_ROTARY_ENCODERS; i++) { int16_t val = getRotaryEncoder(i); int8_t len = limit((int16_t)0, (int16_t)(((val+1024) * BAR_HEIGHT) / 2048), (int16_t)BAR_HEIGHT); #if ROTARY_ENCODERS > 2 #define V_BAR_W 5 V_BAR(LCD_W/2-8+V_BAR_W*i, LCD_H-8, len); #else #define V_BAR_W 5 V_BAR(LCD_W/2-3+V_BAR_W*i, LCD_H-8, len); #endif } #endif // PCBGRUVIN9X && ROTARY_ENCODERS // Logical Switches #if defined(PCBSKY9X) for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++) { int8_t len = getSwitch(SWSRC_SW1+i) ? BAR_HEIGHT : 1; uint8_t x = VSWITCH_X(i); lcd_vline(x-1, VSWITCH_Y-len, len); lcd_vline(x, VSWITCH_Y-len, len); } #elif defined(CPUM2560) for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++) putsSwitches(2*FW-3 + (i/3)*(i/3>2 ? 3*FW+2 : (3*FW-1)) + (i/3>2 ? 2*FW : 0), 4*FH+1 + (i%3)*FH, SWSRC_SW1+i, getSwitch(SWSRC_SW1+i) ? INVERS : 0); #elif !defined(PCBSTD) for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++) putsSwitches(2*FW-2 + (i/3)*(4*FW-1), 4*FH+1 + (i%3)*FH, SWSRC_SW1+i, getSwitch(SWSRC_SW1+i) ? INVERS : 0); #else for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++) putsSwitches(2*FW-3 + (i/3)*(4*FW), 4*FH+1 + (i%3)*FH, SWSRC_SW1+i, getSwitch(SWSRC_SW1+i) ? INVERS : 0); #endif } } else { // timer2 #if defined(TRANSLATIONS_CZ) #define TMR2_LBL_COL (20-FW/2+1) #else #define TMR2_LBL_COL (20-FW/2+5) #endif putsTimer(33+FW+2+10*FWNUM-4, FH*5, timersStates[1].val, DBLSIZE, DBLSIZE); putsTimerMode(timersStates[1].val >= 0 ? TMR2_LBL_COL : TMR2_LBL_COL-7, FH*6, g_model.timers[1].mode); // lcd_outdezNAtt(33+11*FW, FH*6, s_timerVal_10ms[1], LEADING0, 2); // 1/100s } // And ! in case of unexpected shutdown if (unexpectedShutdown) { lcd_putcAtt(REBOOT_X, 0*FH, '!', INVERS); } #if defined(GVARS) && !defined(PCBSTD) if (s_gvar_timer > 0) { s_gvar_timer--; s_warning = STR_GLOBAL_VAR; displayBox(); lcd_putsnAtt(16, 5*FH, g_model.gvars[s_gvar_last].name, LEN_GVAR_NAME, ZCHAR); lcd_putsAtt(16+7*FW, 5*FH, PSTR("[\010]"), BOLD); lcd_outdezAtt(16+7*FW+4*FW+FW/2, 5*FH, GVAR_VALUE(s_gvar_last, getGVarFlightPhase(mixerCurrentFlightMode, s_gvar_last)), BOLD); s_warning = NULL; } #endif #if defined(DSM2) if (moduleFlag[0] == MODULE_BIND) { // Issue 98 lcd_putsAtt(15*FW, 0, PSTR("BIND"), 0); } #endif }
void menuModelFailsafe(uint8_t event) { static bool longNames = false; bool newLongNames = false; uint8_t ch = 0; uint8_t channelStart = g_model.moduleData[g_moduleIdx].channelsStart; if (event == EVT_KEY_LONG(KEY_ENTER)) { killEvents(event); event = 0; if (s_editMode) { g_model.moduleData[g_moduleIdx].failsafeChannels[menuVerticalPosition] = channelOutputs[menuVerticalPosition+channelStart]; eeDirty(EE_MODEL); AUDIO_WARNING1(); s_editMode = 0; SEND_FAILSAFE_NOW(g_moduleIdx); } else { int16_t & failsafe = g_model.moduleData[g_moduleIdx].failsafeChannels[menuVerticalPosition]; if (failsafe < FAILSAFE_CHANNEL_HOLD) failsafe = FAILSAFE_CHANNEL_HOLD; else if (failsafe == FAILSAFE_CHANNEL_HOLD) failsafe = FAILSAFE_CHANNEL_NOPULSE; else failsafe = 0; eeDirty(EE_MODEL); AUDIO_WARNING1(); SEND_FAILSAFE_NOW(g_moduleIdx); } } SIMPLE_SUBMENU_NOTITLE(NUM_CHANNELS(g_moduleIdx)); SET_SCROLLBAR_X(0); #define COL_W (LCD_W/2) const uint8_t SLIDER_W = 64; // Column separator lcd_vline(LCD_W/2, FH, LCD_H-FH); lcd_putsCenter(0*FH, FAILSAFESET); lcd_invert_line(0); unsigned int lim = g_model.extendedLimits ? 640*2 : 512*2; for (uint8_t col=0; col<2; col++) { coord_t x = col*COL_W+1; // Channels for (uint8_t line=0; line<8; line++) { coord_t y = 9+line*7; int32_t channelValue = channelOutputs[ch+channelStart]; int32_t failsafeValue = 0; bool failsafeEditable = false; uint8_t ofs = (col ? 0 : 1); if (ch < NUM_CHANNELS(g_moduleIdx)) { failsafeValue = g_model.moduleData[g_moduleIdx].failsafeChannels[8*col+line]; failsafeEditable = true; } if (failsafeEditable) { // Channel name if present, number if not uint8_t lenLabel = ZLEN(g_model.limitData[ch+channelStart].name); if (lenLabel > 4) { newLongNames = longNames = true; } if (lenLabel > 0) lcd_putsnAtt(x+1-ofs, y, g_model.limitData[ch+channelStart].name, sizeof(g_model.limitData[ch+channelStart].name), ZCHAR | SMLSIZE); else putsChn(x+1-ofs, y, ch+1, SMLSIZE); // Value LcdFlags flags = TINSIZE; if (menuVerticalPosition == ch) { flags |= INVERS; if (s_editMode) { if (failsafeValue == FAILSAFE_CHANNEL_HOLD || failsafeValue == FAILSAFE_CHANNEL_NOPULSE) { s_editMode = 0; } else { flags |= BLINK; CHECK_INCDEC_MODELVAR(event, g_model.moduleData[g_moduleIdx].failsafeChannels[8*col+line], -lim, +lim); } } } #if defined(PPM_UNIT_PERCENT_PREC1) uint8_t wbar = (longNames ? SLIDER_W-16 : SLIDER_W-6); #else uint8_t wbar = (longNames ? SLIDER_W-10 : SLIDER_W); #endif if (failsafeValue == FAILSAFE_CHANNEL_HOLD) { lcd_putsAtt(x+COL_W-4-wbar-ofs-16, y, "HOLD", flags); failsafeValue = 0; } else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) { lcd_putsAtt(x+COL_W-4-wbar-ofs-16, y, "NONE", flags); failsafeValue = 0; } else { #if defined(PPM_UNIT_US) lcd_outdezAtt(x+COL_W-4-wbar-ofs, y, PPM_CH_CENTER(ch)+failsafeValue/2, flags); #elif defined(PPM_UNIT_PERCENT_PREC1) lcd_outdezAtt(x+COL_W-4-wbar-ofs, y, calcRESXto1000(failsafeValue), PREC1|flags); #else lcd_outdezAtt(x+COL_W-4-wbar-ofs, y, calcRESXto1000(failsafeValue)/10, flags); #endif } // Gauge lcd_rect(x+COL_W-3-wbar-ofs, y, wbar+1, 6); unsigned int lenChannel = limit((uint8_t)1, uint8_t((abs(channelValue) * wbar/2 + lim/2) / lim), uint8_t(wbar/2)); unsigned int lenFailsafe = limit((uint8_t)1, uint8_t((abs(failsafeValue) * wbar/2 + lim/2) / lim), uint8_t(wbar/2)); coord_t xChannel = (channelValue>0) ? x+COL_W-ofs-3-wbar/2 : x+COL_W-ofs-2-wbar/2-lenChannel; coord_t xFailsafe = (failsafeValue>0) ? x+COL_W-ofs-3-wbar/2 : x+COL_W-ofs-2-wbar/2-lenFailsafe; lcd_hlineStip(xChannel, y+1, lenChannel, DOTTED, 0); lcd_hlineStip(xChannel, y+2, lenChannel, DOTTED, 0); lcd_hline(xFailsafe, y+3, lenFailsafe); lcd_hline(xFailsafe, y+4, lenFailsafe); } ch++; } } longNames = newLongNames; }