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/)
MenuExample.h@0:4aa25181e995, 2014-09-04 (annotated)
- Committer:
- rominos2
- Date:
- Thu Sep 04 12:29:12 2014 +0000
- Revision:
- 0:4aa25181e995
Initial Release.; Example for Menu Library (http://mbed.org/users/rominos2/code/Menu/); Using RGBLed Library (http://mbed.org/users/rominos2/code/RGBLed/)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rominos2 | 0:4aa25181e995 | 1 | /* |
rominos2 | 0:4aa25181e995 | 2 | Copyright (c) 2014 Romain Berrada |
rominos2 | 0:4aa25181e995 | 3 | |
rominos2 | 0:4aa25181e995 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
rominos2 | 0:4aa25181e995 | 5 | and associated documentation files (the "Software"), to deal in the Software without restriction, |
rominos2 | 0:4aa25181e995 | 6 | including without limitation the rights to use, copy, modify, merge, publish, distribute, |
rominos2 | 0:4aa25181e995 | 7 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
rominos2 | 0:4aa25181e995 | 8 | furnished to do so, subject to the following conditions: |
rominos2 | 0:4aa25181e995 | 9 | |
rominos2 | 0:4aa25181e995 | 10 | The above copyright notice and this permission notice shall be included in all copies or |
rominos2 | 0:4aa25181e995 | 11 | substantial portions of the Software. |
rominos2 | 0:4aa25181e995 | 12 | |
rominos2 | 0:4aa25181e995 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
rominos2 | 0:4aa25181e995 | 14 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
rominos2 | 0:4aa25181e995 | 15 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
rominos2 | 0:4aa25181e995 | 16 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
rominos2 | 0:4aa25181e995 | 17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
rominos2 | 0:4aa25181e995 | 18 | */ |
rominos2 | 0:4aa25181e995 | 19 | |
rominos2 | 0:4aa25181e995 | 20 | #ifndef INCLUDE_MENUEXAMPLE_H |
rominos2 | 0:4aa25181e995 | 21 | #define INCLUDE_MENUEXAMPLE_H |
rominos2 | 0:4aa25181e995 | 22 | |
rominos2 | 0:4aa25181e995 | 23 | #include "RGBLed.h" |
rominos2 | 0:4aa25181e995 | 24 | #include "Menu.h" |
rominos2 | 0:4aa25181e995 | 25 | |
rominos2 | 0:4aa25181e995 | 26 | #define MENUEXAMPLE_BLINK_NUMBER 3 |
rominos2 | 0:4aa25181e995 | 27 | #define MENUEXAMPLE_BLINK_DELAY 0.15 |
rominos2 | 0:4aa25181e995 | 28 | |
rominos2 | 0:4aa25181e995 | 29 | class MenuExample : public Menu { |
rominos2 | 0:4aa25181e995 | 30 | protected: |
rominos2 | 0:4aa25181e995 | 31 | virtual void startMenu(); |
rominos2 | 0:4aa25181e995 | 32 | virtual bool isSelectionChanging(); |
rominos2 | 0:4aa25181e995 | 33 | virtual bool isValidating(); |
rominos2 | 0:4aa25181e995 | 34 | virtual void displaySelectedProgram(void* output_argument); |
rominos2 | 0:4aa25181e995 | 35 | }; |
rominos2 | 0:4aa25181e995 | 36 | |
rominos2 | 0:4aa25181e995 | 37 | void MenuExample::startMenu() { |
rominos2 | 0:4aa25181e995 | 38 | RGBLed led(LED_RED, LED_GREEN, LED_BLUE); |
rominos2 | 0:4aa25181e995 | 39 | unsigned int i; |
rominos2 | 0:4aa25181e995 | 40 | for (i=0; i<MENUEXAMPLE_BLINK_NUMBER; i++) { |
rominos2 | 0:4aa25181e995 | 41 | led.setColor(RGBLed::WHITE); |
rominos2 | 0:4aa25181e995 | 42 | wait(MENUEXAMPLE_BLINK_DELAY); |
rominos2 | 0:4aa25181e995 | 43 | led.setColor(RGBLed::BLACK); |
rominos2 | 0:4aa25181e995 | 44 | wait(MENUEXAMPLE_BLINK_DELAY); |
rominos2 | 0:4aa25181e995 | 45 | } |
rominos2 | 0:4aa25181e995 | 46 | } |
rominos2 | 0:4aa25181e995 | 47 | |
rominos2 | 0:4aa25181e995 | 48 | bool MenuExample::isSelectionChanging() { |
rominos2 | 0:4aa25181e995 | 49 | DigitalIn bootstrap_k64f_sel_sw(SW2); |
rominos2 | 0:4aa25181e995 | 50 | static int last_state=1; |
rominos2 | 0:4aa25181e995 | 51 | bool test = false; |
rominos2 | 0:4aa25181e995 | 52 | if (!bootstrap_k64f_sel_sw && last_state) test=true; |
rominos2 | 0:4aa25181e995 | 53 | last_state = bootstrap_k64f_sel_sw.read(); |
rominos2 | 0:4aa25181e995 | 54 | return test; |
rominos2 | 0:4aa25181e995 | 55 | } |
rominos2 | 0:4aa25181e995 | 56 | |
rominos2 | 0:4aa25181e995 | 57 | bool MenuExample::isValidating() { |
rominos2 | 0:4aa25181e995 | 58 | DigitalIn bootstrap_k64f_val_sw(SW3); |
rominos2 | 0:4aa25181e995 | 59 | static int last_state=1; |
rominos2 | 0:4aa25181e995 | 60 | bool test = false; |
rominos2 | 0:4aa25181e995 | 61 | if (!bootstrap_k64f_val_sw && last_state) test=true; |
rominos2 | 0:4aa25181e995 | 62 | last_state = bootstrap_k64f_val_sw.read(); |
rominos2 | 0:4aa25181e995 | 63 | return test; |
rominos2 | 0:4aa25181e995 | 64 | } |
rominos2 | 0:4aa25181e995 | 65 | |
rominos2 | 0:4aa25181e995 | 66 | void MenuExample::displaySelectedProgram(void* output_argument) { |
rominos2 | 0:4aa25181e995 | 67 | RGBLed led(LED_RED, LED_GREEN, LED_BLUE); |
rominos2 | 0:4aa25181e995 | 68 | RGBLed::Color color = RGBLed::BLACK; |
rominos2 | 0:4aa25181e995 | 69 | if (output_argument!=NULL) color=*(RGBLed::Color*) output_argument; |
rominos2 | 0:4aa25181e995 | 70 | led.setColor(color); |
rominos2 | 0:4aa25181e995 | 71 | } |
rominos2 | 0:4aa25181e995 | 72 | |
rominos2 | 0:4aa25181e995 | 73 | #endif |