예제 #1
0
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, uint8_t flags)
{
    vertpos_t l_posVert = m_posVert;
    horzpos_t l_posHorz = m_posHorz;

    uint8_t maxcol = MAXCOL(l_posVert);

#define scrollUD 0

    if (p2valdiff || scrollUD || p1valdiff) backlightOn(); // on keypress turn the light on

    if (menuTab) {
        uint8_t attr = 0;

        int8_t cc = curr;
        switch (event) {
        case EVT_KEY_LONG(KEY_MENU):
            if (menuTab == menuTabModel) {
                killEvents(event);
                if (modelHasNotes()) {
                    MENU_ADD_SD_ITEM(STR_VIEW_CHANNELS);
                    MENU_ADD_ITEM(STR_VIEW_NOTES);
                    menuHandler = onLongMenuPress;
                }
                else {
                    pushMenu(menuChannelsView);
                    return false;
                }
            }
            break;

        case EVT_KEY_LONG(KEY_PAGE):
            if (curr > 0)
                cc = curr - 1;
            else
                cc = menuTabSize-1;
            killEvents(event);
            break;

        case EVT_KEY_BREAK(KEY_PAGE):
            if (curr < (menuTabSize-1))
                cc = curr + 1;
            else
                cc = 0;
            break;
        }

        if (!calibrationState && cc != curr) {
            chainMenu((MenuFuncP)pgm_read_adr(&menuTab[cc]));
            return false;
        }

        if (!(flags&CHECK_FLAG_NO_SCREEN_INDEX)) {
            displayScreenIndex(curr, menuTabSize, attr);
        }

        lcd_filled_rect(0, 0, LCD_W, FH, SOLID, FILL_WHITE|GREY_DEFAULT);
    }

    DISPLAY_PROGRESS_BAR(menuTab ? lcdLastPos-2*FW-((curr+1)/10*FWNUM)-2 : 20*FW+1);

    if (s_editMode<=0) {
        if (scrollUD) {
            l_posVert = limit((int8_t)0, (int8_t)(l_posVert - scrollUD), (int8_t)maxrow);
            l_posHorz = min((uint8_t)l_posHorz, MAXCOL(l_posVert));
        }

        if (p2valdiff && l_posVert>0) {
            l_posHorz = limit((int8_t)0, (int8_t)((uint8_t)l_posHorz - p2valdiff), (int8_t)maxcol);
        }
    }

    switch(event)
    {
    case EVT_ENTRY:
        menuEntryTime = get_tmr10ms();
        l_posVert = POS_VERT_INIT;
        l_posHorz = POS_HORZ_INIT(l_posVert);
        SET_SCROLLBAR_X(LCD_W-1);
#if defined(ROTARY_ENCODER_NAVIGATION)
        if (menuTab) {
            s_editMode = EDIT_MODE_INIT;
            break;
        }
        // no break
#else
        s_editMode = EDIT_MODE_INIT;
        break;
#endif

    case EVT_ENTRY_UP:
        menuEntryTime = get_tmr10ms();
        s_editMode = 0;
        l_posHorz = POS_HORZ_INIT(l_posVert);
        SET_SCROLLBAR_X(LCD_W-1);
        break;

    case EVT_ROTARY_BREAK:
        if (s_editMode > 1) break;
        if (m_posHorz < 0 && maxcol > 0 && READ_ONLY_UNLOCKED()) {
            l_posHorz = 0;
            break;
        }
        if (!menuTab || l_posVert>0) {
            if (READ_ONLY_UNLOCKED()) {
                s_editMode = (s_editMode<=0);
            }
        }
        break;

#if defined(ROTARY_ENCODER_NAVIGATION)
    case EVT_ROTARY_LONG:
        if (s_editMode > 1) break;
        killEvents(event);
        if (l_posVert != POS_VERT_INIT) {
            l_posVert = POS_VERT_INIT;
            s_editMode = EDIT_MODE_INIT;
            break;
        }
        // no break
#endif
    case EVT_KEY_LONG(KEY_EXIT):
        s_editMode = 0; // TODO needed? we call ENTRY_UP after which does the same
        popMenu();
        return false;

    case EVT_KEY_BREAK(KEY_EXIT):
#if defined(ROTARY_ENCODER_NAVIGATION)
        if (s_editMode == 0)
            s_editMode = EDIT_MODE_INIT;
        else
#endif
            if (s_editMode>0) {
                s_editMode = 0;
                break;
            }

        if (l_posHorz >= 0 && (COLATTR(l_posVert) & NAVIGATION_LINE_BY_LINE)) {
            l_posHorz = -1;
        }
        else
        {
            uint8_t posVertInit = POS_VERT_INIT;
            if (s_pgOfs != 0 || l_posVert != posVertInit) {
                s_pgOfs = 0;
                l_posVert = posVertInit;
                l_posHorz = POS_HORZ_INIT(l_posVert);
            }
            else {
                popMenu();
                return false;
            }
        }
        break;

        CASE_EVT_ROTARY_MOVE_RIGHT
        if (s_editMode != 0) break;
        if ((COLATTR(l_posVert) & NAVIGATION_LINE_BY_LINE)) {
            if (l_posHorz >= 0) {
                INC(l_posHorz, 0, maxcol);
                break;
            }
        }
        else {
            if (l_posHorz < maxcol) {
                l_posHorz++;
                break;
            }
            else {
                l_posHorz = 0;
                if (!IS_ROTARY_MOVE_RIGHT(event))
                    break;
            }
        }

        do {
            INC(l_posVert, POS_VERT_INIT, maxrow);
        } while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));

        s_editMode = 0; // if we go down, we must be in this mode

        l_posHorz = POS_HORZ_INIT(l_posVert);
        break;

        CASE_EVT_ROTARY_MOVE_LEFT
        if (s_editMode != 0) break;
        if ((COLATTR(l_posVert) & NAVIGATION_LINE_BY_LINE)) {
            if (l_posHorz >= 0) {
                DEC(l_posHorz, 0, maxcol);
                break;
            }
        }
        else {
            if (l_posHorz > 0) {
                l_posHorz--;
                break;
            }
            else if (IS_ROTARY_MOVE_LEFT(event) && s_editMode == 0) {
                l_posHorz = 0xff;
            }
            else {
                l_posHorz = maxcol;
                break;
            }
        }

        do {
            DEC(l_posVert, POS_VERT_INIT, maxrow);
        } while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));

        s_editMode = 0; // if we go up, we must be in this mode

        if ((COLATTR(l_posVert) & NAVIGATION_LINE_BY_LINE))
            l_posHorz = -1;
        else
            l_posHorz = min((uint8_t)l_posHorz, MAXCOL(l_posVert));

        break;
    }

