Example of the Menu Library

Dependencies:   Menu RGBLed mbed

Example of the Menu Library (http://mbed.org/users/rominos2/code/Menu/)
Use RGBLed Library (http://mbed.org/users/rominos2/code/RGBLed/)

Files at this revision

API Documentation at this revision

Comitter:
rominos2
Date:
Thu Sep 04 12:29:12 2014 +0000
Commit message:
Initial Release.; Example for Menu Library (http://mbed.org/users/rominos2/code/Menu/); Using RGBLed Library (http://mbed.org/users/rominos2/code/RGBLed/)

Changed in this revision

Menu.lib Show annotated file Show diff for this revision Revisions of this file
MenuExample.h Show annotated file Show diff for this revision Revisions of this file
RGBLed.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Menu.lib	Thu Sep 04 12:29:12 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/rominos2/code/Menu/#0f92518679f3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MenuExample.h	Thu Sep 04 12:29:12 2014 +0000
@@ -0,0 +1,73 @@
+/* 
+    Copyright (c) 2014 Romain Berrada
+    
+    Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
+    and associated documentation files (the "Software"), to deal in the Software without restriction, 
+    including without limitation the rights to use, copy, modify, merge, publish, distribute, 
+    sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in all copies or 
+    substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
+    BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
+    DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef INCLUDE_MENUEXAMPLE_H
+#define INCLUDE_MENUEXAMPLE_H
+
+#include "RGBLed.h"
+#include "Menu.h"
+
+#define MENUEXAMPLE_BLINK_NUMBER 3
+#define MENUEXAMPLE_BLINK_DELAY 0.15
+
+class MenuExample : public Menu {
+protected:
+    virtual void startMenu();
+    virtual bool isSelectionChanging();
+    virtual bool isValidating();
+    virtual void displaySelectedProgram(void* output_argument);
+};
+
+void MenuExample::startMenu() {
+    RGBLed led(LED_RED, LED_GREEN, LED_BLUE);
+    unsigned int i;
+    for (i=0; i<MENUEXAMPLE_BLINK_NUMBER; i++) {
+        led.setColor(RGBLed::WHITE);
+        wait(MENUEXAMPLE_BLINK_DELAY);
+        led.setColor(RGBLed::BLACK);
+        wait(MENUEXAMPLE_BLINK_DELAY);   
+    }
+}
+
+bool MenuExample::isSelectionChanging() {
+    DigitalIn bootstrap_k64f_sel_sw(SW2);
+    static int last_state=1;
+    bool test = false;
+    if (!bootstrap_k64f_sel_sw && last_state) test=true;
+    last_state = bootstrap_k64f_sel_sw.read();
+    return test;
+}
+
+bool MenuExample::isValidating() {
+    DigitalIn bootstrap_k64f_val_sw(SW3);
+    static int last_state=1;
+    bool test = false;
+    if (!bootstrap_k64f_val_sw && last_state) test=true;
+    last_state = bootstrap_k64f_val_sw.read();
+    return test;
+}
+
+void MenuExample::displaySelectedProgram(void* output_argument) {
+    RGBLed led(LED_RED, LED_GREEN, LED_BLUE);
+    RGBLed::Color color = RGBLed::BLACK;
+    if (output_argument!=NULL) color=*(RGBLed::Color*) output_argument;
+    led.setColor(color);
+}
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RGBLed.lib	Thu Sep 04 12:29:12 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/rominos2/code/RGBLed/#b125e5a28295
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 04 12:29:12 2014 +0000
@@ -0,0 +1,46 @@
+/* 
+    Copyright (c) 2014 Romain Berrada
+    
+    Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
+    and associated documentation files (the "Software"), to deal in the Software without restriction, 
+    including without limitation the rights to use, copy, modify, merge, publish, distribute, 
+    sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in all copies or 
+    substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
+    BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
+    DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "mbed.h"
+#include "RGBLed.h"
+#include "MenuExample.h"
+
+Serial pc(USBTX, USBRX);
+int main1();
+int main2(); 
+
+int main() {
+    MenuExample boot = MenuExample();
+    
+    boot.addProgram(&RGBLed::CYAN, main1);
+    boot.addProgram(&RGBLed::MAGENTA, main2);        
+    
+    while (true) {
+        boot.launch();
+    }
+}
+
+int main1() {
+    pc.printf("Program 1\n");
+    return 1;
+}
+int main2() {
+    pc.printf("Program 2\n");
+    return 2;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Sep 04 12:29:12 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013
\ No newline at end of file