Pages: 1 2 [3] 4   Go Down
Author Topic: MenuBackend, new menu managment library  (Read 43841 times)
0 Members and 1 Guest are viewing this topic.
Brno@Czech Republic
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

maybe Exit is not a right name, moveleft maybe. And if it has no left connection move to most top one and then move left.
Logged

Brno@Czech Republic
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or am I missing something obvious?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello I'm new to arduino and i would like to know is there a code for selecting menu with the thumb joystick like the one on sparkfun. Thank you!
Logged

Chennai, India
Offline Offline
God Member
*****
Karma: 0
Posts: 752
Peace!!!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice effort.... Bad that i only bumped into this thread accidentally after programming some complex menus the hard way smiley-sad
Logged

Be The Change...

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The latest source-post at pastebin for v 1.2 is not valid any more. Can someone post the code here at arduino forum please. Thx!
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 13
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've actually lost the sources myself, but I'll have a look in my backups and get back to you.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Hello,

Is there someone who can post version 1.2?

I must agree with vysocan, the moveBack() for exiting from current level is useless. Also I would be very careful with recursive search within few kB of RAM.

Anyway this approach is very good and useful.
Logged

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

I'll try to remember to look when I get home, I don't recall what version I got last.  Its not on my usb stick here at work.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

Here is modified version 1.1.

