Library to abstract Adafruit 16x2 Character LCD menus, favors configuration over code for creating menus and screen navigation.
{
id: String, // -- identifier
name: String, // -- Name of template
enabled: Bool,
actions: {
up: func || string || null || undefined, // Action to perform on button up, function, or a string (string name of menu)
down: func || string || null || undefined, // if null, go up or down a line if template.length > 2
left: func || string || undefined, // undefined does nothing
right: func || string || undefined,
select: func || string || undefined
},
template: [String], // array of template string, line by line, since this is an x2 display we join 0 and 1 by \n
data: func // function to retrieve data
}
const LCDMENU = require('16x2-lcd-menu');
const lcdMenu = new LCDMENU(60, true); // timeout backlight after 60 seconds, debug on
lcdMenu.addMenu({
id: 'testMenu',
name: 'Test Menu',
enabled: true,
actions: {
right: 'testMenu2',
},
template: [
'This is a',
'Test Menu',
'Welcome',
'To the Demo',
],
});
lcdMenu.addMenu({
id: 'testMenu2',
name: 'Test Menu',
enabled: true,
template: [
'Test Menu 2'
],
actions: {
left: 'testMenu',
},
});
lcdMenu.init();
process.on('exit', lcdMenu.close); // Cleanup
Raw access to instantiated lcd plate library
Adds a new menu
- if actions are not set, set it to an empty object (if it is truthy but not an object this could cause a crash)
- Defaults the id to match the name if an id is not set
- sets the first menu as the currentMenu (WIP)
Removes menu specified by id
- Does nothing if id not provided or menu with that id doesn't exist.
- fails if there are no more menus registered
Enables the specified menu
Disables the specified menu
Turns the backlight on or off based on state (truthy)
- Times out the display backlight after the configured # of seconds has passed
- does nothing if timeoutMs is set to 0
- Set the display timeout in seconds.
- Doesn't auto-clear previous timer
- Set re-renders the display if valid, if not valid, does nothing.
Initializes the display
- If no menu is configured, add a default one
- Turn on backlight
- Clears the screen
- Runs render menu
Renders provided or active menu, or 0 indexed menu if none provided
Clears the timeout so the screen backlight stays on.
- Shuts down screen
- Clears screen, turns off backlight, stops polling button presses