test menu
Dependencies: Menu RPG SMARTGPU TextLCD Ton mbed
Fork of lcd_menu by
Revision 4:05868e0f5d7e, committed 2015-05-13
- Comitter:
- jjcimon
- Date:
- Wed May 13 11:42:42 2015 +0000
- Parent:
- 3:30dc8952d0ae
- Commit message:
- new LCDmenuV2
Changed in this revision
diff -r 30dc8952d0ae -r 05868e0f5d7e Menu.lib --- a/Menu.lib Tue Mar 05 22:16:35 2013 +0000 +++ b/Menu.lib Wed May 13 11:42:42 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/pyeh9/code/Menu/#2654dc659298 +http://developer.mbed.org/users/jjcimon/code/Menu/#3cdd377f5899
diff -r 30dc8952d0ae -r 05868e0f5d7e SMARTGPU.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SMARTGPU.lib Wed May 13 11:42:42 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/emmanuelchio/code/SMARTGPU/#8da93960a86b
diff -r 30dc8952d0ae -r 05868e0f5d7e Ton.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Ton.lib Wed May 13 11:42:42 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/AjK/code/Ton/#123a1b30970a
diff -r 30dc8952d0ae -r 05868e0f5d7e main.cpp --- a/main.cpp Tue Mar 05 22:16:35 2013 +0000 +++ b/main.cpp Wed May 13 11:42:42 2015 +0000 @@ -1,23 +1,173 @@ #include "mbed.h" -#include "TextLCD.h" +// #include "TextLCD.h" #include "RPG.h" #include "Selection.h" #include "Menu.h" #include "Navigator.h" #include <vector> #include <string> +#include "SMARTGPU.h" +#include "Ton.h" +Ton t1(11000); +Ton t2(60000); +Ton t3(840000); +char Rtions[5]; +char p; +DigitalOut Out1(LED1); +DigitalOut Out2(LED2); +DigitalOut out3(LED3); +DigitalOut Out4(LED4); +InterruptIn pb(p24); +InterruptIn bt1(p26); +InterruptIn bt2(p28); +int waiting=0; +int n; +//int MTR = 0; +DigitalOut MTR(p19); +int volatile countT=0; +char counter = 0; +//const char Cpass[10]= {0x00}; +char Cpass[10]; +//int volatile old=0; +int old = 0; +int bt1o = 1; +int oldbt2=1; +int Mn1 = 1; +int Mn2 = 3; +void pb_hit_interrupt (void) { + countT++; + if( (old==0 ) & (waiting == 0) &( oldbt2 == 0)&( bt1o == 0) ) { + MTR = 1; + Out4 = !Out4; + Out1=1; + old = 1; + } + } + +void bt1_hit_interrupt (void) { + if( (bt1o==0 )& (old == 0) ) { + bt1o = 1; + } + } + + +void bt2_hit_interrupt (void) { + if( (oldbt2==0 )& (old == 0) ) { + oldbt2 =1; + + }} + +//#include "rpc.h" +Serial pc(USBTX, USBRX); +SMARTGPU lcd(p13,p14,p15); //(TX,RX,Reset); + DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4); -TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7 +//TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7 RPG rpg(p21,p22,p23); + +int oldpass; +int pass; +int oldCons; +int Cons; + +int oldcourbe; +int courbe; +int oldHor; +int Hor; + +int oldJour; +int Jour; + + + using namespace std; +int prevpass; + +char bufCons[3]; +char oldbufCons[3]; +char bufPass[1]; +char oldbufpass[1]; + +char bufcourbe[1]; +char oldbufcourbe[1]; + +char bufJour[1]; +char oldbufJour[1]; + +char bufHor[1]; +char oldbufHor[1]; + // some functions to tie to selections void toggleLED1() { led1 = !led1; } void toggleLED2() { led2 = !led2; } void toggleLED3() { led3 = !led3; } void toggleLED4() { led4 = !led4; } +void incpass() { +oldpass = pass; +pass++; + +sprintf(bufPass, "%d", pass); +} + +void decpass() { +oldpass = pass; +pass--; +sprintf(bufPass, "%d", pass); + } + +void incCons() { +oldCons = Cons; +Cons++; +sprintf(bufCons, "%d", Cons); + } + +void decCons() { +oldCons = Cons; +Cons--; +sprintf(bufCons, "%d", Cons); + } + + +// Horaire +void incHor() { +oldHor = Hor; +Hor++; +sprintf(bufHor, "%d", Hor); + } + void decHor() { +oldHor = Hor; +Hor--; +sprintf(bufHor, "%d", Hor); + } + + // Jour +void incJour() { +oldJour = Jour; +Jour++; +sprintf(bufJour, "%d", Jour); + } +void decJour() { +oldJour = Jour; +Jour--; +sprintf(bufJour, "%d", Jour); + } + + // Courbe +void incCourbe() { +oldcourbe = courbe; +courbe++; +sprintf(bufcourbe, "%d", courbe); + } +void decCourbe() { +oldcourbe = courbe; +courbe--; +sprintf(bufcourbe, "%d", courbe); + } + + void resetLED() { led1 = 0; @@ -27,14 +177,40 @@ } int main() { + Cons = 0; + pass = 2; + Hor = 1; + courbe = 3; + Jour = 7; + lcd.reset(); //physically reset SMARTGPU + lcd.start(); //initialize the SMARTGPU processor + toggleLED2(); + pass = 1; + set_time(1309776930); +pb.mode(PullUp); +bt1.mode(PullUp); +bt2.mode(PullUp); +wait(1); +pb.fall(&pb_hit_interrupt); + +bt1.rise(&bt1_hit_interrupt); +bt2.rise(&bt2_hit_interrupt); + +Rtions[1]=11; + Rtions[2]=12; + Rtions[3]=13; + Rtions[4]=14; + time_t rawtime = time(NULL); + + // In using this library, the user declares "Menus", which are essentially arrays of "Selections". // Selections describe each individual selectable item. // Selections can be tied to functions. Functions must output void and take in no arguments. // Selections can also have references to child menus. - + // It makes sense to declare a root menu first, but you don't have to. // Menus should have an identifier (the argument in constructor). - Menu rootMenu("root"); + Menu rootMenu("Menu Principale"); // Selections are added to menus through the Menu's "add" method. // If a function is to be executed when the RPG is depressed, make a REFERENCE to it. Otherwise null. @@ -42,30 +218,198 @@ // The last is the text to display. *INCLUDE A SPACE IN THE BEGINNING, this is where the cursor goes. // *This means the text is limited to 14 characters (not counting the space) with this display. // **It is 14 not 15 for reasons pertaining to the implementation of the TextLCD library. - Menu ledMenu("LED menu"); - ledMenu.add(Selection(&toggleLED1, 0, NULL, " Toggle LED1")); // The function argument of selection can be added directly - ledMenu.add(Selection(NULL, 1, NULL, " Toggle LED2")); // It can also be set to NULL temporarily and changed later. - ledMenu.selections[1].fun = &toggleLED2; // Useful for when functions are methods in other classes. + Menu ledMenu("Options"); + ledMenu.add(Selection(&toggleLED1, 0, NULL," Toggle LED1")); // The function argument of selection can be added directly + ledMenu.add(Selection(&toggleLED2, 1, NULL, " Toggle LED2")); ledMenu.add(Selection(&toggleLED3, 2, NULL, " Toggle LED3")); - ledMenu.add(Selection(&toggleLED4, 3, NULL, " Toggle LED4")); - ledMenu.add(Selection(&resetLED, 4, &rootMenu, " Go back")); // always add a Selection at the end to point to the parent + ledMenu.add(Selection(&resetLED, 3, &rootMenu, " Retour")); + ledMenu.add(Selection(NULL, 4, NULL, "Options")); // always add a Selection at the end to point to the parent + + Menu AlimMenu("Alimenter"); // about menu crediting us :) + AlimMenu.add(Selection(NULL, 0, NULL, " Voir Courbe")); + AlimMenu.add(Selection(&incpass, 1, NULL, " Augmenter")); + AlimMenu.add(Selection(&decpass, 2, NULL, " Diminuer")); + AlimMenu.add(Selection(NULL, 3, &rootMenu, " Retour")); + AlimMenu.add(Selection(NULL, 4, NULL, "Alimenter")); + + Menu ledCourbe("Courbe"); // about menu crediting us :) + ledCourbe.add(Selection(&incCourbe, 1, NULL, " Augmenter")); + ledCourbe.add(Selection(&decCourbe, 2, NULL, " Diminuer")); + ledCourbe.add(Selection(NULL, 2, NULL, " ")); + ledCourbe.add(Selection(NULL, 3, &rootMenu, " Retour")); + ledCourbe.add(Selection(NULL, 4, NULL, "Courbe")); - Menu aboutMenu("About Menu"); // about menu crediting us :) - aboutMenu.add(Selection(NULL, 0, NULL, " Authors:")); - aboutMenu.add(Selection(NULL, 1, NULL, " Ben Y & Tony T")); - aboutMenu.add(Selection(NULL, 2, NULL, " ECE4180")); - aboutMenu.add(Selection(NULL, 3, &rootMenu, " Go back")); + Menu ledHoraire("Horaire"); // about menu crediting us :) + ledHoraire.add(Selection(&incHor, 1, NULL, " Augmenter")); + ledHoraire.add(Selection(&decHor, 2, NULL, " Diminuer")); + ledHoraire.add(Selection(NULL, 2, NULL, " ")); + ledHoraire.add(Selection(NULL, 3, &rootMenu, " Retour")); + ledHoraire.add(Selection(NULL, 4, NULL, "Horaire")); + + Menu ledJour("Jour"); // about menu crediting us :) + ledJour.add(Selection(&incJour, 1, NULL, " Augmenter")); + ledJour.add(Selection(&decJour, 2, NULL, " Diminuer")); + ledJour.add(Selection(NULL, 2, NULL, " ")); + ledJour.add(Selection(NULL, 3, &rootMenu, " Retour")); + ledJour.add(Selection(NULL, 4, NULL, "Jour")); - // Selections to the root menu should be added last - rootMenu.add(Selection(NULL, 0, &ledMenu, " LED MENU")); - rootMenu.add(Selection(NULL, 1, NULL, " Dummy menu 1")); // a dummy menu, doesn't do anything - rootMenu.add(Selection(NULL, 2, &aboutMenu, " About menu")); + Menu GestMenu("Gestation"); // about menu crediting us :) + GestMenu.add(Selection(NULL, 0,&ledCourbe, " Courbe")); + GestMenu.add(Selection(NULL, 1, &ledHoraire, " Horaire")); + GestMenu.add(Selection(NULL, 2, &ledJour, " Journee Depart")); + GestMenu.add(Selection(NULL, 3, &rootMenu, " Retour")); + GestMenu.add(Selection(NULL, 4, NULL, "Gestation")); + + Menu ledCons("Consom"); // about menu crediting us :) + ledCons.add(Selection(&incCons, 1, NULL, " Augmenter")); + ledCons.add(Selection(&decCons, 2, NULL, " Diminuer")); + ledCons.add(Selection(NULL, 2, NULL, " ")); + ledCons.add(Selection(NULL, 3, &rootMenu, " Retour")); + ledCons.add(Selection(NULL, 4, NULL, "Consom")); + + Menu MBMenu("Mise Bas"); // about menu crediting us :) + MBMenu.add(Selection(NULL, 0, NULL, " Courbe Parite")); + MBMenu.add(Selection(NULL, 1, NULL, " Courbe Horaire")); + MBMenu.add(Selection(NULL, 2, NULL, " Journee Depart")); + MBMenu.add(Selection(NULL, 3, &rootMenu, " Retour")); + MBMenu.add(Selection(NULL, 4, NULL, "Mise Bas")); + + rootMenu.add(Selection(NULL, 0, &AlimMenu, " Alimenter")); + rootMenu.add(Selection(NULL, 1, &GestMenu, " Gestation")); // a dummy menu, doesn't do anything + rootMenu.add(Selection(NULL, 2, &MBMenu, " Mise Bas ")); + rootMenu.add(Selection(NULL, 3, &ledMenu, " Options ")); + // rootMenu.add(Selection(NULL, 4, &ledCourbe, " Courbe ")); + // rootMenu.add(Selection(NULL, 5, &ledHoraire, " Horaire ")); + // rootMenu.add(Selection(NULL, 6, &ledJour, " Jour ")); +// rootMenu.add(Selection(NULL, 7, &ledCons, " Consom ")); + rootMenu.add(Selection(NULL, 4, NULL, "Menu Principale")); // Here is the heart of the system: the navigator. // The navigator takes in a reference to the root, an interface, and a reference to an lcd Navigator navigator(&rootMenu, rpg, &lcd); - + prevpass = 0; while(1){ + // navigator.poll(); + Out2=1; + + +if ( bt1o == 1){ +//++menu if menu > 4 then menu = 0; + Mn1 = ++ Mn1 % 9; +// Mn1 = Menu1(Mn1); + wait(.1); + bt1o = 0; +} + +if ( oldbt2 == 1){ +//++menu if menu2 > 4 then menu2 = 0; + Mn2 = ++ Mn2 % 5; +// Mn2=Menu2(Mn2); + wait(.1); + oldbt2 = 0; +} + // lcd.locate(0,1); + // lcd.printf(" bp out5\n"); + // wait(.5); +if( (out3==1) & (waiting == 840) ){ + + Out1=0; +// lcd.locate(0,1); lcd.printf("Out3-1\n"); + wait(1); + if( t3 ){ + // navigator.poll(); + t3=0; + // lcd.locate(0,1); lcd.printf("Out3wa\n"); + // wait(1); + out3=0; + waiting = 0; + counter = 0; +} +} +if((Out1==1) & (waiting ==11)){ + + +// lcd.locate(0,1); +// lcd.printf("Alimente \n"); + wait(.1); + if( t1 ){ + + Out1=0; + t1=0; + MTR=0; + //lcd.locate(0,1); + //lcd.printf("Out11wait11E \n"); + wait(.1); + waiting = 60; + t2=1; + old=0; + counter ++; + Rtions[p]--; + +} +} + + +if ( (old==1)&(MTR==1) & (waiting == 0) ) { + + +// lcd.locate(0,1); + // lcd.printf("alimente \n"); + wait( 1); + rawtime = time(NULL); + waiting = 11; + t1=1; + // lcd.locate(0,1); + // lcd.printf("nwait w1 \n"); + wait( 1); + + if (counter >= 6) { + + out3=1; + waiting = 840;t3=1; + } + } + +if((Out1==0) & (waiting ==60)){ + + out3=1; +// lcd.locate(0,1); +// lcd.printf("Attend 60 sec "); + wait(61); + if( t2 ){ + + out3=0; + t2=0; +// lcd.locate(0,1); +// lcd.printf(" "); + wait(1); + waiting = 0; + // old=0; + + // lcd.locate(0,1); lcd.printf("apres old-0 \n"); + // wait(1); +} +} + // lcd.string(100,200,300,220,WHITE,FONT6,TRANS," "); // + // oldHor = Hor; oldJour = Jour; oldcourbe = courbe; + + if ( (oldpass != pass)| ( oldCons != Cons) | ( oldHor != Hor) | ( oldcourbe != courbe) | ( oldJour != Jour)){ + + n=sprintf (Cpass, "Pa:%d Cs:%d H:%d Cb:%d Jr:%d", pass,Cons,Hor,courbe,Jour); + lcd.string(15,210,300,220,WHITE,FONT3,TRANS,Cpass); + oldCons = Cons; + oldpass = pass; + oldHor = Hor; + oldcourbe = courbe; + oldJour = Jour; + } + // lcd.string(100,200,300,220,WHITE,FONT6,TRANS,bufPass); // + + // lcd.string(100,200,300,220,WHITE,FONT6,TRANS,bufPass); // + + // lcd.string(150,200,300,220,WHITE,FONT6,TRANS,bufPass); // + navigator.poll(); // In a loop, call navigator's poll method to determine if the user is interacting with the rpg. + } -} \ No newline at end of file +}