Pages: 1 ... 7 8 [9] 10 11 ... 32   Go Down
Author Topic: MENWIZ: yet another character lcd menu wizard library  (Read 68055 times)
0 Members and 1 Guest are viewing this topic.
The Netherlands
Offline Offline
Sr. Member
****
Karma: 4
Posts: 330
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bruno,

Good to see the new 1.0 version and the new extra's.
I have to appologize for not creating yet a new bie manual.
Having heavy time issues on several projects.

Paco
Logged

Never to old to learn and I learn every day

rome
Offline Offline
Sr. Member
****
Karma: 17
Posts: 481
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@dannix

It is hard to say why. I would need to setup the analog buttons as yours, but I have not some of the components.
I'll try to make an old fashioned code inspection ... With the new lib v1.0.0 you do not need to apply the patch I sent.
Did you use the errorMessage  during debug after each instruction? Did you get some message?
I'm committed to solve it before holyday :-)
« Last Edit: July 30, 2012, 11:32:16 am by brunialti » Logged

rome
Offline Offline
Sr. Member
****
Karma: 17
Posts: 481
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@backbone

nice to read you again. If you had a practical application of Menwiz (and it works :-) ), it could be interesting share it with the communiy, even criticism,
Logged

rome
Offline Offline
Sr. Member
****
Karma: 17
Posts: 481
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Paco, by the way, are you using custom buttons or devices using addUsrNav method?
You could help me to test/debug setBehaviour in such a condition!
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 128
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@dannix

It is hard to say why. I would need to setup the analog buttons as yours, but I have not some of the components.
I'll try to make an old fashioned code inspection ... With the new lib v1.0.0 you do not need to apply the patch I sent.
Did you use the errorMessage  during debug after each instruction? Did you get some message?
I'm committed to solve it before holyday :-)

Hi,I'd not used errorMessage but have tried again using it, I get no errors. Code below and using latest library.

Code:
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_SR.h>
#include <buttons.h>
#include <EEPROM.h>
#include <MENWIZ.h>

//INTERRUPT BUTTONS
const int pin = 13;  // test for interrupt
const int buttonPin = A0; // buttons can be read here
volatile byte buttonAct = 0; // flag, follow button press
volatile int buttonValue = 0; // button pressed analog value
volatile byte buttonPressed = 0;  // which button was pressed
volatile byte lastButtonPressed = 0; // prev button pressed
volatile byte state = LOW; // state of led on pin 13

/*
// DEFINE ARDUINO PINS FOR THE NAVIGATION BUTTONS
 #define UP_BOTTON_PIN       9
 #define DOWN_BOTTON_PIN     5
 #define LEFT_BOTTON_PIN     7
 #define RIGHT_BOTTON_PIN    8
 #define CONFIRM_BOTTON_PIN  3
 #define ESCAPE_BOTTON_PIN   4
 */

menwiz tree; //create menwiz object
// create lcd obj using LiquidCrystal lib
LiquidCrystal_SR lcd(10, 11, 12); //Data,Clk,Enable.

int  list,sp=110; 

void setup(){
  Serial.begin(19200);
  Serial.println(F("STARTED"));
  pinMode(pin, OUTPUT);
  attachInterrupt(0, readButtons, RISING); 


  _menu *r,*s1,*s2;



  tree.begin(&lcd,20,4); //declare lcd object and screen size to menwiz lib
  tree.addUsrNav(navMenu);
  r=tree.addMenu(MW_ROOT,NULL,F("Root"));
  s1=tree.addMenu(MW_SUBMENU,r,F("SUBMENU"));
  s2=tree.addMenu(MW_VAR,s1,F("Node3"));
  s2->addVar(MW_LIST,&list);
  s2->addItem(MW_LIST,F("Option1"));
  s2->addItem(MW_LIST,F("Option2"));
  s2->addItem(MW_LIST,F("Option3"));
  s2=tree.addMenu(MW_VAR,s1,F("Node4"));
  s2->addVar(MW_AUTO_INT,&sp,0,120,10);
  s2=tree.addMenu(MW_VAR,s1,F("Exit"));
  s2->addVar(MW_ACTION,exitFunct);
  s2->setBehaviour(MW_ACTION_CONFIRM,false);


  //tree.navButtons(UP_BOTTON_PIN,DOWN_BOTTON_PIN,LEFT_BOTTON_PIN,RIGHT_BOTTON_PIN,ESCAPE_BOTTON_PIN,CONFIRM_BOTTON_PIN);
}

