Go Down

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

brunialti

#105
Jul 19, 2012, 05:07 pm Last Edit: Jul 19, 2012, 05:09 pm by brunialti Reason: 1
Yeah. Someone could also ask for 2.5 buttons ...
Be sure you've got the latest version of menwiz as freeRam *must* compile ...
Until the first version 1.0 (soon to be delivered if I get positive feedback) I'm touching the lib and sometime I've got some regression error. Currently I'm struggling with raspi/arduino integration and I've not time enough to finalize this lib.

dannix

just got my raspi today as it goes :P

I'll look at the freeRam, after some raspi fiddling of course

brunialti

#107
Jul 20, 2012, 07:14 pm Last Edit: Jul 21, 2012, 05:59 pm by brunialti Reason: 1
Please find the new lib version at https://github.com/brunialti/MENWIZ/downloads .
There are the new following methods:

void menwiz::writeEeprom(); //write all MENWIZ binded variables to eeprom
void menwiz::readEeprom();  //read from eeprom the previously saved variable values
void _menu::setBehaviour(byte behaviour, boolean value); //toggle action confirmation, horizontal/vertical scrolling of list

In order to let you have a better idea of the changes, please read the updated quick tour pdf doc here attached.
Due to the eeprom support it is now necessary to include EEPROM.h file in the user sketch. This introduce a small backward compatibility break.

Feedbacks are welcome

dannix

Hi, do you have an example of the setBehaviour? I'm not sure how it should be declared and against what object? tree. _menu etc?

I'm getting errors like "MW_ACTION_IMMEDIATE is not defined"

dannix

Hi, to be clear I'm using version 0.6.1
I'd defined my own button press detection as before, and emulated an exit press by fireing a custom function. While it asked for confirm to run when pressing confirm it ran. Now it doesn't run, asks for confirm, i press confirm and it goes back to the menu list



Code: [Select]

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_SR.h>
#include <buttons.h>
#include <EEPROM.h>
#include <MENWIZ.h>
#include <MemoryFree.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 analogue value
volatile int buttonPressed = 0;  // which button was pressed
volatile byte lastButtonPressed = 0; // prev button pressed
volatile byte state = LOW; // state of led on pin13
volatile byte lastState = HIGH; // unused?

/*
// 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
*/
// #define MW_ACTION_IMMEDIATE
menwiz tree;
// 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.addUsrNav(navMenu);
  tree.begin(&lcd,20,4); //declare lcd object and screen size to menwiz lib
//_menu::setBehaviour(byte MW_ACTION_IMMEDIATE, false);
  r=tree.addMenu(MW_ROOT,NULL,"Root");
  s1=tree.addMenu(MW_SUBMENU,r,"SUBMENU");
  s2=tree.addMenu(MW_VAR,s1,"Node3");
  s2->addVar(MW_LIST,&list);
  s2->addItem(MW_LIST,"Option1");
  s2->addItem(MW_LIST,"Option2");
  s2->addItem(MW_LIST,"Option3");
  s2=tree.addMenu(MW_VAR,s1,"Node4");
  s2->addVar(MW_AUTO_INT,&sp,0,120,10);
  s2=tree.addMenu(MW_VAR,s1,"Exit");
  s2->addVar(MW_ACTION,exitFunct);



  // 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("freeMemory() reports "));
    Serial.println( freeMemory() );
   
    i = 0;
  }else{
    i++;
  }
  tree.draw();
}

void myfunc(){
  Serial.println("ACTION FIRED!");
}


void readButtons(){
  state = !state;
  digitalWrite(pin, 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;

}

int navMenu(){
  //MenuItem currentMenu=menu.getCurrent();
  if(buttonAct){
    buttonAct = 0;
    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;
  }
}

Go Up