Go Down

Topic: MENWIZ: yet another character lcd menu wizard library (Read 84190 times) previous topic - next topic

brunialti

@paco

the problem is over. thnks.
Good luck with your new board!

backbone

OK,

Boards are up and running.
Still using the old lib. for the time being.

Just a question.
To reduce wires from a controller to the MEGA I used an analog port with 10 buttons.
4 of those buttons are now supposed to be used for the menu navigation so no more hardcore switched at the digital inputs.
I thougth it was simple to declare 4 variables as boolean and let the line become
Code: [Select]
menu.navButtons(menuUp,menuDown,menuEscape,menuConfirm);// 4 button navigation

Code: [Select]
// ++++ Buttons 10 in total ++++++

boolean menuUp;
boolean menuDown;
boolean menuConfirm;
boolean menuEscape;

  buttonValue = analogRead(0);   // read the input pin 0
  // internal 20K ohm pullup is enabled on analog pin 0 (54).
  if(buttonValue >= 920 and buttonValue <= 930 )
  {
    menuUp=(HIGH);
    digitalWrite(led7Pin, HIGH);
    delay (200); // 910
  }
    else if(buttonValue >= 820 and buttonValue <= 835)
  {
    menuConfirm=(HIGH);
    digitalWrite(led7Pin, HIGH);
    delay (200);// 827
  }
  else if(buttonValue >= 725 and buttonValue <= 740)
  {
    menuDown=(HIGH);
    digitalWrite(led7Pin, HIGH);
    delay (200); // 731
  }
  else if(buttonValue >= 630 and buttonValue <= 645)
  {
    menuEscape=(HIGH);
    digitalWrite(led7Pin, HIGH);
    delay (200); // 637
  }
else
    digitalWrite(led7Pin,LOW);
    menuUp =(LOW);
    menuDown=(LOW);
    menuConfirm=(LOW);
    menuEscape =(LOW);


Instead of the original code for digital buttons I used this:
Code: [Select]
// DEFINE ARDUINO DIGITAL PINS FOR THE NAVIGATION BUTTONS FOR MENWIZ
#define UP_BUTTON_PIN       menuUp //3
#define DOWN_BUTTON_PIN     menuDown //4
#define CONFIRM_BUTTON_PIN  menuConfirm //2
#define ESCAPE_BUTTON_PIN   menuEscape //5


But that does not work.
Am I working and thinking in the wrong direction?
Never to old to learn and I learn every day

brunialti

Yes. that is the wrong direction.
In the previous posts dannix got the true way.

forget navbuttons. That method is used to activate the builtin methods
if you want to use your own device to replace the standards buttons managed by MENWIZ and Buttons libraries (and declared with navButtons functions) you need to write your own function and to declare it to MENWIZ library using  addUsrNav method.
The user defined function will replace the following internal one:.
In the manual there is a sample of the method to be replaced by your routine.
The trick is just be able to provide as return code one of the same codes the built in funzion returns.
The codea are the following literals:

// BUTTON CODES
// ----------------------------------------------------------------------
#define MW_BTNULL    //null
#define MW_BTU         //up
#define MW_BTD         // down
#define MW_BTL         //RIGTH
#define MW_BTR         //LEFT
#define MW_BTE         //ESCAPE
#define MW_BTC         //CONFIRM

Look at the working code of dannix (your should be a little dfferent) using analog buttnos as you would like to. Be only careful: dannix simulate the forth button ESCAPE (he uses only 3 buttons!) , using a normal MENWIZ menu entry (with an action variable associated) to simulate it. Your code should be even simpler!



backbone

Hi Bruno,

Switched to 1.0 lib and needed to change some code first to get rid of error messages.
I looked in the manual ans saw the sample code for custom buttons.
Also looked at DANNIX his sample code.
Still not sure if I fully understand Dannix his code and if using interrupt is really needed.

If Dannix can explain I would be happy.

Paco

Never to old to learn and I learn every day

brunialti

#139
Aug 10, 2012, 11:16 am Last Edit: Aug 10, 2012, 11:19 am by brunialti Reason: 1
The method addUsrNav allows only to replace the 6 buttons model, that is the
actions performed by MENWIZ are those expected by the 6 buttons model.
The next release of addUsrNav release will allows to explicitly set the replaced
model (4 or 6 buttons mode).
With release 1.0.1 *if* you want to use addUsrNav you can patch with the following
lines in the sketch code

Code: [Select]

extern byte MW_navbtn;
...
// in setup() just after the addUsrNav call
MW_navbtn=4;  // force 4 buttons mode



backbone

Likethis?

top part:
Code: [Select]
// DEFINE ARDUINO DIGITAL PINS FOR THE NAVIGATION BUTTONS FOR MENWIZ
#define MW_BTNULL  //NOBUTTON
#define MW_BTU  //UP
#define MW_BTD  //DOWN
#define MW_BTE  //ESCAPE
#define MW_BTC  //CONFIRM

