diff --git a/src/Makefile b/src/Makefile index 68b73c140..70ae97021 100644 --- a/src/Makefile +++ b/src/Makefile @@ -193,6 +193,10 @@ CURVES = YES # Values = YES, NO XCURVES = YES +# Registers +# Values = YES, NO +REGISTERS = NO + #------- END BUILD OPTIONS --------------------------- # Define programs and commands. @@ -360,6 +364,10 @@ ifeq ($(XCURVES), YES) CPPDEFS += -DXCURVES endif +ifeq ($(REGISTERS), YES) + CPPDEFS += -DREGISTERS +endif + # If STD-Support is enabled ifeq ($(EXT), STD) CPPDEFS += -DEXTSTD diff --git a/src/general_menus.cpp b/src/general_menus.cpp index c9724ff29..23b11f284 100644 --- a/src/general_menus.cpp +++ b/src/general_menus.cpp @@ -90,7 +90,8 @@ void displaySlider(uint8_t x, uint8_t y, uint8_t value, uint8_t attr) #endif enum menuGeneralSetupItems { - IF_RTCLOCK(ITEM_SETUP_RTC) + IF_RTCLOCK(ITEM_SETUP_DATE) + IF_RTCLOCK(ITEM_SETUP_TIME) ITEM_SETUP_BEEPER_MODE, ITEM_SETUP_BEEPER_LENGTH, IF_AUDIO(ITEM_SETUP_SPEAKER_PITCH) @@ -104,7 +105,6 @@ enum menuGeneralSetupItems { IF_PCBSKY9X(ITEM_SETUP_CAPACITY_WARNING) IF_PCBSKY9X(ITEM_SETUP_TEMPERATURE_WARNING) ITEM_SETUP_INACTIVITY_ALARM, - IF_BLUETOOTH(ITEM_SETUP_BT_BAUDRATE) IF_ROTARY_ENCODERS(ITEM_SETUP_RE_NAVIGATION) ITEM_SETUP_FILTER_ADC, ITEM_SETUP_THROTTLE_REVERSED, @@ -126,12 +126,15 @@ enum menuGeneralSetupItems { void menuGeneralSetup(uint8_t event) { - MENU(STR_MENURADIOSETUP, menuTabDiag, e_Setup, ITEM_SETUP_MAX+1, {0, IF_RTCLOCK(5) 0, 0, IF_AUDIO(0) IF_VOICE(0) IF_HAPTIC(0) IF_HAPTIC(0) IF_HAPTIC(0) IF_PCBSKY9X(0) 0, 0, IF_PCBSKY9X(0) IF_PCBSKY9X(0) 0, IF_BLUETOOTH(0) IF_ROTARY_ENCODERS(0) 0, 0, 0, 0, 0, 0, 0, IF_SPLASH(0) 0, 0, IF_FRSKY(0) IF_FRSKY(0) 0, (uint8_t)-1, 1}); + MENU(STR_MENURADIOSETUP, menuTabDiag, e_Setup, ITEM_SETUP_MAX+1, {0, IF_RTCLOCK(2) IF_RTCLOCK(2) 0, 0, IF_AUDIO(0) IF_VOICE(0) IF_HAPTIC(0) IF_HAPTIC(0) IF_HAPTIC(0) IF_PCBSKY9X(0) 0, 0, IF_PCBSKY9X(0) IF_PCBSKY9X(0) 0, IF_ROTARY_ENCODERS(0) 0, 0, 0, 0, 0, 0, 0, IF_SPLASH(0) 0, 0, IF_FRSKY(0) IF_FRSKY(0) 0, (uint8_t)-1, 1}); uint8_t sub = m_posVert - 1; #if defined(RTCLOCK) static struct gtm t; + if ((sub!=ITEM_SETUP_DATE && sub!=ITEM_SETUP_TIME) || s_editMode<=0) { + gettime(&t); + } #endif for (uint8_t i=0; i<7; i++) { @@ -142,19 +145,18 @@ void menuGeneralSetup(uint8_t event) switch(k) { #if defined(RTCLOCK) - case ITEM_SETUP_RTC: - lcd_putsLeft(y, STR_TIME); - lcd_putc(FW*7+6, y, '-'); lcd_putc(FW*10+4, y, '-'); - lcd_putc(FW*15+5, y, ':'); lcd_putc(FW*18+3, y, ':'); - for (uint8_t j=0; j<6; j++) { // 3 settings each for date and time (YMD and HMS) + case ITEM_SETUP_DATE: + lcd_putsLeft(y, PSTR("Date")); + lcd_putc(FW*15+5, y, '-'); lcd_putc(FW*18+3, y, '-'); + for (uint8_t j=0; j<3; j++) { uint8_t rowattr = (m_posHorz==j) ? attr : 0; switch (j) { case 0: - lcd_outdezAtt(FW*7+6, y, t.tm_year+1900, rowattr); + lcd_outdezAtt(FW*15+5, y, t.tm_year+1900, rowattr); if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_year = checkIncDec(event, t.tm_year, 112, 200, 0); break; case 1: - lcd_outdezNAtt(FW*10+4, y, t.tm_mon+1, rowattr|LEADING0, 2); + lcd_outdezNAtt(FW*18+3, y, t.tm_mon+1, rowattr|LEADING0, 2); if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_mon = checkIncDec(event, t.tm_mon, 0, 11, 0); break; case 2: @@ -163,19 +165,34 @@ void menuGeneralSetup(uint8_t event) int8_t dlim = (((((year%4==0) && (year %100!=0)) || (year%400==0)) && (t.tm_mon==1)) ? 1 : 0); int8_t dmon[] = {31,28,31,30,31,30,31,31,30,31,30,31}; // TODO in flash dlim += dmon[t.tm_mon]; - lcd_outdezNAtt(FW*13+2, y, t.tm_mday, rowattr|LEADING0, 2); + lcd_outdezNAtt(FW*21+2, y, t.tm_mday, rowattr|LEADING0, 2); if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_mday = checkIncDec(event, t.tm_mday, 1, dlim, 0); break; } - case 3: + } + } + + if (attr && s_editMode<=0 && event == EVT_KEY_FIRST(KEY_MENU)) { + // set the date and time into RTC chip + rtc_settime(&t); + } + break; + + case ITEM_SETUP_TIME: + lcd_putsLeft(y, STR_TIME); + lcd_putc(FW*15+5, y, ':'); lcd_putc(FW*18+3, y, ':'); + for (uint8_t j=0; j<3; j++) { + uint8_t rowattr = (m_posHorz==j) ? attr : 0; + switch (j) { + case 0: lcd_outdezNAtt(FW*15+5, y, t.tm_hour, rowattr|LEADING0, 2); if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_hour = checkIncDec( event, t.tm_hour, 0, 23, 0); break; - case 4: + case 1: lcd_outdezNAtt(FW*18+3, y, t.tm_min, rowattr|LEADING0, 2); if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_min = checkIncDec( event, t.tm_min, 0, 59, 0); break; - case 5: + case 2: lcd_outdezNAtt(FW*21+2, y, t.tm_sec, rowattr|LEADING0, 2); if (rowattr && (s_editMode>0 || p1valdiff)) t.tm_sec = checkIncDec( event, t.tm_sec, 0, 59, 0); break; @@ -186,9 +203,6 @@ void menuGeneralSetup(uint8_t event) // set the date and time into RTC chip rtc_settime(&t); } - else if (sub!=ITEM_SETUP_RTC || s_editMode<=0) { - gettime(&t); - } break; #endif @@ -305,15 +319,6 @@ void menuGeneralSetup(uint8_t event) if(attr) g_eeGeneral.inactivityTimer = checkIncDec(event, g_eeGeneral.inactivityTimer, 0, 250, EE_GENERAL); //0..250minutes break; -#if defined(BLUETOOTH) - case ITEM_SETUP_BT_BAUDRATE: - g_eeGeneral.btBaudrate = selectMenuItem(GENERAL_PARAM_OFS, y, STR_BAUDRATE, PSTR("\005115k 9600 19200"), g_eeGeneral.btBaudrate, 0, 2, attr, event); - if (attr && checkIncDec_Ret) { - btInit(); - } - break; -#endif - #if defined(ROTARY_ENCODERS) case ITEM_SETUP_RE_NAVIGATION: g_eeGeneral.reNavigation = selectMenuItem(GENERAL_PARAM_OFS, y, STR_RENAVIG, STR_VRENAVIG, g_eeGeneral.reNavigation, 0, ROTARY_ENCODERS, attr, event); @@ -443,6 +448,16 @@ void menuGeneralSdManagerInfo(uint8_t event) lcd_puts(lcdLastPos, 5*FH, "kb/s"); } +inline bool isFilenameGreater(bool isfile, const char * fn, const char * line) +{ + return (isfile && !line[SD_SCREEN_FILE_LENGTH+1]) || (isfile==(bool)line[SD_SCREEN_FILE_LENGTH+1] && strcmp(fn, line) > 0); +} + +inline bool isFilenameLower(bool isfile, const char * fn, const char * line) +{ + return (!isfile && line[SD_SCREEN_FILE_LENGTH+1]) || (isfile==(bool)line[SD_SCREEN_FILE_LENGTH+1] && strcmp(fn, line) < 0); +} + void menuGeneralSdManager(uint8_t event) { FILINFO fno; @@ -483,12 +498,12 @@ void menuGeneralSdManager(uint8_t event) { if (m_posVert > 0) { uint8_t index = m_posVert-1-s_pgOfs; - if (reusableBuffer.sd.flags[index]) { + if (!reusableBuffer.sd.lines[index][SD_SCREEN_FILE_LENGTH+1]) { killEvents(event); f_chdir(reusableBuffer.sd.lines[index]); s_pgOfs = 0; m_posVert = 1; - reusableBuffer.sd.offset = 255; + reusableBuffer.sd.offset = 65535; } } break; @@ -521,30 +536,25 @@ void menuGeneralSdManager(uint8_t event) break; } -#define SD_ALPHABETICAL_ORDER -#ifdef SD_ALPHABETICAL_ORDER if (reusableBuffer.sd.offset != s_pgOfs) { - char hidden_line[SD_SCREEN_FILE_LENGTH+1] = ""; - uint8_t hidden_flag = 0; - if (s_pgOfs == 0) { reusableBuffer.sd.offset = 0; + memset(reusableBuffer.sd.lines, 0, sizeof(reusableBuffer.sd.lines)); } - else if (s_pgOfs >= reusableBuffer.sd.count-7) { - reusableBuffer.sd.offset = s_pgOfs+1; + else if (s_pgOfs == reusableBuffer.sd.count-7) { + reusableBuffer.sd.offset = s_pgOfs; + memset(reusableBuffer.sd.lines, 0, sizeof(reusableBuffer.sd.lines)); } else if (s_pgOfs > reusableBuffer.sd.offset) { - memcpy(hidden_line, reusableBuffer.sd.lines[0], sizeof(hidden_line)); - hidden_flag = reusableBuffer.sd.flags[0]; + memmove(reusableBuffer.sd.lines[0], reusableBuffer.sd.lines[1], 6*sizeof(reusableBuffer.sd.lines[0])); + memset(reusableBuffer.sd.lines[6], 0xff, SD_SCREEN_FILE_LENGTH); + reusableBuffer.sd.lines[6][SD_SCREEN_FILE_LENGTH+1] = 1; } else { - memcpy(hidden_line, reusableBuffer.sd.lines[6], sizeof(hidden_line)); - hidden_flag = reusableBuffer.sd.flags[6]; + memmove(reusableBuffer.sd.lines[1], reusableBuffer.sd.lines[0], 6*sizeof(reusableBuffer.sd.lines[0])); + memset(reusableBuffer.sd.lines[0], 0, sizeof(reusableBuffer.sd.lines[0])); } - memset(reusableBuffer.sd.lines, 0, sizeof(reusableBuffer.sd.lines)); - memset(reusableBuffer.sd.flags, 0, sizeof(reusableBuffer.sd.flags)); - reusableBuffer.sd.count = 0; FRESULT res = f_opendir(&dir, "."); /* Open the directory */ @@ -558,73 +568,53 @@ void menuGeneralSdManager(uint8_t event) #else fn = fno.fname; #endif + if (strlen(fn) > SD_SCREEN_FILE_LENGTH) continue; + reusableBuffer.sd.count++; - bool isdir = (fno.fattrib & AM_DIR); + bool isfile = !(fno.fattrib & AM_DIR); - for (uint8_t i=0; i<7; i++) { - if (s_pgOfs >= reusableBuffer.sd.offset) { + if (s_pgOfs == 0) { + for (uint8_t i=0; i<7; i++) { char *line = reusableBuffer.sd.lines[i]; - if ((!hidden_line[0] || (!isdir && hidden_flag) || (strcmp(hidden_line, fn) < 0)) && (line[0] == '\0' || (isdir&&!reusableBuffer.sd.flags[i]) || strcmp(fn, line) < 0)) { - if (i < 7-1) { - memmove(reusableBuffer.sd.lines[i+1], line, sizeof(reusableBuffer.sd.lines[i]) * (7-1-i)); - memmove(&reusableBuffer.sd.flags[i+1], &reusableBuffer.sd.flags[i], sizeof(reusableBuffer.sd.flags[i]) * (7-1-i)); - } - strncpy(line, fn, SD_SCREEN_FILE_LENGTH); - reusableBuffer.sd.flags[i] = isdir; + if (line[0] == '\0' || isFilenameLower(isfile, fn, line)) { + if (i < 6) memmove(reusableBuffer.sd.lines[i+1], line, sizeof(reusableBuffer.sd.lines[i]) * (6-i)); + memset(line, 0, sizeof(reusableBuffer.sd.lines[i])); + strcpy(line, fn); + line[SD_SCREEN_FILE_LENGTH+1] = isfile; break; } } - else { - char *line = reusableBuffer.sd.lines[6-i]; - if ((!hidden_line[0] || (isdir && !hidden_flag) || (strcmp(hidden_line, fn) > 0)) && (line[0] == '\0' || (!isdir&&reusableBuffer.sd.flags[6-i]) || strcmp(fn, line) > 0)) { - if (i < 7-1) { - memmove(reusableBuffer.sd.lines, reusableBuffer.sd.lines[1], sizeof(reusableBuffer.sd.lines[0]) * (6-i)); - memmove(&reusableBuffer.sd.flags, &reusableBuffer.sd.flags[1], sizeof(reusableBuffer.sd.flags[0]) * (6-i)); - } - strncpy(line, fn, SD_SCREEN_FILE_LENGTH); - reusableBuffer.sd.flags[6-i] = isdir; + } + else if (reusableBuffer.sd.offset == s_pgOfs) { + for (int8_t i=6; i>=0; i--) { + char *line = reusableBuffer.sd.lines[i]; + if (line[0] == '\0' || isFilenameGreater(isfile, fn, line)) { + if (i > 0) memmove(reusableBuffer.sd.lines[0], reusableBuffer.sd.lines[1], sizeof(reusableBuffer.sd.lines[0]) * i); + memset(line, 0, sizeof(reusableBuffer.sd.lines[i])); + strcpy(line, fn); + line[SD_SCREEN_FILE_LENGTH+1] = isfile; break; } } } + else if (s_pgOfs > reusableBuffer.sd.offset) { + if (isFilenameGreater(isfile, fn, reusableBuffer.sd.lines[5]) && isFilenameLower(isfile, fn, reusableBuffer.sd.lines[6])) { + memset(reusableBuffer.sd.lines[6], 0, sizeof(reusableBuffer.sd.lines[0])); + strcpy(reusableBuffer.sd.lines[6], fn); + reusableBuffer.sd.lines[6][SD_SCREEN_FILE_LENGTH+1] = isfile; + } + } + else { + if (isFilenameLower(isfile, fn, reusableBuffer.sd.lines[1]) && isFilenameGreater(isfile, fn, reusableBuffer.sd.lines[0])) { + memset(reusableBuffer.sd.lines[0], 0, sizeof(reusableBuffer.sd.lines[0])); + strcpy(reusableBuffer.sd.lines[0], fn); + reusableBuffer.sd.lines[0][SD_SCREEN_FILE_LENGTH+1] = isfile; + } + } } } } -#else - if (reusableBuffer.sd.offset != s_pgOfs) { - memset(reusableBuffer.sd.lines, 0, sizeof(reusableBuffer.sd.lines)); - memset(reusableBuffer.sd.flags, 0, sizeof(reusableBuffer.sd.flags)); - reusableBuffer.sd.offset = s_pgOfs; - reusableBuffer.sd.count = 0; - uint16_t offset = 0; - uint8_t 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 - reusableBuffer.sd.count++; - if (offset < s_pgOfs) { - offset++; - continue; - } - - if (count < 7) { - reusableBuffer.sd.flags[count] = (fno.fattrib & AM_DIR); - strncpy(reusableBuffer.sd.lines[count], fn, SD_SCREEN_FILE_LENGTH); - count++; - } - } - } - } -#endif reusableBuffer.sd.offset = s_pgOfs; @@ -632,9 +622,11 @@ void menuGeneralSdManager(uint8_t event) uint8_t y = FH+i*FH; uint8_t x = 0; uint8_t attr = (m_posVert-1-s_pgOfs == i ? BSS|INVERS : BSS); - if (reusableBuffer.sd.flags[i]) { lcd_putcAtt(0, y, '[', attr); x += FW; } - lcd_putsAtt(x, y, reusableBuffer.sd.lines[i], attr); - if (reusableBuffer.sd.flags[i]) { lcd_putcAtt(lcdLastPos, y, ']', attr); } + if (reusableBuffer.sd.lines[i][0]) { + if (!reusableBuffer.sd.lines[i][SD_SCREEN_FILE_LENGTH+1]) { lcd_putcAtt(0, y, '[', attr); x += FW; } + lcd_putsAtt(x, y, reusableBuffer.sd.lines[i], attr); + if (!reusableBuffer.sd.lines[i][SD_SCREEN_FILE_LENGTH+1]) { lcd_putcAtt(lcdLastPos, y, ']', attr); } + } } if (s_menu_count) { @@ -883,13 +875,14 @@ void menuGeneralDiagAna(uint8_t event) #if defined(PCBSKY9X) enum menuGeneralHwItems { ITEM_SETUP_HW_OPTREX_DISPLAY, + IF_BLUETOOTH(ITEM_SETUP_HW_BT_BAUDRATE) ITEM_SETUP_HW_MAX }; #define GENERAL_HW_PARAM_OFS (2+(15*FW)) void menuGeneralHardware(uint8_t event) { - MENU(STR_HARDWARE, menuTabDiag, e_Hardware, ITEM_SETUP_HW_MAX+1, {0, 0}); + MENU(STR_HARDWARE, menuTabDiag, e_Hardware, ITEM_SETUP_HW_MAX+1, {0, 0, IF_BLUETOOTH(0)}); uint8_t sub = m_posVert - 1; @@ -903,6 +896,16 @@ void menuGeneralHardware(uint8_t event) case ITEM_SETUP_HW_OPTREX_DISPLAY: g_eeGeneral.optrexDisplay = selectMenuItem(GENERAL_HW_PARAM_OFS, y, STR_LCD, STR_VLCD, g_eeGeneral.optrexDisplay, 0, 1, attr, event); break; + +#if defined(BLUETOOTH) + case ITEM_SETUP_HW_BT_BAUDRATE: + g_eeGeneral.btBaudrate = selectMenuItem(GENERAL_PARAM_OFS, y, STR_BAUDRATE, PSTR("\005115k 9600 19200"), g_eeGeneral.btBaudrate, 0, 2, attr, event); + if (attr && checkIncDec_Ret) { + btInit(); + } + break; +#endif + } } } diff --git a/src/lcd.cpp b/src/lcd.cpp index 1efaf7668..e16ba255a 100644 --- a/src/lcd.cpp +++ b/src/lcd.cpp @@ -596,7 +596,18 @@ void putsSwitches(xcoord_t x, uint8_t y, int8_t idx, uint8_t att) } if (idx > MAX_SWITCH) { idx -= ((att & SWONOFF) ? MAX_SWITCH+1 : MAX_SWITCH); - if (~att & SWCONDENSED) lcd_putcAtt(x+3*FW, y, 'm', att); + char suffix = 'm'; +#if defined(PCBSKY9X) + if (idx > MAX_SWITCH+1) { + suffix = 's'; + idx -= MAX_SWITCH+1; + if (idx > MAX_PSWITCH) { + suffix = 'l'; + idx -= MAX_PSWITCH; + } + } +#endif + if (~att & SWCONDENSED) lcd_putcAtt(x+3*FW, y, suffix, att); } lcd_putsiAtt(x, y, STR_VSWITCHES, idx-1, att); } diff --git a/src/menus.cpp b/src/menus.cpp index 7c7e5f4b0..7e33c7c2f 100644 --- a/src/menus.cpp +++ b/src/menus.cpp @@ -33,7 +33,11 @@ #include "open9x.h" +#if defined(SDCARD) +uint16_t s_pgOfs; +#else uint8_t s_pgOfs; +#endif int8_t s_editMode; uint8_t s_noHi; uint8_t s_noScroll; diff --git a/src/menus.h b/src/menus.h index 417d18af4..26a0caad5 100644 --- a/src/menus.h +++ b/src/menus.h @@ -47,7 +47,11 @@ typedef void (*MenuFuncP)(uint8_t event); void DisplayScreenIndex(uint8_t index, uint8_t count, uint8_t attr); +#if defined(SDCARD) +extern uint16_t s_pgOfs; +#else extern uint8_t s_pgOfs; +#endif extern uint8_t s_noHi; extern uint8_t s_noScroll; diff --git a/src/model_menus.cpp b/src/model_menus.cpp index 597bf10a3..a74330c02 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -2244,7 +2244,7 @@ void menuModelLimits(uint8_t event) #if defined(CURVES) void menuModelCurvesAll(uint8_t event) { - SIMPLE_MENU(STR_MENUCURVES, menuTabModel, e_CurvesAll, 1+MAX_CURVES); + SIMPLE_MENU(STR_MENUCURVES, menuTabModel, e_CurvesAll, 1+MAX_CURVES+MAX_REGISTERS); int8_t sub = m_posVert - 1; @@ -2258,7 +2258,11 @@ void menuModelCurvesAll(uint8_t event) #endif case EVT_KEY_FIRST(KEY_RIGHT): case EVT_KEY_FIRST(KEY_MENU): - if (sub >= 0) { + if (sub >= 0 +#if defined(REGISTERS) + && sub < MAX_CURVES +#endif + ) { s_curveChan = sub; pushMenu(menuModelCurveOne); } @@ -2269,10 +2273,26 @@ void menuModelCurvesAll(uint8_t event) uint8_t y = FH + i*FH; uint8_t k = i + s_pgOfs; uint8_t attr = (sub == k ? INVERS : 0); +#if defined(REGISTERS) + if (k < MAX_CURVES) { + putsStrIdx(0, y, STR_CV, k+1, attr); + } + else { + if (attr && s_editMode>0) attr |= BLINK; + putsStrIdx(0, y, PSTR("Reg.X"), k-MAX_CURVES+1, 0); + lcd_outdezAtt(10*FW, y, g_model.registers[k-MAX_CURVES], attr); + if (attr) CHECK_INCDEC_MODELVAR(event, g_model.registers[k-MAX_CURVES], -125, 125); + } +#else putsStrIdx(0, y, STR_CV, k+1, attr); +#endif } - if (sub >= 0) { + if (sub >= 0 +#if defined(REGISTERS) + && sub < MAX_CURVES +#endif + ) { s_curveChan = sub; DrawCurve(curveFn, 25); } @@ -2575,7 +2595,11 @@ void menuModelFunctionSwitches(uint8_t event) } putsSwitches(3, y, sd->swtch, SWONOFF | attr | ((abs(sd->swtch) <= (MAX_SWITCH+1) && getSwitch(sd->swtch, 0) && (sd->func > FUNC_INSTANT_TRIM || sd->delay)) ? BOLD : 0)); if (active || AUTOSWITCH_MENU_LONG()) { - CHECK_INCDEC_MODELSWITCH(event, sd->swtch, SWITCH_OFF-MAX_SWITCH, SWITCH_ON+MAX_SWITCH+1); +#if defined(PCBSKY9X) + CHECK_INCDEC_MODELSWITCH(event, sd->swtch, SWITCH_OFF-MAX_SWITCH, SWITCH_ON+MAX_SWITCH+1+2*MAX_PSWITCH); +#else + CHECK_INCDEC_MODELSWITCH(event, sd->swtch, SWITCH_OFF-MAX_SWITCH, SWITCH_ON+MAX_SWITCH+1); +#endif } break; case 1: diff --git a/src/myeeprom.h b/src/myeeprom.h index 7517a2d99..49f944a72 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -372,6 +372,7 @@ enum Functions { FUNC_BACKLIGHT, #if defined(PCBSKY9X) FUNC_BACKGND_MUSIC, + FUNC_BACKGND_MUSIC_PAUSE, #endif #if defined(DEBUG) FUNC_TEST, // should remain the last before MAX as not added in companion9x @@ -719,6 +720,14 @@ PACK(typedef struct t_TimerDataExtra { #define EXTRA_MODEL_FIELDS #endif +#if defined(REGISTERS) +#define MAX_REGISTERS 2 +#define EXTRA_REGISTERS uint8_t registers[MAX_REGISTERS] +#else +#define MAX_REGISTERS 0 +#define EXTRA_REGISTERS +#endif + PACK(typedef struct t_ModelData { char name[LEN_MODEL_NAME]; // must be first for eeLoadModelName TimerData timers[MAX_TIMERS]; @@ -756,6 +765,8 @@ PACK(typedef struct t_ModelData { ROTARY_ENCODER_ARRAY_EXTRA; EXTRA_MODEL_FIELDS; + + EXTRA_REGISTERS; }) ModelData; extern EEGeneral g_eeGeneral; diff --git a/src/open9x.cpp b/src/open9x.cpp index d596a6f43..8b813b89a 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -1005,9 +1005,9 @@ void checkBacklight() } if (g_eeGeneral.backlightMode == e_backlight_mode_on || g_LightOffCounter || isFunctionActive(FUNC_BACKLIGHT)) - BACKLIGHT_ON; + BACKLIGHT_ON(); else - BACKLIGHT_OFF; + BACKLIGHT_OFF(); #if defined(PCBSTD) && defined(VOICE) && !defined(SIMU) Voice.voice_process() ; @@ -1754,7 +1754,7 @@ void testFunc() } #endif -uint16_t activeFunctions = 0; +MASK_FUNC_TYPE activeFunctions = 0; MASK_FSW_TYPE activeFunctionSwitches = 0; #if defined(VOICE) @@ -1885,13 +1885,18 @@ PLAY_FUNCTION(playValue, uint8_t idx) #if defined(PCBSKY9X) static uint8_t currentSpeakerVolume = 255; uint8_t requiredSpeakerVolume; +uint8_t fnSwitchDuration[NUM_FSW] = { 0 }; +#define FSW_PRESSLONG_DURATION 100 +#define COMPLEX_SWITCH (momentary || shrt || lng) +#else +#define COMPLEX_SWITCH (momentary) #endif void evalFunctions() { - assert((int)(sizeof(activeFunctions)*8) > (int)(FUNC_MAX-NUM_CHNOUT)); + assert((int)(sizeof(activeFunctions)*8) > (int)(FUNC_MAX-FUNC_TRAINER)); - uint16_t newActiveFunctions = 0; + MASK_FUNC_TYPE newActiveFunctions = 0; for (uint8_t i=0; iswtch; if (swtch) { - uint16_t function_mask = (sd->func >= FUNC_TRAINER ? (1 << (sd->func-FUNC_TRAINER)) : 0); + MASK_FUNC_TYPE function_mask = (sd->func >= FUNC_TRAINER ? ((MASK_FUNC_TYPE)1 << (sd->func-FUNC_TRAINER)) : 0); MASK_FSW_TYPE switch_mask = ((MASK_FSW_TYPE)1 << i); uint8_t momentary = 0; +#if defined(PCBSKY9X) + uint8_t shrt=0, lng=0; + if (swtch > MAX_SWITCH+1+MAX_SWITCH+1+MAX_PSWITCH) { + lng = 1; + swtch -= MAX_SWITCH+1+MAX_SWITCH+1+MAX_PSWITCH; + } + else if (swtch > MAX_SWITCH+1+MAX_SWITCH+1) { + shrt = 1; + swtch -= MAX_SWITCH+1+MAX_SWITCH+1; + } + else +#endif if (swtch > MAX_SWITCH+1) { momentary = 1; swtch -= MAX_SWITCH+1; @@ -1911,7 +1928,23 @@ void evalFunctions() momentary = 1; swtch += MAX_SWITCH+1; } +#if defined(PCBSKY9X) + bool sw; + if ((sw=getSwitch(swtch, 0)) || (shrt&&fnSwitchDuration[i]>0&&fnSwitchDuration[i]=(uint8_t)FSW_PRESSLONG_DURATION)) { + if (shrt || lng) { + if (sw) { + if (fnSwitchDuration[i] < 255) + fnSwitchDuration[i]++; + newActiveFunctions |= (activeFunctions & function_mask); + continue; + } + else { + fnSwitchDuration[i] = 0; + } + } +#else if (getSwitch(swtch, 0)) { +#endif if (sd->delay) { if (sd->func < FUNC_TRAINER) { safetyCh[sd->func] = FSW_PARAM(sd); @@ -1948,7 +1981,7 @@ void evalFunctions() case 2: resetAll(); break; -#ifdef FRSKY +#if defined(FRSKY) case 3: resetTelemetry(); break; @@ -1957,7 +1990,16 @@ void evalFunctions() } } - if ((!momentary) || (~activeFunctionSwitches & switch_mask)) { +#if defined(PCBSKY9X) + if ((shrt || lng) && (activeFunctions & function_mask)) { + if (sd->func == FUNC_BACKGND_MUSIC) { + STOP_PLAY(i+1); + } + } + else +#endif + + if (!COMPLEX_SWITCH || (~activeFunctionSwitches & switch_mask)) { if (sd->func == FUNC_PLAY_SOUND) { AUDIO_PLAY(AU_FRSKY_FIRST+FSW_PARAM(sd)); } @@ -2018,7 +2060,7 @@ void evalFunctions() #endif } - if (momentary) { + if (COMPLEX_SWITCH) { if (~activeFunctionSwitches & switch_mask) { if (~activeFunctions & function_mask) { newActiveFunctions |= function_mask; @@ -2035,13 +2077,16 @@ void evalFunctions() activeFunctionSwitches |= switch_mask; } else { +#if defined(PCBSKY9X) + fnSwitchDuration[i] = 0; +#endif #if defined(PCBSKY9X) && defined(SDCARD) - if (sd->func == FUNC_BACKGND_MUSIC) { + if (!COMPLEX_SWITCH && sd->func == FUNC_BACKGND_MUSIC) { STOP_PLAY(i+1); } #endif activeFunctionSwitches &= (~switch_mask); - if (momentary) + if (COMPLEX_SWITCH) newActiveFunctions |= (activeFunctions & function_mask); } } @@ -3498,7 +3543,7 @@ int main(void) g_eeGeneral.backlightBright = 0; g_eeGeneral.contrast = 25; - BACKLIGHT_ON; + BACKLIGHT_ON(); lcd_clear(); lcd_putcAtt( 48, 24, 'U', DBLSIZE ) ; diff --git a/src/open9x.h b/src/open9x.h index ac3952b6a..11fca9f01 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -796,11 +796,11 @@ void read_9_adc(void ) ; #endif #if defined(PCBSTD) && defined(VOICE) && !defined(SIMU) -#define BACKLIGHT_ON (Voice.Backlight = 1) -#define BACKLIGHT_OFF (Voice.Backlight = 0) +#define BACKLIGHT_ON() (Voice.Backlight = 1) +#define BACKLIGHT_OFF() (Voice.Backlight = 0) #else -#define BACKLIGHT_ON __BACKLIGHT_ON -#define BACKLIGHT_OFF __BACKLIGHT_OFF +#define BACKLIGHT_ON() __BACKLIGHT_ON +#define BACKLIGHT_OFF() __BACKLIGHT_OFF #endif #define BUZZER_ON PORTE |= (1 << OUT_E_BUZZER) @@ -1021,15 +1021,17 @@ inline bool isMixActive(uint8_t mix) #if defined(PCBSKY9X) #define MASK_FSW_TYPE uint32_t // current max = 32 function switches +#define MASK_FUNC_TYPE uint32_t // current max = 32 functions #else #define MASK_FSW_TYPE uint16_t // current max = 16 function switches +#define MASK_FUNC_TYPE uint16_t // current max = 16 functions #endif extern MASK_FSW_TYPE activeFunctionSwitches; -extern uint16_t activeFunctions; +extern MASK_FUNC_TYPE activeFunctions; inline bool isFunctionActive(uint8_t func) { - return activeFunctions & (1 << (func-FUNC_TRAINER)); + return activeFunctions & ((MASK_FUNC_TYPE)1 << (func-FUNC_TRAINER)); } #if defined(ROTARY_ENCODERS) @@ -1180,20 +1182,19 @@ union ReusableBuffer char menu_bss[MENU_MAX_LINES][MENU_LINE_LENGTH]; #endif - } models; // 128bytes used by menuModelSelect (mainname reused for SD card archive / restore) + } models; // 128bytes used by menuModelSelect (mainname reused for SD card archive / restore) struct { int16_t midVals[7]; int16_t loVals[7]; int16_t hiVals[7]; - } calib; // 42 bytes used by menuGeneralCalib + } calib; // 42 bytes used by menuGeneralCalib #if defined(SDCARD) struct { - char lines[7][SD_SCREEN_FILE_LENGTH+1]; - uint8_t flags[7]; + char lines[7][SD_SCREEN_FILE_LENGTH+1+1]; // the last char is used to store the flags (directory) of the line uint32_t available; uint16_t offset; uint16_t count; diff --git a/src/simu.cpp b/src/simu.cpp index fc0d6d3ca..d66e940f9 100644 --- a/src/simu.cpp +++ b/src/simu.cpp @@ -314,7 +314,7 @@ long Open9xSim::onTimeout(FXObject*,FXSelector,void*) #endif #if defined(PCBSKY9X) PIOA->PIO_PDSR |= (0x00800000 | 0x01000000 | 0x00000002 | 0x00000001); - PIOB->PIO_PDSR |= (0x00000010); + PIOB->PIO_PDSR |= (0x00000050); PIOC->PIO_PDSR |= (0x10000000 | 0x00000400 | 0x00000200); #elif defined(PCBGRUVIN9X) pinj = 0; diff --git a/src/sky9x/audio.cpp b/src/sky9x/audio.cpp index 257908a14..b4cc4db9f 100644 --- a/src/sky9x/audio.cpp +++ b/src/sky9x/audio.cpp @@ -335,7 +335,13 @@ void AudioQueue::wakeup() } #if defined(SDCARD) && !defined(SIMU) else if (ridx == widx && prioIdx < 0 && backgroundContext.fragment.file[0]) { - sdWakeup(backgroundContext); + if (!isFunctionActive(FUNC_BACKGND_MUSIC_PAUSE)) { + sdWakeup(backgroundContext); + } + else { + CoSetTmrCnt(audioTimer, 5/*10ms*/, 0); + CoStartTmr(audioTimer); + } } #endif else if (ridx == widx && prioIdx < 0 && backgroundContext.fragment.duration > 0) { diff --git a/src/translations/cz.h b/src/translations/cz.h index 279bb910a..e8c4676b1 100644 --- a/src/translations/cz.h +++ b/src/translations/cz.h @@ -115,7 +115,7 @@ #define TR_SDCLOGS "[Logov\200n\204 SD]" #endif #define TR_FSW_VOLUME "Hlasitost\0 " -#define TR_FSW_BG_MUSIC "Hudba BG\0 " +#define TR_FSW_BG_MUSIC "Hudba BG\0 ""BgMusic Pause" #elif defined(PCBGRUVIN9X) #if defined(SDCARD) #define TR_SDCLOGS "Logování SD " @@ -258,8 +258,8 @@ #define TR_EDITMIX "UPRAVIT MIX " #define TR_SOURCE "Zdroj" #define TR_WEIGHT "V\200ha" -#define TR_EXPO "Expo" -#define TR_SIDE "Strana" +#define TR_EXPO "Expo" +#define TR_SIDE "Side" #define TR_MIXERWEIGHT "V\200ha Mixu" #define TR_DIFFERENTIAL "Dif.V\212chylek" #define TR_OFFSET "Ofset" @@ -301,7 +301,7 @@ #define TR_CONTRAST "Kontrast" #define TR_BATTERYWARNING "Alarm Baterie" #define TR_INACTIVITYALARM "UpozNaNe\201innost" -#define TR_RENAVIG "Navig. RotEnc" +#define TR_RENAVIG "Navig RotEnc" #define TR_FILTERADC "Filtr ADC" #define TR_THROTTLEREVERSE "Revers Plynu" #define TR_MINUTEBEEP "P\204pat: Minuta" @@ -326,7 +326,7 @@ #define TR_MENUTOSTART " [MENU] = START" #define TR_SETMIDPOINT "NASTAV ST\215EDY" #define TR_MOVESTICKSPOTS "H\216BEJ P\213KY/POTY" -#define TR_RXBATT "Rx Bat.:" +#define TR_RXBATT "Rx Batt:" #define TR_TXnRX "Tx:\0Rx:" #define OFS_RX 4 #define TR_ACCEL "Acc:" @@ -395,8 +395,8 @@ #define TR_GPSCOORD "Gps Sou\206adnice" #define TR_VARIO "Vario" #define TR_SHUTDOWN "VYP\214N\213\N\204.." -#define TR_BATT_CALIB "Kalib:Baterie" -#define TR_CURRENT_CALIB " += Proud" +#define TR_BATT_CALIB "Kalibrace Bat" +#define TR_CURRENT_CALIB "Kalib.Proudu" #define TR_VOLTAGE "Nap\203t\204" #define TR_CURRENT "Proud" #define TR_SELECT_MODEL "Vyber Model" @@ -416,20 +416,20 @@ #define TR_SPEAKER_VOLUME "Hlasitost" #define TR_LCD "LCD" #define TR_BRIGHTNESS "Jas" -#define TR_CPU_TEMP "Tepl. CPU\007>" -#define TR_CPU_CURRENT "Proud \011>" -#define TR_CPU_MAH "Spot\206eba" +#define TR_CPU_TEMP "tepl. CPU\007>" +#define TR_CPU_CURRENT "Current\011>" +#define TR_CPU_MAH "Consumpt." #define TR_COPROC "CoProc." -#define TR_COPROC_TEMP "Tepl. MB \007>" -#define TR_CAPAWARNING "Alarm Kapacity" -#define TR_TEMPWARNING "Alarm Teploty" -#define TR_FUNC "Fce." +#define TR_COPROC_TEMP "tepl. MB \007>" +#define TR_CAPAWARNING "Capacity Warning" +#define TR_TEMPWARNING "Temp Warning" +#define TR_FUNC "Fun." #define TR_V1 "V1" #define TR_V2 "V2" #define TR_DURATION "Trv\200n\204" #define TR_DELAY "Zdr\217et" -#define TR_SD_CARD "SD" -#define TR_SDHC_CARD "SD-HC" +#define TR_SD_CARD "SD Karta" +#define TR_SDHC_CARD "SD-HC Karta" #define TR_NO_SOUNDS_ON_SD "\217\200dn\212 zvuk na SD" #define TR_NO_MODELS_ON_SD "\217\200dn\212 model na SD" #define TR_PLAY_FILE "P\206ehr\200t" @@ -437,17 +437,17 @@ #define TR_COPY_FILE "Kop\204rovat" #define TR_RENAME_FILE "P\206ejmenovat" #define TR_REMOVED " odstran\203n" -#define TR_SD_INFO "Informace" -#define TR_SD_FORMAT "Form\200t" +#define TR_SD_INFO "Information" +#define TR_SD_FORMAT "Format" #define TR_NA "[X]" #define TR_HARDWARE "HARDWARE" -#define TR_FORMATTING "Form\200tovan\204.." -#define TR_TEMP_CALIB " += Teplota" -#define TR_TIME "\201as" +#define TR_FORMATTING "Formatting..." +#define TR_TEMP_CALIB "Temp. Calib" +#define TR_TIME "Time" #define TR_BAUDRATE "BT Baudrate" #define TR_SD_INFO_TITLE "SD INFO" -#define TR_SD_TYPE "Typ:" -#define TR_SD_SPEED "Rychlost:" -#define TR_SD_SECTORS "Sektor\211 :" -#define TR_SD_SIZE "Velikost:" -#define TR_CURVE_TYPE TR_SD_TYPE +#define TR_SD_TYPE "Type:" +#define TR_SD_SPEED "Speed:" +#define TR_SD_SECTORS "Sectors:" +#define TR_SD_SIZE "Size:" +#define TR_CURVE_TYPE "Type" diff --git a/src/translations/de.h b/src/translations/de.h index d43153c23..de5afa48e 100644 --- a/src/translations/de.h +++ b/src/translations/de.h @@ -115,7 +115,7 @@ #define TR_SDCLOGS "[SDCARD Logs]" #endif #define TR_FSW_VOLUME "Volume\0 " -#define TR_FSW_BG_MUSIC "Bg Music\0 " +#define TR_FSW_BG_MUSIC "BgMusic\0 ""BgMusic Pause" #elif defined(PCBGRUVIN9X) #if defined(SDCARD) #define TR_SDCLOGS "SDcard Logs " diff --git a/src/translations/en.h b/src/translations/en.h index 3ef086e92..e2f0c13e0 100644 --- a/src/translations/en.h +++ b/src/translations/en.h @@ -115,7 +115,7 @@ #define TR_SDCLOGS "[SDCARD Logs]" #endif #define TR_FSW_VOLUME "Volume\0 " -#define TR_FSW_BG_MUSIC "Bg Music\0 " +#define TR_FSW_BG_MUSIC "BgMusic\0 ""BgMusic Pause" #elif defined(PCBGRUVIN9X) #if defined(SDCARD) #define TR_SDCLOGS "SDCARD Logs " diff --git a/src/translations/fr.h b/src/translations/fr.h index ec10d2421..58c542fca 100644 --- a/src/translations/fr.h +++ b/src/translations/fr.h @@ -110,7 +110,7 @@ #define TR_SDCLOGS "[Logs SD]\0 " #endif #define TR_FSW_VOLUME "Volume\0 " -#define TR_FSW_BG_MUSIC "Bg Music\0 " +#define TR_FSW_BG_MUSIC "BgMusic\0 ""BgMusic Pause" #elif defined(PCBGRUVIN9X) #if defined(SDCARD) #define TR_SDCLOGS "Logs carte SD" diff --git a/src/translations/it.h b/src/translations/it.h index 7c5967f5d..52adbd831 100644 --- a/src/translations/it.h +++ b/src/translations/it.h @@ -115,7 +115,7 @@ #define TR_SDCLOGS "[SDCARD Logs]" #endif #define TR_FSW_VOLUME "Volume\0 " -#define TR_FSW_BG_MUSIC "Bg Music\0 " +#define TR_FSW_BG_MUSIC "BgMusic\0 ""BgMusic Pause" #elif defined(PCBGRUVIN9X) #if defined(SDCARD) #define TR_SDCLOGS "SDCARD Logs" diff --git a/src/translations/se.h b/src/translations/se.h index c9a1a7b16..6fea25a87 100644 --- a/src/translations/se.h +++ b/src/translations/se.h @@ -110,7 +110,7 @@ #define TR_SDCLOGS "[SDCARD Logg]" #endif #define TR_FSW_VOLUME "Volym\0 " -#define TR_FSW_BG_MUSIC "Bg Musik\0 " +#define TR_FSW_BG_MUSIC "BgMusik\0 ""BgMusik Pause" #elif defined(PCBGRUVIN9X) #if defined(SDCARD) #define TR_SDCLOGS "SDCARD Loggar" @@ -160,7 +160,7 @@ #define TR_VALARMFN "<>" #define LEN_VTELPROTO "\007" -#define TR_VTELPROTO "---\0 ""Hub\0 ""WSHH\202g.""Halcyon" +#define TR_VTELPROTO "---\0 ""Hub\0 ""WSHHigh""Halcyon" #define LEN_VOLTSRC "\003" #define TR_VOLTSRC "---""A1\0""A2\0""FAS""Cel" @@ -424,8 +424,8 @@ #define TR_FUNC "Funk" #define TR_V1 "V1" #define TR_V2 "V2" -#define TR_DURATION "Tidlängd" -#define TR_DELAY "Fördröj" +#define TR_DURATION "Varaktighet" +#define TR_DELAY "Fördröjning" #define TR_SD_CARD "SD-kord" #define TR_SDHC_CARD "SD/HC-kort" #define TR_NO_SOUNDS_ON_SD "Inga ljud i SD" @@ -438,14 +438,14 @@ #define TR_SD_INFO "Information" #define TR_SD_FORMAT "Format" #define TR_NA "N/A" -#define TR_HARDWARE "H\203RDVARA" -#define TR_FORMATTING "Formaterar..." -#define TR_TEMP_CALIB "Temp.kalib." -#define TR_TIME "Tid " +#define TR_HARDWARE "HARDWARE" +#define TR_FORMATTING "Formatting..." +#define TR_TEMP_CALIB "Temp. Calib" +#define TR_TIME "Time" #define TR_BAUDRATE "BT Baudrate" #define TR_SD_INFO_TITLE "SD INFO" -#define TR_SD_TYPE "Typ: " -#define TR_SD_SPEED "Hastighet:" -#define TR_SD_SECTORS "Sektorer:" -#define TR_SD_SIZE "Strl:" -#define TR_CURVE_TYPE "Typ " +#define TR_SD_TYPE "Type:" +#define TR_SD_SPEED "Speed:" +#define TR_SD_SECTORS "Sectors:" +#define TR_SD_SIZE "Size:" +#define TR_CURVE_TYPE "Type"