#if defined(CPUARM)
    if (l_posVert<1) {
        s_pgOfs=0;
    }
    else if (menuTab && horTab) {
        if (maxrow > LCD_LINES-1) {
            while (1) {
                vertpos_t line = s_pgOfs+1;
                for (int numLines=0; line<=maxrow && numLines<LCD_LINES-1; line++) {
                    if (MAXCOL(line) != HIDDEN_ROW) {
                        numLines++;
                    }
                }
                int max = line - s_pgOfs - 1;
                if (l_posVert > max+s_pgOfs) {
                    s_pgOfs++;
                }
                else if (l_posVert < 1+s_pgOfs) {
                    s_pgOfs--;
                }
                else {
                    break;
                }
            }
        }
    }
    else {
        uint8_t max = menuTab ? LCD_LINES-1 : LCD_LINES-2;
        if (l_posVert>max+s_pgOfs) {
            s_pgOfs = l_posVert-max;
        }
        else if (l_posVert<1+s_pgOfs) {
            s_pgOfs = l_posVert-1;
        }
    }

#if LCD_W >= 212
    if (maxrow > LCD_LINES-1 && scrollbar_X)
        displayScrollbar(scrollbar_X, FH, LCD_H-FH, s_pgOfs, menuTab ? maxrow : maxrow+1, LCD_LINES-1);
#endif

#else
    uint8_t max = menuTab ? LCD_LINES-1 : LCD_LINES-2;
    if (l_posVert<1) s_pgOfs=0;
    else if (l_posVert>max+s_pgOfs) s_pgOfs = l_posVert-max;
    else if (l_posVert<1+s_pgOfs) s_pgOfs = l_posVert-1;
