Pages: 1 ... 24 25 [26] 27 28 ... 34   Go Down
Author Topic: MENWIZ: yet another character lcd menu wizard library  (Read 75991 times)
0 Members and 1 Guest are viewing this topic.
rome
Offline Offline
Sr. Member
****
Karma: 17
Posts: 487
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks drjm! Fixed.
The serial messages were for debugging. Deleted. As soon as I can I would like to post a new version with some enhancement. Unfortunately I never find the time....
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there any possibility to unload the menu at runtime and reload another one?
Or maybe one could assign a visible/not visible property to single nodes; that wold help me
out of my current problem.

I need to change the menu based on the rights of the user that´s logged in...

Greetings and tanks for the cool library

Chris from AT
Logged

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

Unfortunately the library does not allow to unload menus at run time.
It is not intrinsically difficult to implement such a functionality , but due to the memory heap management, deallocation of previously dinamically allocated memory could return memory chunks not reusable for further allocations. This could very easily exhaust the (small) available memory and halt the sketch in unpredictable manners.
Sorry :-)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for the information, I'm thinking about trying to hack some kind of property into the menu construction, like an integer value assigned to each node being e.G. 0 as always there, 1-9 being access levels at which the nodes get visible. e.G.

Root Menu ... 0 .. everyone gets that menu of course
Node 1 ....... 0 .. every user gets that menu
Node 2 ....... 1 .. only users with privileges 1 and higher get that menu
Node 3 ....... 2 .. users with 2 and higher see this ...

Since I´m not the best of programmers out there i imagine setting a global variable at user login.

What do yo think about the idea? This would make it possible to construct the full menu at startup and display only the menus the user has access to at runtime.
Logged

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

That could be feasible. I like this solution. As far as I can get time i'll do it. The overall overhead is quite small (1 byte for each menu node)
thanks !
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thinking about it again, one could even apply a kind of bit matrix onto the menu entries like:

User 1 Rights  (integer = 5)        0000 0101
User 2 Rights  (integer = 3)        0000 0011

Menu a needs bit 2                   0000 0100 .. user 1 has rights, user 2 won´t see thet one
Menu b needs bit 1                   0000 0010 .. user 2 has rights, user 1 won´t see that one
Menu c needs bit 0                   0000 0001 .. both users have rights

also doesn´t need more than one byte per entry, leaving 8 different access levels open for play. looking  into your code I see, that it goes way beyond my c knowledge, but i´ll hack around anyway, keeping a untouched copy secure ont the side.

have a nice day!
« Last Edit: June 17, 2013, 08:17:13 am by cno1 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Got it, at least kind of. all it does is iterate over menu entries that the user has no right to see.
its cobbled together, works only for submenus and doesn't care about the menu_index, which counts menus that maybe never will appear but it solves my problem. if anyone is interested I could post it here, but since it´s not my code I abused  I´m not sure if it´s okay.

changes in usage of the library look like this:


the creation of the menu:, see the additional integer before 'F'
Code:
menu.setBehaviour(MW_MENU_INDEX,false); 
  menu.setBehaviour(MW_ACTION_CONFIRM,true);
  r=menu.addMenu(MW_ROOT,NULL,0,F("Hauptmenue")); <- the 0 means this menu is always shown
   s1=menu.addMenu(MW_VAR,r,0,F("Licht"));       
    s1->addVar(MW_BOOLEAN,&aussenlicht); 
    s1=menu.addMenu(MW_SUBMENU,r,8,F("Sauna"));    <-- the 8 means the bit 3 (integer 8) of the user's rights is needed for the menu to show up
      s2=menu.addMenu(MW_VAR,s1,8,F("Start/Stop"));     
setting the user right is simply a matter of adding up the single bit's numeric values of the menu entries you want to give him:
 
Code:
    menu.myrights=0;
    if (any user logged in) (menu.myrights)++;
    if (user may see menus with bit 1) (menu.myrights) = (menu.myrights) +2;
    if (user may see menus with bit 2) (menu.myrights) = (menu.myrights) +4;
    if (user may see menus with bit 3) (menu.myrights) = (menu.myrights) +8;
   
« Last Edit: June 18, 2013, 02:34:17 am by cno1 » Logged

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

@cno1
thanks for the effort! I would like to implement the permissions via a setBehaviour interface, in order to let the interface unchanged: by default all the nodes (menus) are visible to any user. When needed the menu can be restricted to one of the 8 available levels.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds cool and a lot cleaner than my approach. I already mentioned I´m not keen in programming in cpp, Started writing spaghetti code with COBOL in 1985 and seem to be stuck in gotos and returns ever since smiley

Logged

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

 smiley
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Though i m one of your greatest MENWIZ fan i sometimes have a small problem. Just like this one:
I am looking for a possibility to switch off the menu and use the LCD for some other output. With a button code i would switch on the menu again..
Can someone give me some help ????
Logged

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

Did you try the addUsrScreen method?
As an example:
Code:
menu.addUsrScreen(msc,10000);

.....

void msc(){
  static  char buf[7];
  strcpy(menu.sbuf,"User screen"); //1st lcd line
  strcat(menu.sbuf,"\nUptime (s): ");strcat(menu.sbuf,itoa((int)(millis()/1000),buf,10));//2nd lcd line
  strcat(menu.sbuf,"\nFree mem  : ");strcat(menu.sbuf,itoa((int)menu.freeRam(),buf,10));//3rd lcd line
  strcat(menu.sbuf,"\n"); //4th lcd line (empty)
  menu.drawUsrScreen(menu.sbuf);
  }


after 10000 miliseconds since the last menu interaction it launches the msc function where you can display your data. If any button is pushed again, the menu takes the display control again.
If this is not enough, try to tell me what would you like to do.
Please note as you should not use sprintf function in order to save about 2K of memory

EDIT: addUsrScreen must be used inside setup function
« Last Edit: June 25, 2013, 12:24:42 pm by brunialti » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow what a fast answer. Thank you Roberto. Well i just tried your proposal. Works like a charm. The only problem is that 4th line is flickering fast . I think this depends on the Arduino loop. Any chance to leave this loop and return on demand ?
Logged

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

it should'nt flicker. It could be due to a slow refesh rate or to text on the 3rd line wider than the display size (if you have a 40 chars display, trying to display 41 characters it could produce some flickering). Control the string length and if it is correct, try to patch the 4th line filling it  with blanks before \n .
No chance to leave ... the draw method manage by itself all the stuff... but ... you can create a node of type action and then inside the action manage the display directly.
« Last Edit: June 25, 2013, 04:10:08 pm by brunialti » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

due to your help i could solve the problem. Everything is working now as it should. Though you suggested not to use sprintf i am using it. The space does not worry me. I am just using about 34.000 out of 131000 for my code. I surely could reduce the code down to use a smaller capacity chip but if you see the cost it is not worth the work.
Okay my next problems are the variables assigned in the menu.
Such as:
MW_AUTO_INT an integer value, with min/max boundaries and increment/decrement step
I don't want to use the left and right button. Instead of that i would like to directly input to the variable via a 4x3 matrix board. I have already implemented the keypad using menu.addUsrNav(menuKeys,6); and using the keys 2,8,4,6,* and #.
I don't hope that i'll have to write a whole keypad input? I read your quick tutorial several times. Have i missed something?
Can you help me with this?
Thanks
Logged

Pages: 1 ... 24 25 [26] 27 28 ... 34   Go Up
Jump to: