GithubHelp home page GithubHelp logo

cpp-lcd-menu's Introduction

cpp-lcd-menu

Create and implement menus on LCD character devices, with long-line scrolling, selection, paging, navigation and actions. Manage LCD devices as well as user input devices (buttons, rotary controllers, etc.). Define menus and device parameters in YAML for easy modification.

This project is copyright © 2020 Jonathan Moscardini, published under the MIT License.

Current device support

Currently, building this project requires all dependencies for all devices. Work is planned to support conditional compilation, so that users can only compile support for the devices they need (and therefore skip the dependencies they don't). Further device support will be welcome after that is implemented.

Displays

  • Adafruit 16x2 I2C LCD + button plates
  • Adafruit SSD1306 128x64 OLED LCD (I2C only)

Input devices

  • Adafruit 16x2 I2C LCD + button plates
  • Raspberry Pi libevdev rotary controllers

Device usage

There are four main components to a cpp-lcd-menu:

  • IMenuRenderer - an output display device (e.g. a 16x2 character LCD)
  • IMenuInputController - a user input navigation device (e.g. a rotary controller with a select button)
  • IMenuView - an object to render a MenuEntryList on an IMenuRenderer
  • MenuController - an object to combine an IMenuInputController with an IMenuView to navigate through a menu & take action

Put together, an IMenuView has an IMenuRenderer, and a MenuController has a MenuEntryList, an IMenuInputController, and an IMenuView.

Additionally, an ITask interface represents the thread controls for the above objects, where applicable.

Roughly speaking, this is intended to resemble a Model-View-Controller (MVC) layout, with the MenuEntryList providing the Model, the IMenuView providing the View, and the MenuController providing the Controller.

Some hardware requires additional components to manage its resources and share them amongst the above components.

See main.cpp for a complete example implementation demonstrating the use and composition of these components.

YAML menu usage

See example_menu.yaml for the available options for defining a YAML menu.

You can load a YAML menu as follows:

std::string path_to_yaml_file{ argv[1] };

textmenu::menu::MenuDefinition menu_definition{ textmenu::menu::LoadYamlMenu(path_to_yaml_file) };

textmenu::menu::MenuDefinition is an std::pair, with the first member being the device configuration and the second member being the menu definition.

Creating a menu

With a YAML menu loaded, you can create the menu list as follows:

    textmenu::menu::MenuEntry menu_list{ menu_definition.first };

Creating display objects

With a YAML menu loaded, for devices with the appropriate factory function, you can also create the appropriate device directly from those parameters:

std::unique_ptr<IMenuRenderer> renderer{ SSD1306MenuRenderer::ConstructFromConfigMap(menu_definition.second.m_display_settings) };

Library dependencies

  • libyaml-cpp
  • libevdev (for evdev rotary controller component)
  • libi2c (for Adafruit 16x2 LCD + button plate component)

cpp-lcd-menu's People

Contributors

ionothanus avatar

Watchers

Brandon Castellano avatar  avatar

cpp-lcd-menu's Issues

Clean up cmake

Everything is in the top-level CMakeLists.txt because I don't know what I'm doing. Fix this

Enable conditional compilation for device drivers

Right now, the code compiles all supported device code, requiring all dependencies for all supported devices. Enable conditional compilation to allow users to only compile support for the devices they need, therefore only requiring the dependencies they need.

Add factory to simplify construction of device objects

Right now the code requires users to type lots of their own std::shared_ptr<> instantiations and correctly construct the objects in the right order. Add a factory to simplify this process & make this library easier to use.

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.