int i = 0;
void loop(){

  if(i > 1000){
    Serial.print(F("freeRam() reports "));
    Serial.println( tree.freeRam() );
    i = 0;
  }
  else{
    i++;
  }
  tree.draw();
  int err = tree.getErrorMessage(true);
  if(err){
    Serial.println(err);
  }
}

void readButtons(){  //fired by interrupt 0
  state = !state;
  digitalWrite(pin, state);  // flip pin 13 led state
  /*   511 : none | 614 : up | 768 : down | 1023 : select   */
  lastButtonPressed = buttonPressed;

  buttonValue = analogRead(buttonPin);
  if(buttonValue >= 900) {
    buttonPressed = 3; // select
  }
  else if(buttonValue >= 700){   
    buttonPressed = 2;  // down
  }
  else if(buttonValue >= 600){   
    buttonPressed = 1;  // up
  }
  buttonAct = 1;
  Serial.print(buttonPressed);
  Serial.print(" XX ");
  Serial.println(buttonValue);
}

void exitFunct(){
  Serial.println("EXIT Called");
  buttonAct = 1;
  buttonPressed = 4;  //simulate exit button press
}

int navMenu(){ //called by menwiz.draw()
  int err = tree.getErrorMessage(true);
  if(err){
    Serial.println(err);
  }
 
  if(buttonAct){ //true if button press not processed
    buttonAct = 0; // run once per button press
    switch (buttonPressed){
    case 4: //simulated escape
      return MW_BTE;
      break;
    case 3: //select     
      return MW_BTC;
      break;
    case 2: //down
      return MW_BTD;
      break;     
    case 1: //up
      return MW_BTU;
      break;     
    }
  }
  else{
    return MW_BTNULL;
  }

}

Logged

rome
Offline Offline
Sr. Member
****
Karma: 17
Posts: 481
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The usernav function (same as the builtin scanNavButtons) is called just and only in one point in the code, at the beginning of draw() method:

Code:
 ret=usrNav.fl?usrNav.fi():scanNavButtons();     //internal method or user defined callback?

as you can see the builtin xor your function, internally coded as usrNav.f(), returns a button code that is therefore processed by the following code.
This imply that if your function returns the same code as the builtin one, the executed code after the call is *exactly* the same. There is no other code  that is performed by builtin function (no initialization, no global or local variables assignment). This is the reason why I cannot understand why the behaviour is different, provided the two functions return the same values for equivalent actions.

So, in a pure deductive way  smiley-cool ... you need to check if the value returned by your function (the value of ret variable) is the one you expected (e.g. is equal to MW_BTC after pushing Confirm button). Try to put a Serial.println trace after that. Of course as the call to draw() are many in the loop you must quickly unplug the usb cable (or put a conditional printing checking for the expected code).

Regarding the  use of tree.getErrorMessage(true),  if no error occourred in the *last* executed MENWIZ method call, it does not print to Serial. If an error occourret it print to Serial both the error code and an error message.
I suggest to use it in the menu structure declarations in such a way:

Code:
 s2=tree.addMenu(MW_VAR,s1,F("Exit"));
  s2->addVar(MW_ACTION,exitFunct);
  s2->setBehaviour(MW_ACTION_CONFIRM,false);
  tree.getErrorMessage(true);

if no message is printed out in the serial terminal, it means no error occourred.

I hope this can help
 
« Last Edit: July 30, 2012, 02:34:49 pm by brunialti » Logged

The Netherlands
Offline Offline
Sr. Member
****
Karma: 4
Posts: 330
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Paco, by the way, are you using custom buttons or devices using addUsrNav method?
You could help me to test/debug setBehaviour in such a condition!

Do not know exactly what you mean.
I burned up my project shield and Mega.
Currently rebuilding the set up with shield and a new Mega.
Used 4 pushbuttons on the digital ports. Do not know if you call that custom buttons.
My code does not use any addUsrNav methods as far as CTRL+f can find......... :-)

Let me know how I can assist in current situation.

If you need the bare code of the MENWIZ I currently use no problem.

Paco
Logged

Never to old to learn and I learn every day

Offline Offline
Full Member
***
Karma: 0
Posts: 128
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

