application for developing a menu

Dependencies:   C12832_lcd mbed

Files at this revision

API Documentation at this revision

Comitter:
Mircea3M
Date:
Fri Mar 21 15:22:35 2014 +0000
Commit message:
Menu example

Changed in this revision

C12832_lcd.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mcu.h Show annotated file Show diff for this revision Revisions of this file
menu.cpp Show annotated file Show diff for this revision Revisions of this file
menu.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 842039476c99 C12832_lcd.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832_lcd.lib	Fri Mar 21 15:22:35 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/C12832_lcd/#8f86576007d6
diff -r 000000000000 -r 842039476c99 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Mar 21 15:22:35 2014 +0000
@@ -0,0 +1,19 @@
+//#include "mbed.h"
+#include "mcu.h"
+
+
+
+int main() {
+    
+    lcd.setmode(NORMAL);
+    lcd.set_contrast(25);
+
+    browse_menu();
+    
+    while(1) {
+        myled = 1;
+        wait(0.2);
+        myled = 0;
+        wait(0.2);
+    }
+}
diff -r 000000000000 -r 842039476c99 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Mar 21 15:22:35 2014 +0000
@@ -0,0 +1,1 @@
+http://world3.dev.mbed.org/users/mbed_official/code/mbed/builds/824293ae5e43
\ No newline at end of file
diff -r 000000000000 -r 842039476c99 mcu.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mcu.h	Fri Mar 21 15:22:35 2014 +0000
@@ -0,0 +1,7 @@
+#include "mbed.h"
+#include "menu.h"
+
+extern C12832_LCD lcd;
+DigitalOut myled(LED1);
+
+
diff -r 000000000000 -r 842039476c99 menu.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/menu.cpp	Fri Mar 21 15:22:35 2014 +0000
@@ -0,0 +1,184 @@
+#include "menu.h"
+
+C12832_LCD lcd;
+BusIn joystick_sel(p12, p14, p15);
+/*
+DigitalIn sw_right(p16);
+DigitalIn sw_up(p15);
+DigitalIn sw_enter(p14);
+DigitalIn sw_left(p13);
+DigitalIn sw_down(p12);
+*/
+DigitalOut myled_2(LED2);
+
+unsigned char menu_selection = 1;
+
+
+const char menu_000[] = "      -Main Screen-      ";
+const char menu_001[] = " Option 1 ";
+const char menu_002[] = " Option 2 ";
+const char menu_003[] = " Option 3 ";
+const char menu_004[] = " Option 4 ";
+const char menu_005[] = " Option 5 ";
+const char menu_006[] = " Option 6 ";
+const char menu_007[] = " Option 7 ";
+const char menu_008[] = " Option 8 ";
+const char menu_009[] = " START ";
+
+
+const char menu_100[] = "    [Sub Menu]    ";
+const char menu_101[] = " SubOption 1 ";
+const char menu_102[] = " SubOption 2 ";
+const char menu_103[] = " SubOption 3 ";
+const char menu_104[] = " SubOption 4 ";
+const char menu_105[] = " SubOption 5 ";
+const char menu_106[] = " SubOption 6 ";
+
+menuEntry menu[] = {
+    {menu_000, 10, 0, 0, 0, 0},
+    {menu_001, 10, 1, 2, 11, 0},
+    {menu_002, 10, 1, 3, 2, 0},
+    {menu_003, 10, 2, 4, 3, 0},
+    {menu_004, 10, 3, 5, 4, 0},
+    {menu_005, 10, 4, 6, 5, 0},
+    {menu_006, 10, 5, 7, 6, 0},
+    {menu_007, 10, 6, 8, 7, 0},
+    {menu_008, 10, 7, 9, 8, 0},
+    {menu_009, 10, 8, 9, 9, start},
+    
+    {menu_100, 7, 0, 0, 0, 0},
+    {menu_101, 7, 11, 12, 11, 0},
+    {menu_102, 7, 11, 13, 12, 0},
+    {menu_103, 7, 12, 14, 13, 0},
+    {menu_104, 7, 13, 15, 14, 0},
+    {menu_105, 7, 14, 16, 15, 0},
+    {menu_106, 7, 15, 16, 1, 0}
+};
+
+void show_menu(void)    
+{
+    unsigned int line_cnt = 0;
+    unsigned char from = 0;
+    unsigned char till = 0;
+    unsigned char temp = 0;
+    
+    while( till <= menu_selection ) 
+    {
+        till += menu[till].menupoints;
+    }
+    
+    from = till - menu[menu_selection].menupoints;
+    till--;
+    
+    temp = from;
+    
+    if( (menu_selection >= (from+2)) && (menu_selection <= (till-1)))
+    {
+        from = menu_selection - 2;   
+        till = from + 3;
+        
+        for(from = from; from <= till; from++)
+        {
+            lcd.locate(7, 8*line_cnt);
+            lcd.printf("%s", menu[from].text);
+            line_cnt++;
+        }
+        lcd.locate(0, 8*2);
+        lcd.printf(">"); 
+    }else{
+        // selection is within the top - 2 last 2 spaces
+        if(menu_selection <= (from+2))
+        {
+            till = from + 3;
+            for(from = from; from <= till; from++)
+            {
+                lcd.locate(7, 8*line_cnt);
+                lcd.printf("%s", menu[from].text);
+                line_cnt++;
+            }
+            lcd.locate(0, 8*(menu_selection-temp));
+            lcd.printf(">");            
+        }
+        if(menu_selection == till)
+        {
+            from = till - 3;
+            
+            for(from = from; from <= till; from++)
+            {
+                lcd.locate(7, 8*line_cnt);
+                lcd.printf("%s", menu[from].text);
+                line_cnt++;
+            }
+            lcd.locate(0, 8*3);
+            lcd.printf(">");             
+        }
+    } 
+            lcd.locate(0,0);
+        lcd.printf("%d %d", menu_selection, line_cnt);  
+}
+
+void browse_menu(void)
+{
+    do{
+
+        show_menu();
+        switch(joystick_sel){
+            case 0x01:
+                    menu_selection = menu[menu_selection].down;
+                break;
+            case 0x02:
+                    menu_selection = menu[menu_selection].enter;
+                    if(menu[menu_selection].fp != 0)
+                    {
+                        menu[menu_selection].fp();
+                        
+                        menu_selection = menu[menu_selection].enter;
+                    }
+                break;  
+            case 0x04:
+                    menu_selection = menu[menu_selection].up;
+                break;     
+        }
+
+ //       while(1)
+   //     {
+            myled_2 = 1;
+    
+            wait(0.25);
+            myled_2 = 0;
+    
+            wait(0.25);
+     //   }
+ /*       if(sw_up){
+            menu_selection = menu[menu_selection].up;
+        }
+        if(sw_down){
+            menu_selection = menu[menu_selection].down;
+        }
+            if(sw_left){
+                menu_selection = menu[menu_selection].up;
+            }        
+        if(sw_enter){
+            menu_selection = menu[menu_selection].enter;
+            if(menu[menu_selection].fp != 0)
+            {
+                menu[menu_selection].fp();
+                
+                menu_selection = menu[menu_selection].enter;
+            }
+            wait(0.05);
+        }      
+*/
+    }while(1);   
+}
+
+
+void start(void)
+{
+    lcd.cls();
+    lcd.locate(0, 0); lcd.printf("Start option selected");  
+    
+    while(1)
+    {
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 842039476c99 menu.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/menu.h	Fri Mar 21 15:22:35 2014 +0000
@@ -0,0 +1,23 @@
+#ifndef __MENU_H_INCLUDED__
+#define __MENU_H_INCLUDED__
+
+#include "mbed.h"
+#include "C12832_lcd.h"
+
+
+typedef const struct menuStructure{
+    const char *text;
+    unsigned char menupoints;
+    unsigned char up;
+    unsigned char down;
+    unsigned char enter;
+    void (*fp) (void);
+}menuEntry;
+
+void start(void);
+void show_menu(void);
+void browse_menu(void);
+
+
+
+#endif
\ No newline at end of file