Page 1 of 1

Help overloading ReefAngelClass::SetupOption

Posted: Tue May 14, 2013 1:23 pm
by KRavEN
I'm trying to overload ReefAngelClass::SetupOption so I can do 3 and 4 options. Here is what I have that works but the values don't show for all the options when the screen is first drawn and when you joystick left the values stay highlighted when they shouldn't. I pulled out the bSingle support while troubleshooting. Any help figuring out what I'm doing wrong would be appreciated.

Code: Select all

bool ReefAngelClass::SetupOption(int &v, int &w, int &x, int &y, int rangemin, int rangemax, byte maxdigits, char* unit, char* subunit, char* title, char* prefix1,
    char* prefix2, char* prefix3, char* prefix4) {
  // return true to save value stored in out in memory
  enum choices {
    OPT1, OPT2, OPT3, OPT4, OK, CANCEL
  };
  byte sel = OPT1;
  bool bSave = false;
  bool bDone = false;
  bool bRedraw = true;
  bool bDrawButtons = true;
  byte offset = 50;
  ClearScreen(DefaultBGColor);
  LCD.DrawText(DefaultFGColor, DefaultBGColor, MENU_START_COL, MENU_START_ROW, title);

  // prefix for each option
  LCD.DrawText(DefaultFGColor, DefaultBGColor, MENU_START_COL, MENU_START_ROW * 3, prefix1);
  LCD.DrawText(DefaultFGColor, DefaultBGColor, MENU_START_COL, MENU_START_ROW * 5, prefix2);
  LCD.DrawText(DefaultFGColor, DefaultBGColor, MENU_START_COL, MENU_START_ROW * 7, prefix3);
  LCD.DrawText(DefaultFGColor, DefaultBGColor, MENU_START_COL, MENU_START_ROW * 9, prefix4);

  do {

    wdt_reset();

    if (bRedraw) {
      switch (sel) {
        case OPT1:
          LCD.DrawOption(v, 1, MENU_START_COL + offset, MENU_START_ROW * 3, unit, subunit, maxdigits);
          if (bDrawButtons) {
            LCD.DrawOK(false);
            LCD.DrawCancel(false);
          }
          break;

        case OPT2:
          LCD.DrawOption(v, 0, MENU_START_COL + offset, MENU_START_ROW * 3, unit, subunit, maxdigits);
          LCD.DrawOption(y, 1, MENU_START_COL + offset, MENU_START_ROW * 5, unit, subunit, maxdigits);
          if (bDrawButtons) {
            LCD.DrawOK(false);
            LCD.DrawCancel(false);
          }
          break;

        case OPT3:
          LCD.DrawOption(v, 0, MENU_START_COL + offset, MENU_START_ROW * 5, unit, subunit, maxdigits);
          LCD.DrawOption(y, 1, MENU_START_COL + offset, MENU_START_ROW * 7, unit, subunit, maxdigits);
          if (bDrawButtons) {
            LCD.DrawOK(false);
            LCD.DrawCancel(false);
          }
          break;

        case OPT4:
          LCD.DrawOption(v, 0, MENU_START_COL + offset, MENU_START_ROW * 7, unit, subunit, maxdigits);
          LCD.DrawOption(y, 1, MENU_START_COL + offset, MENU_START_ROW * 9, unit, subunit, maxdigits);
          if (bDrawButtons) {
            LCD.DrawOK(false);
            LCD.DrawCancel(false);
          }
          break;

        case OK:
          if (bDrawButtons) {
            LCD.DrawOption(v, 0, MENU_START_COL + offset, MENU_START_ROW * 7, unit, subunit, maxdigits);
            LCD.DrawOption(y, 0, MENU_START_COL + offset, MENU_START_ROW * 9, unit, subunit, maxdigits);
            LCD.DrawOK(true);
            LCD.DrawCancel(false);
          }
          break;

        case CANCEL:
          if (bDrawButtons) {
            LCD.DrawOption(v, 0, MENU_START_COL + offset, MENU_START_ROW * 7, unit, subunit, maxdigits);
            LCD.DrawOption(y, 0, MENU_START_COL + offset, MENU_START_ROW * 9, unit, subunit, maxdigits);
            LCD.DrawOK(false);
            LCD.DrawCancel(true);
          }
          break;

      }
      bRedraw = false;
      bDrawButtons = false;
    } // if bRedraw

    if (Joystick.IsUp()) {
      bRedraw = true;
      if (sel == OPT1) {
        v++;
        if (v > rangemax || v < rangemin) {
          v = rangemin;
        }
      }
      else if (sel == OPT2) {
        w++;
        if (w > rangemax || w < rangemin) {
          w = rangemin;
        }
      }
      else if (sel == OPT3) {
        x++;
        if (x > rangemax || x < rangemin) {
          x = rangemin;
        }
      }
      else if (sel == OPT4) {
        y++;
        if (y > rangemax || y < rangemin) {
          y = rangemin;
        }
      }
    }
    if (Joystick.IsDown()) {
      bRedraw = true;
      if (sel == OPT1) {
        v--;
        if (v < rangemin || v > rangemax) {
          v = rangemax;
        }
      }
      else if (sel == OPT2) {
        w--;
        if (w < rangemin || w > rangemax) {
          w = rangemax;
        }
      }
      else if (sel == OPT3) {
        x--;
        if (x < rangemin || x > rangemax) {
          x = rangemax;
        }
      }
      else if (sel == OPT4) {
        y--;
        if (y < rangemin || y > rangemax) {
          y = rangemax;
        }
      }
    }
    if (Joystick.IsRight()) {
      bRedraw = true;
      bDrawButtons = true;  // only redraw the buttons if we are moving right or left
      // move right, if we are on cancel, wrap around to opt1
      sel++;
      if (sel > CANCEL) {
        sel = OPT1;
      }
    }
    if (Joystick.IsLeft()) {
      bRedraw = true;
      bDrawButtons = true;
      // move left, if we are on opt1, wrap around to cancel
      sel--;
      if (sel > CANCEL) {
        sel = CANCEL;
      }
    }
    if (Joystick.IsButtonPressed()) {
      // only break when button pressed on ok or cancel
      if (sel == OK) {
        bDone = true;
        bSave = true;
      }
      else if (sel == CANCEL) {
        bDone = true;
      }
    }
  }
  while (!bDone);

  // return true saves the value, false ignores the value
  return bSave;
}

Re: Help overloading ReefAngelClass::SetupOption

Posted: Tue May 14, 2013 10:38 pm
by rimai
I think for each option on your switch statement, you need to draw all 4 options and both buttons.
So, you should have 6 drawing in each switch.
You are only drawing v and y... And you must draw x and w too.

Re: Help overloading ReefAngelClass::SetupOption

Posted: Wed May 15, 2013 5:05 am
by KRavEN
Okay, now I think I understand whats going on. Thanks. I'll post up the completed method once I get it right.