#endif
    m_posVert = l_posVert;
    m_posHorz = l_posHorz;
    if (s_pgOfs > 0) {
        l_posVert--;
        if (l_posVert == s_pgOfs && CURSOR_NOT_ALLOWED_IN_ROW(l_posVert)) {
            s_pgOfs = l_posVert-1;
        }
    }
    return true;
}
예제 #2
0
void check(const char *name, check_event_t event, uint8_t curr, const menuHandlerFunc *menuTab, uint8_t menuTabSize, const pm_uint8_t *horTab, uint8_t horTabMax, vertpos_t rowcount, uint8_t flags)
{
  vertpos_t l_posVert = menuVerticalPosition;
  horzpos_t l_posHorz = menuHorizontalPosition;

  uint8_t maxcol = MAXCOL(l_posVert);

  if (menuTab) {
    int cc = curr;
    switch (event) {
      case EVT_KEY_LONG(KEY_MENU):
        if (menuTab == menuTabModel) {
          killEvents(event);
          if (modelHasNotes()) {
            POPUP_MENU_ADD_SD_ITEM(STR_VIEW_CHANNELS);
            POPUP_MENU_ADD_ITEM(STR_VIEW_NOTES);
            popupMenuHandler = onLongMenuPress;
          }
          else {
            pushMenu(menuChannelsView);
          }
        }
        break;

      case EVT_KEY_LONG(KEY_PAGE):
        if (curr > 0)
          cc = curr - 1;
        else
          cc = menuTabSize-1;
        killEvents(event);
        break;

      case EVT_KEY_BREAK(KEY_PAGE):
        if (curr < (menuTabSize-1))
          cc = curr + 1;
        else
          cc = 0;
        break;
    }

    if (!calibrationState && cc != curr) {
      chainMenu((menuHandlerFunc)pgm_read_adr(&menuTab[cc]));
    }

    if (!(flags&CHECK_FLAG_NO_SCREEN_INDEX)) {
      displayScreenIndex(curr, menuTabSize, 0);
    }

    drawFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, SOLID, FILL_WHITE|GREY_DEFAULT);
  }

  DISPLAY_PROGRESS_BAR(menuTab ? lcdLastPos-2*FW-((curr+1)/10*FWNUM)-2 : 20*FW+1);

  switch(event)
  {
    case EVT_ENTRY:
      menuEntryTime = get_tmr10ms();
      l_posVert = POS_VERT_INIT;
      l_posHorz = POS_HORZ_INIT(l_posVert);
      SET_SCROLLBAR_X(LCD_W-1);
      s_editMode = EDIT_MODE_INIT;
      break;

    case EVT_ENTRY_UP:
      menuEntryTime = get_tmr10ms();
      s_editMode = 0;
      l_posHorz = POS_HORZ_INIT(l_posVert);
      SET_SCROLLBAR_X(LCD_W-1);
      break;

    case EVT_ROTARY_BREAK:
      if (s_editMode > 1) break;
      if (menuHorizontalPosition < 0 && maxcol > 0 && READ_ONLY_UNLOCKED()) {
        l_posHorz = 0;
        break;
      }
      if (READ_ONLY_UNLOCKED()) {
        s_editMode = (s_editMode<=0);
      }
      break;

    case EVT_KEY_LONG(KEY_EXIT):
      s_editMode = 0; // TODO needed? we call ENTRY_UP after which does the same
      popMenu();
      break;

    case EVT_KEY_BREAK(KEY_EXIT):
      if (s_editMode>0) {
        s_editMode = 0;
        break;
      }

      if (l_posHorz >= 0 && (COLATTR(l_posVert) & NAVIGATION_LINE_BY_LINE)) {
        l_posHorz = -1;
      }
      else
      {
        uint8_t posVertInit = POS_VERT_INIT;
        if (menuVerticalOffset != 0 || l_posVert != posVertInit) {
          menuVerticalOffset = 0;
          l_posVert = posVertInit;
          l_posHorz = POS_HORZ_INIT(l_posVert);
        }
        else {
          popMenu();
        }
      }
      break;

    CASE_EVT_ROTARY_MOVE_RIGHT
      if (s_editMode != 0) break;
      if ((COLATTR(l_posVert) & NAVIGATION_LINE_BY_LINE)) {
        if (l_posHorz >= 0) {
          INC(l_posHorz, 0, maxcol);
          break;
        }
      }
      else {
        if (l_posHorz < maxcol) {
          l_posHorz++;
          break;
        }
        else {
          l_posHorz = 0;
          if (!IS_ROTARY_MOVE_RIGHT(event))
            break;
        }
      }

      do {
        INC(l_posVert, POS_VERT_INIT, rowcount-1);
      } while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));

      s_editMode = 0; // if we go down, we must be in this mode

      l_posHorz = POS_HORZ_INIT(l_posVert);
      break;

    CASE_EVT_ROTARY_MOVE_LEFT
      if (s_editMode != 0) break;
      if ((COLATTR(l_posVert) & NAVIGATION_LINE_BY_LINE)) {
        if (l_posHorz >= 0) {
          DEC(l_posHorz, 0, maxcol);
          break;
        }
      }
      else {
        if (l_posHorz > 0) {
          l_posHorz--;
          break;
        }
        else if (IS_ROTARY_MOVE_LEFT(event) && s_editMode == 0) {
          l_posHorz = 0xff;
        }
        else {
          l_posHorz = maxcol;
          break;
        }
      }

      do {
        DEC(l_posVert, POS_VERT_INIT, rowcount-1);
      } while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));

      s_editMode = 0; // if we go up, we must be in this mode

      if ((COLATTR(l_posVert) & NAVIGATION_LINE_BY_LINE))
        l_posHorz = -1;
      else
        l_posHorz = min((uint8_t)l_posHorz, MAXCOL(l_posVert));

      break;
  }

  int linesCount = rowcount;

  if (l_posVert == 0 || (l_posVert==1 && MAXCOL(vertpos_t(0)) >= HIDDEN_ROW) || (l_posVert==2 && MAXCOL(vertpos_t(0)) >= HIDDEN_ROW && MAXCOL(vertpos_t(1)) >= HIDDEN_ROW)) {
    menuVerticalOffset = 0;
    if (horTab) {
      linesCount = 0;
      for (int i=0; i<rowcount; i++) {
        if (i>horTabMax || horTab[i] != HIDDEN_ROW) {
          linesCount++;
        }
      }
    }
  }
  else if (horTab) {
    if (rowcount > NUM_BODY_LINES) {
      while (1) {
        vertpos_t firstLine = 0;
        for (int numLines=0; firstLine<rowcount && numLines<menuVerticalOffset; firstLine++) {
          if (firstLine>=horTabMax || horTab[firstLine] != HIDDEN_ROW) {
            numLines++;
          }
        }
        if (l_posVert < firstLine) {
          menuVerticalOffset--;
        }
        else {
          vertpos_t lastLine = firstLine;
          for (int numLines=0; lastLine<rowcount && numLines<NUM_BODY_LINES; lastLine++) {
            if (lastLine>=horTabMax || horTab[lastLine] != HIDDEN_ROW) {
              numLines++;
            }
          }
          if (l_posVert >= lastLine) {
            menuVerticalOffset++;
          }
          else {
            linesCount = menuVerticalOffset + NUM_BODY_LINES;
            for (int i=lastLine; i<rowcount; i++) {
              if (i>horTabMax || horTab[i] != HIDDEN_ROW) {
                linesCount++;
              }
            }
            break;
          }
        }
      }
    }
  }
  else {
    if (l_posVert>=NUM_BODY_LINES+menuVerticalOffset) {
      menuVerticalOffset = l_posVert-NUM_BODY_LINES+1;
    }
    else if (l_posVert<menuVerticalOffset) {
      menuVerticalOffset = l_posVert;
    }
  }

  if (scrollbar_X && linesCount > NUM_BODY_LINES) {
    displayScrollbar(scrollbar_X, MENU_HEADER_HEIGHT, LCD_H-MENU_HEADER_HEIGHT, menuVerticalOffset, linesCount, NUM_BODY_LINES);
  }

  if (name) {
    title(name);
  }

  menuVerticalPosition = l_posVert;
  menuHorizontalPosition = l_posHorz;
}