I believe it contains more usable solution for exiting from menu levels. It was achieved just by setting back pointer during initialization of the MenuItem class and propagation of this pointer for items added later into the chain (only if they don't have back pointer specified). I also remove those chunks of code which was in my opinion useless or oversized.

For example, now if you want to have getBack method working in the proper way, the initialization should looks like this:

Code:
MenuItem miFile = MenuItem("File",&menu.getRoot());
            MenuItem miNew = MenuItem("New");
            MenuItem miOpen = MenuItem("Open");
            MenuItem miExamples = MenuItem("Examples");
                  MenuItem miArduinoISP = MenuItem("ArduinoISP",&miNew);

Where hitting back on item "ArduinoISP" will restore the current position to item "New", which is the first item for submenu "File". I think this kind of behavior is more suitable for LCD screens.

Code:
/*
||
|| @file MenuBackend.h
|| @version 1.1-lite
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
|| @note some minor changes Adrian Brzezinski adrb@wp.pl
||
|| @description
|| | Provide an easy way of making menus
|| #
||
|| @license
|| | This library is free software; you can redistribute it and/or
|| | modify it under the terms of the GNU Lesser General Public
|| | License as published by the Free Software Foundation; version
|| | 2.1 of the License.
|| |
|| | This library is distributed in the hope that it will be useful,
|| | but WITHOUT ANY WARRANTY; without even the implied warranty of
|| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
|| | Lesser General Public License for more details.
|| |
|| | You should have received a copy of the GNU Lesser General Public
|| | License along with this library; if not, write to the Free Software
|| | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
|| #
||
*/

#ifndef MenuBackend_h
#define MenuBackend_h

class MenuItem {
public:

      MenuItem(const char* itemName, MenuItem *backpoint=0 ) : name(itemName), back(backpoint) {
            before = 0;
            right = 0;
            after = 0;
            left = 0;
      }

      const char* getName() const { return name; }
      MenuItem* getBack() { return back; }
      MenuItem* getBefore() { return before; }
      MenuItem* getRight() { return right; }
      MenuItem* getAfter() { return after; }
      MenuItem* getLeft() { return left; }

      MenuItem* moveUp() { return before; }
      MenuItem* moveDown() { return after; }
      MenuItem* moveLeft() { return left; }
      MenuItem* moveRight() { return right; }

      //default vertical menu
      MenuItem &add(MenuItem &mi) { return addAfter(mi); }

      MenuItem &addBefore(MenuItem &mi) {
            mi.after = this;
            before = &mi;
            if ( !mi.back ) mi.back = back;
            return mi;
      }
      MenuItem &addRight(MenuItem &mi) {
            mi.left = this;
            right = &mi;
            if ( !mi.back ) mi.back = back;
            return mi;
      }
      MenuItem &addAfter(MenuItem &mi) {
            mi.before = this;
            after = &mi;
            if ( !mi.back ) mi.back = back;
            return mi;
      }
      MenuItem &addLeft(MenuItem &mi) {
            mi.right = this;
            left = &mi;
            if ( !mi.back ) mi.back = back;
            return mi;
      }
protected:

      const char* name;

      MenuItem *before;
      MenuItem *right;
      MenuItem *after;
      MenuItem *left;
      MenuItem *back;
};

//no dependant inclusion of string or cstring
bool menuTestStrings(const char *a, const char *b) {
      while (*a) { if (*a != *b) { return false; } b++; a++; }
      return true;
}
bool operator==(MenuItem &lhs, char* test) {
      return menuTestStrings(lhs.getName(),test);
}
bool operator==(const MenuItem &lhs, char* test) {
      return menuTestStrings(lhs.getName(),test);
}
bool operator==(MenuItem &lhs, MenuItem &rhs) {
      return menuTestStrings(lhs.getName(),rhs.getName());
}
bool operator==(const MenuItem &lhs, MenuItem &rhs) {
      return menuTestStrings(lhs.getName(),rhs.getName());
}

struct MenuChangeEvent {
      const MenuItem &from;
      const MenuItem &to;
};

struct MenuUseEvent {
      const MenuItem &item;
};

typedef void (*cb_change)(MenuChangeEvent);
typedef void (*cb_use)(MenuUseEvent);

class MenuBackend {
public:

      MenuBackend(cb_use menuUse, cb_change menuChange = 0) : root("MenuRoot") {
            current = &root;
            cb_menuChange = menuChange;
            cb_menuUse = menuUse;
      }

      MenuItem &getRoot() {
            return root;
      }
      MenuItem &getCurrent() {
            return *current;
      }

      void moveBack() {
            setCurrent(current->getBack());
      }

      void moveUp() {
            setCurrent(current->moveUp());
      }

      void moveDown() {
            setCurrent(current->moveDown());
      }

      void moveLeft() {
            setCurrent(current->moveLeft());
      }

      void moveRight() {
            setCurrent(current->moveRight());
      }

      void use() {
            if (cb_menuUse) {
                  MenuUseEvent mue = { *current };
                  cb_menuUse(mue);
            }
      }

private:
      void setCurrent( MenuItem *next ) {
            if (!next) return;

            if (cb_menuChange) {
                  MenuChangeEvent mce = { *current, *next };
                  cb_menuChange(mce);
            }

            current = next;
      }

      MenuItem root;
      MenuItem *current;

      cb_change cb_menuChange;
      cb_use cb_menuUse;
};

#endif

[edit]
Actually there was some small bug, which i have just fixed.
[/edit]
« Last Edit: September 09, 2010, 10:08:07 am by arian » Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 13
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks good smiley
« Last Edit: September 09, 2010, 08:25:09 pm by AlphaBeta » Logged

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

Sorry I failed, I only have a 1.0 maybe its 1.1.  But I see thats alreayd posted again.  So thats good.
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 13
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've started to do some work on this library again.

I will post a new version within a weeks time (I am in the middle of writing a paper for my masters and I am busy busy busy).
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow, I've been looking for something like this for a while now, looks quite impressive!

Question: Was the MenuBackend example code specifically written for serial LCD's? If yes, how could one go about making it work with 4bit/8bit controlled 44780's LCDisplays?

Cheers,
RJ
« Last Edit: November 19, 2010, 02:45:30 pm by Kulty » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 43
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is 1.0 the latest version to use or is there a getter one I saw 1.1 and 1.2 but the links are dead
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 13
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is currently the newest version: http://www.arduino.cc/playground/uploads/Profiles/MenuBackend
Logged

Pages: 1 2 [3] 4   Go Up
Jump to: