void menuGeneralDiagAna(uint8_t event) { SIMPLE_MENU(STR_MENUANA, menuTabGeneral, e_Ana, 1); STICK_SCROLL_DISABLE(); for (int i=0; i<NUM_STICKS+NUM_POTS; i++) { #if (NUM_STICKS+NUM_POTS) > 9 coord_t y = MENU_HEADER_HEIGHT + 1 + (i/3)*FH; const uint8_t x_coord[] = {0, 70, 154}; uint8_t x = x_coord[i%3]; lcd_outdezNAtt(x, y, i+1, LEADING0|LEFT, 2); lcd_putc(x+2*FW-2, y, ':'); #else coord_t y = MENU_HEADER_HEIGHT + 1 + (i/2)*FH; uint8_t x = i&1 ? 64+5 : 0; putsStrIdx(x, y, PSTR("A"), i+1); lcd_putc(lcdNextPos, y, ':'); #endif lcd_outhex4(x+3*FW-1, y, anaIn(i)); lcd_outdez8(x+10*FW-1, y, (int16_t)calibratedStick[CONVERT_MODE(i)]*25/256); } lcd_putsLeft(MENU_HEADER_HEIGHT+1+5*FH, STR_BATT_CALIB); static int32_t adcBatt; adcBatt = ((adcBatt * 7) + anaIn(TX_VOLTAGE)) / 8; uint32_t batCalV = (adcBatt + (adcBatt*g_eeGeneral.txVoltageCalibration)/128) * BATT_SCALE; batCalV >>= 11; batCalV += 2; // because of the diode putsVolts(LEN_CALIB_FIELDS*FW+4*FW, MENU_HEADER_HEIGHT+1+5*FH, batCalV, s_editMode > 0 ? BLINK|INVERS : INVERS); if (s_editMode > 0) CHECK_INCDEC_GENVAR(event, g_eeGeneral.txVoltageCalibration, -127, 127); }
void menuGeneralVersion(uint8_t event) { if (s_warning_result) { s_warning_result = 0; displayPopup(STR_EEPROMFORMATTING); eeErase(false); #if !defined(SIMU) NVIC_SystemReset(); #else exit(0); #endif } SIMPLE_MENU(STR_MENUVERSION, menuTabGeneral, e_Vers, 1); lcd_putsLeft(MENU_HEADER_HEIGHT+1, vers_stamp); lcd_putsLeft(MENU_HEADER_HEIGHT+5*FH+1, STR_EEBACKUP); lcd_putsLeft(MENU_HEADER_HEIGHT+6*FH+1, STR_FACTORYRESET); drawFilledRect(0, MENU_HEADER_HEIGHT+5*FH, LCD_W, 2*FH+1, SOLID); if (event == EVT_KEY_LONG(KEY_ENTER)) { backupEeprom(); } else if (event == EVT_KEY_LONG(KEY_MENU)) { POPUP_CONFIRMATION(STR_CONFIRMRESET); } }
void menuGeneralDiagAna(uint8_t event) { #if defined(TX_CAPACITY_MEASUREMENT) #define ANAS_ITEMS_COUNT 4 #else #define ANAS_ITEMS_COUNT 2 #endif SIMPLE_MENU(STR_MENUANA, menuTabGeneral, e_Ana, ANAS_ITEMS_COUNT); STICK_SCROLL_DISABLE(); for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) { #if (NUM_STICKS+NUM_POTS) > 9 coord_t y = MENU_HEADER_HEIGHT + 1 + (i/3)*FH; const uint8_t x_coord[] = {0, 70, 154}; uint8_t x = x_coord[i%3]; lcdDrawNumberNAtt(x, y, i+1, LEADING0|LEFT, 2); lcdDrawChar(x+2*FW-2, y, ':'); #else coord_t y = MENU_HEADER_HEIGHT + 1 + (i/2)*FH; uint8_t x = i&1 ? 64+5 : 0; lcdDrawStringWithIndex(x, y, PSTR("A"), i+1); lcdDrawChar(lcdNextPos, y, ':'); #endif lcd_outhex4(x+3*FW-1, y, anaIn(i)); lcd_outdez8(x+10*FW-1, y, (int16_t)calibratedStick[CONVERT_MODE(i)]*25/256); } // Display raw BandGap result (debug) lcdDrawText(64+5, MENU_HEADER_HEIGHT+1+3*FH, STR_BG); lcdDrawNumberAttUnit(64+5+6*FW-3, 1+4*FH, BandGap, 0); #if defined(PCBGRUVIN9X) lcdDrawTextLeft(6*FH-2, STR_BATT_CALIB); // Gruvin wants 2 decimal places and instant update of volts calib field when button pressed static uint16_t adcBatt; adcBatt = ((adcBatt * 7) + anaIn(TX_VOLTAGE)) / 8; // running average, sourced directly (to avoid unending debate :P) uint32_t batCalV = ((uint32_t)adcBatt*1390 + (10*(int32_t)adcBatt*g_eeGeneral.txVoltageCalibration)/8) / BandGap; lcdDrawNumberNAtt(LEN_CALIB_FIELDS*FW+4*FW, 6*FH-2, batCalV, PREC2|(menuVerticalPosition==1 ? INVERS : 0)); #else lcdDrawTextLeft(6*FH-2, STR_BATT_CALIB); lcdPutsVolts(LEN_CALIB_FIELDS*FW+4*FW, 6*FH-2, g_vbat100mV, (menuVerticalPosition==1 ? INVERS : 0)); #endif if (menuVerticalPosition==1) CHECK_INCDEC_GENVAR(event, g_eeGeneral.txVoltageCalibration, -127, 127); #if defined(TX_CAPACITY_MEASUREMENT) lcdDrawTextLeft(6*FH+1, STR_CURRENT_CALIB); lcdPutsValueWithUnit(LEN_CALIB_FIELDS*FW+4*FW, 6*FH+1, getCurrent(), UNIT_MILLIAMPS, (menuVerticalPosition==2 ? INVERS : 0)) ; if (menuVerticalPosition==2) CHECK_INCDEC_GENVAR(event, g_eeGeneral.txCurrentCalibration, -49, 49); #endif }
void menuGeneralVersion(uint8_t event) { SIMPLE_MENU(STR_MENUVERSION, menuTabDiag, e_Vers, 1); lcd_putsLeft(2*FH, stamp1); lcd_putsLeft(3*FH, stamp2); lcd_putsLeft(4*FH, stamp3); #if defined(PCBSKY9X) && !defined(REVA) if (Coproc_valid == 1) { lcd_putsLeft(5*FH, PSTR("CoPr:")); lcd_outdez8(10*FW, 5*FH, Coproc_read); } else { lcd_putsLeft(5*FH, PSTR("CoPr: ---")); } #endif lcd_putsLeft(7*FH, eeprom_stamp); }
void menuGeneralDiagKeys(uint8_t event) { SIMPLE_MENU(STR_MENUDIAG, menuTabDiag, e_Keys, 1); lcd_puts(14*FW, 3*FH, STR_VTRIM); for(uint8_t i=0; i<9; i++) { uint8_t y = i*FH; //+FH; #if !defined(PCBTARANIS) if(i>(SW_ID0-SW_BASE)) y-=FH; //overwrite ID0 putsSwitches(8*FW, y, i+1, 0); //ohne off,on displayKeyState(11*FW+2, y, (EnumKeys)(SW_BASE+i)); #endif if (i<8) { y = i/2*FH+FH*4; lcd_img(14*FW, y, sticks, i/2, 0); displayKeyState(i&1? 20*FW : 18*FW, y, (EnumKeys)(TRM_BASE+i)); } if (i<6) { y = (5-i)*FH+2*FH; lcd_putsiAtt(0, y, STR_VKEYS, i, 0); displayKeyState(5*FW+2, y, (EnumKeys)(KEY_MENU+i)); } } #if defined(ROTARY_ENCODERS) || defined(ROTARY_ENCODER_NAVIGATION) for(uint8_t i=0; i<DIM(g_rotenc); i++) { uint8_t y = i*FH + FH; lcd_putsiAtt(14*FW, y, STR_VRENCODERS, i, 0); lcd_outdezNAtt(18*FW, y, g_rotenc[i], LEFT|(switchState((EnumKeys)(BTN_REa+i)) ? INVERS : 0)); } #endif }
void menuModelPhaseOne(uint8_t event) { FlightModeData *fm = flightModeAddress(s_currIdx); putsFlightMode(13*FW, 0, s_currIdx+1, (getFlightMode()==s_currIdx ? BOLD : 0)); #if defined(GVARS) && !defined(PCBSTD) static const pm_uint8_t mstate_tab_fm1[] PROGMEM = {0, 0, 0, (uint8_t)-1, 1, 1, 1, 1, 1}; static const pm_uint8_t mstate_tab_others[] PROGMEM = {0, 0, 3, IF_ROTARY_ENCODERS(NUM_ROTARY_ENCODERS-1) 0, 0, (uint8_t)-1, 2, 2, 2, 2, 2}; check(event, 0, NULL, 0, (s_currIdx == 0) ? mstate_tab_fm1 : mstate_tab_others, DIM(mstate_tab_others)-1, ITEM_MODEL_PHASE_MAX - 1 - (s_currIdx==0 ? (ITEM_MODEL_PHASE_FADE_IN-ITEM_MODEL_PHASE_SWITCH) : 0)); TITLE(STR_MENUFLIGHTPHASE); #define PHASE_ONE_FIRST_LINE (1+1*FH) #else SUBMENU(STR_MENUFLIGHTPHASE, 3 + (s_currIdx==0 ? 0 : 2 + (bool)NUM_ROTARY_ENCODERS), {0, 0, 3, IF_ROTARY_ENCODERS(NUM_ROTARY_ENCODERS-1) 0/*, 0*/}); #define PHASE_ONE_FIRST_LINE (1+1*FH) #endif int8_t sub = m_posVert; int8_t editMode = s_editMode; #if defined(GVARS) && !defined(PCBSTD) if (s_currIdx == 0 && sub>=ITEM_MODEL_PHASE_SWITCH) sub += ITEM_MODEL_PHASE_FADE_IN-ITEM_MODEL_PHASE_SWITCH; for (uint8_t k=0; k<LCD_LINES-1; k++) { coord_t y = MENU_HEADER_HEIGHT + 1 + k*FH; int8_t i = k + s_pgOfs; if (s_currIdx == 0 && i>=ITEM_MODEL_PHASE_SWITCH) i += ITEM_MODEL_PHASE_FADE_IN-ITEM_MODEL_PHASE_SWITCH; uint8_t attr = (sub==i ? (editMode>0 ? BLINK|INVERS : INVERS) : 0); #else for (uint8_t i=0, k=0, y=PHASE_ONE_FIRST_LINE; i<ITEM_MODEL_PHASE_MAX; i++, k++, y+=FH) { if (s_currIdx == 0 && i==ITEM_MODEL_PHASE_SWITCH) i = ITEM_MODEL_PHASE_FADE_IN; uint8_t attr = (sub==k ? (editMode>0 ? BLINK|INVERS : INVERS) : 0); #endif switch(i) { case ITEM_MODEL_PHASE_NAME: editSingleName(MIXES_2ND_COLUMN, y, STR_PHASENAME, fm->name, sizeof(fm->name), event, attr); break; case ITEM_MODEL_PHASE_SWITCH: fm->swtch = switchMenuItem(MIXES_2ND_COLUMN, y, fm->swtch, attr, event); break; case ITEM_MODEL_PHASE_TRIMS: lcd_putsLeft(y, STR_TRIMS); for (uint8_t t=0; t<NUM_STICKS; t++) { putsTrimMode(MIXES_2ND_COLUMN+(t*FW), y, s_currIdx, t, m_posHorz==t ? attr : 0); if (attr && m_posHorz==t && ((editMode>0) || p1valdiff)) { int16_t v = getRawTrimValue(s_currIdx, t); if (v < TRIM_EXTENDED_MAX) v = TRIM_EXTENDED_MAX; v = checkIncDec(event, v, TRIM_EXTENDED_MAX, TRIM_EXTENDED_MAX+MAX_FLIGHT_MODES-1, EE_MODEL); if (checkIncDec_Ret) { if (v == TRIM_EXTENDED_MAX) v = 0; setTrimValue(s_currIdx, t, v); } } } break; #if ROTARY_ENCODERS > 0 case ITEM_MODEL_PHASE_ROTARY_ENCODERS: lcd_putsLeft(y, STR_ROTARY_ENCODER); for (uint8_t t=0; t<NUM_ROTARY_ENCODERS; t++) { putsRotaryEncoderMode(MIXES_2ND_COLUMN+(t*FW), y, s_currIdx, t, m_posHorz==t ? attr : 0); if (attr && m_posHorz==t && ((editMode>0) || p1valdiff)) { int16_t v = flightModeAddress(s_currIdx)->rotaryEncoders[t]; if (v < ROTARY_ENCODER_MAX) v = ROTARY_ENCODER_MAX; v = checkIncDec(event, v, ROTARY_ENCODER_MAX, ROTARY_ENCODER_MAX+MAX_FLIGHT_MODES-1, EE_MODEL); if (checkIncDec_Ret) { if (v == ROTARY_ENCODER_MAX) v = 0; flightModeAddress(s_currIdx)->rotaryEncoders[t] = v; } } } break; #endif case ITEM_MODEL_PHASE_FADE_IN: fm->fadeIn = EDIT_DELAY(0, y, event, attr, STR_FADEIN, fm->fadeIn); break; case ITEM_MODEL_PHASE_FADE_OUT: fm->fadeOut = EDIT_DELAY(0, y, event, attr, STR_FADEOUT, fm->fadeOut); break; #if defined(GVARS) && !defined(PCBSTD) case ITEM_MODEL_PHASE_GVARS_LABEL: lcd_putsLeft(y, STR_GLOBAL_VARS); break; default: { uint8_t idx = i-ITEM_MODEL_PHASE_GV1; uint8_t posHorz = m_posHorz; if (attr && posHorz > 0 && s_currIdx==0) posHorz++; putsStrIdx(INDENT_WIDTH, y, STR_GV, idx+1); editName(4*FW, y, g_model.gvars[idx].name, LEN_GVAR_NAME, event, posHorz==0 ? attr : 0); int16_t v = fm->gvars[idx]; if (v > GVAR_MAX) { uint8_t p = v - GVAR_MAX - 1; if (p >= s_currIdx) p++; putsFlightMode(11*FW, y, p+1, posHorz==1 ? attr : 0); } else { lcd_putsAtt(11*FW, y, STR_OWN, posHorz==1 ? attr : 0); } if (attr && s_currIdx>0 && posHorz==1 && (editMode>0 || p1valdiff)) { if (v < GVAR_MAX) v = GVAR_MAX; v = checkIncDec(event, v, GVAR_MAX, GVAR_MAX+MAX_FLIGHT_MODES-1, EE_MODEL); if (checkIncDec_Ret) { if (v == GVAR_MAX) v = 0; fm->gvars[idx] = v; } } uint8_t p = getGVarFlightPhase(s_currIdx, idx); lcd_outdezAtt(21*FW, y, GVAR_VALUE(idx, p), posHorz==2 ? attr : 0); if (attr && posHorz==2 && ((editMode>0) || p1valdiff)) { GVAR_VALUE(idx, p) = checkIncDec(event, GVAR_VALUE(idx, p), -GVAR_LIMIT, GVAR_LIMIT, EE_MODEL); } break; } #endif } } } #if defined(ROTARY_ENCODERS) #if ROTARY_ENCODERS > 2 #define NAME_OFS (-4-12) #define SWITCH_OFS (-FW/2-2-13) #define TRIMS_OFS (-FW/2-4-15) #define ROTARY_ENC_OFS (0) #else #define NAME_OFS (-4) #define SWITCH_OFS (-FW/2-2) #define TRIMS_OFS (-FW/2-4) #define ROTARY_ENC_OFS (2) #endif #else #define NAME_OFS 0 #define SWITCH_OFS (FW/2) #define TRIMS_OFS (FW/2) #endif void menuModelFlightModesAll(uint8_t event) { SIMPLE_MENU(STR_MENUFLIGHTPHASES, menuTabModel, e_FlightModesAll, 1+MAX_FLIGHT_MODES+1); int8_t sub = m_posVert - 1; switch (event) { CASE_EVT_ROTARY_BREAK case EVT_KEY_FIRST(KEY_ENTER): if (sub == MAX_FLIGHT_MODES) { s_editMode = 0; trimsCheckTimer = 200; // 2 seconds } // no break case EVT_KEY_FIRST(KEY_RIGHT): if (sub >= 0 && sub < MAX_FLIGHT_MODES) { s_currIdx = sub; pushMenu(menuModelPhaseOne); } break; } uint8_t att; for (uint8_t i=0; i<MAX_FLIGHT_MODES; i++) { #if defined(CPUARM) int8_t y = 1 + (1+i-s_pgOfs)*FH; if (y<1*FH+1 || y>(LCD_LINES-1)*FH+1) continue; #else uint8_t y = 1 + (i+1)*FH; #endif att = (i==sub ? INVERS : 0); FlightModeData *p = flightModeAddress(i); putsFlightMode(0, y, i+1, att|(getFlightMode()==i ? BOLD : 0)); lcd_putsnAtt(4*FW+NAME_OFS, y, p->name, sizeof(p->name), ZCHAR); if (i == 0) { lcd_puts((5+LEN_FLIGHT_MODE_NAME)*FW+SWITCH_OFS, y, STR_DEFAULT); } else { putsSwitches((5+LEN_FLIGHT_MODE_NAME)*FW+SWITCH_OFS, y, p->swtch, 0); for (uint8_t t=0; t<NUM_STICKS; t++) { putsTrimMode((9+LEN_FLIGHT_MODE_NAME+t)*FW+TRIMS_OFS, y, i, t, 0); } #if defined(CPUM2560) for (uint8_t t=0; t<NUM_ROTARY_ENCODERS; t++) { putsRotaryEncoderMode((13+LEN_FLIGHT_MODE_NAME+t)*FW+TRIMS_OFS+ROTARY_ENC_OFS, y, i, t, 0); } #endif } if (p->fadeIn || p->fadeOut) { lcd_putc(LCD_W-FW-MENUS_SCROLLBAR_WIDTH, y, (p->fadeIn && p->fadeOut) ? '*' : (p->fadeIn ? 'I' : 'O')); } } #if defined(CPUARM) if (s_pgOfs != MAX_FLIGHT_MODES-(LCD_LINES-2)) return; #endif lcd_putsLeft((LCD_LINES-1)*FH+1, STR_CHECKTRIMS); putsFlightMode(OFS_CHECKTRIMS, (LCD_LINES-1)*FH+1, mixerCurrentFlightMode+1); if (sub==MAX_FLIGHT_MODES && !trimsCheckTimer) { lcd_status_line(); } }
void menuGeneralSdManager(uint8_t _event) { if (s_warning_result) { s_warning_result = 0; displayPopup(STR_FORMATTING); closeLogs(); audioQueue.stopSD(); if (f_mkfs(0, 1, 0) == FR_OK) { f_chdir("/"); REFRESH_FILES(); } else { POPUP_WARNING(STR_SDCARD_ERROR); } } int lastPos = m_posVert; uint8_t event = (EVT_KEY_MASK(_event) == KEY_ENTER ? 0 : _event); SIMPLE_MENU(SD_IS_HC() ? STR_SDHC_CARD : STR_SD_CARD, menuTabGeneral, e_Sd, reusableBuffer.sdmanager.count); int index = m_posVert-s_pgOfs; switch(_event) { case EVT_ENTRY: f_chdir(ROOT_PATH); REFRESH_FILES(); lastPos = -1; break; case EVT_KEY_LONG(KEY_MENU): if (!READ_ONLY() && s_editMode == 0) { killEvents(_event); MENU_ADD_ITEM(STR_SD_INFO); MENU_ADD_ITEM(STR_SD_FORMAT); menuHandler = onSdManagerMenu; } break; case EVT_KEY_BREAK(KEY_EXIT): REFRESH_FILES(); break; case EVT_KEY_BREAK(KEY_ENTER): if (s_editMode > 0) { break; } else { if (!reusableBuffer.sdmanager.lines[index][SD_SCREEN_FILE_LENGTH+1]) { f_chdir(reusableBuffer.sdmanager.lines[index]); s_pgOfs = 0; m_posVert = 1; index = 1; REFRESH_FILES(); killEvents(_event); return; } } // no break case EVT_KEY_LONG(KEY_ENTER): if (s_editMode == 0) { killEvents(_event); char *line = reusableBuffer.sdmanager.lines[index]; char *ext = getFileExtension(line, SD_SCREEN_FILE_LENGTH+1); if (ext) { if (!strcasecmp(ext, SOUNDS_EXT)) { MENU_ADD_ITEM(STR_PLAY_FILE); } else if (!strcasecmp(ext, BITMAPS_EXT)) { if (!READ_ONLY() && (ext-line) <= (int)sizeof(g_model.header.bitmap)) { MENU_ADD_ITEM(STR_ASSIGN_BITMAP); } } else if (!strcasecmp(ext, TEXT_EXT)) { MENU_ADD_ITEM(STR_VIEW_TEXT); } #if defined(LUA) else if (!strcasecmp(ext, SCRIPTS_EXT)) { MENU_ADD_ITEM(STR_EXECUTE_FILE); } #endif else if (!READ_ONLY() && !strcasecmp(ext, FIRMWARE_EXT)) { TCHAR lfn[_MAX_LFN + 1]; getSelectionFullPath(lfn); if (isBootloader(lfn)) { MENU_ADD_ITEM(STR_FLASH_BOOTLOADER); } } else if (!READ_ONLY() && !strcasecmp(ext, SPORT_FIRMWARE_EXT)) { MENU_ADD_ITEM(STR_FLASH_EXTERNAL_DEVICE); MENU_ADD_ITEM(STR_FLASH_INTERNAL_MODULE); } } if (!READ_ONLY()) { if (line[SD_SCREEN_FILE_LENGTH+1]) // it's a file MENU_ADD_ITEM(STR_COPY_FILE); if (clipboard.type == CLIPBOARD_TYPE_SD_FILE) MENU_ADD_ITEM(STR_PASTE); MENU_ADD_ITEM(STR_RENAME_FILE); MENU_ADD_ITEM(STR_DELETE_FILE); } menuHandler = onSdManagerMenu; } break; } if (reusableBuffer.sdmanager.offset != s_pgOfs) { FILINFO fno; DIR dir; char *fn; /* This function is assuming non-Unicode cfg. */ TCHAR lfn[_MAX_LFN + 1]; fno.lfname = lfn; fno.lfsize = sizeof(lfn); if (s_pgOfs == 0) { reusableBuffer.sdmanager.offset = 0; memset(reusableBuffer.sdmanager.lines, 0, sizeof(reusableBuffer.sdmanager.lines)); } else if (s_pgOfs == reusableBuffer.sdmanager.count-7) { reusableBuffer.sdmanager.offset = s_pgOfs; memset(reusableBuffer.sdmanager.lines, 0, sizeof(reusableBuffer.sdmanager.lines)); } else if (s_pgOfs > reusableBuffer.sdmanager.offset) { memmove(reusableBuffer.sdmanager.lines[0], reusableBuffer.sdmanager.lines[1], 6*sizeof(reusableBuffer.sdmanager.lines[0])); memset(reusableBuffer.sdmanager.lines[6], 0xff, SD_SCREEN_FILE_LENGTH); reusableBuffer.sdmanager.lines[6][SD_SCREEN_FILE_LENGTH+1] = 1; } else { memmove(reusableBuffer.sdmanager.lines[1], reusableBuffer.sdmanager.lines[0], 6*sizeof(reusableBuffer.sdmanager.lines[0])); memset(reusableBuffer.sdmanager.lines[0], 0, sizeof(reusableBuffer.sdmanager.lines[0])); } reusableBuffer.sdmanager.count = 0; FRESULT res = f_opendir(&dir, "."); /* Open the directory */ if (res == FR_OK) { for (;;) { res = f_readdir(&dir, &fno); /* Read a directory item */ if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ if (fno.fname[0] == '.' && fno.fname[1] == '\0') continue; /* Ignore dot entry */ #if _USE_LFN fn = *fno.lfname ? fno.lfname : fno.fname; #else fn = fno.fname; #endif if (strlen(fn) > SD_SCREEN_FILE_LENGTH) continue; reusableBuffer.sdmanager.count++; bool isfile = !(fno.fattrib & AM_DIR); if (s_pgOfs == 0) { for (int i=0; i<NUM_BODY_LINES; i++) { char *line = reusableBuffer.sdmanager.lines[i]; if (line[0] == '\0' || isFilenameLower(isfile, fn, line)) { if (i < 6) memmove(reusableBuffer.sdmanager.lines[i+1], line, sizeof(reusableBuffer.sdmanager.lines[i]) * (6-i)); memset(line, 0, sizeof(reusableBuffer.sdmanager.lines[i])); strcpy(line, fn); line[SD_SCREEN_FILE_LENGTH+1] = isfile; break; } } } else if (reusableBuffer.sdmanager.offset == s_pgOfs) { for (int8_t i=6; i>=0; i--) { char *line = reusableBuffer.sdmanager.lines[i]; if (line[0] == '\0' || isFilenameGreater(isfile, fn, line)) { if (i > 0) memmove(reusableBuffer.sdmanager.lines[0], reusableBuffer.sdmanager.lines[1], sizeof(reusableBuffer.sdmanager.lines[0]) * i); memset(line, 0, sizeof(reusableBuffer.sdmanager.lines[i])); strcpy(line, fn); line[SD_SCREEN_FILE_LENGTH+1] = isfile; break; } } } else if (s_pgOfs > reusableBuffer.sdmanager.offset) { if (isFilenameGreater(isfile, fn, reusableBuffer.sdmanager.lines[5]) && isFilenameLower(isfile, fn, reusableBuffer.sdmanager.lines[6])) { memset(reusableBuffer.sdmanager.lines[6], 0, sizeof(reusableBuffer.sdmanager.lines[0])); strcpy(reusableBuffer.sdmanager.lines[6], fn); reusableBuffer.sdmanager.lines[6][SD_SCREEN_FILE_LENGTH+1] = isfile; } } else { if (isFilenameLower(isfile, fn, reusableBuffer.sdmanager.lines[1]) && isFilenameGreater(isfile, fn, reusableBuffer.sdmanager.lines[0])) { memset(reusableBuffer.sdmanager.lines[0], 0, sizeof(reusableBuffer.sdmanager.lines[0])); strcpy(reusableBuffer.sdmanager.lines[0], fn); reusableBuffer.sdmanager.lines[0][SD_SCREEN_FILE_LENGTH+1] = isfile; } } } } } reusableBuffer.sdmanager.offset = s_pgOfs; for (int i=0; i<NUM_BODY_LINES; i++) { coord_t y = MENU_HEADER_HEIGHT + 1 + i*FH; lcdNextPos = 0; LcdFlags attr = (index == i ? BSS|INVERS : BSS); if (reusableBuffer.sdmanager.lines[i][0]) { if (!reusableBuffer.sdmanager.lines[i][SD_SCREEN_FILE_LENGTH+1]) { lcd_putcAtt(0, y, '[', s_editMode == EDIT_MODIFY_STRING ? 0 : attr); } if (s_editMode == EDIT_MODIFY_STRING && attr) { editName(lcdNextPos, y, reusableBuffer.sdmanager.lines[i], SD_SCREEN_FILE_LENGTH-4, _event, attr, 0); if (s_editMode == 0) { unsigned int len = effectiveLen(reusableBuffer.sdmanager.lines[i], SD_SCREEN_FILE_LENGTH-LEN_FILE_EXTENSION); char * ext = getFileExtension(reusableBuffer.sdmanager.originalName, sizeof(reusableBuffer.sdmanager.originalName)); if (ext) { strAppend(&reusableBuffer.sdmanager.lines[i][len], ext); } f_rename(reusableBuffer.sdmanager.originalName, reusableBuffer.sdmanager.lines[i]); REFRESH_FILES(); } } else { lcd_putsAtt(lcdNextPos, y, reusableBuffer.sdmanager.lines[i], attr); } if (!reusableBuffer.sdmanager.lines[i][SD_SCREEN_FILE_LENGTH+1]) { lcd_putcAtt(lcdNextPos, y, ']', s_editMode == EDIT_MODIFY_STRING ? 0 : attr); } } } char *ext = getFileExtension(reusableBuffer.sdmanager.lines[index], SD_SCREEN_FILE_LENGTH+1); if (ext && !strcasecmp(ext, BITMAPS_EXT)) { if (lastPos != m_posVert) { if (bmpLoad(modelBitmap, reusableBuffer.sdmanager.lines[index], MODEL_BITMAP_WIDTH, MODEL_BITMAP_HEIGHT)) { memcpy(modelBitmap, logo_taranis, MODEL_BITMAP_SIZE); } } lcd_bmp(22*FW+2, 2*FH+FH/2, modelBitmap); } }
void menuModelExpoMix(uint8_t expo, uint8_t event) { uint8_t sub = m_posVert; if (s_editMode > 0) s_editMode = 0; uint8_t chn = (expo ? expoAddress(s_currIdx)->chn+1 : mixAddress(s_currIdx)->destCh+1); switch (event) { case EVT_ENTRY: case EVT_ENTRY_UP: s_copyMode = 0; s_copyTgtOfs = 0; break; case EVT_KEY_LONG(KEY_EXIT): if (s_copyMode && s_copyTgtOfs == 0) { deleteExpoMix(expo, s_currIdx); killEvents(event); event = 0; } // no break case EVT_KEY_BREAK(KEY_EXIT): if (s_copyMode) { if (s_copyTgtOfs) { // cancel the current copy / move operation if (s_copyMode == COPY_MODE) { deleteExpoMix(expo, s_currIdx); } else { do { swapExpoMix(expo, s_currIdx, s_copyTgtOfs > 0); s_copyTgtOfs += (s_copyTgtOfs < 0 ? +1 : -1); } while (s_copyTgtOfs != 0); eeDirty(EE_MODEL); } m_posVert = s_copySrcRow; s_copyTgtOfs = 0; } s_copyMode = 0; event = 0; } break; case EVT_KEY_BREAK(KEY_ENTER): if ((!s_currCh || (s_copyMode && !s_copyTgtOfs)) && !READ_ONLY()) { s_copyMode = (s_copyMode == COPY_MODE ? MOVE_MODE : COPY_MODE); s_copySrcIdx = s_currIdx; s_copySrcCh = chn; s_copySrcRow = sub; break; } // no break case EVT_KEY_LONG(KEY_ENTER): killEvents(event); if (s_copyTgtOfs) { s_copyMode = 0; s_copyTgtOfs = 0; } else { if (READ_ONLY()) { if (!s_currCh) { pushMenu(expo ? menuModelExpoOne : menuModelMixOne); } } else { if (s_copyMode) s_currCh = 0; if (s_currCh) { if (reachExpoMixCountLimit(expo)) break; insertExpoMix(expo, s_currIdx); pushMenu(expo ? menuModelExpoOne : menuModelMixOne); s_copyMode = 0; } else { event = 0; s_copyMode = 0; MENU_ADD_ITEM(STR_EDIT); MENU_ADD_ITEM(STR_INSERT_BEFORE); MENU_ADD_ITEM(STR_INSERT_AFTER); MENU_ADD_ITEM(STR_COPY); MENU_ADD_ITEM(STR_MOVE); MENU_ADD_ITEM(STR_DELETE); menuHandler = onExpoMixMenu; } } } break; case EVT_KEY_LONG(KEY_LEFT): case EVT_KEY_LONG(KEY_RIGHT): if (s_copyMode && !s_copyTgtOfs) { if (reachExpoMixCountLimit(expo)) break; s_currCh = chn; if (event == EVT_KEY_LONG(KEY_RIGHT)) { s_currIdx++; m_posVert++; } insertExpoMix(expo, s_currIdx); pushMenu(expo ? menuModelExpoOne : menuModelMixOne); s_copyMode = 0; killEvents(event); } break; case EVT_KEY_FIRST(KEY_MOVE_UP): case EVT_KEY_REPT(KEY_MOVE_UP): case EVT_KEY_FIRST(KEY_MOVE_DOWN): case EVT_KEY_REPT(KEY_MOVE_DOWN): if (s_copyMode) { uint8_t key = (event & 0x1f); uint8_t next_ofs = (key==KEY_MOVE_UP ? s_copyTgtOfs - 1 : s_copyTgtOfs + 1); if (s_copyTgtOfs==0 && s_copyMode==COPY_MODE) { // insert a mix on the same channel (just above / just below) if (reachExpoMixCountLimit(expo)) break; copyExpoMix(expo, s_currIdx); if (key==KEY_MOVE_DOWN) s_currIdx++; else if (sub-s_pgOfs >= 6) s_pgOfs++; } else if (next_ofs==0 && s_copyMode==COPY_MODE) { // delete the mix deleteExpoMix(expo, s_currIdx); if (key==KEY_MOVE_UP) s_currIdx--; } else { // only swap the mix with its neighbor if (!swapExpoMix(expo, s_currIdx, key==KEY_MOVE_UP)) break; eeDirty(EE_MODEL); } s_copyTgtOfs = next_ofs; } break; } if (expo) { lcd_outdezAtt(FW*sizeof(TR_MENUINPUTS)+FW+FW/2, 0, getExpoMixCount(true)); lcd_puts(FW*sizeof(TR_MENUINPUTS)+FW+FW/2, 0, STR_MAX(MAX_EXPOS)); // Value uint8_t index = expoAddress(s_currIdx)->chn; if (!s_currCh) { lcd_outdezAtt(127, 2, calcRESXto1000(anas[index]), PREC1|TINSIZE); } SIMPLE_MENU(STR_MENUINPUTS, menuTabModel, e_InputsAll, s_maxLines); // Gauge if (!s_currCh) { drawGauge(127, 1, 58, 6, anas[index], 1024); } } else { lcd_outdezAtt(FW*sizeof(TR_MIXER)+FW+FW/2, 0, getExpoMixCount(false)); lcd_puts(FW*sizeof(TR_MIXER)+FW+FW/2, 0, STR_MAX(MAX_MIXERS)); // Value uint8_t index = mixAddress(s_currIdx)->destCh; if (!s_currCh) { displayHeaderChannelName(index); lcd_outdezAtt(127, 2, calcRESXto1000(ex_chans[index]), PREC1|TINSIZE); } SIMPLE_MENU(STR_MIXER, menuTabModel, e_MixAll, s_maxLines); // Gauge if (!s_currCh) { drawGauge(127, 1, 58, 6, ex_chans[index], 1024); } } sub = m_posVert; s_currCh = 0; int cur = 0; int i = 0; for (int ch=1; ch<=(expo ? NUM_INPUTS : NUM_CHNOUT); ch++) { void *pointer = NULL; MixData * &md = (MixData * &)pointer; ExpoData * &ed = (ExpoData * &)pointer; coord_t y = MENU_HEADER_HEIGHT+1+(cur-s_pgOfs)*FH; if (expo ? (i<MAX_EXPOS && (ed=expoAddress(i))->chn+1 == ch && EXPO_VALID(ed)) : (i<MAX_MIXERS && (md=mixAddress(i))->srcRaw && md->destCh+1 == ch)) { if (cur-s_pgOfs >= 0 && cur-s_pgOfs < NUM_BODY_LINES) { if (expo) { putsMixerSource(0, y, ch, 0); } else { putsChn(0, y, ch, 0); // show CHx } } uint8_t mixCnt = 0; do { if (s_copyMode) { if (s_copyMode == MOVE_MODE && cur-s_pgOfs >= 0 && cur-s_pgOfs < NUM_BODY_LINES && s_copySrcCh == ch && s_copyTgtOfs != 0 && i == (s_copySrcIdx + (s_copyTgtOfs<0))) { lcd_rect(expo ? 18 : 22, y-1, expo ? LCD_W-18 : LCD_W-22, 9, DOTTED); cur++; y+=FH; } if (s_currIdx == i) { sub = m_posVert = cur; s_currCh = ch; } } else if (sub == cur) { s_currIdx = i; } if (cur-s_pgOfs >= 0 && cur-s_pgOfs < NUM_BODY_LINES) { uint8_t attr = ((s_copyMode || sub != cur) ? 0 : INVERS); if (expo) { GVAR_MENU_ITEM(EXPO_LINE_WEIGHT_POS, y, ed->weight, MIN_EXPO_WEIGHT, 100, attr | (isExpoActive(i) ? BOLD : 0), 0, 0); displayExpoLine(y, ed); if (ed->mode!=3) { lcd_putc(EXPO_LINE_SIDE_POS, y, ed->mode == 2 ? 126 : 127); } } else { if (mixCnt > 0) lcd_putsiAtt(FW, y, STR_VMLTPX2, md->mltpx, 0); putsMixerSource(MIX_LINE_SRC_POS, y, md->srcRaw, 0); gvarWeightItem(MIX_LINE_WEIGHT_POS, y, md, attr | (isMixActive(i) ? BOLD : 0), 0); displayMixLine(y, md); char cs = ' '; if (md->speedDown || md->speedUp) cs = 'S'; if (md->delayUp || md->delayDown) cs = (cs =='S' ? '*' : 'D'); lcd_putc(MIX_LINE_DELAY_POS, y, cs); } if (s_copyMode) { if ((s_copyMode==COPY_MODE || s_copyTgtOfs == 0) && s_copySrcCh == ch && i == (s_copySrcIdx + (s_copyTgtOfs<0))) { /* draw a border around the raw on selection mode (copy/move) */ lcd_rect(expo ? EXPO_LINE_SELECT_POS : 22, y-1, expo ? (LCD_W-EXPO_LINE_SELECT_POS) : (LCD_W-22), 9, s_copyMode == COPY_MODE ? SOLID : DOTTED); } if (cur == sub) { /* invert the raw when it's the current one */ drawFilledRect(expo ? EXPO_LINE_SELECT_POS+1 : 23, y, expo ? (LCD_W-EXPO_LINE_SELECT_POS-2) : (LCD_W-24), 7); } } } cur++; y+=FH; mixCnt++; i++; if (expo) ed++; else md++; } while (expo ? (i<MAX_EXPOS && ed->chn+1 == ch && EXPO_VALID(ed)) : (i<MAX_MIXERS && md->srcRaw && md->destCh+1 == ch)); if (s_copyMode == MOVE_MODE && cur-s_pgOfs >= 0 && cur-s_pgOfs < NUM_BODY_LINES && s_copySrcCh == ch && i == (s_copySrcIdx + (s_copyTgtOfs<0))) { lcd_rect(expo ? EXPO_LINE_SELECT_POS : 22, y-1, expo ? LCD_W-EXPO_LINE_SELECT_POS : LCD_W-22, 9, DOTTED); cur++; y+=FH; } } else { uint8_t attr = 0; if (sub == cur) { s_currIdx = i; s_currCh = ch; if (!s_copyMode) { attr = INVERS; } } if (cur-s_pgOfs >= 0 && cur-s_pgOfs < NUM_BODY_LINES) { if (expo) { putsMixerSource(0, y, ch, attr); } else { putsChn(0, y, ch, attr); // show CHx } if (s_copyMode == MOVE_MODE && s_copySrcCh == ch) { lcd_rect(expo ? EXPO_LINE_SELECT_POS : 22, y-1, expo ? (LCD_W-EXPO_LINE_SELECT_POS) : (LCD_W-22), 9, DOTTED); } } cur++; y+=FH; } } s_maxLines = cur; if (sub >= s_maxLines-1) m_posVert = s_maxLines-1; }
void menuGeneralSdManager(uint8_t event) { FILINFO fno; DIR dir; char *fn; /* This function is assuming non-Unicode cfg. */ #if _USE_LFN TCHAR lfn[_MAX_LFN + 1]; fno.lfname = lfn; fno.lfsize = sizeof(lfn); #else char lfn[SD_SCREEN_FILE_LENGTH]; #endif #if defined(SDCARD) if (s_warning_result) { s_warning_result = 0; displayPopup(STR_FORMATTING); closeLogs(); #if defined(PCBSKY9X) Card_state = SD_ST_DATA; #endif #if defined(CPUARM) audioQueue.stopSD(); #endif if (f_mkfs(0, 1, 0) == FR_OK) { f_chdir("/"); reusableBuffer.sdmanager.offset = -1; } else { POPUP_WARNING(STR_SDCARD_ERROR); } } #endif SIMPLE_MENU(SD_IS_HC() ? STR_SDHC_CARD : STR_SD_CARD, menuTabDiag, e_Sd, 1+reusableBuffer.sdmanager.count); if (s_editMode > 0) s_editMode = 0; switch(event) { case EVT_ENTRY: f_chdir(ROOT_PATH); reusableBuffer.sdmanager.offset = 65535; break; #if defined(PCBTARANIS) case EVT_KEY_LONG(KEY_MENU): killEvents(event); // MENU_ADD_ITEM(STR_SD_INFO); TODO: Implement MENU_ADD_ITEM(STR_SD_FORMAT); menuHandler = onSdManagerMenu; break; #endif #if defined(PCBTARANIS) case EVT_KEY_BREAK(KEY_ENTER): #else CASE_EVT_ROTARY_BREAK case EVT_KEY_FIRST(KEY_RIGHT): case EVT_KEY_FIRST(KEY_ENTER): #endif { if (m_posVert > 0) { vertpos_t index = m_posVert-1-s_pgOfs; if (!reusableBuffer.sdmanager.lines[index][SD_SCREEN_FILE_LENGTH+1]) { f_chdir(reusableBuffer.sdmanager.lines[index]); s_pgOfs = 0; m_posVert = 1; reusableBuffer.sdmanager.offset = 65535; break; } } if (!IS_ROTARY_BREAK(event) || m_posVert==0) break; // no break; } case EVT_KEY_LONG(KEY_ENTER): killEvents(event); #if !defined(PCBTARANIS) if (m_posVert == 0) { MENU_ADD_ITEM(STR_SD_INFO); MENU_ADD_ITEM(STR_SD_FORMAT); } else #endif { #if defined(CPUARM) uint8_t index = m_posVert-1-s_pgOfs; // TODO duplicated code for finding extension char * ext = reusableBuffer.sdmanager.lines[index]; ext += strlen(ext) - 4; /* TODO if (!strcasecmp(ext, MODELS_EXT)) { s_menu[s_menu_count++] = STR_LOAD_FILE; } else */ if (!strcasecmp(ext, SOUNDS_EXT)) { MENU_ADD_ITEM(STR_PLAY_FILE); } #if defined(PCBTARANIS) else if (!strcasecmp(ext, BITMAPS_EXT)) { MENU_ADD_ITEM(STR_ASSIGN_BITMAP); } #endif #endif MENU_ADD_ITEM(STR_DELETE_FILE); // MENU_ADD_ITEM(STR_RENAME_FILE); TODO: Implement // MENU_ADD_ITEM(STR_COPY_FILE); TODO: Implement } menuHandler = onSdManagerMenu; break; } if (reusableBuffer.sdmanager.offset != s_pgOfs) { if (s_pgOfs == 0) { reusableBuffer.sdmanager.offset = 0; memset(reusableBuffer.sdmanager.lines, 0, sizeof(reusableBuffer.sdmanager.lines)); } else if (s_pgOfs == reusableBuffer.sdmanager.count-7) { reusableBuffer.sdmanager.offset = s_pgOfs; memset(reusableBuffer.sdmanager.lines, 0, sizeof(reusableBuffer.sdmanager.lines)); } else if (s_pgOfs > reusableBuffer.sdmanager.offset) { memmove(reusableBuffer.sdmanager.lines[0], reusableBuffer.sdmanager.lines[1], 6*sizeof(reusableBuffer.sdmanager.lines[0])); memset(reusableBuffer.sdmanager.lines[6], 0xff, SD_SCREEN_FILE_LENGTH); reusableBuffer.sdmanager.lines[6][SD_SCREEN_FILE_LENGTH+1] = 1; } else { memmove(reusableBuffer.sdmanager.lines[1], reusableBuffer.sdmanager.lines[0], 6*sizeof(reusableBuffer.sdmanager.lines[0])); memset(reusableBuffer.sdmanager.lines[0], 0, sizeof(reusableBuffer.sdmanager.lines[0])); } reusableBuffer.sdmanager.count = 0; FRESULT res = f_opendir(&dir, "."); /* Open the directory */ if (res == FR_OK) { for (;;) { res = f_readdir(&dir, &fno); /* Read a directory item */ if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ if (fno.fname[0] == '.' && fno.fname[1] == '\0') continue; /* Ignore dot entry */ #if _USE_LFN fn = *fno.lfname ? fno.lfname : fno.fname; #else fn = fno.fname; #endif if (strlen(fn) > SD_SCREEN_FILE_LENGTH) continue; reusableBuffer.sdmanager.count++; bool isfile = !(fno.fattrib & AM_DIR); if (s_pgOfs == 0) { for (uint8_t i=0; i<LCD_LINES-1; i++) { char *line = reusableBuffer.sdmanager.lines[i]; if (line[0] == '\0' || isFilenameLower(isfile, fn, line)) { if (i < 6) memmove(reusableBuffer.sdmanager.lines[i+1], line, sizeof(reusableBuffer.sdmanager.lines[i]) * (6-i)); memset(line, 0, sizeof(reusableBuffer.sdmanager.lines[i])); strcpy(line, fn); line[SD_SCREEN_FILE_LENGTH+1] = isfile; break; } } } else if (reusableBuffer.sdmanager.offset == s_pgOfs) { for (int8_t i=6; i>=0; i--) { char *line = reusableBuffer.sdmanager.lines[i]; if (line[0] == '\0' || isFilenameGreater(isfile, fn, line)) { if (i > 0) memmove(reusableBuffer.sdmanager.lines[0], reusableBuffer.sdmanager.lines[1], sizeof(reusableBuffer.sdmanager.lines[0]) * i); memset(line, 0, sizeof(reusableBuffer.sdmanager.lines[i])); strcpy(line, fn); line[SD_SCREEN_FILE_LENGTH+1] = isfile; break; } } } else if (s_pgOfs > reusableBuffer.sdmanager.offset) { if (isFilenameGreater(isfile, fn, reusableBuffer.sdmanager.lines[5]) && isFilenameLower(isfile, fn, reusableBuffer.sdmanager.lines[6])) { memset(reusableBuffer.sdmanager.lines[6], 0, sizeof(reusableBuffer.sdmanager.lines[0])); strcpy(reusableBuffer.sdmanager.lines[6], fn); reusableBuffer.sdmanager.lines[6][SD_SCREEN_FILE_LENGTH+1] = isfile; } } else { if (isFilenameLower(isfile, fn, reusableBuffer.sdmanager.lines[1]) && isFilenameGreater(isfile, fn, reusableBuffer.sdmanager.lines[0])) { memset(reusableBuffer.sdmanager.lines[0], 0, sizeof(reusableBuffer.sdmanager.lines[0])); strcpy(reusableBuffer.sdmanager.lines[0], fn); reusableBuffer.sdmanager.lines[0][SD_SCREEN_FILE_LENGTH+1] = isfile; } } } } } reusableBuffer.sdmanager.offset = s_pgOfs; for (uint8_t i=0; i<LCD_LINES-1; i++) { uint8_t y = 1 + FH + i*FH; uint8_t x = 0; uint8_t attr = (m_posVert-1-s_pgOfs == i ? BSS|INVERS : BSS); if (reusableBuffer.sdmanager.lines[i][0]) { if (!reusableBuffer.sdmanager.lines[i][SD_SCREEN_FILE_LENGTH+1]) { lcd_putcAtt(0, y, '[', attr); x += FW; } lcd_putsAtt(x, y, reusableBuffer.sdmanager.lines[i], attr); if (!reusableBuffer.sdmanager.lines[i][SD_SCREEN_FILE_LENGTH+1]) { lcd_putcAtt(lcdLastPos, y, ']', attr); } } } #if defined(PCBTARANIS) static vertpos_t sdBitmapIdx = 0xFFFF; static uint8_t sdBitmap[MODEL_BITMAP_SIZE]; vertpos_t index = m_posVert-1-s_pgOfs; if (m_posVert > 0) { char * ext = reusableBuffer.sdmanager.lines[index]; ext += strlen(ext) - 4; if (!strcasecmp(ext, BITMAPS_EXT)) { if (sdBitmapIdx != m_posVert) { sdBitmapIdx = m_posVert; if (bmpLoad(sdBitmap, reusableBuffer.sdmanager.lines[index], MODEL_BITMAP_WIDTH, MODEL_BITMAP_HEIGHT)) memcpy(sdBitmap, logo_taranis, MODEL_BITMAP_SIZE); } lcd_bmp(22*FW+2, 2*FH+FH/2, sdBitmap); } } #endif }
void menuCommonCalib(uint8_t event) { for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) { //get low and high vals for sticks and trims int16_t vt = anaIn(i); reusableBuffer.calib.loVals[i] = min(vt, reusableBuffer.calib.loVals[i]); reusableBuffer.calib.hiVals[i] = max(vt, reusableBuffer.calib.hiVals[i]); #if defined(PCBTARANIS) if(i >= NUM_STICKS && i < NUM_STICKS+NUM_POTS-2) { #else if (i >= NUM_STICKS) { #endif reusableBuffer.calib.midVals[i] = (reusableBuffer.calib.hiVals[i] + reusableBuffer.calib.loVals[i]) / 2; } } s_noScroll = reusableBuffer.calib.state; // make sure we don't scroll while calibrating switch(event) { case EVT_ENTRY: reusableBuffer.calib.state = 0; break; case EVT_KEY_BREAK(KEY_ENTER): reusableBuffer.calib.state++; break; } switch (reusableBuffer.calib.state) { case 0: // START CALIBRATION lcd_putsLeft(3*FH, STR_MENUTOSTART); break; case 1: // SET MIDPOINT lcd_putsAtt(0*FW, 2*FH, STR_SETMIDPOINT, s_noScroll ? INVERS : 0); lcd_putsLeft(3*FH, STR_MENUWHENDONE); for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) { reusableBuffer.calib.loVals[i] = 15000; reusableBuffer.calib.hiVals[i] = -15000; reusableBuffer.calib.midVals[i] = anaIn(i); } break; case 2: // MOVE STICKS/POTS STICK_SCROLL_DISABLE(); lcd_putsAtt(0*FW, 2*FH, STR_MOVESTICKSPOTS, s_noScroll ? INVERS : 0); lcd_putsLeft(3*FH, STR_MENUWHENDONE); for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) { if (abs(reusableBuffer.calib.loVals[i]-reusableBuffer.calib.hiVals[i])>50) { g_eeGeneral.calibMid[i] = reusableBuffer.calib.midVals[i]; int16_t v = reusableBuffer.calib.midVals[i] - reusableBuffer.calib.loVals[i]; g_eeGeneral.calibSpanNeg[i] = v - v/STICK_TOLERANCE; v = reusableBuffer.calib.hiVals[i] - reusableBuffer.calib.midVals[i]; g_eeGeneral.calibSpanPos[i] = v - v/STICK_TOLERANCE; } } break; case 3: g_eeGeneral.chkSum = evalChkSum(); eeDirty(EE_GENERAL); reusableBuffer.calib.state = 4; break; default: reusableBuffer.calib.state = 0; break; } doMainScreenGraphics(); #if defined(PCBTARANIS) drawPotsBars(); #endif } void menuGeneralCalib(uint8_t event) { SIMPLE_MENU(STR_MENUCALIBRATION, menuTabDiag, e_Calib, 1); menuCommonCalib(event); }
void menuGeneralDiagAna(uint8_t event) { #if defined(PCBSKY9X) && !defined(REVA) #define ANAS_ITEMS_COUNT 4 #elif defined(PCBSKY9X) #define ANAS_ITEMS_COUNT 3 #else #define ANAS_ITEMS_COUNT 2 #endif SIMPLE_MENU(STR_MENUANA, menuTabDiag, e_Ana, ANAS_ITEMS_COUNT); STICK_SCROLL_DISABLE(); for (uint8_t i=0; i<NUM_STICKS+NUM_POTS; i++) { uint8_t y = 1+FH+(i/2)*FH; uint8_t x = i&1 ? 64+5 : 0; putsStrIdx(x, y, PSTR("A"), i+1); lcd_putc(x+2*FWNUM, y, ':'); lcd_outhex4(x+3*FW-1, y, anaIn(i)); lcd_outdez8(x+10*FW-1, y, (int16_t)calibratedStick[CONVERT_MODE(i+1)-1]*25/256); } #if !defined(CPUARM) // Display raw BandGap result (debug) lcd_puts(64+5, 1+4*FH, STR_BG); lcd_outdezAtt(64+5+6*FW-3, 1+4*FH, BandGap, 0); #endif #if defined(PCBTARANIS) lcd_putsLeft(6*FH+1, STR_BATT_CALIB); static int32_t adcBatt; adcBatt = ((adcBatt * 7) + anaIn(8)) / 8; uint32_t batCalV = (adcBatt + (adcBatt*g_eeGeneral.vBatCalib)/128) * BATT_SCALE; batCalV >>= 11; batCalV += 2; // because of the diode putsVolts(LEN_CALIB_FIELDS*FW+4*FW, 6*FH+1, batCalV, (m_posVert==1 ? INVERS : 0)); #elif defined(PCBSKY9X) lcd_putsLeft(5*FH+1, STR_BATT_CALIB); static int32_t adcBatt; adcBatt = ((adcBatt * 7) + anaIn(7)) / 8; uint32_t batCalV = (adcBatt + adcBatt*(g_eeGeneral.vBatCalib)/128) * 4191; batCalV /= 55296; putsVolts(LEN_CALIB_FIELDS*FW+4*FW, 5*FH+1, batCalV, (m_posVert==1 ? INVERS : 0)); #elif defined(PCBGRUVIN9X) lcd_putsLeft(6*FH-2, STR_BATT_CALIB); // Gruvin wants 2 decimal places and instant update of volts calib field when button pressed static uint16_t adcBatt; adcBatt = ((adcBatt * 7) + anaIn(7)) / 8; // running average, sourced directly (to avoid unending debate :P) uint32_t batCalV = ((uint32_t)adcBatt*1390 + (10*(int32_t)adcBatt*g_eeGeneral.vBatCalib)/8) / BandGap; lcd_outdezNAtt(LEN_CALIB_FIELDS*FW+4*FW, 6*FH-2, batCalV, PREC2|(m_posVert==1 ? INVERS : 0)); #else lcd_putsLeft(6*FH-2, STR_BATT_CALIB); putsVolts(LEN_CALIB_FIELDS*FW+4*FW, 6*FH-2, g_vbat100mV, (m_posVert==1 ? INVERS : 0)); #endif if (m_posVert==1) CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatCalib, -127, 127); #if defined(PCBSKY9X) && !defined(REVA) lcd_putsLeft(6*FH+1, STR_CURRENT_CALIB); putsTelemetryValue(LEN_CALIB_FIELDS*FW+4*FW, 6*FH+1, getCurrent(), UNIT_MILLIAMPS, (m_posVert==2 ? INVERS : 0)) ; if (m_posVert==2) CHECK_INCDEC_GENVAR(event, g_eeGeneral.currentCalib, -49, 49); #endif #if defined(PCBSKY9X) lcd_putsLeft(7*FH+1, STR_TEMP_CALIB); putsTelemetryValue(LEN_CALIB_FIELDS*FW+4*FW, 7*FH+1, getTemperature(), UNIT_DEGREES, (m_posVert==3 ? INVERS : 0)) ; if (m_posVert==3) CHECK_INCDEC_GENVAR(event, g_eeGeneral.temperatureCalib, -100, 100); #endif }
void menuModelLogicalSwitches(uint8_t event) { SIMPLE_MENU(STR_MENULOGICALSWITCHES, menuTabModel, e_LogicalSwitches, NUM_LOGICAL_SWITCH+1); coord_t y = 0; uint8_t k = 0; int8_t sub = m_posVert - 1; switch (event) { #if defined(ROTARY_ENCODER_NAVIGATION) case EVT_ROTARY_BREAK: #endif case EVT_KEY_FIRST(KEY_RIGHT): case EVT_KEY_FIRST(KEY_ENTER): if (sub >= 0) { s_currIdx = sub; pushMenu(menuModelLogicalSwitchOne); } break; } for (uint8_t i=0; i<LCD_LINES-1; i++) { y = 1 + (i+1)*FH; k = i+s_pgOfs; LogicalSwitchData * cs = lswAddress(k); // CSW name uint8_t sw = SWSRC_SW1+k; putsSwitches(0, y, sw, (sub==k ? INVERS : 0) | (getSwitch(sw) ? BOLD : 0)); if (cs->func > 0) { // CSW func lcd_putsiAtt(CSW_1ST_COLUMN, y, STR_VCSWFUNC, cs->func, 0); // CSW params uint8_t cstate = lswFamily(cs->func); if (cstate == LS_FAMILY_BOOL || cstate == LS_FAMILY_STICKY) { putsSwitches(CSW_2ND_COLUMN, y, cs->v1, 0); putsSwitches(CSW_3RD_COLUMN, y, cs->v2, 0); } else if (cstate == LS_FAMILY_COMP) { putsMixerSource(CSW_2ND_COLUMN, y, cs->v1, 0); putsMixerSource(CSW_3RD_COLUMN, y, cs->v2, 0); } else if (cstate == LS_FAMILY_EDGE) { putsSwitches(CSW_2ND_COLUMN, y, cs->v1, 0); putsEdgeDelayParam(CSW_3RD_COLUMN, y, cs, 0, 0); } else if (cstate == LS_FAMILY_TIMER) { lcd_outdezAtt(CSW_2ND_COLUMN, y, cs->v1+1, LEFT); lcd_outdezAtt(CSW_3RD_COLUMN, y, cs->v2+1, LEFT); } else { uint8_t v1 = cs->v1; putsMixerSource(CSW_2ND_COLUMN, y, v1, 0); if (v1 >= MIXSRC_FIRST_TELEM) { putsTelemetryChannelValue(CSW_3RD_COLUMN, y, v1 - MIXSRC_FIRST_TELEM, convertLswTelemValue(cs), LEFT); } else { lcd_outdezAtt(CSW_3RD_COLUMN, y, cs->v2, LEFT); } } // CSW and switch putsSwitches(CSW_4TH_COLUMN, y, cs->andsw, 0); } } }