Callbacks

 1#include <ItemToggle.h>
 2#include <LcdMenu.h>
 3#include <MenuScreen.h>
 4#include <display/LiquidCrystal_I2CAdapter.h>
 5#include <input/KeyboardAdapter.h>
 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}