[X9D] Navigation reworked
This commit is contained in:
+51
-21
@@ -213,7 +213,7 @@ int8_t checkIncDecGen(uint8_t event, int8_t i_val, int8_t i_min, int8_t i_max)
|
||||
}
|
||||
#endif
|
||||
|
||||
bool check_simple(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t menuTabSize, maxrow_t maxrow)
|
||||
bool check_simple(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t menuTabSize, vertpos_t maxrow)
|
||||
{
|
||||
return check(event, curr, menuTab, menuTabSize, 0, 0, maxrow);
|
||||
}
|
||||
@@ -231,14 +231,14 @@ void title(const pm_char * s)
|
||||
#define SCROLL_TH 64
|
||||
#define SCROLL_POT1_TH 32
|
||||
|
||||
#define MAXCOL(row) (horTab ? pgm_read_byte(horTab+min(row, (maxrow_t)horTabMax)) : (const uint8_t)0)
|
||||
#define MAXCOL(row) (horTab ? pgm_read_byte(horTab+min(row, (vertpos_t)horTabMax)) : (const uint8_t)0)
|
||||
#define INC(val, min, max) if (val<max) {val++;} else {val=min;}
|
||||
#define DEC(val, min, max) if (val>min) {val--;} else {val=max;}
|
||||
|
||||
bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t menuTabSize, const pm_uint8_t *horTab, uint8_t horTabMax, maxrow_t maxrow)
|
||||
bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t menuTabSize, const pm_uint8_t *horTab, uint8_t horTabMax, vertpos_t maxrow)
|
||||
{
|
||||
maxrow_t l_posVert = m_posVert;
|
||||
uint8_t l_posHorz = m_posHorz;
|
||||
vertpos_t l_posVert = m_posVert;
|
||||
horzpos_t l_posHorz = m_posHorz;
|
||||
|
||||
uint8_t maxcol = MAXCOL(l_posVert);
|
||||
|
||||
@@ -371,11 +371,11 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t
|
||||
if (s_editMode<=0) {
|
||||
if (scrollUD) {
|
||||
l_posVert = limit((int8_t)0, (int8_t)(l_posVert - scrollUD), (int8_t)maxrow);
|
||||
l_posHorz = min(l_posHorz, MAXCOL(l_posVert));
|
||||
l_posHorz = min((uint8_t)l_posHorz, MAXCOL(l_posVert));
|
||||
}
|
||||
|
||||
if (scrollLR && l_posVert>0) {
|
||||
l_posHorz = limit((int8_t)0, (int8_t)(l_posHorz - scrollLR), (int8_t)maxcol);
|
||||
l_posHorz = limit((int8_t)0, (int8_t)((uint8_t)l_posHorz - scrollLR), (int8_t)maxcol);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t
|
||||
{
|
||||
case EVT_ENTRY:
|
||||
l_posVert = POS_VERT_INIT;
|
||||
l_posHorz = 0;
|
||||
l_posHorz = POS_HORZ_INIT;
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
if (menuTab) {
|
||||
s_editMode = EDIT_MODE_INIT;
|
||||
@@ -401,7 +401,14 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION) || defined(PCBX9D)
|
||||
#if defined(PCBX9D)
|
||||
case EVT_ROTARY_BREAK:
|
||||
if (s_editMode > 1) break;
|
||||
if (m_posHorz < 0 && maxcol > 0) {
|
||||
l_posHorz = 0;
|
||||
break;
|
||||
}
|
||||
#elif defined(ROTARY_ENCODER_NAVIGATION)
|
||||
case EVT_ROTARY_BREAK:
|
||||
if (s_editMode > 1) break;
|
||||
#endif
|
||||
@@ -440,12 +447,16 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t
|
||||
break;
|
||||
}
|
||||
#if defined(PCBX9D)
|
||||
if (l_posHorz >= 0 && maxcol > 0) {
|
||||
l_posHorz = POS_HORZ_INIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t posVertInit = POS_VERT_INIT;
|
||||
if (s_pgOfs != 0 || l_posHorz != 0 || l_posVert != posVertInit) {
|
||||
if (s_pgOfs != 0 || l_posVert != posVertInit) {
|
||||
s_pgOfs = 0;
|
||||
l_posVert = posVertInit;
|
||||
l_posHorz = 0;
|
||||
l_posHorz = POS_HORZ_INIT;
|
||||
}
|
||||
else {
|
||||
popMenu();
|
||||
@@ -474,11 +485,16 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t
|
||||
if (!horTab || s_editMode>0) break;
|
||||
#endif
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION) || defined(PCBX9D)
|
||||
#if defined(PCBX9D)
|
||||
CASE_EVT_ROTARY_MOVE_RIGHT
|
||||
if (s_editMode != 0) break;
|
||||
if (l_posHorz >= 0) {
|
||||
INC(l_posHorz, 0, maxcol);
|
||||
break;
|
||||
}
|
||||
#elif defined(ROTARY_ENCODER_NAVIGATION)
|
||||
CASE_EVT_ROTARY_MOVE_RIGHT
|
||||
if (s_editMode != 0) break;
|
||||
// TODO s_editMode test is duplicated
|
||||
// TODO could be written in a smarter way!
|
||||
if (l_posHorz < maxcol) {
|
||||
l_posHorz++;
|
||||
break;
|
||||
@@ -508,7 +524,12 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION) || defined(PCBX9D)
|
||||
s_editMode = 0; // if we go down, we must be in this mode
|
||||
#endif
|
||||
|
||||
#if defined(PCBX9D)
|
||||
l_posHorz = POS_HORZ_INIT;
|
||||
#else
|
||||
l_posHorz = min(l_posHorz, MAXCOL(l_posVert));
|
||||
#endif
|
||||
break;
|
||||
|
||||
#if !defined(PCBX9D)
|
||||
@@ -520,9 +541,15 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t
|
||||
if (!horTab || s_editMode>0) break;
|
||||
#endif
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION) || defined(PCBX9D)
|
||||
#if defined(PCBX9D)
|
||||
CASE_EVT_ROTARY_MOVE_LEFT
|
||||
if (s_editMode != 0) break;
|
||||
if (l_posHorz >= 0) {
|
||||
DEC(l_posHorz, 0, maxcol);
|
||||
break;
|
||||
}
|
||||
#elif defined(ROTARY_ENCODER_NAVIGATION)
|
||||
CASE_EVT_ROTARY_MOVE_LEFT
|
||||
// TODO could be written in a smarter way!
|
||||
if (s_editMode != 0) break;
|
||||
if (l_posHorz > 0) {
|
||||
l_posHorz--;
|
||||
@@ -556,9 +583,12 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t
|
||||
s_editMode = 0; // if we go up, we must be in this mode
|
||||
#endif
|
||||
|
||||
l_posHorz = min(l_posHorz, MAXCOL(l_posVert));
|
||||
#if defined(PCBX9D)
|
||||
l_posHorz = POS_HORZ_INIT;
|
||||
#else
|
||||
l_posHorz = min((uint8_t)l_posHorz, MAXCOL(l_posVert));
|
||||
#endif
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
uint8_t max = menuTab ? LCD_LINES-1 : LCD_LINES-2;
|
||||
@@ -573,8 +603,8 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t
|
||||
MenuFuncP g_menuStack[5];
|
||||
uint8_t g_menuPos[4];
|
||||
uint8_t g_menuStackPtr = 0;
|
||||
maxrow_t m_posVert;
|
||||
uint8_t m_posHorz;
|
||||
vertpos_t m_posVert;
|
||||
horzpos_t m_posHorz;
|
||||
|
||||
void popMenu()
|
||||
{
|
||||
@@ -582,7 +612,7 @@ void popMenu()
|
||||
|
||||
g_menuStackPtr = g_menuStackPtr-1;
|
||||
AUDIO_KEYPAD_UP();
|
||||
m_posHorz = 0;
|
||||
m_posHorz = POS_HORZ_INIT;
|
||||
m_posVert = g_menuPos[g_menuStackPtr];
|
||||
(*g_menuStack[g_menuStackPtr])(EVT_ENTRY_UP);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user