// Create global object for menu and lcd
menwiz menu;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Addr, En, Rw, Rs, d4, d5, d6, d7, backlightpin, polarity


void setup():
Code: [Select]
// initialize the menu object (20 colums x 4 rows LCD)
  menu.begin(&lcd,20,4);
  menu.addUsrNav(navMenu);
  MW_navbtn=4;  // force 4 buttons mode


  //create the menu tree
  r=menu.addMenu(MW_ROOT,NULL,F("MAIN MENU"));                      //create a root menu at first (required)
 
  //--------------- 
  s1=menu.addMenu(MW_SUBMENU,r,F("SET1"));                        //add a submenu node 1 to the root menu
 
  s2=menu.addMenu(MW_VAR,s1,F("MD"));                         //add a terminal node in the menu tree (that is "variable");
  s2->addVar(MW_AUTO_BYTE,&modelNumber,1,10,1);            //Set value
  s2=menu.addMenu(MW_VAR,s1,F("BR"));                         //add a terminal node in the menu tree (that is "variable");
  s2->addVar(MW_AUTO_BYTE,&brakeRValue,1,255,stepsMValue); //Set value
  s2=menu.addMenu(MW_VAR,s1,F("RH"));                         //add a terminal node in the menu tree (that is "variable");
  s2->addVar(MW_AUTO_BYTE,&regenHyValue,1,25,1);           //Set value
  //---------------
  s1=menu.addMenu(MW_SUBMENU,r,F("SET2"));                    //add a submenu node 2 to the root menu
 
  s2=menu.addMenu(MW_VAR,s1,F("CP"));                         //add a terminal node in the menu tree (that is "variable");
  s2->addVar(MW_AUTO_INT,&endCurvePower,1,50,1);              //Set value
  s2=menu.addMenu(MW_VAR,s1,F("DB"));                         //add a terminal node in the menu tree (that is "variable");
  s2->addVar(MW_AUTO_BYTE,&deadbandXvalue,1,25,1);         //Set value
  s2=menu.addMenu(MW_VAR,s1,F("SQ"));                         //add a terminal node in the menu tree (that is "variable");
  s2->addVar(MW_AUTO_BYTE,&stepsQValue,0,10,1);            //Set value
  s2=menu.addMenu(MW_VAR,s1,F("SM"));                         //add a terminal node in the menu tree (that is "variable");
  s2->addVar(MW_AUTO_BYTE,&stepsMValue,0,10,1);            //Set value
  //---------------
  s1=menu.addMenu(MW_SUBMENU,r,F("SET3"));                    //add a submenu node 3 to the root menu
 
  s2=menu.addMenu(MW_VAR,s1,F("RS"));                         //add a terminal node in the menu tree (that is "variable");
  s2->addVar(MW_BOOLEAN,&regbrakeState);                   //Set value
  s2=menu.addMenu(MW_VAR,s1,F("RCALIB"));                     //add a terminal node in the menu tree (that is "variable");
  s2->addVar(MW_ACTION,resetCalibration);                  //Set value
  s2=menu.addMenu(MW_VAR,s1,F("SCALIB"));                     //add a terminal node in the menu tree (that is "variable");
  s2->addVar(MW_ACTION,saveCalibration);                  //Set value

  //++++++ Splash screen +++++++
  sprintf(menu.sbuf,"SLOT WIZARD MEGA\nSLOT RACE\nuCONTROLLER JC-1\nVersion 3.124 CP \n \n",1); //==============================================================================================================================
  menu.addSplash((char *) menu.sbuf, 1000);

  //++++++ Userscreen ++++++++++
  // create an user define screen callback to activate after X secs since last button push
  menu.addUsrScreen(msc,3000);


void loop():
Code: [Select]
// NAVIGATION MANAGEMENT & DRAWING ON LCD. NOT BLOCKING has to be the first in the void loop
  menu.draw();

// ++++ Buttons 10 in total ++++++
  buttonValue = analogRead(0);   // read the input pin 0
  // internal 20K ohm pullup is enabled on analog pin 0 (54).
 
  int navMenu(){ //called by menwiz.draw()
  }
  if(buttonValue >= 920 and buttonValue <= 930 )
  {
    MW_BTU //Up button
    //digitalWrite(led7Pin, HIGH);
    delay (200); // 910
  }
    else if(buttonValue >= 820 and buttonValue <= 835)
  {
    MW_BTC // Confirm button
    //digitalWrite(led7Pin, HIGH);
    delay (200);// 827
  }
    else if(buttonValue >= 725 and buttonValue <= 740)
  {
    MW_BTD //Down button
    //digitalWrite(led7Pin, HIGH);
    delay (200); // 731
  }
    else if(buttonValue >= 630 and buttonValue <= 645)
  {
    MW_BTE //Escape button
    //digitalWrite(led7Pin, HIGH);
    delay (200); // 637
  }
    else if(buttonValue >= 535 and buttonValue <= 550)
  {
    switchpointYValue = switchpointYValue - stepsQValue;
    delay (200); // 542
  }
    else if(buttonValue >= 440 and buttonValue <= 455)
  { 
    switchpointXValue = switchpointXValue - stepsQValue;
    delay (200); //446
  }
    else if(buttonValue >= 340 and buttonValue <= 355)
  { 
    speedstartValue = speedstartValue - stepsQValue;
    delay (200); //347
  }
    else if(buttonValue >= 235 and buttonValue <= 250)
  { 
    speedstartValue = speedstartValue + stepsQValue;
    delay (200); //241
  }
    else if(buttonValue >= 125 and buttonValue <= 140)
  { 
    switchpointXValue = switchpointXValue + stepsQValue;
    delay (200); //131
  }
    else if(buttonValue >= 5 and buttonValue <= 20)
  { 
    switchpointYValue = switchpointYValue + stepsQValue;
    delay (200); //13
  }
    else
    MW_BTNULL
Never to old to learn and I learn every day

brunialti

The patch i well positioned. But at first glance i see some point in teh code wrong or unclear.

Keep the #define for buttons  codes (MW_BTU ,...) off, as they are in the MENWIZ.h (and they require a number to be defined with literal).
If I'm not wrong the literal NULL should be lower cased to null.
I noticed that you define navMenu inside main loop()  (or may be it is a code extract).
You could have some debouncing problems with navMenu  function (transition and persistence of analog values) with unwanted multiple push resulted.
If the user keep the button pushed, the code returns the multiple identical values for each call to menu.draw(), instead of once (as expected).
There should be some libraries for analog buttons that avoid the above mentioned problems, otherway your code must manage them (using toggling variables for last pushed button).

backbone

Bruno,

Dannix code and your sample says MW_NULL not MW_null or are we talking about different things?
I had to declare MW_navbtn as int too in top section.

Now code stops at   r=menu.addMenu(MW_ROOT,NULL,F("MAIN MENU"));                      //create a root menu at first (required)
telling no matching call to 'MENWIZ::addMenu(int,NULL,_FlashStringHelper*)' 

I now about the debounce butfirst I have the four menu buttons to work.
I think the delay in the button call is enough but have to see.

Paco
Never to old to learn and I learn every day

brunialti

You are using a pre 1.0.0 lib version with sketch code syntax of the latest version.
I was wondering about NULL Use in the function arg of addMenu

backbone

Nope, as far as I know I replaced the old libs and use 1.0.1 now.
In th CPP and H file there is no versionumber to be checked.

Paco
Never to old to learn and I learn every day

backbone

To be sure I dowloaded the 1_0_1 version from github. When I unzip and look in the readme file it says version 1.0.0!

See screenshot.

Paco
Never to old to learn and I learn every day

brunialti

#146
Aug 10, 2012, 10:46 pm Last Edit: Aug 10, 2012, 11:08 pm by brunialti Reason: 1
The lib version is stored in the internal variable MW_ver and is accessible by the method getVer().
The lib itself consist mainly of MENWIZ.h and MENWIZ.cpp (and keywords.txt as ancillary file).
The other files are "frills" and can be misaligned. I did'nt rebuild the zip package to avoid users got confused by two slightly different files with the same version. By the way the lib has been downloaded by many tens of users.
The reported error occourred to me only when I have some old versions rechable by the ide (delete all existing menwiz version *everywhere* and install the new version): it states that the declated template in MENWIZ.h differs from the one encountered in the sketch (_FlashStringHelper* type for strings has been introduced instead of char* type starting from ver 1.0.1).

The next version of MENWIZ:
- addUsrNav modified interface (explicitly declaration of 4 or 6 buttons)
- new menu behaviour option: collapsed view (preview of variable values within the menu item list)


backbone

I already repaced all Menwiz meus I hav on various PC (did not restartPC) copied the .h and .cpp from response #132.
Then without restart PC I got rid of that problem. So one step further.

Then an other compile error  :) I think that is cause the 4-6 button option is not yet in this version.
Never to old to learn and I learn every day

brunialti

it is hard to say without the code.
Anyway:
- the first error could be because you did'nt defined MW_navbtn as extern. MW_navbtn is of type byte and is defined in MENWIZ.cpp, extern is a compiler directive to let it know that the variable is already allocated by one of the module that are going to be linked
- the last errrors (e.g. undefined reference to navMenu)  are sketch errors I cannot say anything about

Download the library from https://github.com/brunialti/MENWIZ/downloads
That is the (only) "official repository".
Even I downloaded from githib the 1.0.1 version. At any time in my pc I have only the version I'm working with

backbone

If I go to github and right click on MENWIZ 1_0_1.zip and say "save target as" and unzip this file it says 1.0.0 in the read me!
This way I expect the 1.0.1 version to be saved atmy disk.
If I click DOWNLOAD as ZIP on the GITHUB page I get the 1.0.1 version to be shown in the read me!
Do not know if this is correct GITHUB behaviour............ :-)
Never to old to learn and I learn every day

Go Up