[X9D] Custom Switches screen reworked

This commit is contained in:
bsongis
2013-02-22 18:36:34 +00:00
parent d9d52762ae
commit 3e91b3f46d
12 changed files with 158 additions and 71 deletions
+2 -1
View File
@@ -283,8 +283,9 @@ void audioTimerHandle(void)
#ifndef SIMU
void audioTask(void* pdata)
{
while (audioQueue.busy())
while (!audioQueue.started()) {
CoWaitForSingleFlag(audioFlag, 0);
}
#if defined(SDCARD)
if (!unexpectedShutdown) {
+5
View File
@@ -107,6 +107,11 @@ class AudioQueue {
bool isPlaying(uint8_t id);
bool started()
{
return (state != AUDIO_NOT_STARTED);
}
bool busy()
{
#ifdef SIMU
+1
View File
@@ -406,6 +406,7 @@ void eeLoadModel(uint8_t id)
activeSwitches = 0;
activeFnSwitches = 0;
activeFunctions = 0;
memclear(lastFunctionTime, sizeof(lastFunctionTime));
for (uint8_t i=0; i<MAX_TIMERS; i++) {
if (g_model.timers[i].remanent) {
+1
View File
@@ -177,5 +177,6 @@ void sdPoll10ms();
// Power driver
uint8_t pwrCheck();
#define UNEXPECTED_SHUTDOWN() ((mcusr & (1 << WDRF)) || g_eeGeneral.unexpectedShutdown)
#endif
+2 -2
View File
@@ -445,10 +445,10 @@ void menuMainView(uint8_t event)
displaySliders();
#if defined(PCBX9D)
if(modelBitmapLoaded == NULL)
if (modelBitmapLoaded == NULL)
lcd_bmp(BITMAP_X, BITMAP_Y, modelBitmap);
else
lcd_bmp(BITMAP_X, BITMAP_Y, x9d_logo);
lcd_bmp(BITMAP_X, BITMAP_Y, x9d_logo);
#endif
// Switches
+108 -34
View File
@@ -109,7 +109,8 @@ inline uint8_t eeFindEmptyModel(uint8_t id, bool down)
}
#if defined(SDCARD)
bool listSdFiles(const char *path, const char *extension, const uint8_t maxlen, const char *selection)
#define LIST_NONE_SD_FILE 1
bool listSdFiles(const char *path, const char *extension, const uint8_t maxlen, const char *selection, uint8_t flags=0)
{
FILINFO fno;
DIR dir;
@@ -121,9 +122,11 @@ bool listSdFiles(const char *path, const char *extension, const uint8_t maxlen,
#endif
static uint16_t s_last_menu_offset = 0;
static uint8_t s_last_flags;
#if defined(CPUARM)
if (selection) {
s_last_flags = flags;
memset(reusableBuffer.models.menu_bss, 0, sizeof(reusableBuffer.models.menu_bss));
strcpy(reusableBuffer.models.menu_bss[0], path);
strcat(reusableBuffer.models.menu_bss[0], "/");
@@ -133,6 +136,9 @@ bool listSdFiles(const char *path, const char *extension, const uint8_t maxlen,
selection = NULL;
}
}
else {
flags = s_last_flags;
}
#endif
if (s_menu_offset == 0) {
@@ -140,7 +146,8 @@ bool listSdFiles(const char *path, const char *extension, const uint8_t maxlen,
memset(reusableBuffer.models.menu_bss, 0, sizeof(reusableBuffer.models.menu_bss));
}
else if (s_menu_offset == s_last_menu_offset) {
return true; // should not happen, only there because of Murphy's law
// should not happen, only there because of Murphy's law
return true;
}
else if (s_menu_offset > s_last_menu_offset) {
memmove(reusableBuffer.models.menu_bss[0], reusableBuffer.models.menu_bss[1], (MENU_MAX_LINES-1)*MENU_LINE_LENGTH);
@@ -156,6 +163,21 @@ bool listSdFiles(const char *path, const char *extension, const uint8_t maxlen,
FRESULT res = f_opendir(&dir, path); /* Open the directory */
if (res == FR_OK) {
if (flags & LIST_NONE_SD_FILE) {
s_menu_count++;
if (!selection) {
char *line;
if (s_menu_offset > 0 && s_menu_offset > s_last_menu_offset)
line = reusableBuffer.models.menu_bss[MENU_MAX_LINES-1];
else {
line = reusableBuffer.models.menu_bss[0];
memset(line, 0, MENU_LINE_LENGTH);
strcpy(line, "---");
}
}
}
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 */
@@ -792,7 +814,7 @@ void menuModelSetup(uint8_t event)
if (attr && event==EVT_KEY_BREAK(KEY_ENTER)) {
s_editMode = 0;
_event = 0;
if (!listSdFiles(BITMAPS_PATH, BITMAPS_EXT, sizeof(g_model.bitmap), g_model.bitmap)) {
if (!listSdFiles(BITMAPS_PATH, BITMAPS_EXT, sizeof(g_model.bitmap), g_model.bitmap, LIST_NONE_SD_FILE)) {
s_warning = STR_NO_BITMAPS_ON_SD;
s_menu_flags = 0;
}
@@ -2939,16 +2961,23 @@ void menuModelGVars(uint8_t event)
}
#endif
#if defined(CPUARM)
enum CustomSwitchFields {
CSW_FIELD_FUNCTION,
CSW_FIELD_V1,
CSW_FIELD_V2,
CSW_FIELD_ANDSW,
#if defined(CPUARM)
CSW_FIELD_DURATION,
CSW_FIELD_DELAY,
CSW_FIELD_COUNT
#endif
CSW_FIELD_COUNT,
CSW_FIELD_LAST = CSW_FIELD_COUNT-1
};
#define CSW_2ND_COLUMN (9*FW)
#if defined(CPUARM) && LCD_W < 212
#define CSWONE_2ND_COLUMN (11*FW)
void menuModelCustomSwitchOne(uint8_t event)
{
TITLE(STR_MENUCUSTOMSWITCH);
@@ -2961,14 +2990,14 @@ void menuModelCustomSwitchOne(uint8_t event)
int8_t sub = m_posVert;
for (uint8_t k=0; k<LCD_LINES-1; k++) {
uint8_t y = 1 + (k+2)*FH;
uint8_t y = 1 + (k+1)*FH;
uint8_t i = k + s_pgOfs;
uint8_t attr = (sub==i ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0);
uint8_t cstate = CS_STATE(cs->func);
switch(i) {
case CSW_FIELD_FUNCTION:
lcd_putsLeft(y, STR_FUNC);
lcd_putsiAtt(CSW_2ND_COLUMN, y, STR_VCSWFUNC, cs->func, attr);
lcd_putsiAtt(CSWONE_2ND_COLUMN, y, STR_VCSWFUNC, cs->func, attr);
if (attr) {
CHECK_INCDEC_MODELVAR_ZERO(event, cs->func, CS_MAXF);
if (cstate != CS_STATE(cs->func)) {
@@ -2982,11 +3011,11 @@ void menuModelCustomSwitchOne(uint8_t event)
lcd_putsLeft(y, STR_V1);
int8_t v1_min=0, v1_max=MIXSRC_LAST_CH+NUM_TELEMETRY;
if (cstate == CS_VBOOL) {
putsSwitches(CSW_2ND_COLUMN, y, cs->v1, attr);
putsSwitches(CSWONE_2ND_COLUMN, y, cs->v1, attr);
v1_min = SWSRC_OFF+1; v1_max = SWSRC_ON-1;
}
else {
putsMixerSource(CSW_2ND_COLUMN, y, cs->v1, attr);
putsMixerSource(CSWONE_2ND_COLUMN, y, cs->v1, attr);
}
if (attr) {
CHECK_INCDEC_MODELVAR(event, cs->v1, v1_min, v1_max);
@@ -2998,16 +3027,16 @@ void menuModelCustomSwitchOne(uint8_t event)
lcd_putsLeft(y, STR_V2);
int8_t v2_min=0, v2_max=MIXSRC_LAST_CH+NUM_TELEMETRY;
if (cstate == CS_VBOOL) {
putsSwitches(CSW_2ND_COLUMN, y, cs->v2, attr);
putsSwitches(CSWONE_2ND_COLUMN, y, cs->v2, attr);
v2_min = SWSRC_OFF+1; v2_max = SWSRC_OFF-1;
}
else if (cstate == CS_VCOMP) {
putsMixerSource(CSW_2ND_COLUMN, y, cs->v2, attr);
putsMixerSource(CSWONE_2ND_COLUMN, y, cs->v2, attr);
}
else {
#if defined(FRSKY)
if (cs->v1 > MIXSRC_LAST_CH) {
putsTelemetryChannel(CSW_2ND_COLUMN, y, cs->v1 - MIXSRC_LAST_CH - 1, convertCswTelemValue(cs), attr|LEFT);
putsTelemetryChannel(CSWONE_2ND_COLUMN, y, cs->v1 - MIXSRC_LAST_CH - 1, convertCswTelemValue(cs), attr|LEFT);
v2_max = maxTelemValue(cs->v1 - MIXSRC_LAST_CH);
if (cstate == CS_VOFS) {
v2_min = -128;
@@ -3026,7 +3055,7 @@ void menuModelCustomSwitchOne(uint8_t event)
#endif
{
v2_min = -125; v2_max = 125;
lcd_outdezAtt(CSW_2ND_COLUMN, y, cs->v2, attr|LEFT);
lcd_outdezAtt(CSWONE_2ND_COLUMN, y, cs->v2, attr|LEFT);
}
}
@@ -3035,26 +3064,36 @@ void menuModelCustomSwitchOne(uint8_t event)
}
break;
}
case CSW_FIELD_ANDSW:
lcd_putsLeft(y, PSTR("AND Switch"));
lcd_putsiAtt(CSWONE_2ND_COLUMN, y, STR_VSWITCHES_SHORT, cs->andsw, attr);
if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, cs->andsw, 15);
break;
case CSW_FIELD_DURATION:
lcd_putsLeft(y, STR_DURATION);
if (cs->duration > 0)
lcd_outdezAtt(CSW_2ND_COLUMN, y, 5*cs->duration, attr|PREC1|LEFT);
lcd_outdezAtt(CSWONE_2ND_COLUMN, y, 5*cs->duration, attr|PREC1|LEFT);
else
lcd_putsiAtt(CSW_2ND_COLUMN, y, STR_MMMINV, 0, attr);
lcd_putsiAtt(CSWONE_2ND_COLUMN, y, STR_MMMINV, 0, attr);
if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, cs->duration, MAX_CSW_DURATION);
break;
case CSW_FIELD_DELAY:
lcd_putsLeft(y, STR_DELAY);
if (cs->delay > 0)
lcd_outdezAtt(CSW_2ND_COLUMN, y, 5*cs->delay, attr|PREC1|LEFT);
lcd_outdezAtt(CSWONE_2ND_COLUMN, y, 5*cs->delay, attr|PREC1|LEFT);
else
lcd_putsiAtt(CSW_2ND_COLUMN, y, STR_MMMINV, 0, attr);
lcd_putsiAtt(CSWONE_2ND_COLUMN, y, STR_MMMINV, 0, attr);
if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, cs->delay, MAX_CSW_DELAY);
break;
}
}
}
#define CSW_1ST_COLUMN (4*FW-3)
#define CSW_2ND_COLUMN (10*FW+1)
#define CSW_3RD_COLUMN (18*FW+2)
#define CSW_4TH_COLUMN (20*FW+1)
void menuModelCustomSwitches(uint8_t event)
{
SIMPLE_MENU(STR_MENUCUSTOMSWITCHES, menuTabModel, e_CustomSwitches, NUM_CSW+1);
@@ -3090,32 +3129,35 @@ void menuModelCustomSwitches(uint8_t event)
if (cs->func > 0) {
// CSW func
lcd_putsiAtt(4*FW-3, y, STR_VCSWFUNC, cs->func, 0);
lcd_putsiAtt(CSW_1ST_COLUMN, y, STR_VCSWFUNC, cs->func, 0);
// CSW params
uint8_t cstate = CS_STATE(cs->func);
if (cstate == CS_VBOOL) {
putsSwitches(10*FW, y, cs->v1, 0);
putsSwitches(16*FW, y, cs->v2, 0);
putsSwitches(CSW_2ND_COLUMN, y, cs->v1, 0);
putsSwitches(CSW_3RD_COLUMN, y, cs->v2, 0);
}
else if (cstate == CS_VCOMP) {
putsMixerSource(10*FW, y, cs->v1, 0);
putsMixerSource(16*FW, y, cs->v2, 0);
putsMixerSource(CSW_2ND_COLUMN, y, cs->v1, 0);
putsMixerSource(CSW_3RD_COLUMN, y, cs->v2, 0);
}
else {
putsMixerSource(10*FW, y, cs->v1, 0);
putsMixerSource(CSW_2ND_COLUMN, y, cs->v1, 0);
#if defined(FRSKY)
if (cs->v1 > MIXSRC_LAST_CH) {
putsTelemetryChannel(18*FW+2, y, cs->v1 - MIXSRC_LAST_CH - 1, convertCswTelemValue(cs), 0);
putsTelemetryChannel(CSW_3RD_COLUMN, y, cs->v1 - MIXSRC_LAST_CH - 1, convertCswTelemValue(cs), 0);
}
else
#endif
{
lcd_outdezAtt(19*FW, y, cs->v2, 0);
lcd_outdezAtt(CSW_3RD_COLUMN, y, cs->v2, 0);
}
}
// CSW and switch
lcd_putsiAtt(CSW_4TH_COLUMN, y, STR_VSWITCHES_SHORT, cs->andsw, 0);
}
}
}
@@ -3124,11 +3166,13 @@ void menuModelCustomSwitches(uint8_t event)
#define CSW_1ST_COLUMN (4*FW-3)
#define CSW_2ND_COLUMN (10*FW+1)
#define CSW_3RD_COLUMN (18*FW+2)
#define CSW_4TH_COLUMN (20*FW+1)
#define CSW_4TH_COLUMN (21*FW+1)
#define CSW_5TH_COLUMN (26*FW+1)
#define CSW_6TH_COLUMN (31*FW+1)
void menuModelCustomSwitches(uint8_t event)
{
MENU(STR_MENUCUSTOMSWITCHES, menuTabModel, e_CustomSwitches, NUM_CSW+1, {0, 3/*repeated...*/});
MENU(STR_MENUCUSTOMSWITCHES, menuTabModel, e_CustomSwitches, NUM_CSW+1, {0, CSW_FIELD_LAST/*repeated...*/});
uint8_t y = 0;
uint8_t k = 0;
@@ -3190,26 +3234,56 @@ void menuModelCustomSwitches(uint8_t event)
}
// CSW and switch
#if defined(PCBX9D)
putsSwitches(CSW_4TH_COLUMN, y, cs->andsw, m_posHorz==3 ? attr : 0);
#else
lcd_putsiAtt(CSW_4TH_COLUMN, y, STR_VSWITCHES_SHORT, cs->andsw, m_posHorz==3 ? attr : 0);
#endif
#if defined(CPUARM)
// CSW duration
if (cs->duration > 0)
lcd_outdezAtt(CSW_5TH_COLUMN, y, 5*cs->duration, (m_posHorz==4 ? attr : 0)|PREC1|LEFT);
else
lcd_putsiAtt(CSW_5TH_COLUMN, y, STR_MMMINV, 0, m_posHorz==4 ? attr : 0);
// CSW delay
if (cs->delay > 0)
lcd_outdezAtt(CSW_6TH_COLUMN, y, 5*cs->delay, (m_posHorz==5 ? attr : 0)|PREC1|LEFT);
else
lcd_putsiAtt(CSW_6TH_COLUMN, y, STR_MMMINV, 0, m_posHorz==5 ? attr : 0);
#endif
if ((s_editMode>0 || p1valdiff) && attr) {
switch (m_posHorz) {
case 0:
case CSW_FIELD_FUNCTION:
CHECK_INCDEC_MODELVAR_ZERO(event, cs->func, CS_MAXF);
if (cstate != CS_STATE(cs->func)) {
cs->v1 = 0;
cs->v2 = 0;
}
break;
case 1:
case CSW_FIELD_V1:
CHECK_INCDEC_MODELVAR(event, cs->v1, v1_min, v1_max);
break;
case 2:
case CSW_FIELD_V2:
CHECK_INCDEC_MODELVAR(event, cs->v2, v2_min, v2_max);
break;
case 3:
CHECK_INCDEC_MODELVAR(event, cs->andsw, 0, 15);
break;
case CSW_FIELD_ANDSW:
#if defined(PCBX9D)
CHECK_INCDEC_MODELVAR_ZERO(event, cs->andsw, SWSRC_ON-1);
#else
CHECK_INCDEC_MODELVAR_ZERO(event, cs->andsw, 15);
#endif
break;
#if defined(CPUARM)
case CSW_FIELD_DURATION:
CHECK_INCDEC_MODELVAR_ZERO(event, cs->duration, MAX_CSW_DURATION);
break;
case CSW_FIELD_DELAY:
CHECK_INCDEC_MODELVAR_ZERO(event, cs->delay, MAX_CSW_DELAY);
break;
#endif
}
}
}
+10 -9
View File
@@ -96,7 +96,7 @@ ModelData g_model;
#if defined(PCBX9D) && defined(SDCARD)
uint8_t modelBitmap[MODEL_BITMAP_SIZE];
pm_char * modelBitmapLoaded;
pm_char * modelBitmapLoaded = NULL;
void loadModelBitmap()
{
char lfn[] = BITMAPS_PATH "/xxxxxxxxxx.bmp";
@@ -792,9 +792,7 @@ bool __getSwitch(int8_t swtch)
CustomSwData * cs = cswaddress(cs_idx);
uint8_t s = cs->andsw;
#if defined(PCBX9D)
// TODO
#else
#if !defined(PCBX9D)
if (s >= SWSRC_TRN) s += SWSRC_SW3-SWSRC_TRN;
#endif
if (cs->func == CS_OFF || (s && !__getSwitch(s))) {
@@ -3512,13 +3510,10 @@ uint16_t stack_free()
#endif
#if defined(PCBGRUVIN9X)
#define UNEXPECTED_SHUTDOWN() ((mcusr & (1 << WDRF)) || g_eeGeneral.unexpectedShutdown)
#define OPEN9X_INIT_ARGS const uint8_t mcusr
#elif defined(PCBSTD)
#define UNEXPECTED_SHUTDOWN() (mcusr & (1 << WDRF))
#define OPEN9X_INIT_ARGS const uint8_t mcusr
#else
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
#define OPEN9X_INIT_ARGS
#endif
@@ -3532,13 +3527,16 @@ inline void open9xInit(OPEN9X_INIT_ARGS)
eeReadAll();
#if defined(CPUARM)
if (UNEXPECTED_SHUTDOWN())
unexpectedShutdown = 1;
#endif
#if defined(VOICE)
setVolume(g_eeGeneral.speakerVolume+VOLUME_LEVEL_DEF);
#endif
#if defined(CPUARM)
if (UNEXPECTED_SHUTDOWN())
unexpectedShutdown = 1;
audioQueue.start();
setBacklight(g_eeGeneral.backlightBright);
#endif
@@ -3559,7 +3557,10 @@ inline void open9xInit(OPEN9X_INIT_ARGS)
if (g_eeGeneral.backlightMode != e_backlight_mode_off) backlightOn(); // on Tx start turn the light on
if (UNEXPECTED_SHUTDOWN()) {
#if !defined(CPUARM)
// is done above on ARM
unexpectedShutdown = 1;
#endif
#if defined(CPUARM)
eeLoadModel(g_eeGeneral.currModel);
#endif
+24 -23
View File
@@ -1025,30 +1025,30 @@ extern void instantTrim();
extern void moveTrimsToOffsets();
#if defined(CPUARM)
#define ACTIVE_EXPOS_TYPE uint32_t
#define ACTIVE_MIXES_TYPE uint64_t
#define ACTIVE_PHASES_TYPE uint16_t
#define ACTIVE_EXPOS_TYPE uint32_t
#define ACTIVE_MIXES_TYPE uint64_t
#define ACTIVE_PHASES_TYPE uint16_t
#else
#define ACTIVE_EXPOS_TYPE uint16_t
#define ACTIVE_MIXES_TYPE uint32_t
#define ACTIVE_PHASES_TYPE uint8_t
#define ACTIVE_EXPOS_TYPE uint16_t
#define ACTIVE_MIXES_TYPE uint32_t
#define ACTIVE_PHASES_TYPE uint8_t
#endif
#ifdef BOLD_FONT
extern ACTIVE_EXPOS_TYPE activeExpos;
extern ACTIVE_MIXES_TYPE activeMixes;
inline bool isExpoActive(uint8_t expo)
{
return activeExpos & ((ACTIVE_EXPOS_TYPE)1 << expo);
}
extern ACTIVE_EXPOS_TYPE activeExpos;
extern ACTIVE_MIXES_TYPE activeMixes;
inline bool isExpoActive(uint8_t expo)
{
return activeExpos & ((ACTIVE_EXPOS_TYPE)1 << expo);
}
inline bool isMixActive(uint8_t mix)
{
return activeMixes & ((ACTIVE_MIXES_TYPE)1 << mix);
}
inline bool isMixActive(uint8_t mix)
{
return activeMixes & ((ACTIVE_MIXES_TYPE)1 << mix);
}
#else
#define isExpoActive(x) false
#define isMixActive(x) false
#define isExpoActive(x) false
#define isMixActive(x) false
#endif
#if defined(CPUARM)
@@ -1066,22 +1066,23 @@ extern MASK_CFN_TYPE activeSwitches;
extern MASK_CFN_TYPE activeFnSwitches;
extern MASK_FUNC_TYPE activeFunctions;
extern tmr10ms_t lastFunctionTime[NUM_CFN];
inline bool isFunctionActive(uint8_t func)
{
return activeFunctions & ((MASK_FUNC_TYPE)1 << (func-FUNC_TRAINER));
}
#if defined(CPUARM)
typedef int32_t rotenc_t;
typedef int32_t rotenc_t;
#else
typedef int8_t rotenc_t;
typedef int8_t rotenc_t;
#endif
#if defined(ROTARY_ENCODERS)
// Global rotary encoder registers
extern volatile rotenc_t g_rotenc[ROTARY_ENCODERS];
// Global rotary encoder registers
extern volatile rotenc_t g_rotenc[ROTARY_ENCODERS];
#elif defined(ROTARY_ENCODER_NAVIGATION)
extern volatile rotenc_t g_rotenc[1];
extern volatile rotenc_t g_rotenc[1];
#endif
#ifdef JETI
+2 -2
View File
@@ -283,7 +283,7 @@ void *main_thread(void *)
doSplash();
#endif
#if defined(PCBSKY9X)
#if defined(CPUARM)
eeLoadModel(g_eeGeneral.currModel);
#endif
@@ -291,7 +291,7 @@ void *main_thread(void *)
checkAll();
}
else {
#if defined(PCBSKY9X)
#if defined(CPUARM)
eeLoadModel(g_eeGeneral.currModel);
#endif
}
+1
View File
@@ -231,6 +231,7 @@ void btPushByte(uint8_t data);
void pwrInit();
void pwrOff();
uint32_t pwrCheck();
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
// EEPROM driver
void eepromInit();
+1
View File
@@ -83,6 +83,7 @@
// Power driver (none)
#define pwrCheck() (e_power_on)
#define pwrOff()
#define UNEXPECTED_SHUTDOWN() (mcusr & (1 << WDRF))
// Trainer driver
bool checkSlaveMode();
+1
View File
@@ -137,6 +137,7 @@ extern volatile uint16_t Analog_values[];
void pwrInit();
uint32_t pwrCheck();
void pwrOff();
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
// Backlight driver
#define setBacklight(xx)