I've added the trace calls and It returns as expected. This is without setBehaviour declared, so run confirm expected. my funct passed MW_BTC but isn't followed by "EXIT called" as if my custom function ins't called.

Code:
STARTED
3 XX 1016
SELECT
2 XX 762
DOWN
freeRam() reports 898
2 XX 763
DOWN
3 XX 1016
SELECT
3 XX 1017
SELECT   <---- my funct passed MW_BTC
freeRam() reports 898
freeRam() reports 898
freeRam() reports 898

This is with s2->setBehaviour(MW_ACTION_CONFIRM,false);

Code:
STARTED
freeRam() reports 898
3 XX 1017
SELECT
2 XX 763
DOWN
2 XX 764
DOWN
3 XX 1015
SELECT
EXIT Called
ESCAPE
freeRam() reports 898
freeRam() reports 898

yet this time it works, when select (MW_BTC) is passed, my function returns EXIT Called as expected sets the button values and MW_BTE is passed as can be seen by the ESCAPE. menwiz goes back a level, except in the new version of the library the line below isn't cleared. It was before.

When I press a button the interrupt fires "3 XX 1015" then I see its corresponding value sent to menwiz SELECT/MW_BTC if it was an exit i see the simulated escape being passed ESCAPE.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 128
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have some buttons, What i'll do is hook them up to digital pins thereby removing the custom button function and see if the same thing happens. I'm certain it's not my button implementation though.

Thanks for your help
Logged

rome
Offline Offline
Sr. Member
****
Karma: 17
Posts: 481
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll do the same, using digital button with your code!
thanks for your patience.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 128
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I've tried using 4 digital buttons. Its exactly the same. Confirm to run does not actually run the custom function. If confirm disabled it runs the custom function once selected.

Using the digital escape button goes back a level but line 3 of the lcd isn't cleared (Node4) and can't be selected. Again, it didn't do this in the previous library version, this is a regression in the latest code.

Here is the code I ran with little changes, buttons defined and addUsrNav commented out

Code:
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_SR.h>
#include <buttons.h>
#include <EEPROM.h>
#include <MENWIZ.h>

//INTERRUPT BUTTONS
const int pin = 13;  // test for interrupt
const int buttonPin = A0; // buttons can be read here
volatile byte buttonAct = 0; // flag, follow button press
volatile int buttonValue = 0; // button pressed analog value
volatile byte buttonPressed = 0;  // which button was pressed
volatile byte lastButtonPressed = 0; // prev button pressed
volatile byte state = LOW; // state of led on pin 13


// DEFINE ARDUINO PINS FOR THE NAVIGATION BUTTONS
 #define UP_BOTTON_PIN       8
 #define DOWN_BOTTON_PIN     7
/*
 #define LEFT_BOTTON_PIN     7
 #define RIGHT_BOTTON_PIN    8
 */
 #define CONFIRM_BOTTON_PIN  4
 #define ESCAPE_BOTTON_PIN   3
 

menwiz tree; //create menwiz object
// create lcd obj using LiquidCrystal lib
LiquidCrystal_SR lcd(10, 11, 12); //Data,Clk,Enable.

int  list,sp=110;  

void setup(){
  Serial.begin(19200);
  Serial.println(F("STARTED"));
  pinMode(pin, OUTPUT);
  attachInterrupt(0, readButtons, RISING);  


  _menu *r,*s1,*s2;
anyErrors();


  tree.begin(&lcd,20,4); //declare lcd object and screen size to menwiz lib
  anyErrors();
  //tree.addUsrNav(navMenu);
  anyErrors();
  r=tree.addMenu(MW_ROOT,NULL,F("Root"));
  anyErrors();
  s1=tree.addMenu(MW_SUBMENU,r,F("SUBMENU"));
  anyErrors();
  s2=tree.addMenu(MW_VAR,s1,F("Node3"));
  anyErrors();
  s2->addVar(MW_LIST,&list);
  anyErrors();
  s2->addItem(MW_LIST,F("Option1"));
  anyErrors();
  s2->addItem(MW_LIST,F("Option2"));
  anyErrors();
  s2->addItem(MW_LIST,F("Option3"));
  anyErrors();
  s2=tree.addMenu(MW_VAR,s1,F("Node4"));
  anyErrors();
  s2->addVar(MW_AUTO_INT,&sp,0,120,10);
  anyErrors();
  s2=tree.addMenu(MW_VAR,s1,F("Exit"));
  anyErrors();
  s2->addVar(MW_ACTION,exitFunct);
  anyErrors();
  //s2->setBehaviour(MW_ACTION_CONFIRM,false);
anyErrors();

Serial.print(MW_BTNULL);Serial.print(MW_BTU);Serial.print(MW_BTD);
Serial.print(MW_BTC);Serial.println(MW_BTE);  
  tree.navButtons(UP_BOTTON_PIN,DOWN_BOTTON_PIN,ESCAPE_BOTTON_PIN,CONFIRM_BOTTON_PIN);
}

