A simple Menu Library

Dependents:   MenuExample

A Menu is light and easy to use. It's composed of a:

  • an output interface to show which program is selected,
  • a way to change the selection,
  • a way to validate the selection and launch the linked program.

If you want a example on how to use it, look at the MenuExample program (http://mbed.org/users/rominos2/code/MenuExample/)

Committer:
rominos2
Date:
Thu Sep 04 12:25:13 2014 +0000
Revision:
0:0f92518679f3
Initial Release.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rominos2 0:0f92518679f3 1 /*
rominos2 0:0f92518679f3 2 Copyright (c) 2014 Romain Berrada
rominos2 0:0f92518679f3 3
rominos2 0:0f92518679f3 4 Permission is hereby granted, free of charge, to any person obtaining a copy of this software
rominos2 0:0f92518679f3 5 and associated documentation files (the "Software"), to deal in the Software without restriction,
rominos2 0:0f92518679f3 6 including without limitation the rights to use, copy, modify, merge, publish, distribute,
rominos2 0:0f92518679f3 7 sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
rominos2 0:0f92518679f3 8 furnished to do so, subject to the following conditions:
rominos2 0:0f92518679f3 9
rominos2 0:0f92518679f3 10 The above copyright notice and this permission notice shall be included in all copies or
rominos2 0:0f92518679f3 11 substantial portions of the Software.
rominos2 0:0f92518679f3 12
rominos2 0:0f92518679f3 13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
rominos2 0:0f92518679f3 14 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
rominos2 0:0f92518679f3 15 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
rominos2 0:0f92518679f3 16 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
rominos2 0:0f92518679f3 17 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
rominos2 0:0f92518679f3 18 */
rominos2 0:0f92518679f3 19
rominos2 0:0f92518679f3 20 #ifndef INCLUDE_MENU_H
rominos2 0:0f92518679f3 21 #define INCLUDE_MENU_H
rominos2 0:0f92518679f3 22
rominos2 0:0f92518679f3 23 /** A simple Menu Library \n
rominos2 0:0f92518679f3 24 A Menu is light and easy to use. It's composed of a : \n
rominos2 0:0f92518679f3 25 - an output interface to show which program is selected, \n
rominos2 0:0f92518679f3 26 - a way to change the selection, \n
rominos2 0:0f92518679f3 27 - a way to validate the selection and launch the linked program. \n
rominos2 0:0f92518679f3 28
rominos2 0:0f92518679f3 29 If you want a example on how to use it, look at the MenuExample program (http://mbed.org/users/rominos2/code/MenuExample/)
rominos2 0:0f92518679f3 30 */
rominos2 0:0f92518679f3 31 class Menu {
rominos2 0:0f92518679f3 32 private:
rominos2 0:0f92518679f3 33 /** A Program is reprensented with this nested class.
rominos2 0:0f92518679f3 34 */
rominos2 0:0f92518679f3 35 class Program {
rominos2 0:0f92518679f3 36 private:
rominos2 0:0f92518679f3 37 void* _output_interface_argument; /**< the output displayed when this program is seletected. For example, a LED Color or a message. */
rominos2 0:0f92518679f3 38 int(*_program)(); /**< the function to call when the program is validated. */
rominos2 0:0f92518679f3 39 Program* _next; /**< the next program in the chained list */
rominos2 0:0f92518679f3 40
rominos2 0:0f92518679f3 41 Program(void* output_argument, int(*program)()); /**< Constructor of a Program */
rominos2 0:0f92518679f3 42
rominos2 0:0f92518679f3 43 friend class Menu;
rominos2 0:0f92518679f3 44 };
rominos2 0:0f92518679f3 45
rominos2 0:0f92518679f3 46 Program* _first; /**< First program of the chained list. */
rominos2 0:0f92518679f3 47
rominos2 0:0f92518679f3 48 protected:
rominos2 0:0f92518679f3 49 /** Start the Menu.
rominos2 0:0f92518679f3 50 Implementation can make LED blinks or print a message on a screen for example
rominos2 0:0f92518679f3 51 */
rominos2 0:0f92518679f3 52 virtual void startMenu() = 0;
rominos2 0:0f92518679f3 53 /** Implementation must links an input to know if the user change the selection.
rominos2 0:0f92518679f3 54 For example, a switch can be checked.
rominos2 0:0f92518679f3 55 @return 1 if the selection changes, else false.
rominos2 0:0f92518679f3 56 */
rominos2 0:0f92518679f3 57 virtual bool isSelectionChanging() = 0;
rominos2 0:0f92518679f3 58 /** Implementation must links an input to know if the user validate the selection.
rominos2 0:0f92518679f3 59 For example, a switch can be checked.
rominos2 0:0f92518679f3 60 @return 1 if the user validates, else false.
rominos2 0:0f92518679f3 61 */
rominos2 0:0f92518679f3 62 virtual bool isValidating() = 0;
rominos2 0:0f92518679f3 63
rominos2 0:0f92518679f3 64 /** Implementation must links an output to show the selected program has changed.
rominos2 0:0f92518679f3 65 For example, the color of a LED can be changed or a message printed.
rominos2 0:0f92518679f3 66 @param output_argument the argument of the selected program. If NULL, the interface must clear.
rominos2 0:0f92518679f3 67 */
rominos2 0:0f92518679f3 68 virtual void displaySelectedProgram(void* output_argument) = 0;
rominos2 0:0f92518679f3 69
rominos2 0:0f92518679f3 70 public:
rominos2 0:0f92518679f3 71 /** Construcor of the Menu.
rominos2 0:0f92518679f3 72 */
rominos2 0:0f92518679f3 73 Menu();
rominos2 0:0f92518679f3 74
rominos2 0:0f92518679f3 75 /** Add a program to the Menu.
rominos2 0:0f92518679f3 76 @param output_argument the output displayed when this program is seletected. For example, a LED Color or a message.
rominos2 0:0f92518679f3 77 @param the function to call when the program is validated.
rominos2 0:0f92518679f3 78 */
rominos2 0:0f92518679f3 79 void addProgram(void* output_argument, int(*program)());
rominos2 0:0f92518679f3 80 /** Free the alocated memory of the Bootstrap.
rominos2 0:0f92518679f3 81 All program will be removed from the list.
rominos2 0:0f92518679f3 82 */
rominos2 0:0f92518679f3 83 void clean();
rominos2 0:0f92518679f3 84 /** Start the Menu. \n
rominos2 0:0f92518679f3 85 First startMenu() is called. \n
rominos2 0:0f92518679f3 86 Then the output interface show the chosen program (with the output argument) and the Bootstrap check isSelectionChanging() and isValidating(). \n
rominos2 0:0f92518679f3 87 Once validate, the function of the program is called. \n
rominos2 0:0f92518679f3 88 @return the result of the program's function.
rominos2 0:0f92518679f3 89 */
rominos2 0:0f92518679f3 90 int launch();
rominos2 0:0f92518679f3 91 };
rominos2 0:0f92518679f3 92
rominos2 0:0f92518679f3 93 #endif