Go Down

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

brunialti

Apr 03, 2012, 05:00 pm Last Edit: Apr 29, 2014, 10:13 pm by brunialti Reason: 1
EDIT: latest MENWIZ version 1.3.2 beta  is now available on https://github.com/brunialti/MENWIZ_1_3_2
       please sign as follower in order to be notified about new versions!

I had to implement a sketch for sensor management with LCD to set some parameters and to show the mesure in real time.
I abstracted the menu management and i wrote a new library called MENWIZ (menu wizard).

The pros are:
- non blocking: that is the library does not take mu control while working, usefull if your sketch need to work while you are changing the settings
- simple to use (few primitives and compact code)
- user defined splash screen (optional): if you need to show something at startup. The time is user defined.
- user defined callback default screen (optional) activated after a user defined elapsed time since last button push. The menu gently leave the screen to the user, untill any button is pushed.  
- automatic user defined variables binding: that is all parameters changes inside the menus affects also the user defined binded variables
- user defined navigation callback routine (so you can use any navigation device you like, inside the framework)
- actions: callback routines to be executed from menu

Warnings
- MENWIZ requires LiquidCrystal_I2C and Buttons libraries, enclosed with the package
- I tested MENWIZ mainly with 4x20 I2C lcd screens. It *should* work also with other lcds (e.g 16x2)), but i did'nt testvit extensively
- Menu labels require memory. Be carefull not to run out of  memory (a simple memory-check function is included inthe lib: use it!)

Latest version of MENWIZ:
https://github.com/brunialti/MENWIZ/downloads

Any feed back is welcome. Should you be interested I can mantain and expand.
Keep in mind that I want to keep it simple.

The TEST_LIB zip file contains the library used to test the MENWIZ lib.
It should be standard, neverthless should you have some problem, try using it

robtillaart

Please change the title to lowercase, uppercase is considered shouting ...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

brunialti


robtillaart

No need to apologize, thank you for "not shouting" ;)

I like new libraries, this is what makes open source great !

Do you have some sample sketches as show case?



Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

brunialti

#4
Apr 03, 2012, 08:49 pm Last Edit: Apr 03, 2012, 09:05 pm by brunialti Reason: 1
Here following the example:


Code: [Select]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <buttons.h>
#include <MENWIZ.h>

// DEFINE ARDUINO PINS FOR THE NAVIGATION BUTTONS
#define UP_BOTTON_PIN       9
#define DOWN_BOTTON_PIN     10
#define LEFT_BOTTON_PIN     7
#define RIGHT_BOTTON_PIN    8
#define CONFIRM_BOTTON_PIN  12
#define ESCAPE_BOTTON_PIN   11

//Create global object LCD and MENU
menwiz menu;
LiquidCrystal_I2C lcd(0x27,20,4);

//instantiate global variables to bind to menu
byte tp=2;
int  gp=26;
boolean wr=0;

void setup(){
 char b[84];
 _menu *r,*s1,*s2;
 _var *v;
 int  mem;

 Serial.begin(19200);  
 // have a look on memory before menu creation
 mem=menu.freeRam();
 
 // inizialize the menu object (20 colums x 4 rows LCD)
 menu.begin(&lcd,20,4);

 //create the menu tree
 r=menu.addMenu(MW_ROOT,NULL,"MAIN MENU");           //create a root menu at first (required)
   s1=menu.addMenu(MW_SUBMENU,r,"MEASURE SUBMENU");   //add a submenu node to the root menu
     s2=menu.addMenu(MW_VAR,s1,"Choose T scale");//add a terminal node in the menu tree (that is "variable");
         s2->addVar(MW_LIST,&tp);                    //create the terminal node variable of type OPTION LIST and bind it to the app variable "tp"
         s2->addItem(MW_LIST,"Celsius");             //add an option to the OPTION LIST
         s2->addItem(MW_LIST,"Farenheit");           //add an other option to the OPTION LIST
         s2->addItem(MW_LIST,"Raw sensor data");     //add the third and last option to the OPTION LIST
     s2=menu.addMenu(MW_VAR,s1,"Set T1 trigger");
         s2->addVar(MW_AUTO_INT,&gp,10,100,2);
     s2=menu.addMenu(MW_VAR,s1,"Enable warmer");
         s2->addVar(MW_BOOLEAN,&wr);

 //(optional) create a splash screen (lap 6 seconds) with some usefull infos
 //the character # marks end of line
 //(tip): use preallocated internal menu.sbuf buffer to save memory space!
 sprintf(menu.sbuf,"MENWIZ TEST V %s#Free memory   : %d#Menu mem alloc: %d#Splash lap sec: %d",menu.getVer(),menu.freeRam(),mem-menu.freeRam(),6);
 menu.addSplash((char *) menu.sbuf, 6000);

 //declare navigation buttons (required)
 // equivalent shorter call: menu.navButtons(9,10,7,8,11,12);
 menu.navButtons(UP_BOTTON_PIN,DOWN_BOTTON_PIN,LEFT_BOTTON_PIN,RIGHT_BOTTON_PIN,ESCAPE_BOTTON_PIN,CONFIRM_BOTTON_PIN);
 // create a user define screen callback to activate after 7 secs since last button push
 menu.addUsrScreen(msc,7000);
 }

void loop(){
 // NAVIGATION MANAGEMENT & DRAWING ON LCD. NOT BLOCKING
 menu.draw();
 //PUT APPLICATION CODE HERE
 }

// user defined default screen
void msc(){
 lcd.setCursor(0,0);
 lcd.print("                    ");
 lcd.setCursor(0,1);
 lcd.print("Test user screen");
 lcd.setCursor(0,2);
 lcd.print(millis()/1000);  lcd.print("        ");
 lcd.setCursor(0,3);
 lcd.print("                    ");
 }

Go Up