int i = 0;
void loop(){

  if(i > 1000){
    Serial.print(F("freeRam() reports "));
    Serial.println( tree.freeRam() );
    i = 0;
  }
  else{
    i++;
  }
  tree.draw();
  anyErrors();
}

void readButtons(){  //fired by interrupt 0
  state = !state;
  digitalWrite(pin, state);  // flip pin 13 led state
  /*   511 : none | 614 : up | 768 : down | 1023 : select   */
  lastButtonPressed = buttonPressed;

  buttonValue = analogRead(buttonPin);
  if(buttonValue >= 900) {
    buttonPressed = 3; // select
  }
  else if(buttonValue >= 700){    
    buttonPressed = 2;  // down
  }
  else if(buttonValue >= 600){    
    buttonPressed = 1;  // up
  }
  buttonAct = 1;
  Serial.print(buttonPressed);
  Serial.print(" XX ");
  Serial.println(buttonValue);
anyErrors();
}

void exitFunct(){
  Serial.println("EXIT Called");
  buttonAct = 1;
  buttonPressed = 4;  //simulate exit button press
//tree.draw();
}

void anyErrors(){
 int err = tree.getErrorMessage(true);
  if(err){
    Serial.println(err);
  }
}

int navMenu(){ //called by menwiz.draw()
  if(buttonAct){ //true if button press not processed
    buttonAct = 0; // run once per button press
    switch (buttonPressed){
    case 4: //simulated escape
      Serial.println(F("ESCAPE"));
      return MW_BTE;
      break;
    case 3: //select
      Serial.println(F("SELECT"));    
      return MW_BTC;
      break;
    case 2: //down
    Serial.println(F("DOWN"));
      return MW_BTD;
      break;    
    case 1: //up
    Serial.println(F("UP"));
      return MW_BTU;
      break;    
    }
  }
  else{
    return MW_BTNULL;
  }

}

« Last Edit: July 31, 2012, 06:14:16 am by dannix » Logged

rome
Offline Offline
Sr. Member
****
Karma: 17
Posts: 481
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok. Now I can replicate the problem.
I confirm the regression :-(
Logged

rome
Offline Offline
Sr. Member
****
Karma: 17
Posts: 481
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Confirm to run does not actually run the custom function.
-FIXED

If confirm disabled it runs the custom function once selected.
-FIXED

Using the digital escape button goes back a level but line 3 of the lcd isn't cleared (Node4) and can't be selected. Again, it didn't do this in the previous library version, this is a regression in the latest code.
-FIXED

Dannix, can I ask you to test the fixed code before to deliver a new version?
Please find here attached the file to replace the existing ones.

* MENWIZ.h (7.13 KB - downloaded 21 times.)
* MENWIZ.cpp (25.18 KB - downloaded 18 times.)
« Last Edit: July 31, 2012, 03:19:25 pm by brunialti » Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 128
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dannix, can I ask you to test the fixed code before to deliver a new version?
Please find here attached the file to replace the existing ones.

It works as expected both with digital buttons or with the custom button function! This library will save me alot of time in my project, I can start fleshing it out now. Thank you for all your work brunialti this could be the default Arduino IDE menu library

 
Logged

rome
Offline Offline
Sr. Member
****
Karma: 17
Posts: 481
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice to read the problems are over.
I inserted the new lib v 1.0.1 in git hub at https://github.com/brunialti/MENWIZ/downloads

I think it is unfair for me as author to promote the lib. It is up to the community to signal if there is something new and interesting on the net :-)
Logged

Pages: 1 ... 7 8 [9] 10 11 ... 32   Go Up
Jump to: