diff --git a/_images/custom-cursor.gif b/_images/custom-cursor.gif new file mode 100644 index 00000000..820bc02e Binary files /dev/null and b/_images/custom-cursor.gif differ diff --git a/_images/no-arrows.png b/_images/no-arrows.png new file mode 100644 index 00000000..abc5b79d Binary files /dev/null and b/_images/no-arrows.png differ diff --git a/_images/no-cursor-no-arrows.webp b/_images/no-cursor-no-arrows.webp new file mode 100644 index 00000000..63ed2f2e Binary files /dev/null and b/_images/no-cursor-no-arrows.webp differ diff --git a/_images/no-cursor.webp b/_images/no-cursor.webp new file mode 100644 index 00000000..106d36e1 Binary files /dev/null and b/_images/no-cursor.webp differ diff --git a/genindex.html b/genindex.html index c4b54c0e..25a1c794 100644 --- a/genindex.html +++ b/genindex.html @@ -148,6 +148,10 @@
  • Rotary Encoder Adapter
  • +
  • Rendering the menu +
  • Reference

    @@ -287,80 +292,82 @@

    C

  • C2_CSI_TERMINAL_MIN (C macro)
  • - - - - - -

    D

    - - + - + +
    + +

    D

    + + + @@ -677,26 +684,26 @@

    L

    +
  • +
  • Reference

    diff --git a/objects.inv b/objects.inv index e2ee4b39..57f9dabc 100644 Binary files a/objects.inv and b/objects.inv differ diff --git a/overview/control/button.html b/overview/control/button.html index 1512f77b..fb6fa7a3 100644 --- a/overview/control/button.html +++ b/overview/control/button.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    diff --git a/overview/control/index.html b/overview/control/index.html index dc204c37..8f9cc5b0 100644 --- a/overview/control/index.html +++ b/overview/control/index.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    diff --git a/overview/control/keyboard.html b/overview/control/keyboard.html index 3852335c..0c3d4bec 100644 --- a/overview/control/keyboard.html +++ b/overview/control/keyboard.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    diff --git a/overview/control/rotary-encoder.html b/overview/control/rotary-encoder.html index dab83008..8c17ac51 100644 --- a/overview/control/rotary-encoder.html +++ b/overview/control/rotary-encoder.html @@ -18,7 +18,7 @@ - + + + +
    + Skip to content +
    + +
    +
    +
    + +
    +
    +
    +
    +
    +
    + + + +
    +
    +

    Character display renderer

    +

    The character display renderer is a simple renderer that displays the menu items on a character display. +It is a good choice if you are using a character display with your project.

    +

    The renderer supports the following features:

    +
      +
    • Displaying menu items on a character display

    • +
    • Truncating long menu items

    • +
    • Highlighting the selected menu item

    • +
    • Customizing the cursor character

    • +
    • Customizing the up and down arrow characters

    • +
    • Disabling the cursor and/arrows arrows

    • +
    +

    The renderer is easy to use and provides a number of options for customizing the display.

    +
    +

    How to use the character display renderer

    +

    To use the character display renderer, you need to create an instance of the CharacterDisplayRenderer class and pass it +to the LcdMenu class when you create it. Here is an example:

    +
    + +
    +
    #include <LcdMenu.h>
    +#include <LiquidCrystal_I2C.h>
    +#include <display/LiquidCrystal_I2CAdapter.h>
    +#include <renderer/CharacterDisplayRenderer.h>
    +
    +LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS);
    +LiquidCrystal_I2CAdapter lcdAdater(&lcd);
    +CharacterDisplayRenderer renderer(&lcdAdater, LCD_COLS, LCD_ROWS);
    +LcdMenu menu(renderer);
    +
    +
    +
    + +
    +
    #include <LcdMenu.h>
    +#include <LiquidCrystal.h>
    +#include <display/LiquidCrystalAdapter.h>
    +#include <renderer/CharacterDisplayRenderer.h>
    +
    +LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    +LiquidCrystalAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS);
    +CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS);
    +LcdMenu menu(renderer);
    +
    +
    +
    +
    +

    Don’t forget to replace LCD_COLS and LCD_ROWS with the number of columns and rows on your display.

    +

    After you have created the renderer, you then have to call the begin() method on the renderer to initialize it.

    +
    void setup() {
    +    renderer.begin();
    +}
    +
    +
    +
    +
    +

    Customizing the character display renderer

    +

    The character display renderer provides a number of options for customizing the display. You can set the following options:

    +
      +
    • The cursor characters (normal and editing)

    • +
    • The up and down arrow characters

    • +
    • Whether to display the cursor and/or arrows

    • +
    +

    Here is an example of how to customize the renderer:

    +
    +

    Use custom cursor characters

    +

    You can set custom cursor characters to use when rendering the selected menu item.

    +
    CharacterDisplayRenderer renderer(
    +    new LiquidCrystal_I2CAdapter(&lcd),
    +    LCD_COLS,
    +    LCD_ROWS,
    +    0xA5,  // cursorChar
    +    0x5F   // editCursorChar
    +);
    +
    +
    +Custom cursor characters + +
    +

    Note

    +

    Please refer to the datasheet of your display to find the character codes for the custom cursor characters.

    +
    +
    +
    +

    Hide the arrows only

    +

    You may want to hide the up and down arrows if you don’t need them or want more space for rendering the menu items. +Set the up and down arrow characters to NULL to hide them.

    +
    CharacterDisplayRenderer renderer(
    +    &lcdAdapter,
    +    LCD_COLS,
    +    LCD_ROWS,
    +    0x7E,  // cursorChar
    +    0x7F,  // editCursorChar
    +    NULL,  // upArrow
    +    NULL   // downArrow
    +);
    +
    +
    +Hide the arrows + +
    +
    +

    Hide the cursor only

    +

    Set the cursor characters to 0 to hide the cursor.

    +
    CharacterDisplayRenderer renderer(
    +    &lcdAdapter,
    +    LCD_COLS,
    +    LCD_ROWS,
    +    0,  // cursorChar
    +    0   // editCursorChar
    +);
    +
    +
    +Hide the cursor + +
    +
    +

    Hide both the cursor and arrows

    +
    CharacterDisplayRenderer renderer(
    +    &lcdAdapter,
    +    LCD_COLS,
    +    LCD_ROWS,
    +    0,  // cursorChar
    +    0,  // editCursorChar
    +    NULL,  // upArrow
    +    NULL   // downArrow
    +);
    +
    +
    +Hide both the cursor and arrows + +

    If these options are not enough for you, you can always create your own custom renderer by subclassing the CharacterDisplayRenderer class.

    +

    Here is basic example of how to create a custom renderer:

    +
    class MyCustomRenderer : public CharacterDisplayRenderer {
    +public:
    +    MyCustomRenderer(CharacterDisplayInterface *display, uint8_t cols, uint8_t rows)
    +        : CharacterDisplayRenderer(display, cols, rows) {
    +    }
    +
    +    void drawItem(const char* text) override {
    +        // Custom rendering code here
    +        // The text parameter contains the menu item text and the value of the item if present
    +        // eg. "Item 1" or "Item 1:42"
    +        //
    +        // You can append a cursor character to the text if the item is selected etc.
    +    }
    +};
    +
    +MyCustomRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS);
    +
    +
    +

    Find more information about the character display renderer in the API reference.

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    © 2024, Thomas Forntoh 

    +
    +
    +
    +
    + + + + + + + \ No newline at end of file diff --git a/overview/rendering/index.html b/overview/rendering/index.html new file mode 100644 index 00000000..f0b0fc6a --- /dev/null +++ b/overview/rendering/index.html @@ -0,0 +1,280 @@ + + + + + + + + + +Rendering the menu | LcdMenu + + + + + + + + + + + + + + + +
    + Skip to content +
    + +
    +
    +
    + +
    +
    +
    +
    +
    +
    + + + +
    +
    +

    Rendering the menu

    +

    LcdMenu provides a set of built-in renderers that you can use to display the menu items on different output devices. +The renderers are responsible for drawing the menu items on the screen. They can be customized to suit your needs.

    +

    There are lots of opportunities to create your own custom renderer. You can create a renderer for any output device that you like. +For example, you could create a renderer for a TFT display, a touchscreen, or even a 3D printer 😄 (the frame rate would be atrocious)

    +
    +

    The library comes with the following built-in renderers:

    + +
    +

    Don’t see a renderer for your favorite output device? Feel free to create a new one and share it with the community!

    +

    Here are some that would be cool to have:

    +
      +
    • Serial renderer

    • +
    • Web renderer

    • +
    • TFT renderer

    • +
    • OLED renderer

    • +
    +
    +
    +
    +
    +
    +
    +
    +

    © 2024, Thomas Forntoh 

    +
    +
    +
    +
    + + + + + + + \ No newline at end of file diff --git a/reference/api/ItemBack.html b/reference/api/ItemBack.html index d3eb530f..7873afe1 100644 --- a/reference/api/ItemBack.html +++ b/reference/api/ItemBack.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    diff --git a/reference/api/ItemCommand.html b/reference/api/ItemCommand.html index c9ce17c3..e668b49f 100644 --- a/reference/api/ItemCommand.html +++ b/reference/api/ItemCommand.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    diff --git a/reference/api/ItemFloatRange.html b/reference/api/ItemFloatRange.html index 45adb542..2ee51344 100644 --- a/reference/api/ItemFloatRange.html +++ b/reference/api/ItemFloatRange.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    diff --git a/reference/api/ItemInput.html b/reference/api/ItemInput.html index b76f1758..024b4e3f 100644 --- a/reference/api/ItemInput.html +++ b/reference/api/ItemInput.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -301,8 +306,8 @@

    ItemInput

    Protected Functions

    -
    -inline uint8_t getViewSize(DisplayInterface *display)
    +
    +inline uint8_t getViewSize(MenuRenderer *renderer)

    The number of visible characters.

             visible area
            ┌───────────────┐
    @@ -311,22 +316,15 @@ 

    ItemInput │<── viewSize ─>│

    -

    Effectively const, but initialized lately when display is injected.

    +

    Effectively const, but initialized lately when renderer is injected.

    -
    -inline uint8_t constrainBlinkerPosition(DisplayInterface *display, uint8_t blinkerPosition)
    -
    -
    -
    -inline virtual void draw(DisplayInterface *display, uint8_t row) override
    -

    Draw this menu item on specified display on specified line.

    +
    +inline virtual void draw(MenuRenderer *renderer) override
    +

    Draw this menu item on specified display on current row.

    Parameters:
    -
      -
    • display – Pointer to the DisplayInterface object used for rendering.

    • -
    • row – the number of row to draw on

    • -
    +

    renderer – The renderer to use for drawing.

    @@ -347,44 +345,44 @@

    ItemInput -
    -inline void enter(DisplayInterface *display)
    +
    +inline void enter(MenuRenderer *renderer)
    -
    -inline void back(DisplayInterface *display)
    +
    +inline void back(MenuRenderer *renderer)
    -
    -inline void left(DisplayInterface *display)
    +
    +inline void left(MenuRenderer *renderer)
    -
    -inline void right(DisplayInterface *display)
    +
    +inline void right(MenuRenderer *renderer)

    Moves the cursor to the right within the input value.

    -
    -inline void backspace(DisplayInterface *display)
    +
    +inline void backspace(MenuRenderer *renderer)

    Handles the backspace action for the input field.

    -
    -inline void typeChar(DisplayInterface *display, const unsigned char character)
    +
    +inline void typeChar(MenuRenderer *renderer, const unsigned char character)

    Types a character into the current input value at the cursor position.

    -

    This function inserts a character into the value string at the current cursor position. If the cursor is within the current length of the string, the string is split and the character is inserted in between. If the cursor is at the end of the string, the character is appended. The cursor is then incremented, and the view is adjusted if necessary. Finally, the display is updated and the blinker position is reset.

    +

    This function inserts a character into the value string at the current cursor position. If the cursor is within the current length of the string, the string is split and the character is inserted in between. If the cursor is at the end of the string, the character is appended. The cursor is then incremented, and the view is adjusted if necessary. Finally, the renderer is updated and the blinker position is reset.

    Parameters:
      -
    • display – Pointer to the DisplayInterface object used for rendering.

    • +
    • renderer – Pointer to the MenuRenderer object used for rendering.

    • character – The character to be typed into the input value.

    -
    -inline void clear(DisplayInterface *display)
    +
    +inline void clear(MenuRenderer *renderer)

    Clear the value of the input field.

    @@ -455,17 +453,16 @@

    ItemInputItemInput::getValue()
  • ItemInput::setValue()
  • ItemInput::getCallbackStr()
  • -
  • ItemInput::getViewSize()
  • -
  • ItemInput::constrainBlinkerPosition()
  • -
  • ItemInput::draw()
  • +
  • ItemInput::getViewSize()
  • +
  • ItemInput::draw()
  • ItemInput::process()
  • -
  • ItemInput::enter()
  • -
  • ItemInput::back()
  • -
  • ItemInput::left()
  • -
  • ItemInput::right()
  • -
  • ItemInput::backspace()
  • -
  • ItemInput::typeChar()
  • -
  • ItemInput::clear()
  • +
  • ItemInput::enter()
  • +
  • ItemInput::back()
  • +
  • ItemInput::left()
  • +
  • ItemInput::right()
  • +
  • ItemInput::backspace()
  • +
  • ItemInput::typeChar()
  • +
  • ItemInput::clear()
  • ItemInput::value
  • ItemInput::view
  • ItemInput::cursor
  • diff --git a/reference/api/ItemInputCharset.html b/reference/api/ItemInputCharset.html index ee608302..c35202ca 100644 --- a/reference/api/ItemInputCharset.html +++ b/reference/api/ItemInputCharset.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -230,7 +235,7 @@

    ItemInputCharset
    Parameters:
    +
  • +
  • Reference

    diff --git a/reference/api/ItemList.html b/reference/api/ItemList.html index 091399a5..08277f94 100644 --- a/reference/api/ItemList.html +++ b/reference/api/ItemList.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -310,15 +315,12 @@

    ItemList

    Protected Functions

    -
    -inline virtual void draw(DisplayInterface *display, uint8_t row) override
    -

    Draw this menu item on specified display on specified line.

    +
    +inline virtual void draw(MenuRenderer *renderer) override
    +

    Draw this menu item on specified display on current row.

    Parameters:
    -
      -
    • display – Pointer to the DisplayInterface object used for rendering.

    • -
    • row – the number of row to draw on

    • -
    +

    renderer – The renderer to use for drawing.

    @@ -339,12 +341,12 @@

    ItemList

    -
    -inline void selectPrevious(DisplayInterface *display)
    +
    +inline void selectPrevious(MenuRenderer *renderer)
    -
    -inline void selectNext(DisplayInterface *display)
    +
    +inline void selectNext(MenuRenderer *renderer)
    @@ -396,10 +398,10 @@

    ItemList
  • ItemList::getItemCount()
  • ItemList::getItems()
  • ItemList::getValue()
  • -
  • ItemList::draw()
  • +
  • ItemList::draw()
  • ItemList::process()
  • -
  • ItemList::selectPrevious()
  • -
  • ItemList::selectNext()
  • +
  • ItemList::selectPrevious()
  • +
  • ItemList::selectNext()
  • ItemList::callback
  • ItemList::items
  • ItemList::itemCount
  • diff --git a/reference/api/ItemRangeBase.html b/reference/api/ItemRangeBase.html index 0fff3938..dff8f771 100644 --- a/reference/api/ItemRangeBase.html +++ b/reference/api/ItemRangeBase.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -295,15 +300,12 @@

    ItemRangeBase

    Protected Functions

    -
    -inline virtual void draw(DisplayInterface *display, uint8_t row) override
    -

    Draw this menu item on specified display on specified line.

    +
    +inline virtual void draw(MenuRenderer *renderer) override
    +

    Draw this menu item on specified display on current row.

    Parameters:
    -
      -
    • display – Pointer to the DisplayInterface object used for rendering.

    • -
    • row – the number of row to draw on

    • -
    +

    renderer – The renderer to use for drawing.

    @@ -384,7 +386,7 @@

    ItemRangeBaseItemRangeBase::setCurrentValue()
  • ItemRangeBase::getCurrentValue()
  • ItemRangeBase::getDisplayValue()
  • -
  • ItemRangeBase::draw()
  • +
  • ItemRangeBase::draw()
  • ItemRangeBase::process()
  • ItemRangeBase::minValue
  • ItemRangeBase::maxValue
  • diff --git a/reference/api/ItemSubMenu.html b/reference/api/ItemSubMenu.html index 67fa3ee5..92589bb8 100644 --- a/reference/api/ItemSubMenu.html +++ b/reference/api/ItemSubMenu.html @@ -18,7 +18,7 @@ - + + + +
    + Skip to content +
    + +
    +
    +
    + +
    +
    +
    +
    +
    +
    + + + +
    +
    +

    CharacterDisplayInterface

    +
    +
    +class CharacterDisplayInterface : public DisplayInterface
    +
    +#include <CharacterDisplayInterface.h>
    +

    An interface for character-based display devices.

    +

    This interface extends the DisplayInterface and provides additional methods specific to character-based displays, such as creating custom characters and controlling a blinker.

    +
    +

    Note

    +

    This is an abstract class and cannot be instantiated directly.

    +
    +

    Subclassed by LiquidCrystalAdapter, LiquidCrystal_I2CAdapter

    +
    +

    Public Functions

    +
    +
    +inline virtual ~CharacterDisplayInterface()
    +

    Virtual destructor for the CharacterDisplayInterface.

    +
    +
    +
    +virtual void createChar(uint8_t id, uint8_t *c) = 0
    +

    Creates a custom character on the display.

    +
    +
    Parameters:
    +
      +
    • id – The identifier for the custom character.

    • +
    • c – A pointer to an array representing the custom character.

    • +
    +
    +
    +
    +
    +
    +virtual void drawBlinker() = 0
    +

    Draws a blinker on the display.

    +
    +
    +
    +virtual void clearBlinker() = 0
    +

    Clears the blinker from the display.

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    © 2024, Thomas Forntoh 

    +
    +
    +
    +
    + + + + + + + \ No newline at end of file diff --git a/reference/api/display/DisplayInterface.html b/reference/api/display/DisplayInterface.html index 3183a1c5..af625668 100644 --- a/reference/api/display/DisplayInterface.html +++ b/reference/api/display/DisplayInterface.html @@ -19,7 +19,7 @@ - + + + +
    + Skip to content +
    + +
    +
    +
    + +
    +
    +
    +
    +
    +
    + + + +
    +
    +

    CharacterDisplayRenderer

    +
    +
    +class CharacterDisplayRenderer : public MenuRenderer
    +
    +#include <CharacterDisplayRenderer.h>
    +

    A renderer for character-based displays, extending the MenuRenderer class.

    +

    This class provides functionality to render menus on character-based displays. It supports custom icons for cursor and edit cursor, as well as up and down arrows for navigation indicators.

    +

    The CharacterDisplayRenderer class is designed to work with displays that implement the CharacterDisplayInterface. It provides methods to draw menu items, cursors, and navigation indicators. The class also handles text truncation and cursor movement.

    +
    +

    Note

    +

    The class uses dynamic memory allocation for the upArrow and downArrow icons.

    +
    +
    +

    Public Functions

    +
    +
    +CharacterDisplayRenderer(CharacterDisplayInterface *display, const uint8_t maxCols, const uint8_t maxRows, const uint8_t cursorIcon = 0x7E, const uint8_t editCursorIcon = 0x7F, uint8_t *upArrow = new uint8_t[8]{0x04, 0x0E, 0x1F, 0x04, 0x04, 0x04, 0x04, 0x04}, uint8_t *downArrow = new uint8_t[8]{0x04, 0x04, 0x04, 0x04, 0x04, 0x1F, 0x0E, 0x04})
    +

    Constructor for CharacterDisplayRenderer. Initializes the renderer with the display, maximum columns, and maximum rows. Also sets the up and down arrow icons, cursor icons, and edit cursor icons.

    +
    +

    Note

    +

    slots 1 and 2 are reserved for up and down arrow icons. The available custom characters slots are 0 and 3 to 7.

    +
    +
    +
    Parameters:
    +
      +
    • display – A pointer to the CharacterDisplayInterface object.

    • +
    • maxCols – The maximum number of columns on the display.

    • +
    • maxRows – The maximum number of rows on the display.

    • +
    • cursorIcon – A byte representing the cursor icon, default is →, if 0, cursor will not be displayed

    • +
    • editCursorIcon – A byte representing the edit cursor icon, default is ←, if 0, edit cursor will not be displayed

    • +
    • upArrow – A pointer to an array of bytes representing the up arrow icon, default is ↑, if null, up arrow will not be displayed

    • +
    • downArrow – A pointer to an array of bytes representing the down arrow icon, default is ↓, if null, down arrow will not be displayed

    • +
    +
    +
    +
    +
    +
    +virtual void begin() override
    +

    Initializes the renderer and creates custom characters on the display.

    +
    +
    +
    +virtual void drawItem(const char *text) override
    +

    Draws a menu item on the character display.

    +

    This function overrides the base class implementation to draw a menu item on the character display. It handles appending a cursor to the text, truncating the text if it’s too long, padding the text with spaces, appending an indicator to the text, and finally drawing the text on the display.

    +
    +
    Parameters:
    +

    text – The text of the menu item to be drawn.

    +
    +
    +
    +
    +
    +virtual void draw(uint8_t byte) override
    +

    Function to draw a byte on the display.

    +
    +
    Parameters:
    +

    byte – The byte to be drawn.

    +
    +
    +
    +
    +
    +virtual void drawBlinker() override
    +

    Function to draw the blinker on the display.

    +
    +
    +
    +virtual void clearBlinker() override
    +

    Function to clear the blinker from the display.

    +
    +
    +
    +virtual void moveCursor(uint8_t cursorCol, uint8_t cursorRow) override
    +

    Moves the cursor to a specified position.

    +
    +
    Parameters:
    +
      +
    • cursorCol – Column position to move the cursor to.

    • +
    • cursorRow – Row position to move the cursor to.

    • +
    +
    +
    +
    +
    +
    +

    Protected Functions

    +
    +
    +void appendCursorToText(const char *text, char *buf)
    +

    Appends a cursor icon to the given text if the specified screen row is active.

    +
    +
    Parameters:
    +
      +
    • text – The original text to which the cursor icon will be appended.

    • +
    • buf – The buffer where the resulting text with the cursor icon will be stored.

    • +
    +
    +
    +
    +
    +
    +void appendIndicatorToText(const char *text, char *buf)
    +

    Appends an indicator to the provided text based on the item index and screen row.

    +
    +
    Parameters:
    +
      +
    • text – The original text to which the indicator may be appended.

    • +
    • buf – The buffer where the resulting text with the indicator will be stored.

    • +
    +
    +
    +
    +
    +
    +void padText(const char *text, char *buf)
    +

    Pads the given text with spaces to fit within the available length.

    +

    This function takes a text string and pads it with spaces so that the total length of the text fits within the available length of the display. If the text is longer than the available length, no padding is added.

    +
    +
    Parameters:
    +
      +
    • text – The input text to be padded.

    • +
    • buf – The buffer where the padded text will be stored. It should be large enough to hold the padded text.

    • +
    +
    +
    +
    +
    +
    +uint8_t calculateAvailableLength()
    +

    Calculates the available length for display.

    +

    This function computes the number of columns available for displaying content on the character display. It takes into account the presence of up and down arrows, which occupy one column if either is present.

    +
    +
    Returns:
    +

    The number of columns available for displaying content.

    +
    +
    +
    +
    +
    +

    Protected Attributes

    +
    +
    +uint8_t *upArrow
    +
    +
    +
    +uint8_t *downArrow
    +
    +
    +
    +const uint8_t cursorIcon
    +
    +
    +
    +const uint8_t editCursorIcon
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    © 2024, Thomas Forntoh 

    +
    +
    +
    +
    + + + + + + + \ No newline at end of file diff --git a/reference/api/renderer/MenuRenderer.html b/reference/api/renderer/MenuRenderer.html new file mode 100644 index 00000000..e1b4a2fe --- /dev/null +++ b/reference/api/renderer/MenuRenderer.html @@ -0,0 +1,499 @@ + + + + + + + + + +MenuRenderer | LcdMenu + + + + + + + + + + + + + + + +
    + Skip to content +
    + +
    +
    +
    + +
    +
    +
    +
    +
    +
    + + + +
    + +
    +
    +
    +
    +
    +
    +

    © 2024, Thomas Forntoh 

    +
    +
    +
    +
    + + + + + + + \ No newline at end of file diff --git a/reference/api/renderer/index.html b/reference/api/renderer/index.html new file mode 100644 index 00000000..14d1be44 --- /dev/null +++ b/reference/api/renderer/index.html @@ -0,0 +1,266 @@ + + + + + + + + + +renderer | LcdMenu + + + + + + + + + + + + + + + +
    + + + + + + + \ No newline at end of file diff --git a/reference/changelog.html b/reference/changelog.html index 34f16ccf..e9475ecd 100644 --- a/reference/changelog.html +++ b/reference/changelog.html @@ -134,11 +134,23 @@

    Changelog

    This is the changelog of LcdMenu library. It contains information about the changes between versions.

    -
    -

    LcdMenu v5.0.0

    +
    +

    LcdMenu v5.1.0

    What’s Changed

      +
    • Remove itemIndex dependency from renderer by @forntoh in #234

    • +
    • Patch/remove screen row dependency in renderer by @forntoh in #235

    • +
    • [Feat] Add Menu Renderer by @forntoh in #233

    • +
    +

    Full Changelog: https://github.com/forntoh/LcdMenu/compare/5.0.0…5.1.0

    +
    +
    +
    +

    LcdMenu v5.0.0

    +
    +

    What’s Changed

    +
    • Move logic from LcdMenu to items by @ShishkinDmitriy in #193

    • Expand RotaryEncoder usability for text input by @forntoh in #196

    • Update ClangFormat settings and add linting workflow by @forntoh in #201

    • @@ -176,8 +188,8 @@

      Breaking Changes

      LcdMenu v4.2.0

      -
      -

      What’s Changed

      +
      +

      What’s Changed

      • Make global util functions inline by @ShishkinDmitriy in #192

      • Add SimpleNavConfig and deprecate processMenuCommand by @forntoh in #189

      • @@ -213,8 +225,8 @@

        Bug Fixes:

        LcdMenu 4.0.0

        This release introduces a major refactor of the display management system, aimed at making it more modular and flexible. The key change is the introduction of a display interface abstraction that decouples the display logic from the specific hardware, allowing for easier integration of different display types.

        -
        -

        What’s Changed

        +
        +

        What’s Changed

        • Display Interface Abstraction: * A new DisplayInterface class has been introduced to define a common interface for all display types. @@ -235,8 +247,8 @@

          Bug Fixes and Improvements -

          Breaking Changes

          +
          +

          Breaking Changes

          • API Changes: The introduction of the DisplayInterface class and its implementation may require changes to existing projects. Users must update their code to work with the new interface and adapters.

          • Some methods and features directly tied to the LiquidCrystal_I2C library have been refactored or removed. Please review [the migration guide](https://lcdmenu.forntoh.dev/reference/migration-guide) for details on how to update your code.

          • @@ -246,8 +258,8 @@

            Breaking Changes

            LcdMenu 3.5.6

            -
            -

            What’s Changed

            +
            +

            What’s Changed

            • Make isAtTheStart and isAtTheEnd public by @forntoh in #172

            @@ -256,8 +268,8 @@

            What’s Changed

            LcdMenu 3.5.5

            -
            -

            What’s Changed

            +
            +

            What’s Changed

            • #167 Update condition to check if cursor is at the top and bottom. by @forntoh in #170

            @@ -266,8 +278,8 @@

            What’s Changed

            LcdMenu 3.5.4

            -
            -

            What’s Changed

            +
            +

            What’s Changed

            • BugFix: After setCursorPosition navigation is broken by @forntoh in #165

            @@ -276,8 +288,8 @@

            What’s Changed

            LcdMenu 3.5.3

            -
            -

            What’s Changed

            +
            +

            What’s Changed

            • BugFix: Fixed setText and getSubMenu not working by @forntoh in #164

            @@ -286,8 +298,8 @@

            What’s Changed

            LcdMenu 3.5.2

            -
            -

            What’s Changed

            +
            +

            What’s Changed

            • BugFix - Charset Input value copied to all Input items on screen by @forntoh in #159

            @@ -296,8 +308,8 @@

            What’s Changed

            LcdMenu 3.5.1

            -
            -

            What’s Changed

            +
            +

            What’s Changed

            • BugFix - Update ItemList only in edit mode by @forntoh in #154

            • Add more logging functions by @forntoh in #155

            • @@ -320,8 +332,8 @@

              What’s New

              LcdMenu 3.4.0

              -
              -

              What’s Changed

              +
              +

              What’s Changed

              • Moved utils and constants to utils directory by @forntoh in #149

              • Allow a current progress to be set on ItemProgress by @PaulEmich in #150

              • @@ -337,14 +349,14 @@

                New Contributors

                LcdMenu 3.3.4

                -
                -

                What’s Changed

                +
                +

                What’s Changed

                • fix: compilation error with standard lcd by @andcan in #142

                -
                -

                New Contributors

                +
                +

                New Contributors

                • @andcan made their first contribution in #142

                @@ -353,8 +365,8 @@

                New Contributors

                LcdMenu 3.3.3

                -
                -

                What’s Changed

                +
                +

                What’s Changed

                • Update bug_report.yml by @forntoh in #130

                • Separated utils definition from declaration by @forntoh in #135

                • @@ -364,8 +376,8 @@

                  What’s Changed

                  LcdMenu 3.3.2

                  -
                  -

                  What’s Changed

                  +
                  +

                  What’s Changed

                  • Update callback function parameter types to use uint16_t instead of uint8_t. by @forntoh in #126

                  @@ -374,8 +386,8 @@

                  What’s Changed

                  LcdMenu 3.3.1

                  -
                  -

                  What’s Changed

                  +
                  +

                  What’s Changed

                  • Update LICENSE by @forntoh in #115

                  • added stale bot by @forntoh in #122

                  • @@ -386,8 +398,8 @@

                    What’s Changed

                    LcdMenu 3.3.0

                    -
                    -

                    ⭐ What’s new

                    +
                    +

                    ⭐ What’s new

                    • Progress, Integer and Float values support by @forntoh in #114

                    • Added custom edit mode cursor by @forntoh in #110

                    • @@ -404,8 +416,8 @@

                      🐛 Bugfix

                      LcdMenu 3.2.0

                      -
                      -

                      What’s Changed

                      +
                      +

                      What’s Changed

                      • Update bug_report.yml by @forntoh in #103

                      • Fixed ItemSubMenu text not displayed by @forntoh in #102

                      • @@ -418,8 +430,8 @@

                        What’s Changed

                        LcdMenu 3.1.1

                        -
                        -

                        What’s Changed

                        +
                        +

                        What’s Changed

                        • Fixed compile warnings related to ItemList by @forntoh in #101

                        @@ -428,8 +440,8 @@

                        What’s Changed

                        LcdMenu 3.1.0

                        -
                        -

                        What’s Changed

                        +
                        +

                        What’s Changed

                        • added unit testing and changed most instances of String to char* by @forntoh in #86

                        @@ -438,14 +450,14 @@

                        What’s Changed

                        LcdMenu 3.0.1

                        -
                        -

                        What’s Changed

                        +
                        +

                        What’s Changed

                        • Fixed library unusable without I2C 🐛 by 🫡 @dejanmeznarc in #93

                        -
                        -

                        New Contributors

                        +
                        +

                        New Contributors

                        • @dejanmeznarc made their first contribution in #93

                        @@ -461,14 +473,14 @@

                        Chore

                        LcdMenu 3.0.0 🚀

                        -
                        -

                        What’s new 🚀

                        +
                        +

                        What’s new 🚀

                        In previous versions of LcdMenu, the menu used a lot of memory since space has to be reserved for every field on the menu even if it is not used, this release fixes that by allowing the user to import only MenuItems which is needed.

                        You can expect to save up to 10% on memory usage (or even more 😎), depending on which menu item types you use.

                        There’s also a new way to create menus, check the readme.

                        -
                        -

                        Changelog

                        +
                        +

                        Changelog

    diff --git a/reference/faq.html b/reference/faq.html index 9e7a1024..871dc8f6 100644 --- a/reference/faq.html +++ b/reference/faq.html @@ -112,6 +112,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    diff --git a/reference/migration/index.html b/reference/migration/index.html index 8bd3c2bb..29d27caa 100644 --- a/reference/migration/index.html +++ b/reference/migration/index.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -211,17 +216,55 @@

    Migration

    This guide details the changes and how to change your code between versions of the LcdMenu library.

    -
    -

    Migration from v4.x to v5.x

    -

    This guide details the changes and how to change your code to migrate to LcdMenu v5.x.

    +
    +

    Migration from v5.0.0 to v5.1.x

    +

    This guide details the changes and how to change your code to migrate to LcdMenu v5.1.x

    +
    +

    LcdMenu initialization changes

    +

    In v5.0.0, the menu was initialized with the display adapter interface. +In this version, the menu is initialized with a renderer.

    +
    +

    Imports

    +

    The first change you’ll need to make is to add the import for the renderer. +Currently, the only renderer available is the CharacterDisplayRenderer.

    +
    #include <renderer/CharacterDisplayRenderer.h>
    +
    +
    +
    +
    +

    Construct the renderer interface

    +

    The renderer instance is created and passed to the menu.

    +
     LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS);
    + LiquidCrystal_I2CAdapter lcdAdapter(&lcd);
    + CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS);
    + LcdMenu menu(renderer);
    +
    +
    +
    +
    +
    +

    Setup changes

    +

    The setup function remains the same, but the menu is now initialized with the renderer.

    +
     void setup() {
    +     lcdAdapter.begin();
    +     renderer.begin();
    + }
    +
    +
    +

    This change allows for more flexibility in the display interface and the ability to create custom renderers.

    +
    +
    +
    +

    Migration from v4.x.x to v5.0.0

    +

    This guide details the changes and how to change your code to migrate to LcdMenu v5.0.0

    This is a major release with a lot of changes.

    Display interface changes

    In v4.x, the display instance was created and initialised in the display adapter. In this version, the display instance is created separately and passed to the display adapter. The existing display adapters have been renamed and placed in a new directory to closely match the display they are designed for.

    -
    -

    Imports

    +
    +

    Imports

    The first change you’ll need to make is to add the import for your desired display interface.

    @@ -344,8 +387,8 @@

    New imports -

    Construct the display adapter interface

    +
    +

    Construct the display adapter interface

    The second change is to construct the display adapter interface. For example, if you are using the LiquidCrystalI2CAdapter, you will need to construct it like this:

    LiquidCrystalI2CAdapter lcd(0x27, 16, 2);
    @@ -398,9 +441,18 @@ 

    Other changes

    Reference

    @@ -162,7 +167,7 @@
    @@ -203,12 +208,12 @@ -
    /
    Migration from v4.x to v5.x +
    /
    Migration from v4.x.x to v5.0.0
    -
    -

    Migration from v4.x to v5.x

    -

    This guide details the changes and how to change your code to migrate to LcdMenu v5.x.

    +
    +

    Migration from v4.x.x to v5.0.0

    +

    This guide details the changes and how to change your code to migrate to LcdMenu v5.0.0

    This is a major release with a lot of changes.

    Display interface changes

    diff --git a/reference/migration/v5.0.0-v5.1.x.html b/reference/migration/v5.0.0-v5.1.x.html new file mode 100644 index 00000000..e028f68c --- /dev/null +++ b/reference/migration/v5.0.0-v5.1.x.html @@ -0,0 +1,286 @@ + + + + + + + + + +Migration from v5.0.0 to v5.1.x | LcdMenu + + + + + + + + + + + + + +
    + Skip to content +
    + +
    +
    +
    + +
    +
    +
    +
    +
    +
    + + + +
    +
    +

    Migration from v5.0.0 to v5.1.x

    +

    This guide details the changes and how to change your code to migrate to LcdMenu v5.1.x

    +
    +

    LcdMenu initialization changes

    +

    In v5.0.0, the menu was initialized with the display adapter interface. +In this version, the menu is initialized with a renderer.

    +
    +

    Imports

    +

    The first change you’ll need to make is to add the import for the renderer. +Currently, the only renderer available is the CharacterDisplayRenderer.

    +
    #include <renderer/CharacterDisplayRenderer.h>
    +
    +
    +
    +
    +

    Construct the renderer interface

    +

    The renderer instance is created and passed to the menu.

    +
     LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS);
    + LiquidCrystal_I2CAdapter lcdAdapter(&lcd);
    + CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS);
    + LcdMenu menu(renderer);
    +
    +
    +
    +
    +
    +

    Setup changes

    +

    The setup function remains the same, but the menu is now initialized with the renderer.

    +
     void setup() {
    +     lcdAdapter.begin();
    +     renderer.begin();
    + }
    +
    +
    +

    This change allows for more flexibility in the display interface and the ability to create custom renderers.

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    © 2024, Thomas Forntoh 

    +
    +
    +
    +
    + + + + + + + \ No newline at end of file diff --git a/reference/samples/Basic.html b/reference/samples/Basic.html index 586130ef..e57702fd 100644 --- a/reference/samples/Basic.html +++ b/reference/samples/Basic.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -215,35 +220,36 @@

    Basic 2#include <MenuScreen.h> 3#include <display/LiquidCrystal_I2CAdapter.h> 4#include <input/KeyboardAdapter.h> - 5 - 6#define LCD_ROWS 2 - 7#define LCD_COLS 16 - 8 - 9// Initialize the main menu items -10// clang-format off -11MENU_SCREEN(mainScreen, mainItems, -12 ITEM_BASIC("Start service"), -13 ITEM_BASIC("Connect to WiFi"), -14 ITEM_BASIC("Settings"), -15 ITEM_BASIC("Blink SOS"), -16 ITEM_BASIC("Blink random")); -17// clang-format on -18 -19LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); -20LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); -21LcdMenu menu(lcdAdapter); -22KeyboardAdapter keyboard(&menu, &Serial); -23 -24void setup() { -25 Serial.begin(9600); -26 // Initialize LcdMenu with the menu items -27 lcdAdapter.begin(); -28 menu.setScreen(mainScreen); -29} -30 -31void loop() { -32 keyboard.observe(); -33} + 5#include <renderer/CharacterDisplayRenderer.h> + 6 + 7#define LCD_ROWS 2 + 8#define LCD_COLS 16 + 9 +10// Initialize the main menu items +11// clang-format off +12MENU_SCREEN(mainScreen, mainItems, +13 ITEM_BASIC("Start service"), +14 ITEM_BASIC("Connect to WiFi"), +15 ITEM_BASIC("Settings"), +16 ITEM_BASIC("Blink SOS"), +17 ITEM_BASIC("Blink random")); +18// clang-format on +19 +20LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +21CharacterDisplayRenderer renderer(new LiquidCrystal_I2CAdapter(&lcd), LCD_COLS, LCD_ROWS); +22LcdMenu menu(renderer); +23KeyboardAdapter keyboard(&menu, &Serial); +24 +25void setup() { +26 Serial.begin(9600); +27 // Initialize LcdMenu with the menu items +28 renderer.begin(); +29 menu.setScreen(mainScreen); +30} +31 +32void loop() { +33 keyboard.observe(); +34}

    diff --git a/reference/samples/ButtonAdapter.html b/reference/samples/ButtonAdapter.html index 4cedb234..3fd0389f 100644 --- a/reference/samples/ButtonAdapter.html +++ b/reference/samples/ButtonAdapter.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -217,50 +222,52 @@

    ButtonAdapter 4#include <MenuScreen.h> 5#include <display/LiquidCrystal_I2CAdapter.h> 6#include <input/ButtonAdapter.h> - 7 - 8#define LCD_ROWS 2 - 9#define LCD_COLS 16 -10 -11// Declare the call back function -12void toggleBacklight(bool isOn); -13 -14// clang-format off -15MENU_SCREEN(mainScreen, mainItems, -16 ITEM_BASIC("Start service"), -17 ITEM_BASIC("Connect to WiFi"), -18 ITEM_TOGGLE("Backlight", toggleBacklight), -19 ITEM_BASIC("Blink SOS"), -20 ITEM_BASIC("Blink random")); -21// clang-format on -22 -23LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); -24LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); -25LcdMenu menu(lcdAdapter); -26Button upBtn(2); -27ButtonAdapter upBtnA(&menu, &upBtn, UP); -28Button downBtn(3); -29ButtonAdapter downBtnA(&menu, &downBtn, DOWN); -30Button enterBtn(4); -31ButtonAdapter enterBtnA(&menu, &enterBtn, ENTER); -32 -33void setup() { -34 upBtn.begin(); -35 downBtn.begin(); -36 enterBtn.begin(); -37 lcdAdapter.begin(); -38 Serial.begin(9600); -39 menu.setScreen(mainScreen); -40} -41 -42void loop() { -43 upBtnA.observe(); -44 downBtnA.observe(); -45 enterBtnA.observe(); -46} -47/** -48 * Define callback -49 */ -50void toggleBacklight(bool isOn) { lcdAdapter.setBacklight(isOn); } + 7#include <renderer/CharacterDisplayRenderer.h> + 8 + 9#define LCD_ROWS 2 +10#define LCD_COLS 16 +11 +12// Declare the call back function +13void toggleBacklight(bool isOn); +14 +15// clang-format off +16MENU_SCREEN(mainScreen, mainItems, +17 ITEM_BASIC("Start service"), +18 ITEM_BASIC("Connect to WiFi"), +19 ITEM_TOGGLE("Backlight", toggleBacklight), +20 ITEM_BASIC("Blink SOS"), +21 ITEM_BASIC("Blink random")); +22// clang-format on +23 +24LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +25LiquidCrystal_I2CAdapter lcdAdapter(&lcd); +26CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS); +27LcdMenu menu(renderer); +28Button upBtn(5); +29ButtonAdapter upBtnA(&menu, &upBtn, UP); +30Button downBtn(6); +31ButtonAdapter downBtnA(&menu, &downBtn, DOWN); +32Button enterBtn(7); +33ButtonAdapter enterBtnA(&menu, &enterBtn, ENTER); +34 +35void setup() { +36 upBtn.begin(); +37 downBtn.begin(); +38 enterBtn.begin(); +39 renderer.begin(); +40 Serial.begin(9600); +41 menu.setScreen(mainScreen); +42} +43 +44void loop() { +45 upBtnA.observe(); +46 downBtnA.observe(); +47 enterBtnA.observe(); +48} +49/** +50 * Define callback +51 */ +52void toggleBacklight(bool isOn) { lcdAdapter.setBacklight(isOn); }

    diff --git a/reference/samples/ButtonWithRotaryAdapter.html b/reference/samples/ButtonWithRotaryAdapter.html index eab2697a..c6451719 100644 --- a/reference/samples/ButtonWithRotaryAdapter.html +++ b/reference/samples/ButtonWithRotaryAdapter.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -224,58 +229,60 @@

    ButtonWithRotaryAdapter11#include <display/LiquidCrystal_I2CAdapter.h> 12#include <input/ButtonAdapter.h> 13#include <input/SimpleRotaryAdapter.h> -14 -15#define LCD_ROWS 2 -16#define LCD_COLS 16 -17 -18// Declare the callbacks -19void colorsCallback(uint8_t pos); -20void toggleBacklight(bool isOn); -21void inputCallback(char* value); -22 -23String colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"}; -24 -25// clang-format off -26MENU_SCREEN(mainScreen, mainItems, -27 ITEM_INPUT_CHARSET("User", (const char*)"ABCDEFGHIJKLMNOPQRSTUVWXYZ", inputCallback), -28 ITEM_STRING_LIST("Color", colors, 8, colorsCallback), -29 ITEM_TOGGLE("Backlight", toggleBacklight), -30 ITEM_BASIC("Placeholder 1"), -31 ITEM_BASIC("Placeholder 2")); -32// clang-format on -33 -34LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); -35LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); -36LcdMenu menu(lcdAdapter); -37SimpleRotary encoder(2, 3, 4); -38SimpleRotaryAdapter rotaryInput(&menu, &encoder); // Rotary input adapter -39Button backspaceBtn(5); -40ButtonAdapter backspaceBtnA(&menu, &backspaceBtn, BACKSPACE); // Push button for backspace -41 -42void setup() { -43 backspaceBtn.begin(); -44 lcdAdapter.begin(); -45 Serial.begin(9600); -46 menu.setScreen(mainScreen); -47} -48 -49void loop() { -50 rotaryInput.observe(); -51 backspaceBtnA.observe(); -52} -53 -54// Define the callbacks -55void toggleBacklight(bool isOn) { -56 lcdAdapter.setBacklight(isOn); -57} -58 -59void colorsCallback(uint8_t pos) { -60 Serial.println(colors[pos]); -61} -62 -63void inputCallback(char* value) { -64 Serial.println(value); -65} +14#include <renderer/CharacterDisplayRenderer.h> +15 +16#define LCD_ROWS 2 +17#define LCD_COLS 16 +18 +19// Declare the callbacks +20void colorsCallback(uint8_t pos); +21void toggleBacklight(bool isOn); +22void inputCallback(char* value); +23 +24String colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"}; +25 +26// clang-format off +27MENU_SCREEN(mainScreen, mainItems, +28 ITEM_INPUT_CHARSET("User", (const char*)"ABCDEFGHIJKLMNOPQRSTUVWXYZ", inputCallback), +29 ITEM_STRING_LIST("Color", colors, 8, colorsCallback), +30 ITEM_TOGGLE("Backlight", toggleBacklight), +31 ITEM_BASIC("Placeholder 1"), +32 ITEM_BASIC("Placeholder 2")); +33// clang-format on +34 +35LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +36LiquidCrystal_I2CAdapter lcdAdapter(&lcd); +37CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS); +38LcdMenu menu(renderer); +39SimpleRotary encoder(2, 3, 4); +40SimpleRotaryAdapter rotaryInput(&menu, &encoder); // Rotary input adapter +41Button backspaceBtn(11); +42ButtonAdapter backspaceBtnA(&menu, &backspaceBtn, BACKSPACE); // Push button for backspace +43 +44void setup() { +45 backspaceBtn.begin(); +46 renderer.begin(); +47 Serial.begin(9600); +48 menu.setScreen(mainScreen); +49} +50 +51void loop() { +52 rotaryInput.observe(); +53 backspaceBtnA.observe(); +54} +55 +56// Define the callbacks +57void toggleBacklight(bool isOn) { +58 lcdAdapter.setBacklight(isOn); +59} +60 +61void colorsCallback(uint8_t pos) { +62 Serial.println(colors[pos]); +63} +64 +65void inputCallback(char* value) { +66 Serial.println(value); +67}

    diff --git a/reference/samples/Callbacks.html b/reference/samples/Callbacks.html index d7d8bb4f..2d5fc39a 100644 --- a/reference/samples/Callbacks.html +++ b/reference/samples/Callbacks.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -216,43 +221,45 @@

    Callbacks 3#include <MenuScreen.h> 4#include <display/LiquidCrystal_I2CAdapter.h> 5#include <input/KeyboardAdapter.h> - 6 - 7#define LCD_ROWS 2 - 8#define LCD_COLS 16 - 9 -10// Declare the call back function -11void toggleBacklight(bool isOn); -12 -13// clang-format off -14MENU_SCREEN(mainScreen, mainItems, -15 ITEM_BASIC("Start service"), -16 ITEM_BASIC("Connect to WiFi"), -17 ITEM_TOGGLE("Backlight", toggleBacklight), -18 ITEM_BASIC("Blink SOS"), -19 ITEM_BASIC("Blink random")); -20// clang-format on -21 -22LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); -23LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); -24LcdMenu menu(lcdAdapter); -25KeyboardAdapter keyboard(&menu, &Serial); -26 -27void setup() { -28 Serial.begin(9600); -29 lcdAdapter.begin(); -30 menu.setScreen(mainScreen); -31} -32 -33void loop() { -34 keyboard.observe(); -35} -36 -37/** -38 * Define callback -39 */ -40void toggleBacklight(bool isOn) { -41 lcdAdapter.setBacklight(isOn); -42} + 6#include <renderer/CharacterDisplayRenderer.h> + 7 + 8#define LCD_ROWS 2 + 9#define LCD_COLS 16 +10 +11// Declare the call back function +12void toggleBacklight(bool isOn); +13 +14// clang-format off +15MENU_SCREEN(mainScreen, mainItems, +16 ITEM_BASIC("Start service"), +17 ITEM_BASIC("Connect to WiFi"), +18 ITEM_TOGGLE("Backlight", toggleBacklight), +19 ITEM_BASIC("Blink SOS"), +20 ITEM_BASIC("Blink random")); +21// clang-format on +22 +23LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +24LiquidCrystal_I2CAdapter lcdAdapter(&lcd); +25CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS); +26LcdMenu menu(renderer); +27KeyboardAdapter keyboard(&menu, &Serial); +28 +29void setup() { +30 Serial.begin(9600); +31 renderer.begin(); +32 menu.setScreen(mainScreen); +33} +34 +35void loop() { +36 keyboard.observe(); +37} +38 +39/** +40 * Define callback +41 */ +42void toggleBacklight(bool isOn) { +43 lcdAdapter.setBacklight(isOn); +44}

    diff --git a/reference/samples/CharsetInput.html b/reference/samples/CharsetInput.html index 67500821..44755025 100644 --- a/reference/samples/CharsetInput.html +++ b/reference/samples/CharsetInput.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -217,46 +222,47 @@

    CharsetInput 4#include <MenuScreen.h> 5#include <display/LiquidCrystal_I2CAdapter.h> 6#include <input/KeyboardAdapter.h> - 7 - 8#define LCD_ROWS 2 - 9#define LCD_COLS 16 -10 -11// Create your charset -12const char* charset = "0123456789"; -13 -14// Declare the call back function -15void inputCallback(char* value); -16 -17// clang-format off -18MENU_SCREEN(mainScreen, mainItems, -19 ITEM_INPUT_CHARSET("Con", "0123456", charset, inputCallback), -20 ITEM_BASIC("Connect to WiFi"), -21 ITEM_BASIC("Blink SOS"), -22 ITEM_BASIC("Blink random")); -23// clang-format on -24 -25LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); -26LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); -27LcdMenu menu(lcdAdapter); -28KeyboardAdapter keyboard(&menu, &Serial); -29 -30void setup() { -31 Serial.begin(9600); -32 lcdAdapter.begin(); -33 menu.setScreen(mainScreen); -34} -35 -36void loop() { -37 keyboard.observe(); -38} -39/** -40 * Define callback -41 */ -42void inputCallback(char* value) { -43 // Do stuff with value -44 Serial.print(F("# ")); -45 Serial.println(value); -46} + 7#include <renderer/CharacterDisplayRenderer.h> + 8 + 9#define LCD_ROWS 2 +10#define LCD_COLS 16 +11 +12// Create your charset +13const char* charset = "0123456789"; +14 +15// Declare the call back function +16void inputCallback(char* value); +17 +18// clang-format off +19MENU_SCREEN(mainScreen, mainItems, +20 ITEM_INPUT_CHARSET("Con", "0123456", charset, inputCallback), +21 ITEM_BASIC("Connect to WiFi"), +22 ITEM_BASIC("Blink SOS"), +23 ITEM_BASIC("Blink random")); +24// clang-format on +25 +26LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +27CharacterDisplayRenderer renderer(new LiquidCrystal_I2CAdapter(&lcd), LCD_COLS, LCD_ROWS); +28LcdMenu menu(renderer); +29KeyboardAdapter keyboard(&menu, &Serial); +30 +31void setup() { +32 Serial.begin(9600); +33 renderer.begin(); +34 menu.setScreen(mainScreen); +35} +36 +37void loop() { +38 keyboard.observe(); +39} +40/** +41 * Define callback +42 */ +43void inputCallback(char* value) { +44 // Do stuff with value +45 Serial.print(F("# ")); +46 Serial.println(value); +47}

    diff --git a/reference/samples/InputRotary.html b/reference/samples/InputRotary.html index 29231fba..e48f117b 100644 --- a/reference/samples/InputRotary.html +++ b/reference/samples/InputRotary.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -220,57 +225,58 @@

    InputRotary 7#include <SimpleRotary.h> 8#include <display/LiquidCrystal_I2CAdapter.h> 9#include <input/SimpleRotaryAdapter.h> -10 -11#define LCD_ROWS 2 -12#define LCD_COLS 16 -13 -14// Create your charset -15const char* charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -16 -17// Declare the call back functions -18void inputCallback(char* value); -19void clearInput(); -20 -21extern MenuScreen* userScreen; -22 -23// clang-format off -24MENU_SCREEN(mainScreen, mainItems, -25 ITEM_SUBMENU("Set user", userScreen), -26 ITEM_BASIC("Settings"), -27 ITEM_BASIC("More Settings"), -28 ITEM_BASIC("And more Settings")); -29 -30MENU_SCREEN(userScreen, userItems, -31 ITEM_INPUT_CHARSET("User", charset, inputCallback), -32 ITEM_COMMAND("Clear", clearInput)); -33// clang-format on -34 -35LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); -36LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); -37LcdMenu menu(lcdAdapter); -38SimpleRotary encoder(2, 3, 4); -39SimpleRotaryAdapter rotaryInput(&menu, &encoder); -40 -41void setup() { -42 Serial.begin(9600); -43 lcdAdapter.begin(); -44 menu.setScreen(mainScreen); -45} -46 -47void loop() { rotaryInput.observe(); } -48 -49// Define the callbacks -50void inputCallback(char* value) { -51 // Do stuff with value -52 Serial.print(F("# ")); -53 Serial.println(value); -54} -55 -56void clearInput() { -57 if ((static_cast<ItemInput*>(userItems[0]))->setValue((char*)"")) { -58 menu.refresh(); -59 } -60} +10#include <renderer/CharacterDisplayRenderer.h> +11 +12#define LCD_ROWS 2 +13#define LCD_COLS 16 +14 +15// Create your charset +16const char* charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +17 +18// Declare the call back functions +19void inputCallback(char* value); +20void clearInput(); +21 +22extern MenuScreen* userScreen; +23 +24// clang-format off +25MENU_SCREEN(mainScreen, mainItems, +26 ITEM_SUBMENU("Set user", userScreen), +27 ITEM_BASIC("Settings"), +28 ITEM_BASIC("More Settings"), +29 ITEM_BASIC("And more Settings")); +30 +31MENU_SCREEN(userScreen, userItems, +32 ITEM_INPUT_CHARSET("User", charset, inputCallback), +33 ITEM_COMMAND("Clear", clearInput)); +34// clang-format on +35 +36LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +37CharacterDisplayRenderer renderer(new LiquidCrystal_I2CAdapter(&lcd), LCD_COLS, LCD_ROWS); +38LcdMenu menu(renderer); +39SimpleRotary encoder(2, 3, 4); +40SimpleRotaryAdapter rotaryInput(&menu, &encoder); +41 +42void setup() { +43 Serial.begin(9600); +44 renderer.begin(); +45 menu.setScreen(mainScreen); +46} +47 +48void loop() { rotaryInput.observe(); } +49 +50// Define the callbacks +51void inputCallback(char* value) { +52 // Do stuff with value +53 Serial.print(F("# ")); +54 Serial.println(value); +55} +56 +57void clearInput() { +58 if ((static_cast<ItemInput*>(userItems[0]))->setValue((char*)"")) { +59 menu.refresh(); +60 } +61}

    diff --git a/reference/samples/IntFloatValues.html b/reference/samples/IntFloatValues.html index 76dd8ab3..5c627005 100644 --- a/reference/samples/IntFloatValues.html +++ b/reference/samples/IntFloatValues.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -217,50 +222,51 @@

    IntFloatValues 4#include <MenuScreen.h> 5#include <display/LiquidCrystal_I2CAdapter.h> 6#include <input/KeyboardAdapter.h> - 7 - 8#define LCD_ROWS 2 - 9#define LCD_COLS 16 -10 -11// Declare the callbacks -12void callbackInt(int value); -13void callbackFloat(float value); -14 -15// Initialize the main menu items -16// clang-format off -17MENU_SCREEN(mainScreen, mainItems, -18 ITEM_BASIC("Con"), -19 ITEM_INT_RANGE("Dist", 100, 200, 100, callbackInt, (const char*) "m"), -20 ITEM_FLOAT_RANGE("Curr", -1.0f, 1.0f, -1.0f, callbackFloat, (const char*) "mA", 0.01f), -21 ITEM_BASIC("Blink SOS"), -22 ITEM_BASIC("Blink random")); -23// clang-format on -24 -25// Construct the LcdMenu -26LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); -27LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); -28LcdMenu menu(lcdAdapter); -29KeyboardAdapter keyboard(&menu, &Serial); -30 -31void setup() { -32 Serial.begin(9600); -33 // Initialize LcdMenu with the menu items -34 lcdAdapter.begin(); -35 menu.setScreen(mainScreen); -36} -37 -38void loop() { -39 keyboard.observe(); -40} -41 -42void callbackInt(int value) { -43 // do something with the integer value -44 Serial.println(value); -45} -46 -47void callbackFloat(float value) { -48 // do something with the float value -49 Serial.println(value); -50} + 7#include <renderer/CharacterDisplayRenderer.h> + 8 + 9#define LCD_ROWS 2 +10#define LCD_COLS 16 +11 +12// Declare the callbacks +13void callbackInt(int value); +14void callbackFloat(float value); +15 +16// Initialize the main menu items +17// clang-format off +18MENU_SCREEN(mainScreen, mainItems, +19 ITEM_BASIC("Con"), +20 ITEM_INT_RANGE("Dist", 100, 200, 100, callbackInt, (const char*) "m"), +21 ITEM_FLOAT_RANGE("Curr", -1.0f, 1.0f, -1.0f, callbackFloat, (const char*) "mA", 0.01f), +22 ITEM_BASIC("Blink SOS"), +23 ITEM_BASIC("Blink random")); +24// clang-format on +25 +26// Construct the LcdMenu +27LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +28CharacterDisplayRenderer renderer(new LiquidCrystal_I2CAdapter(&lcd), LCD_COLS, LCD_ROWS); +29LcdMenu menu(renderer); +30KeyboardAdapter keyboard(&menu, &Serial); +31 +32void setup() { +33 Serial.begin(9600); +34 // Initialize LcdMenu with the menu items +35 renderer.begin(); +36 menu.setScreen(mainScreen); +37} +38 +39void loop() { +40 keyboard.observe(); +41} +42 +43void callbackInt(int value) { +44 // do something with the integer value +45 Serial.println(value); +46} +47 +48void callbackFloat(float value) { +49 // do something with the float value +50 Serial.println(value); +51}

    diff --git a/reference/samples/ItemBack.html b/reference/samples/ItemBack.html index 65f09019..f8868b97 100644 --- a/reference/samples/ItemBack.html +++ b/reference/samples/ItemBack.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -217,44 +222,45 @@

    ItemBack 4#include <MenuScreen.h> 5#include <display/LiquidCrystal_I2CAdapter.h> 6#include <input/KeyboardAdapter.h> - 7 - 8#define LCD_ROWS 2 - 9#define LCD_COLS 16 -10 -11extern MenuScreen* settingsScreen; -12 -13// Define the main menu -14// clang-format off -15MENU_SCREEN(mainScreen, mainItems, -16 ITEM_BASIC("Start service"), -17 ITEM_BASIC("Connect to WiFi"), -18 ITEM_SUBMENU("Settings", settingsScreen), -19 ITEM_BASIC("Blink SOS"), -20 ITEM_BASIC("Blink random")); -21 -22// Create submenu and precise its parent -23MENU_SCREEN(settingsScreen, settingsItems, -24 ITEM_BASIC("Backlight"), -25 ITEM_BASIC("Contrast"), -26 ITEM_BACK()); -27// clang-format on -28 -29LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); -30LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); -31LcdMenu menu(lcdAdapter); -32 -33// Initialize the KeyboardAdapter -34KeyboardAdapter keyboard(&menu, &Serial); -35 -36void setup() { -37 Serial.begin(9600); -38 lcdAdapter.begin(); -39 menu.setScreen(mainScreen); -40} -41 -42void loop() { -43 keyboard.observe(); -44} + 7#include <renderer/CharacterDisplayRenderer.h> + 8 + 9#define LCD_ROWS 2 +10#define LCD_COLS 16 +11 +12extern MenuScreen* settingsScreen; +13 +14// Define the main menu +15// clang-format off +16MENU_SCREEN(mainScreen, mainItems, +17 ITEM_BASIC("Start service"), +18 ITEM_BASIC("Connect to WiFi"), +19 ITEM_SUBMENU("Settings", settingsScreen), +20 ITEM_BASIC("Blink SOS"), +21 ITEM_BASIC("Blink random")); +22 +23// Create submenu and precise its parent +24MENU_SCREEN(settingsScreen, settingsItems, +25 ITEM_BASIC("Backlight"), +26 ITEM_BASIC("Contrast"), +27 ITEM_BACK()); +28// clang-format on +29 +30LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +31CharacterDisplayRenderer renderer(new LiquidCrystal_I2CAdapter(&lcd), LCD_COLS, LCD_ROWS); +32LcdMenu menu(renderer); +33 +34// Initialize the KeyboardAdapter +35KeyboardAdapter keyboard(&menu, &Serial); +36 +37void setup() { +38 Serial.begin(9600); +39 renderer.begin(); +40 menu.setScreen(mainScreen); +41} +42 +43void loop() { +44 keyboard.observe(); +45} diff --git a/reference/samples/KeyboardAdapter.html b/reference/samples/KeyboardAdapter.html index 9ae23c93..f988a50c 100644 --- a/reference/samples/KeyboardAdapter.html +++ b/reference/samples/KeyboardAdapter.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -216,46 +221,47 @@

    KeyboardAdapter 3#include <MenuScreen.h> 4#include <display/LiquidCrystal_I2CAdapter.h> 5#include <input/KeyboardAdapter.h> - 6 - 7#define LCD_ROWS 2 - 8#define LCD_COLS 16 - 9 -10// Create your charset -11const char* charset = "0123456789"; -12 -13// Declare the call back function -14void inputCallback(char* value); -15 -16// clang-format off -17MENU_SCREEN(mainScreen, mainItems, -18 ITEM_INPUT_CHARSET("Con", "0123456", charset, inputCallback), -19 ITEM_BASIC("Connect to WiFi"), -20 ITEM_BASIC("Blink SOS"), -21 ITEM_BASIC("Blink random")); -22// clang-format on -23 -24LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); -25LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); -26LcdMenu menu(lcdAdapter); -27KeyboardAdapter keyboard(&menu, &Serial); -28 -29void setup() { -30 Serial.begin(9600); -31 lcdAdapter.begin(); -32 menu.setScreen(mainScreen); -33} -34 -35void loop() { -36 keyboard.observe(); -37} -38/** -39 * Define callback -40 */ -41void inputCallback(char* value) { -42 // Do stuff with value -43 Serial.print(F("# ")); -44 Serial.println(value); -45} + 6#include <renderer/CharacterDisplayRenderer.h> + 7 + 8#define LCD_ROWS 2 + 9#define LCD_COLS 16 +10 +11// Create your charset +12const char* charset = "0123456789"; +13 +14// Declare the call back function +15void inputCallback(char* value); +16 +17// clang-format off +18MENU_SCREEN(mainScreen, mainItems, +19 ITEM_INPUT_CHARSET("Con", "0123456", charset, inputCallback), +20 ITEM_BASIC("Connect to WiFi"), +21 ITEM_BASIC("Blink SOS"), +22 ITEM_BASIC("Blink random")); +23// clang-format on +24 +25LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +26CharacterDisplayRenderer renderer(new LiquidCrystal_I2CAdapter(&lcd), LCD_COLS, LCD_ROWS); +27LcdMenu menu(renderer); +28KeyboardAdapter keyboard(&menu, &Serial); +29 +30void setup() { +31 Serial.begin(9600); +32 renderer.begin(); +33 menu.setScreen(mainScreen); +34} +35 +36void loop() { +37 keyboard.observe(); +38} +39/** +40 * Define callback +41 */ +42void inputCallback(char* value) { +43 // Do stuff with value +44 Serial.print(F("# ")); +45 Serial.println(value); +46} diff --git a/reference/samples/List.html b/reference/samples/List.html index a9a42672..8aa0e963 100644 --- a/reference/samples/List.html +++ b/reference/samples/List.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -216,59 +221,60 @@

    List 3#include <MenuScreen.h> 4#include <display/LiquidCrystal_I2CAdapter.h> 5#include <input/KeyboardAdapter.h> - 6 - 7#define LCD_ROWS 2 - 8#define LCD_COLS 16 - 9 -10// Declare the callbacks -11void colorsCallback(uint8_t pos); -12void numsCallback(uint8_t pos); -13 -14// Declare the array -15extern String colors[]; -16// Initialize the array -17String colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"}; -18 -19// Declare the array -20extern String nums[]; -21// Initialize the array -22String nums[] = {"5", "7", "9", "12", "32"}; -23 -24// Initialize the main menu items -25// clang-format off -26MENU_SCREEN(mainScreen, mainItems, -27 ITEM_BASIC("List demo"), -28 ITEM_STRING_LIST("Col", colors, 8, colorsCallback), -29 ITEM_STRING_LIST("Num", nums, 5, numsCallback), -30 ITEM_BASIC("Example")); -31// clang-format on -32 -33// Construct the LcdMenu -34LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); -35LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); -36LcdMenu menu(lcdAdapter); -37KeyboardAdapter keyboard(&menu, &Serial); -38 -39void setup() { -40 Serial.begin(9600); -41 lcdAdapter.begin(); -42 menu.setScreen(mainScreen); -43} -44 -45void loop() { -46 keyboard.observe(); -47} -48 -49// Define the callbacks -50void colorsCallback(uint8_t pos) { -51 // do something with the index -52 Serial.println(colors[pos]); -53} -54 -55void numsCallback(uint8_t pos) { -56 // do something with the index -57 Serial.println(nums[pos]); -58} + 6#include <renderer/CharacterDisplayRenderer.h> + 7 + 8#define LCD_ROWS 2 + 9#define LCD_COLS 16 +10 +11// Declare the callbacks +12void colorsCallback(uint8_t pos); +13void numsCallback(uint8_t pos); +14 +15// Declare the array +16extern String colors[]; +17// Initialize the array +18String colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"}; +19 +20// Declare the array +21extern String nums[]; +22// Initialize the array +23String nums[] = {"5", "7", "9", "12", "32"}; +24 +25// Initialize the main menu items +26// clang-format off +27MENU_SCREEN(mainScreen, mainItems, +28 ITEM_BASIC("List demo"), +29 ITEM_STRING_LIST("Col", colors, 8, colorsCallback), +30 ITEM_STRING_LIST("Num", nums, 5, numsCallback), +31 ITEM_BASIC("Example")); +32// clang-format on +33 +34// Construct the LcdMenu +35LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +36CharacterDisplayRenderer renderer(new LiquidCrystal_I2CAdapter(&lcd), LCD_COLS, LCD_ROWS); +37LcdMenu menu(renderer); +38KeyboardAdapter keyboard(&menu, &Serial); +39 +40void setup() { +41 Serial.begin(9600); +42 renderer.begin(); +43 menu.setScreen(mainScreen); +44} +45 +46void loop() { +47 keyboard.observe(); +48} +49 +50// Define the callbacks +51void colorsCallback(uint8_t pos) { +52 // do something with the index +53 Serial.println(colors[pos]); +54} +55 +56void numsCallback(uint8_t pos) { +57 // do something with the index +58 Serial.println(nums[pos]); +59} diff --git a/reference/samples/MenuTimeout.html b/reference/samples/MenuTimeout.html index 3c9bdfad..913f9439 100644 --- a/reference/samples/MenuTimeout.html +++ b/reference/samples/MenuTimeout.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -215,40 +220,42 @@

    MenuTimeout 2#include <MenuScreen.h> 3#include <display/LiquidCrystal_I2CAdapter.h> 4#include <input/KeyboardAdapter.h> - 5 - 6#define LCD_ROWS 2 - 7#define LCD_COLS 16 - 8 - 9// clang-format off -10MENU_SCREEN(mainScreen, mainItems, -11 ITEM_BASIC("Start service"), -12 ITEM_BASIC("Connect to WiFi"), -13 ITEM_BASIC("Settings"), -14 ITEM_BASIC("Blink SOS"), -15 ITEM_BASIC("Blink random")); -16// clang-format on -17 -18LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); -19LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); -20LcdMenu menu(lcdAdapter); -21 -22// Initialize the KeyboardAdapter -23KeyboardAdapter keyboard(&menu, &Serial); -24 -25void setup() { -26 Serial.begin(9600); -27 lcdAdapter.begin(); -28 menu.setScreen(mainScreen); -29} -30 -31void loop() { -32 /** -33 * IMPORTANT: You must call this function for the timeout to work -34 * The default timeout is 10000ms -35 */ -36 lcdAdapter.updateTimer(); -37 keyboard.observe(); -38} + 5#include <renderer/CharacterDisplayRenderer.h> + 6 + 7#define LCD_ROWS 2 + 8#define LCD_COLS 16 + 9 +10// clang-format off +11MENU_SCREEN(mainScreen, mainItems, +12 ITEM_BASIC("Start service"), +13 ITEM_BASIC("Connect to WiFi"), +14 ITEM_BASIC("Settings"), +15 ITEM_BASIC("Blink SOS"), +16 ITEM_BASIC("Blink random")); +17// clang-format on +18 +19LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +20LiquidCrystal_I2CAdapter lcdAdapter(&lcd); +21CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS); +22LcdMenu menu(renderer); +23 +24// Initialize the KeyboardAdapter +25KeyboardAdapter keyboard(&menu, &Serial); +26 +27void setup() { +28 Serial.begin(9600); +29 renderer.begin(); +30 menu.setScreen(mainScreen); +31} +32 +33void loop() { +34 /** +35 * IMPORTANT: You must call this function for the timeout to work +36 * The default timeout is 10000ms +37 */ +38 renderer.updateTimer(); +39 keyboard.observe(); +40} diff --git a/reference/samples/RTOS.html b/reference/samples/RTOS.html index 32d99fe2..fd1a6988 100644 --- a/reference/samples/RTOS.html +++ b/reference/samples/RTOS.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -219,116 +224,118 @@

    RTOS 6#include <MenuScreen.h> 7#include <display/LiquidCrystal_I2CAdapter.h> 8#include <input/KeyboardAdapter.h> - 9 - 10// 2x20 LCD Display - 11#define LCD_ROWS 4 - 12#define LCD_COLS 20 - 13 - 14float temperature1; - 15float temperature2; - 16float temperature3; - 17 - 18bool relay1State, relay2State, relay3State; - 19 - 20// Relay 1 Toggle - 21void toggleRelay1(bool isOn) { - 22 printLog(F("relay1State")); - 23} - 24 - 25// Relay 2 Toggle - 26void toggleRelay2(bool isOn) { - 27 printLog(F("relay2State")); - 28} - 29 - 30// Relay 3 Toggle - 31void toggleRelay3(bool isOn) { - 32 printLog(F("relay3State")); - 33} - 34 - 35LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); - 36LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); - 37LcdMenu menu(lcdAdapter); - 38KeyboardAdapter keyboard(&menu, &Serial); - 39 - 40extern MenuScreen* relayScreen; - 41extern MenuScreen* tempScreen; - 42 - 43// clang-format off - 44MENU_SCREEN(mainScreen, mainItems, - 45 ITEM_BASIC("Relay Test"), - 46 ITEM_SUBMENU("Temp. Observing", tempScreen), - 47 ITEM_BASIC("Hello World"), - 48 ITEM_BASIC("I'm World")); - 49// clang-format on - 50 - 51// Sub Menu 1: Relays - 52// clang-format off - 53MENU_SCREEN(relayScreen, relayItems, - 54 ITEM_TOGGLE("Relay 1", toggleRelay1), - 55 ITEM_TOGGLE("Relay 2", toggleRelay2), - 56 ITEM_TOGGLE("Relay 3", toggleRelay3)); - 57// clang-format on - 58 - 59// Sub Menu 2: Temperature Values - 60// clang-format off - 61MENU_SCREEN(tempScreen, tempItems, - 62 ITEM_BASIC(""), - 63 ITEM_BASIC(""), - 64 ITEM_BASIC("")); - 65// clang-format on - 66 - 67// RTOS func. to measure temperature value - 68static void tempMeas(void* pvParameters) { - 69 (void)pvParameters; - 70 for (;;) { - 71 //-------------------BEGIN: TEST WITH RANDOM------------------// - 72 temperature1 = random(1, 1000) / 100.0; // Generate random float - 73 temperature2 = random(1, 2000) / 100.0; // Generate random float - 74 temperature3 = random(1, 3000) / 100.0; // Generate random float - 75 //-------------------END: TEST WITH RANDOM--------------------// - 76 - 77 char buffer1[8]; - 78 tempItems[0]->setText(dtostrf(temperature1, 5, 2, buffer1)); - 79 - 80 char buffer2[8]; - 81 tempItems[1]->setText(dtostrf(temperature2, 5, 2, buffer2)); - 82 - 83 char buffer3[8]; - 84 tempItems[2]->setText(dtostrf(temperature3, 5, 2, buffer3)); - 85 - 86 if (menu.getScreen() == tempScreen) { - 87 menu.refresh(); - 88 } - 89 vTaskDelay(5000 / portTICK_PERIOD_MS); // wait for five seconds - 90 } - 91} - 92 - 93// RTOS func to read serial input from keyboard - 94static void keyPad(void* pvParameters) { - 95 (void)pvParameters; // Unused parameter - 96 - 97 for (;;) { - 98 keyboard.observe(); - 99 vTaskDelay(1); -100 } -101} -102 -103void setup() { -104 Serial.begin(9600); -105 // LCD activation -106 lcdAdapter.begin(); -107 menu.setScreen(mainScreen); -108 // Run RTOS func. -109 xTaskCreate(keyPad, "keyPad", 128, NULL, tskIDLE_PRIORITY + 2, NULL); -110 xTaskCreate(tempMeas, "tempMeas", 128, NULL, tskIDLE_PRIORITY + 1, NULL); -111 // Setup random seed -112 pinMode(A0, INPUT); -113 randomSeed(analogRead(A0)); -114} -115 -116void loop() { -117 lcdAdapter.updateTimer(); -118} + 9#include <renderer/CharacterDisplayRenderer.h> + 10 + 11// 2x20 LCD Display + 12#define LCD_ROWS 4 + 13#define LCD_COLS 20 + 14 + 15float temperature1; + 16float temperature2; + 17float temperature3; + 18 + 19bool relay1State, relay2State, relay3State; + 20 + 21// Relay 1 Toggle + 22void toggleRelay1(bool isOn) { + 23 printLog(F("relay1State")); + 24} + 25 + 26// Relay 2 Toggle + 27void toggleRelay2(bool isOn) { + 28 printLog(F("relay2State")); + 29} + 30 + 31// Relay 3 Toggle + 32void toggleRelay3(bool isOn) { + 33 printLog(F("relay3State")); + 34} + 35 + 36LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); + 37LiquidCrystal_I2CAdapter lcdAdapter(&lcd); + 38CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS); + 39LcdMenu menu(renderer); + 40KeyboardAdapter keyboard(&menu, &Serial); + 41 + 42extern MenuScreen* relayScreen; + 43extern MenuScreen* tempScreen; + 44 + 45// clang-format off + 46MENU_SCREEN(mainScreen, mainItems, + 47 ITEM_BASIC("Relay Test"), + 48 ITEM_SUBMENU("Temp. Observing", tempScreen), + 49 ITEM_BASIC("Hello World"), + 50 ITEM_BASIC("I'm World")); + 51// clang-format on + 52 + 53// Sub Menu 1: Relays + 54// clang-format off + 55MENU_SCREEN(relayScreen, relayItems, + 56 ITEM_TOGGLE("Relay 1", toggleRelay1), + 57 ITEM_TOGGLE("Relay 2", toggleRelay2), + 58 ITEM_TOGGLE("Relay 3", toggleRelay3)); + 59// clang-format on + 60 + 61// Sub Menu 2: Temperature Values + 62// clang-format off + 63MENU_SCREEN(tempScreen, tempItems, + 64 ITEM_BASIC(""), + 65 ITEM_BASIC(""), + 66 ITEM_BASIC("")); + 67// clang-format on + 68 + 69// RTOS func. to measure temperature value + 70static void tempMeas(void* pvParameters) { + 71 (void)pvParameters; + 72 for (;;) { + 73 //-------------------BEGIN: TEST WITH RANDOM------------------// + 74 temperature1 = random(1, 1000) / 100.0; // Generate random float + 75 temperature2 = random(1, 2000) / 100.0; // Generate random float + 76 temperature3 = random(1, 3000) / 100.0; // Generate random float + 77 //-------------------END: TEST WITH RANDOM--------------------// + 78 + 79 char buffer1[8]; + 80 tempItems[0]->setText(dtostrf(temperature1, 5, 2, buffer1)); + 81 + 82 char buffer2[8]; + 83 tempItems[1]->setText(dtostrf(temperature2, 5, 2, buffer2)); + 84 + 85 char buffer3[8]; + 86 tempItems[2]->setText(dtostrf(temperature3, 5, 2, buffer3)); + 87 + 88 if (menu.getScreen() == tempScreen) { + 89 menu.refresh(); + 90 } + 91 vTaskDelay(5000 / portTICK_PERIOD_MS); // wait for five seconds + 92 } + 93} + 94 + 95// RTOS func to read serial input from keyboard + 96static void keyPad(void* pvParameters) { + 97 (void)pvParameters; // Unused parameter + 98 + 99 for (;;) { +100 keyboard.observe(); +101 vTaskDelay(1); +102 } +103} +104 +105void setup() { +106 Serial.begin(9600); +107 // LCD activation +108 renderer.begin(); +109 menu.setScreen(mainScreen); +110 // Run RTOS func. +111 xTaskCreate(keyPad, "keyPad", 128, NULL, tskIDLE_PRIORITY + 2, NULL); +112 xTaskCreate(tempMeas, "tempMeas", 128, NULL, tskIDLE_PRIORITY + 1, NULL); +113 // Setup random seed +114 pinMode(A0, INPUT); +115 randomSeed(analogRead(A0)); +116} +117 +118void loop() { +119 renderer.updateTimer(); +120} diff --git a/reference/samples/SimpleInput.html b/reference/samples/SimpleInput.html index 696bf870..c48573b1 100644 --- a/reference/samples/SimpleInput.html +++ b/reference/samples/SimpleInput.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -216,43 +221,44 @@

    SimpleInput 3#include <MenuScreen.h> 4#include <display/LiquidCrystal_I2CAdapter.h> 5#include <input/KeyboardAdapter.h> - 6 - 7#define LCD_ROWS 2 - 8#define LCD_COLS 16 - 9 -10// Declare the call back function -11void inputCallback(char* value); -12 -13// clang-format off -14MENU_SCREEN(mainScreen, mainItems, -15 ITEM_INPUT("Con", inputCallback), -16 ITEM_BASIC("Connect to WiFi"), -17 ITEM_BASIC("Blink SOS"), -18 ITEM_BASIC("Blink random")); -19// clang-format on -20 -21LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); -22LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); -23LcdMenu menu(lcdAdapter); -24KeyboardAdapter keyboard(&menu, &Serial); -25 -26void setup() { -27 Serial.begin(9600); -28 lcdAdapter.begin(); -29 menu.setScreen(mainScreen); -30} -31 -32void loop() { -33 keyboard.observe(); -34} -35 -36/** -37 * Define callback -38 */ -39void inputCallback(char* value) { -40 // do something with the input value -41 Serial.println(value); -42} + 6#include <renderer/CharacterDisplayRenderer.h> + 7 + 8#define LCD_ROWS 2 + 9#define LCD_COLS 16 +10 +11// Declare the call back function +12void inputCallback(char* value); +13 +14// clang-format off +15MENU_SCREEN(mainScreen, mainItems, +16 ITEM_INPUT("Con", inputCallback), +17 ITEM_BASIC("Connect to WiFi"), +18 ITEM_BASIC("Blink SOS"), +19 ITEM_BASIC("Blink random")); +20// clang-format on +21 +22LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +23CharacterDisplayRenderer renderer(new LiquidCrystal_I2CAdapter(&lcd), LCD_COLS, LCD_ROWS); +24LcdMenu menu(renderer); +25KeyboardAdapter keyboard(&menu, &Serial); +26 +27void setup() { +28 Serial.begin(9600); +29 renderer.begin(); +30 menu.setScreen(mainScreen); +31} +32 +33void loop() { +34 keyboard.observe(); +35} +36 +37/** +38 * Define callback +39 */ +40void inputCallback(char* value) { +41 // do something with the input value +42 Serial.println(value); +43} diff --git a/reference/samples/SimpleRotary.html b/reference/samples/SimpleRotary.html index e02d2d73..dd360ac4 100644 --- a/reference/samples/SimpleRotary.html +++ b/reference/samples/SimpleRotary.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -219,53 +224,55 @@

    SimpleRotary 6#include <SimpleRotary.h> 7#include <display/LiquidCrystal_I2CAdapter.h> 8#include <input/SimpleRotaryAdapter.h> - 9 -10#define LCD_ROWS 2 -11#define LCD_COLS 16 -12 -13// Declare the callbacks -14void callback(int pos); -15void colorsCallback(uint8_t pos); -16void toggleBacklight(bool isOn); -17 -18String colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"}; -19 -20// clang-format off -21MENU_SCREEN(mainScreen, mainItems, -22 ITEM_BASIC("Connect to WiFi"), -23 ITEM_STRING_LIST("Color", colors, 8, colorsCallback), -24 ITEM_BASIC("Blink SOS"), -25 ITEM_INT_RANGE("Dist", 0, 50, 0, callback, (const char*) "m"), -26 ITEM_TOGGLE("Backlight", toggleBacklight), -27 ITEM_BASIC("Blink random")); -28// clang-format on -29 -30LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); -31LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); -32LcdMenu menu(lcdAdapter); -33SimpleRotary encoder(2, 3, 4); -34SimpleRotaryAdapter rotaryInput(&menu, &encoder); -35 -36void setup() { -37 Serial.begin(9600); -38 lcdAdapter.begin(); -39 menu.setScreen(mainScreen); -40} -41 -42void loop() { rotaryInput.observe(); } + 9#include <renderer/CharacterDisplayRenderer.h> +10 +11#define LCD_ROWS 2 +12#define LCD_COLS 16 +13 +14// Declare the callbacks +15void callback(int pos); +16void colorsCallback(uint8_t pos); +17void toggleBacklight(bool isOn); +18 +19String colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"}; +20 +21// clang-format off +22MENU_SCREEN(mainScreen, mainItems, +23 ITEM_BASIC("Connect to WiFi"), +24 ITEM_STRING_LIST("Color", colors, 8, colorsCallback), +25 ITEM_BASIC("Blink SOS"), +26 ITEM_INT_RANGE("Dist", 0, 50, 0, callback, (const char*) "m"), +27 ITEM_TOGGLE("Backlight", toggleBacklight), +28 ITEM_BASIC("Blink random")); +29// clang-format on +30 +31LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +32LiquidCrystal_I2CAdapter lcdAdapter(&lcd); +33CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS); +34LcdMenu menu(renderer); +35SimpleRotary encoder(2, 3, 4); +36SimpleRotaryAdapter rotaryInput(&menu, &encoder); +37 +38void setup() { +39 Serial.begin(9600); +40 renderer.begin(); +41 menu.setScreen(mainScreen); +42} 43 -44// Define the callbacks -45void toggleBacklight(bool isOn) { -46 lcdAdapter.setBacklight(isOn); -47} -48 -49void callback(int pos) { -50 Serial.println(pos); -51} -52 -53void colorsCallback(uint8_t pos) { -54 Serial.println(colors[pos]); -55} +44void loop() { rotaryInput.observe(); } +45 +46// Define the callbacks +47void toggleBacklight(bool isOn) { +48 lcdAdapter.setBacklight(isOn); +49} +50 +51void callback(int pos) { +52 Serial.println(pos); +53} +54 +55void colorsCallback(uint8_t pos) { +56 Serial.println(colors[pos]); +57} diff --git a/reference/samples/SubMenu.html b/reference/samples/SubMenu.html index 786b17e7..b9c6d7cb 100644 --- a/reference/samples/SubMenu.html +++ b/reference/samples/SubMenu.html @@ -113,6 +113,10 @@
  • Rotary Encoder Adapter
  • +
  • +
  • Reference

    @@ -216,55 +221,56 @@

    SubMenu 3#include <MenuScreen.h> 4#include <display/LiquidCrystal_I2CAdapter.h> 5#include <input/KeyboardAdapter.h> - 6 - 7#define LCD_ROWS 2 - 8#define LCD_COLS 16 - 9 -10extern MenuScreen* settingsScreen; -11extern MenuScreen* settings2Screen; -12 -13// Define the main menu -14// clang-format off -15MENU_SCREEN(mainScreen, mainItems, -16 ITEM_SUBMENU("Settings", settingsScreen), -17 ITEM_BASIC("Start service"), -18 ITEM_BASIC("Connect to WiFi"), -19 ITEM_BASIC("Blink SOS"), -20 ITEM_BASIC("Blink random"), -21 ITEM_SUBMENU("Settings 2", settings2Screen)); -22 -23// Create submenu and precise its parent -24MENU_SCREEN(settingsScreen, settingsItems, -25 ITEM_BASIC("Backlight"), -26 ITEM_BASIC("Contrast"), -27 ITEM_BASIC("Contrast1"), -28 ITEM_BASIC("Contrast2"), -29 ITEM_BASIC("Contrast3"), -30 ITEM_BASIC("Contrast4"), -31 ITEM_BASIC("Contrast5"), -32 ITEM_BASIC("Contrast6"), -33 ITEM_BASIC("Contrast7"), -34 ITEM_SUBMENU("Settings2", settings2Screen)); -35 -36MENU_SCREEN(settings2Screen, settings2Items, -37 ITEM_BASIC("Backlight"), -38 ITEM_BASIC("Contrast")); -39// clang-format on -40 -41LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); -42LiquidCrystal_I2CAdapter lcdAdapter(&lcd, LCD_COLS, LCD_ROWS); -43LcdMenu menu(lcdAdapter); -44KeyboardAdapter keyboard(&menu, &Serial); -45 -46void setup() { -47 Serial.begin(9600); -48 lcdAdapter.begin(); -49 menu.setScreen(mainScreen); -50} -51 -52void loop() { -53 keyboard.observe(); -54} + 6#include <renderer/CharacterDisplayRenderer.h> + 7 + 8#define LCD_ROWS 2 + 9#define LCD_COLS 16 +10 +11extern MenuScreen* settingsScreen; +12extern MenuScreen* settings2Screen; +13 +14// Define the main menu +15// clang-format off +16MENU_SCREEN(mainScreen, mainItems, +17 ITEM_SUBMENU("Settings", settingsScreen), +18 ITEM_BASIC("Start service"), +19 ITEM_BASIC("Connect to WiFi"), +20 ITEM_BASIC("Blink SOS"), +21 ITEM_BASIC("Blink random"), +22 ITEM_SUBMENU("Settings 2", settings2Screen)); +23 +24// Create submenu and precise its parent +25MENU_SCREEN(settingsScreen, settingsItems, +26 ITEM_BASIC("Backlight"), +27 ITEM_BASIC("Contrast"), +28 ITEM_BASIC("Contrast1"), +29 ITEM_BASIC("Contrast2"), +30 ITEM_BASIC("Contrast3"), +31 ITEM_BASIC("Contrast4"), +32 ITEM_BASIC("Contrast5"), +33 ITEM_BASIC("Contrast6"), +34 ITEM_BASIC("Contrast7"), +35 ITEM_SUBMENU("Settings2", settings2Screen)); +36 +37MENU_SCREEN(settings2Screen, settings2Items, +38 ITEM_BASIC("Backlight"), +39 ITEM_BASIC("Contrast")); +40// clang-format on +41 +42LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +43CharacterDisplayRenderer renderer(new LiquidCrystal_I2CAdapter(&lcd), LCD_COLS, LCD_ROWS); +44LcdMenu menu(renderer); +45KeyboardAdapter keyboard(&menu, &Serial); +46 +47void setup() { +48 Serial.begin(9600); +49 renderer.begin(); +50 menu.setScreen(mainScreen); +51} +52 +53void loop() { +54 keyboard.observe(); +55} diff --git a/reference/samples/index.html b/reference/samples/index.html index 28791625..3ffa5bf6 100644 --- a/reference/samples/index.html +++ b/reference/samples/index.html @@ -19,7 +19,7 @@ - +