Giter Club home page Giter Club logo

menu's Introduction

MicroMenu

Copyright (c) 2014 [email protected]

Simple and concise Embedded Menu System for Arduino.

Please check out the comprehensive example applications.

Note: This has been developed and tested with Arduino 1.5.x only.

Demo Videos

TODO

Feature Set

Simple API

  • Only three core methods, navigate(), invoke() and render(),
  • plus simple helpers for navigation: next(), prev(), parent() and child().

Any hardware

  • You simply implement a handler for your
    • Clickwheels, Encoders (see examples)
    • < > Buttons
  • that will call navigate() with any of the helpers as an argument, depending on direction intended (e.g. navigate(child()) or navigate(next())).

Great display flexibility

  • Usable with any display: Text LCD, Graphic LCD, Serial Port, ...
  • Any menu type: vertical or horizontal, circular, ...
    • you only need to implement one method capable of rendering a single menu item

Single callback per menu item, multiple actions

Handles all events, eg.

  • Show the menu item label
    • can also be used to display current sensor data instead of the static text label
  • Display the menu widget
    • this is where you'd implement your 'widget', the actual funcktionality associate with a menu item
  • Trigger at the menu item
    • invoked when the user selects the item again, if already active
    • useful for:
      • save
      • accept calibration data when displaying live values
      • switching between two options or functions within a single menu item
        • e.g. to configure precision and unit for numeric values in a single menu (000.0 -> 00.00 -> 0.000 mV -> V -> kV
          • so you see a live preview 00.00kW or 000.0mV
  • Before Move to Parent (or exit the menu)
    • for instance to call a save method when you exit
    • the return value determines if the user can move to the parent or not, useful to handle unsave data
  • Stores menu data in Flash, saving RAM

Installation

Clone this repository or download the current version as an archive, copy or link it to your Arduino libraries folder, e.g. ~/Documents/Arduino/libraries on a Mac, then restart the Arduino IDE.

Usage and Concept

The code base resides in it's own namespace Menu. So you need to either prefix all methods with Menu:: or add using namespace Menu; somewhere in your code. I prefer to be explicit by opting for the prefix.

1) Define menu an structure

Begin with a dummy exit menu item. With it, you can utilize all events and functions, e.g. the parent event will be invoked, allowing you to save all data when you leave the menu or even prevent to leave. Also, you can simply clear the display when the user leaves the menu. The arguments to the macro MenuItem are: Name, Label, Next, Previous, Parent, Child, Callback. If you have no child or sibling or parent, substitute with Menu::NullItem, this is a typesafe replacement for NULL

MenuItem(miExit, "", Menu::NullItem, Menu::NullItem, Menu::NullItem, miSettings, menuExit);
    MenuItem(miSettings, "Settings", miTest1, Menu::NullItem, miExit, miCalibrateLo, menuDummy);
      MenuItem(miCalibrateLo,  "Calibrate Lo", miCalibrateHi,  Menu::NullItem,       miSettings, Menu::NullItem, menuDummy);
      MenuItem(miCalibrateHi,  "Calibrate Hi", miChannel0, miCalibrateLo,  miSettings, Menu::NullItem, menuDummy);

2) Implement a callback to render a single menu item

This example is for a 4-line text LCD, usable with the LiquidCrystal library shipped with Arduino.

void renderMenuItem(const Menu::Item_t *mi, uint8_t pos) {
    lcd.setCursor(0, pos);
    lcd.print(engine->label(mi));
}

3) Handle menu events

 bool myMenuItemCallback(Menu::Action_t act) {
  switch (act) {
    case actionParent: 
      saveAll();
      return true; // return false to prevent navigation to parent
      break;
    case actionTrigger:
      adcSaveCalibrationData();
      break;
  }
}

Example Hardware Configuration

TODO: Image LCD and TFT Boards

Licensing

The MIT License (MIT)

Copyright (c) 2014 [email protected]
All rights reserved.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.