/* * Copyright (C) OpenTX * * Based on code named * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include "opentx.h" #define BIGSIZE MIDSIZE #define LBOX_CENTERX (BOX_WIDTH/2 + 16) #define RBOX_CENTERX (LCD_W-LBOX_CENTERX-1) #define MODELNAME_X (15) #define MODELNAME_Y (11) #define VBATT_X (MODELNAME_X+26) #define VBATT_Y (FH+3) #define VBATTUNIT_X (VBATT_X-2) #define VBATTUNIT_Y VBATT_Y #define BITMAP_X ((LCD_W-64)/2) #define BITMAP_Y (LCD_H/2) #define PHASE_X BITMAP_X #define PHASE_Y (3*FH) #define PHASE_FLAGS (0) #define TIMERS_X 145 #define TIMERS_Y 20 #define TIMERS_H 25 #define TIMERS_R 193 #define REBOOT_X (LCD_W-FW) #define VSWITCH_X(i) (((i>=MAX_LOGICAL_SWITCHES*3/4) ? BITMAP_X+28 : ((i>=MAX_LOGICAL_SWITCHES/2) ? BITMAP_X+25 : ((i>=MAX_LOGICAL_SWITCHES/4) ? 21 : 18))) + 3*i) #define VSWITCH_Y (LCD_H-9) #define TRIM_LH_X (32+9) #define TRIM_LV_X 10 #define TRIM_RV_X (LCD_W-11) #define TRIM_RH_X (LCD_W-32-9) #define TRIM_LEN 27 #define MARKER_WIDTH 5 const pm_uchar logo_taranis[] PROGMEM = { #include "logo.lbm" }; const pm_uchar icons[] PROGMEM = { #include "icons.lbm" }; #define ICON_RSSI 0, 9 #define ICON_SPEAKER0 9, 8 #define ICON_SPEAKER1 17, 8 #define ICON_SPEAKER2 25, 8 #define ICON_SPEAKER3 33, 8 #define ICON_SD 41, 11 #define ICON_LOGS 51, 11 #define ICON_TRAINER 61, 11 #define ICON_TRAINEE 71, 11 #define ICON_USB 81, 11 #define ICON_REBOOT 91, 11 #define ICON_ALTITUDE 102, 9 void doMainScreenGraphics() { int16_t calibStickVert = calibratedStick[CONVERT_MODE(1)]; if (g_model.throttleReversed && CONVERT_MODE(1) == THR_STICK) calibStickVert = -calibStickVert; drawStick(LBOX_CENTERX, calibratedStick[CONVERT_MODE(0)], calibStickVert); calibStickVert = calibratedStick[CONVERT_MODE(2)]; if (g_model.throttleReversed && CONVERT_MODE(2) == THR_STICK) calibStickVert = -calibStickVert; drawStick(RBOX_CENTERX, calibratedStick[CONVERT_MODE(3)], calibStickVert); } void displayTrims(uint8_t phase) { for (unsigned int i=0; i TRIM_MAX) { exttrim = true; } if (val < -(TRIM_LEN+1)*4) { val = -(TRIM_LEN+1); } else if (val > (TRIM_LEN+1)*4) { val = TRIM_LEN+1; } else { val /= 4; } if (vert[i]) { ym = 31; lcdDrawSolidVerticalLine(xm, ym-TRIM_LEN, TRIM_LEN*2); if (i!=2 || !g_model.thrTrim) { lcdDrawSolidVerticalLine(xm-1, ym-1, 3); lcdDrawSolidVerticalLine(xm+1, ym-1, 3); } ym -= val; lcdDrawFilledRect(xm-3, ym-3, 7, 7, SOLID, att|ERASE); if (trim >= 0) { lcdDrawSolidHorizontalLine(xm-1, ym-1, 3); } if (trim <= 0) { lcdDrawSolidHorizontalLine(xm-1, ym+1, 3); } if (exttrim) { lcdDrawSolidHorizontalLine(xm-1, ym, 3); } if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && trim != 0) { if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS || (trimsDisplayTimer > 0 && (trimsDisplayMask & (1<0 ? 22 : 54, xm-2, -abs(trim), RIGHT|TINSIZE|VERTICAL); } } } else { ym = 60; lcdDrawSolidHorizontalLine(xm-TRIM_LEN, ym, TRIM_LEN*2); lcdDrawSolidHorizontalLine(xm-1, ym-1, 3); lcdDrawSolidHorizontalLine(xm-1, ym+1, 3); xm += val; lcdDrawFilledRect(xm-3, ym-3, 7, 7, SOLID, att|ERASE); if (trim >= 0) { lcdDrawSolidVerticalLine(xm+1, ym-1, 3); } if (trim <= 0) { lcdDrawSolidVerticalLine(xm-1, ym-1, 3); } if (exttrim) { lcdDrawSolidVerticalLine(xm, ym-1, 3); } if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && trim != 0) { if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS || (trimsDisplayTimer > 0 && (trimsDisplayMask & (1<0 ? -11 : 20), ym-2, -abs(trim), RIGHT|TINSIZE); } } } lcdDrawSquare(xm-3, ym-3, 7, att); } } void drawSliders() { for (uint8_t i=NUM_STICKS; i=SLIDER1 ? LCD_H/2+1 : 1); #endif lcdDrawSolidVerticalLine(x, y, LCD_H/2-2); lcdDrawSolidVerticalLine(x+1, y, LCD_H/2-2); y += LCD_H/2-4; y -= ((calibratedStick[i]+RESX)*(LCD_H/2-4)/(RESX*2)); // calculate once per loop lcdDrawSolidVerticalLine(x-1, y, 2); lcdDrawSolidVerticalLine(x+2, y, 2); } } #define BAR_X 14 #define BAR_Y 1 #define BAR_W 184 #define BAR_H 9 #define BAR_NOTIFS_X BAR_X+133 #define BAR_VOLUME_X BAR_X+147 #define BAR_TIME_X BAR_X+159 void displayTopBarGauge(coord_t x, int count, bool blinking=false) { if (!blinking || BLINK_ON_PHASE) lcdDrawFilledRect(x+1, BAR_Y+2, 11, 5, SOLID, ERASE); for (int i=0; i 0) { displayTopBarGauge(batt_icon_x+5*FW, TELEMETRY_RSSI() / 10, TELEMETRY_RSSI() < getRssiAlarmValue(0)); } } void displayTimers() { // Main and Second timer for (unsigned int i=0; i<2; i++) { if (g_model.timers[i].mode) { TimerState & timerState = timersStates[i]; TimerData & timerData = g_model.timers[i]; uint8_t y = TIMERS_Y + i*TIMERS_H; if (ZLEN(timerData.name) > 0) { lcdDrawSizedText(TIMERS_X, y-7, timerData.name, LEN_TIMER_NAME, ZCHAR|SMLSIZE); } else { drawTimerMode(TIMERS_X, y-7, timerData.mode, SMLSIZE); } drawTimer(TIMERS_X, y, timerState.val, TIMEHOUR|MIDSIZE|LEFT, TIMEHOUR|MIDSIZE|LEFT); if (timerData.persistent) { lcdDrawChar(TIMERS_R, y+1, 'P', SMLSIZE); } if (timerState.val < 0) { if (BLINK_ON_PHASE) { lcdDrawFilledRect(TIMERS_X-7, y-8, 60, 20); } } } } } void menuMainViewChannelsMonitor(uint8_t event) { switch(event) { case EVT_KEY_BREAK(KEY_PAGE): case EVT_KEY_BREAK(KEY_EXIT): chainMenu(menuMainView); event = 0; break; } return menuChannelsView(event); } void onMainViewMenu(const char *result) { if (result == STR_RESET_TIMER1) { timerReset(0); } else if (result == STR_RESET_TIMER2) { timerReset(1); } #if TIMERS > 2 else if (result == STR_RESET_TIMER3) { timerReset(2); } #endif else if (result == STR_VIEW_NOTES) { pushModelNotes(); } else if (result == STR_RESET_SUBMENU) { POPUP_MENU_ADD_ITEM(STR_RESET_FLIGHT); POPUP_MENU_ADD_ITEM(STR_RESET_TIMER1); POPUP_MENU_ADD_ITEM(STR_RESET_TIMER2); POPUP_MENU_ADD_ITEM(STR_RESET_TIMER3); POPUP_MENU_ADD_ITEM(STR_RESET_TELEMETRY); } else if (result == STR_RESET_TELEMETRY) { telemetryReset(); } else if (result == STR_RESET_FLIGHT) { flightReset(); } else if (result == STR_STATISTICS) { chainMenu(menuStatisticsView); } else if (result == STR_ABOUT_US) { chainMenu(menuAboutView); } } void displaySwitch(coord_t x, coord_t y, int width, unsigned int index) { if (SWITCH_EXISTS(index)) { int val = getValue(MIXSRC_FIRST_SWITCH+index); if (val >= 0) { lcdDrawSolidHorizontalLine(x, y, width); lcdDrawSolidHorizontalLine(x, y+2, width); y += 4; if (val > 0) { lcdDrawSolidHorizontalLine(x, y, width); lcdDrawSolidHorizontalLine(x, y+2, width); y += 4; } } lcdDrawChar(width==5 ? x+1 : x, y, 'A'+index, TINSIZE); y += 6; if (val <= 0) { lcdDrawSolidHorizontalLine(x, y, width); lcdDrawSolidHorizontalLine(x, y+2, width); if (val < 0) { lcdDrawSolidHorizontalLine(x, y+4, width); lcdDrawSolidHorizontalLine(x, y+6, width); } } } } const MenuItem MAIN_MENU[] = { { "RADIO SETTINGS", menuRadioSetup }, { "MODEL SELECT", menuModelSelect }, { "MODEL SETTINGS", menuModelSetup }, { "CHECKLIST", menuModelNotes }, { "SD MANAGER", menuRadioSdManager }, { "VERSION", menuRadioVersion } }; bool isMenuAvailable(int index) { if (index == 4) { return modelHasNotes(); } else { return true; } } int getSwitchCount() { int count = 0; for (int i=0; i= VIEW_COUNT) { g_model.view = 0; chainMenu(menuMainViewChannelsMonitor); } break; case EVT_KEY_LONG(KEY_PAGE): if (!IS_FAI_ENABLED()) chainMenu(menuViewTelemetryFrsky); killEvents(event); break; case EVT_KEY_FIRST(KEY_EXIT): #if defined(GVARS) if (gvarDisplayTimer > 0) { gvarDisplayTimer = 0; } #endif break; } // Flight Mode Name int mode = mixerCurrentFlightMode; lcdDrawSizedText(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); // Trims sliders displayTrims(mode); // Top bar displayTopBar(); // Sliders (Pots / Sliders) drawSliders(); lcdDrawBitmap(BITMAP_X, BITMAP_Y, modelBitmap); // Switches if (getSwitchCount() > 8) { for (int i=0; i= 14) qr2.rem += 1; const coord_t x[4] = { 50, 142 }; const coord_t y[4] = { 25, 42, 25, 42 }; displaySwitch(x[qr.quot]+qr2.rem*4, y[qr2.quot], 3, i); } else { displaySwitch(17+qr.rem*6, 25+qr.quot*17, 5, i); } } } else { int index = 0; for (int i=0; i= 5 ? 3 : 0); LogicalSwitchData * cs = lswAddress(sw); if (cs->func == LS_FUNC_NONE) { lcdDrawSolidHorizontalLine(x, y+6, 4); lcdDrawSolidHorizontalLine(x, y+7, 4); } else if (getSwitch(SWSRC_SW1+sw)) { lcdDrawFilledRect(x, y, 4, 8); } else { lcdDrawRect(x, y, 4, 8); } } } #if defined(GVARS) if (gvarDisplayTimer > 0) { gvarDisplayTimer--; lcdDrawFilledRect(BITMAP_X, BITMAP_Y, 64, 32, SOLID, ERASE); lcdDrawRect(BITMAP_X, BITMAP_Y, 64, 32); drawStringWithIndex(BITMAP_X+FW, BITMAP_Y+FH-1, STR_GV, gvarLastChanged+1); lcdDrawSizedText(BITMAP_X+4*FW+FW/2, BITMAP_Y+FH-1, g_model.gvars[gvarLastChanged].name, LEN_GVAR_NAME, ZCHAR); lcdDrawText(BITMAP_X+FW, BITMAP_Y+2*FH+3, PSTR("["), BOLD); drawGVarValue(BITMAP_X+2*FW, BITMAP_Y+2*FH+3, gvarLastChanged, GVAR_VALUE(gvarLastChanged, getGVarFlightMode(mixerCurrentFlightMode, gvarLastChanged)), LEFT|BOLD); lcdDrawText(lcdLastPos, BITMAP_Y+2*FH+3, PSTR("]"), BOLD); } #endif }