Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List support #22

Closed
wants to merge 12 commits into from
Closed

Conversation

thijstriemstra
Copy link
Collaborator

@thijstriemstra thijstriemstra commented Jun 21, 2021

I needed to pick strings and ints from a list so I hacked this together. I'm sure it can be improved so any suggestions are welcome.

Usage:

char * ANIMATION_TYPE = "Type";
char * EQUALIZER = "EQ";
char * COLOR = "Color";
char * BRIGHTNESS = "Brightness";

// AUDIO
std::vector<String> eqModes = {"Normal", "Pop", "Rock", "Jazz", "Classic", "Bass"};

// ANIMATION
uint8_t animationBrightness = 7;
std::vector<int> brightnessTypes = {2, 3, 7, 9, 12, 30, 60, 100, 180, 255};

uint8_t animationIndex = 0;
std::vector<String> animationTypes = {"Ocean", "Pride", "BlendWave", "Sinelon", "Confetti"};

uint8_t colorIndex = 0;
std::vector<String> colors = {
    "Random",
    "Red",
    "Orange",
    "Yellow",
    "Green",
    "Aqua",
    "Blue",
    "Purple",
    "Pink"
};

// declare callback functions
void changeIntList();
void changeStringList();

extern MenuItem mainMenu[];

MenuItem mainMenu[] = {
  ItemHeader(),
  ItemStringList(ANIMATION_TYPE, animationTypes, 0, changeStringList),
  ItemStringList(COLOR, colors, 0, changeStringList),
  ItemIntList(BRIGHTNESS, brightnessTypes, 0, changeIntList),
  ItemStringList(EQUALIZER, eqModes, 0, changeStringList),
  ItemFooter()
};

LcdMenu menu(LCD_ROWS, LCD_COLS);

// initialize menu
menu.setupLcdWithMenu(
    DisplayRSPin,
    DisplayENPin,
    DisplayD4Pin,
    DisplayD5Pin,
    DisplayD6Pin,
    DisplayD7Pin,
    DisplayBacklightPin,
    mainMenu
);

void changeIntList() {
  uint8_t index = menu.getCursorPosition();
  MenuItem* item = menu.getItemAt(index);
  const char* menuLabel = item->getText();
  int selectedIndex = item->getSelectedIndex();
  int selectedLabel = item->getIntItems().at(selectedIndex);

  Log.info(F("%s: %d - %d" CR), menuLabel, selectedLabel, selectedIndex);

  if (menuLabel == BRIGHTNESS) {
    animationBrightness = selectedIndex;
    _neopixels->setBrightness(brightnessTypes.at(animationBrightness));
  }
}

I also needed to redraw the menu, like this:

// update menu
mainMenu[1].setSelectedIndex(animationIndex);
mainMenu[2].setSelectedIndex(colorIndex);
mainMenu[3].setSelectedIndex(animationBrightness);
mainMenu[4].setSelectedIndex(_player->equalizerMode);
menu.redraw();

The PR also includes a fix/workaround for #21

@forntoh
Copy link
Owner

forntoh commented Jun 22, 2021

Hello, can you take a quick picture of how the lists are displayed and upload it here, I'm currently in a position where I can't test. Thanks

@thijstriemstra
Copy link
Collaborator Author

thijstriemstra commented Jun 22, 2021

Sounds good. Might take a day or two. It'll be a video though ;)

Copy link
Owner

@forntoh forntoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for supporting 😊

@@ -49,6 +52,9 @@ class MenuItem {
char* text;
char* textOn;
char* textOff;
std::vector<String> items;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some microprocessor architectures don't support the std::vector, whereas pointers are supported everywhere, that's why I used pointers. If you could find a way to use pointers instead of vectors, that'd be great, otherwise, you could just duplicate these files and make it specific for architectures that support std::vector, this way, users with lower arch are not left out (like me 😁). Using pointers will be the universal solution...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use vectors because I am from a Python/JS/AS3 background, not well versed in this language, but I hope you could help 'make it sane'.

MenuItem* menu) {
this->lcd = new LiquidCrystal(rs, en, d0, d1, d2, d3);
this->lcd = new LiquidCrystal(rs, en, d0, d1, d2, d3, backlight, POSITIVE);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no statistic as to how many users still use the original LiquidCrystal lib by Arduino (I still use it tho), if the number is minimal, I could divert to your proposal. Do you have any stats?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my platformio.ini contains this entry in lib_deps: fmalpartida/LiquidCrystal

Is that the 'original LiquidCrystal lib by Arduino'? I use what worked..

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the one by Arduino arduino-libraries/LiquidCrystal@^1.0.7

Copy link
Collaborator Author

@thijstriemstra thijstriemstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened ticket #23 for cursor change.

@thijstriemstra
Copy link
Collaborator Author

Opened #26 for the redraw method introduced in this PR.

@thijstriemstra
Copy link
Collaborator Author

ps. I think you should release 2.0.0 as it is (it's beta now?), and use this pr as ideas for newer version, e.g. 3.0. I like how this library kept things minimal and it always should.

@forntoh
Copy link
Owner

forntoh commented Jun 24, 2021

I have updated the CONTRIBUTING.md, please update this PR to reflect the guideline.

@thijstriemstra
Copy link
Collaborator Author

this sounds quite hostile hehe. this pr is a sketch or work in progress i was hoping we could discuss. i will review these guidelines

@forntoh
Copy link
Owner

forntoh commented Jun 24, 2021

this sounds quite hostile hehe. this pr is a sketch or work in progress i was hoping we could discuss. i will review these guidelines

Since I don't have time to test, let GitHub do the testing, the most important part is including an example project, for simpler PRs, I will just merge if all checks pass, that's what I wanted you to see 😄.

@forntoh
Copy link
Owner

forntoh commented Aug 26, 2021

char * ANIMATION_TYPE = "Type";
char * EQUALIZER = "EQ";
char * COLOR = "Color";
char * BRIGHTNESS = "Brightness";

@thijstriemstra You don't need to do 👆 anymore 😁, those c++11 warnings will not show in the new release 🤞

@forntoh forntoh closed this Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants