Arduino 框架通用 菜单/交互 系统
Full automated or user code driven navigation system.
全自动化用户代码驱动导航系统。
With this system you can define menus, submenus, input fields and other iteration objects that deal with all input/output and can call user defined handler as a result of user iteration.
使用这个系统,你可以定义菜单、子菜单、输入字段和其他迭代对象来处理所有的输入输出,并且可以调用用户定义的处理程序作为用户迭代的结果。
The user function can be operated as a single action called on click/enter or as a event driven function responding to focus In/Out or Enter/Esc events.
用户函数可以作为单一的被称之为 click/enter 的动作,或者作为事件驱动函数响应 In/Out 或 Enter/Esc 焦点事件。
The system is designed as a non blocking polling system, allowing concurrent task to run.
系统被设计为非阻塞式轮询系统,允许运行当前任务。
Optionally the system can be operated in semi-automated mode, issuing navigation command from user code.
系统也可选半自动运行模式,从用户代码发出导航命令。
See the wiki
#include <menu.h>
#include <menuIO/serialOut.h>
#include <menuIO/chainStream.h>
#include <menuIO/serialIn.h>
using namespace Menu;
#define LEDPIN LED_BUILTIN
#define MAX_DEPTH 1
unsigned int timeOn=10;
unsigned int timeOff=90;
MENU(mainMenu, "Blink menu", Menu::doNothing, Menu::noEvent, Menu::wrapStyle
,FIELD(timeOn,"On","ms",0,1000,10,1, Menu::doNothing, Menu::noEvent, Menu::noStyle)
,FIELD(timeOff,"Off","ms",0,10000,10,1,Menu::doNothing, Menu::noEvent, Menu::noStyle)
,EXIT("<Back")
);
serialIn serial(Serial);
MENU_INPUTS(in,&serial);
MENU_OUTPUTS(out,MAX_DEPTH
,SERIAL_OUT(Serial)
,NONE//注意最少含有两个项目
);
NAVROOT(nav,mainMenu,MAX_DEPTH,in,out);
void setup() {
pinMode(LEDPIN, OUTPUT);
Serial.begin(115200);
while(!Serial);
Serial.println("Menu 4.x");
Serial.println("Use keys + - * /");
Serial.println("to control the menu navigation");
}
bool blink(int timeOn,int timeOff) {return millis()%(unsigned long)(timeOn+timeOff)<(unsigned long)timeOn;}
void loop() {
nav.poll();
digitalWrite(LEDPIN, blink(timeOn,timeOff));
}
- Small footprint on RAM using PROGMEM on system where it is available.
- 在可用的系统上使用PROGMEM的RAM占用空间小
- Wide variety of input/output devices supported.
- 宽泛的输入/输出设备适应性
- Easy to define menus (macros).
- 容易定义菜单(宏)
- Minimalistic user code base.
- 极简用户代码库
- Fields edit values hooked to existing program variables (references).
- 字段编辑的值与现有程序变量挂钩
- Editing text fields with per character validation.
- 编辑文本字段具备字符验证
- Fields can edit numeric variables of any type (templates).
- 字段可以编辑任何类型的数值变量(模板)
- Reflexive fields, showing variable changes done outside the menu system.
- 反白字段,菜单系统之外显示变量更改
- Numerical field edit and range validation.
- 数值字段编辑和范围验证
- Enumerated fields for numeric and non-numeric types
- 数字和非数字类型的枚举字段
- Customizable (colors and cursors).
- 可自定义(颜色和光标)
- Able to work over Serial stream IO as a base level.
- 能够在串行流IO上作为基本级别工作
- Supports multiple inputs and outputs in parallel.
- 支持并行的多个输入和输出
- static allocation of RAM, avoiding heap fragmentation, all RAM needed to define menu structure is allocated at program startup.
- 静态分配RAM,避免堆栈碎片化,定义菜单结构所需的所有RAM在程序启动时分配
- events available for menus and prompts
- 可用于菜单和提示的事件
- simply returns when no input available and no needed to draw.
- 当没有可用的输入并且不需要绘制时简单地返回
- lazy drawing, only draws when changed, avoiding time consumption and flicking.
- 简化的绘画,只在改变时才绘画,避免时间消耗和弹跳
- sync/async navigation API functions
- 同步/异步导航 API 函数
- async navigation for stateless clients (as web)
- 无状态客户端的异步导航(作为WEB)
- web interface (experimental)
- WEB 界面(实验性的)
- can be confined to a display area (numeric fields can still overflow the area, user should take account for them)
- 可限制在展示区内(数值字段仍可能溢出该区域,用户应该考虑到它们)
- Tested on Arduino AVR's & ARM, Teensy, ESP8266, Esp32, nRF52, STM32
- 在 Arduino AVR's & ARM, Teensy, ESP8266, Esp32, nRF52, STM32 测试通过
Plugins are particular menu combinations or item customized behaviors and/or drawing.
插件是特定的菜单组合或项目自定义行为和/或绘图
Some plugins might be platform specific or require some hardware.
一些插件可能局限于特定平台或硬件需求
- barField - displays a bar for numeric field on LCD
- barField - 在LCD上显示一个数字条字段
- cancelField - allows to restore previous numeric value on escape.
- cancelField - 取消时允许恢复上一个数值
- SDMenu - full automated SD Card file picker, using standard Arduino SD lib.
- SDMenu - 全自动SD卡文件拾取,使用标准的 Arduino SD 库
- SdFatMenu - full automated SD Card file picker, using standard SdFat (https://github.com/greiman/SdFat).
- SdFatMenu - 全自动SD卡文件拾取,使用标准的 SdFat
Some applications/tutorials using ArduinoMenu, (current and older versions).
Do you have another? please let me know on gitter or email me.
一些使用 ArduinoMenu 的应用/教学示例(当前或以前的版本)
Arduino script for temperature sensor and timer. It allows to turn on heater and light accordingly to schedule
Arduino 温度传感器和定时器脚本,它可以根据计划打开加热器和灯光。
https://github.com/vikulin/LCD_LAT
Project-GlassKilnController electrically-heated kiln for making "Warm Glass"
Project-GlassKilnController 制造“暖玻璃”的电热窑
https://arduinoinfo.mywikis.net/wiki/Project-GlassKilnController
ArduinoMenu demo TTGO T-Display awesome tutorial.
https://sites.google.com/site/jmaathuis/arduino/lilygo-ttgo-t-display-esp32/arduinomenu-demo-ttgo-t-display
mvc-interface ArduinoMenu tutorial
https://zaragozamakerspace.com/index.php/courses/mvc-interface/
Arduino Automatic Copper Tape Cutter
https://www.thingiverse.com/thing:3557719
Reloading powder hopper level gauge and alarm
https://github.com/nathandarnell/Reloading-Powder-Hopper-Level-Gauge-and-Alarm
ServoBox Servo tester & monitor
https://github.com/jarkman/ServoBox
PANOBOT A Panorama robot
https://github.com/RobertFach/panobot
teensy-midi-looper Microcontroller-based midi performance sequencer
https://github.com/newdigate/teensy-midi-looper
AmplifierControl Automate procedure to switch on/off amplifier and band decode of Kenwood
https://github.com/petrlab/AmplifierControl
spna An Arduino Single Port Network Analyzer (SPNA)
https://github.com/tczerwonka/spna
LRDuino In car multi gauge system - STM32, SSD1306, MAX31856, ADXL345, ELM327
https://github.com/BennehBoy/LRDuino
LRDuinoTD5 In car multi gauge system - STM32, SSD1306, MAX31856, ADXL345, L9637D, TD5 ECU
https://github.com/BennehBoy/LRDuinoTD5
thom-radio Internet radio build
https://github.com/evfool/thom-radio
MIDI_drums 7 chanel piezo MIDI drum box with menu on LCD
https://github.com/Sobollion/MIDI_drums
BalancingRobot
https://github.com/SLBarker/BalancingRobot
swatili 50l water meter with valve control, lcd, buttons, rtc and hall effect pulse reader
https://github.com/daniel-leonard-robinson/swatili
Fielduino hardware PWM generator using menu to select frequency and dutty.
https://github.com/neu-rah/Fielduino
ArduinoMultiDesktop MultiDesktop concept for hardware devices
https://github.com/dontsovcmc/ArduinoMultiDesktop
SmartGreenHouse
https://github.com/dontsovcmc/SmartGreenHouse/tree/master/src
console.arduino Portable serial debug console project using ILI9341
https://github.com/malachib/console.arduino
Atmel AVR, Atmel SAM, Espressif 32, Espressif 8266, Intel ARC32, Microchip PIC32, Nordic nRF51, Nordic nRF52, ST STM32, Teensy, TI MSP430
Arduino IDE - Install using the library manager (ArduinoMenu library - Rui Azevedo)
Platformio - http://platformio.org/lib/show/1468/ArduinoMenu%20library
Serial
https://www.arduino.cc/en/Reference/Serial
- Serial monitor.
Standard arduino LCD library
https://www.arduino.cc/en/Reference/LiquidCrystal
- hd44780
F Malpartida's LCDs
https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
- HD44780 direct
- HD44780 I2C
- HD44780 SPI
Matthias Hertel PCF8574 driver
https://github.com/mathertel/LiquidCrystal_PCF8574
- HD44780
Arduino TFT devices
https://www.arduino.cc/en/Guide/TFT
SSD1306Ascii
https://github.com/greiman/SSD1306Ascii
- OLED Screens based on SSD1306 controller
TFT_eSPI
An Arduino IDE compatible graphics and fonts library for ESP8266 and ESP32
https://github.com/Bodmer/TFT_eSPI
- ILI9341, ILI9163, ST7735, S6D02A1, ILI9481, ILI9486, ILI9488, HX8357D, ST7789, ILI9486
- Waveshare 2 and 3 colour SPI ePaper displays
TFT_HX8357 driver
https://github.com/Bodmer/TFT_HX8357
- HX8357B, HX8357C, ILI9481 and ILI9486
Adafruit's GFX devices
https://github.com/adafruit/Adafruit-GFX-Library
- RGBmatrixPanel, 16x32 and 32x32 RGB LED matrix panels.
- Adafruit_TFTLCD, 2.8" TFT LCD touchscreen breakout and TFT Touch Shield for Arduino.
- Adafruit_HX8340B, 2.2" TFT Display with microSD.
- Adafruit_ST7735, 1.8" TFT Display with microSD.
- Adafruit_PCD8544, for the Nokia 5110/3310 monochrome LCD.
- Adafruit-Graphic-VFD-Display-Library, for 128x64 Graphic VFD.
- Adafruit-SSD1331-OLED-Driver-Library-for-Arduino for the 0.96" 16-bit Color OLED w/microSD Holder.
- Adafruit_SSD1306 for the Monochrome 128x64 and 128x32 OLEDs.
UTFT devices
http://www.rinkydinkelectronics.com/library.php?id=51
- ITDB02 series - ITead Studio
- TFT01 series - ElecFreaks
- RGB LCD - NKC Electronics.
U8glib devices
https://github.com/olikraus/U8glib_Arduino
SSD1306, 128x64, SSD1306, 128x32, SSD1306, 64x48, SSD1309, 128x64, SSD1322, 256x64, SSD1325, 128x64, SSD1327, 96x96, SH1106, 128x64, UC1601, 128x32, UC1608, 240x64, UC1610, 160x104, UC1611, 240x64, UC1611, 240x128, UC1701, 128x64, UC1701, 102x64, ST7565, 128x64, ST7565, 128x32, ST7920, 128x64, ST7920, 192x32, ST7920, 202x32, LD7032, 60x32, PCD8544, 84x48, TLS8204 , 84x48, PCF8812 , 96x65, KS0108 , 128x64, T6963, 128x64, T6963, 128x128, T6963, 240x64, T6963, 240x128, SBN1661, 122x32, LC7981, 160x80, LC7981, 240x64, LC7981, 240x128, LC7981, 320x64, SSD1351, HT1632, 24x16, Flipdisk, 28x14, Virtual Screen Device
U8G2 and U8x8 devices
https://github.com/olikraus/U8g2_Arduino
SSD1305 128X32_NONAME, SSD1305 128X32_NONAME, SSD1305 128X64_ADAFRUIT, SSD1305 128X64_ADAFRUIT, SSD1306 128X64_NONAME, SSD1306 128X64_VCOMH0, SSD1306 128X64_ALT0, SSD1306 128X64_NONAME, SSD1306 128X64_VCOMH0, SSD1306 128X64_ALT0, SH1106 128X64_NONAME, SH1106 128X64_VCOMH0, SH1106 128X64_WINSTAR, SH1106 128X64_NONAME, SH1106 128X64_VCOMH0, SH1106 128X64_WINSTAR, SH1106 72X40_WISE, SH1106 72X40_WISE, SH1106 64X32, SH1106 64X32, SH1107 64X128, SH1107 64X128, SH1107 SEEED_96X96, SH1107 SEEED_96X96, SH1107 128X128, SH1107 128X128, SH1122 256X64, SH1122 256X64, SSD1306 128X32_UNIVISION, SSD1306 128X32_UNIVISION, SSD1306 64X48_ER, SSD1306 64X48_ER, SSD1306 48X64_WINSTAR, SSD1306 48X64_WINSTAR, SSD1306 64X32_NONAME, SSD1306 64X32_1F, SSD1306 64X32_NONAME, SSD1306 64X32_1F, SSD1306 96X16_ER, SSD1306 96X16_ER, SSD1309 128X64_NONAME2, SSD1309 128X64_NONAME2, SSD1309 128X64_NONAME0, SSD1309 128X64_NONAME0, SSD1325 NHD_128X64, SSD1325 NHD_128X64, SSD1326 ER_256X32, SSD1326 ER_256X32, SSD1327 SEEED_96X96, SSD1327 SEEED_96X96, SSD1327 MIDAS_128X128, SSD1327 MIDAS_128X128, SSD1329 128X96_NONAME, LD7032 60X32, LD7032 60X32, ST7920 192X32, ST7920 192X32, ST7920 192X32, ST7920 128X64, ST7920 128X64, ST7920 128X64, LS013B7DH03 128X128, UC1701 EA_DOGS102, UC1701 MINI12864, PCD8544 84X48, PCF8812 96X65, HX1230 96X68, UC1604 JLX19264, UC1604 JLX19264, UC1608 ERC24064, UC1608 ERC24064, UC1608 ERC240120, UC1608 ERC240120, UC1608 240X128, UC1608 240X128, UC1638 160X128, UC1610 EA_DOGXL160, UC1610 EA_DOGXL160, UC1611 EA_DOGM240, UC1611 EA_DOGM240, UC1611 EA_DOGXL240, UC1611 EA_DOGXL240, UC1611 EW50850, UC1611 EW50850, ST7565 EA_DOGM128, ST7565 64128N, ST7565 ZOLEN_128X64, ST7565 LM6059, ST7565 LX12864, ST7565 ERC12864, ST7565 NHD_C12864, ST7565 JLX12864, ST7565 NHD_C12832, UC1601 128X32, UC1601 128X32, ST7565 EA_DOGM132, ST7567 PI_132X64, ST7567 JLX12864, ST7567 ENH_DG128064, ST7567 ENH_DG128064I, ST7588 JLX12864, ST7588 JLX12864, ST75256 JLX256128, ST75256 JLX256128, ST75256 JLX256160, ST75256 JLX256160, ST75256 JLX240160, ST75256 JLX240160, ST75256 JLX25664, ST75256 JLX25664, ST75256 JLX172104, ST75256 JLX172104, NT7534 TG12864R, IST3020 ERC19264, SBN1661 122X32, SED1520 122X32, KS0108 128X64, KS0108 ERM19264, LC7981 160X80, LC7981 160X160, LC7981 240X128, T6963 240X128, T6963 240X64, T6963 256X64, T6963 128X64, SSD1322 NHD_256X64, SSD1322 NHD_128X64, SSD1606 172X72, SSD1607 200X200, SSD1607 GD_200X200, IL3820 296X128, IL3820 V2_296X128, SED1330 240X128, RA8835 NHD_240X128, RA8835 320X240, MAX7219 32X8, A2PRINTER 384X240
UCGLib devices
https://github.com/olikraus/Ucglib_Arduino
ST7735, ILI9163, ILI9325, ILI9341, ILI9486, LD50T6160, PCF8833, SEPS225, SSD1331, SSD1351, HX8352C
Serial ANSI terminal
https://github.com/neu-rah/AnsiStream
- Unix terminal
Web browser
- ESP8266 (builtin)
Web JSON
- ESP8266 (builtin)
Websockets
- ESP8266 (builtin)
note: esp8266 will require a streaming library even if not using web interface, along with #include <menuIO/esp8266Out.h>
depending on your output driver it may be one of (can install both)
Serial https://www.arduino.cc/en/Reference/Serial
quadEncoder - Generic encoder using PCINT (builtin)
Buttons - simple digital keyboard (builtin)
Generic keyboard (no PCINT) - configurable for digital or analog keyboards (builtin)
ClickEncoder https://github.com/0xPIT/encoder
Matrix keypad
http://playground.arduino.cc/Code/Keypad
https://github.com/Nullkraft/Keypad
PCF8574 based i2c matrix keypad https://github.com/whatnick/i2ckeypad
User defined input calling menu navigation API
Web browser (experimental) when using ESP devices
This library depends on the following libraries:
这个库依赖于下面的库:
- streamFlow https://github.com/neu-rah/streamFlow (on debug mode)
Depending on the type of input or output, other libraries might be needed. Essentially any library needed for your devices.
根据输入输出的类型,需要其他的库。基本上是你的设备所需的库。
- when using macros the menu is limited to 16 options (current macro limnit).
- 使用菜单宏限制在16个选项(当前宏的限制)
- menus must have at least 2 options when built using macros.
- 创建使用宏的时候,菜单至少必须有2个选项
- maximum 127 options.
- 最大127个选项
- fast access (numeric keys) only supports 9 options (1 to 9)
- 快速进入(数字键)仅支持9个选项(1-9)
- prompts can overflow on panels with less than 4 characters width
- 宽度小于4个字符的面板上的提示可能溢出
- menu system is character based, so choose monometric font to achieve best results, it will work with any font but the text can overflow.
- 菜单系统是基于字符的,因此所以选择单度量字体以获得最佳效果,它可以使用任何字体,但文本可能溢出
- Character based information display.
- 基于字符的信息显示
- Line based menu organization.
- 基于行的菜单组织
- Stream IO + specializations.
- 流IO+专业化
更多信息在
wiki pages, issues or r-site.net
Please report errors, problems or enhancement ideas, I apreciate the feedback. Thanks.
On issues report please specify the input and output drivers or devices as well as target platform.
encoder now needs begin() to be called on setup (2.x)
编码器现在需要调用 begin() 在版本(2.x)上
input is read from generic streams, included simple streams for encoders and keyboards - provided encoder driver uses internal pull-ups and reverse logic
从泛型流读取输入,包括编码器和键盘的简单流 - 提供的编码器驱动程序使用内部上拉和反向逻辑
multiple stream packing for input to mix encoder stream with encoder keyboard (usually 1 or 2 keys)
多个流打包输入,可与编码器键盘混合编码器流(通常为1或2个按键)
- SdFat plugin and example
- EscControl examle
- support Bodmer/TFT_eSPI
- SDCard file picker plugin
- Allow virtual/dynamic data custom menus
- alternative key driver with explicit pin modes
- More examples
- Text edit fields with validation *
- Pad style menus (horizontal list)
- inline pad menus can input custom formats like IP/Date/Time, experimental and just for devices that can position a cursor
- Plugins, alternative menu items potentially device specific
- Allow multiple concurrent menus
- Support UCGLib displays
- Support U8x8 displays
- Support Arduino TFT
- Support PCF8574 I2C LCD
- Support Analog Joystick input
- Added input burst config option
- VALUEOBJ macro, user allocated values
- menuIn class for menu inputs (allows device field invertion) *
- some options have been distributed to some other classes
- allow dynamic menu construction (ram) even for AVR's
invertFieldKeys option removed, invertion is now supported by specific menuIn objects.
regression: still needed to ease simple input cases.
numValueInput moved to menuIn object
navRoot extra options, previously on global options object
bool nav2D=false;//not used
bool canExit=true;//v4.0 moved from global options
bool useUpdateEvent=false;//if false, use enterEvent when field value is changed.
idx_t inputBurst=1;//limit of inputs that can be processed before output
Serial is no longer accepted as an input directly, use serialIn instead
printTo member function changed from:
Used printTo(navRoot&,bool,menuOut&,idx_t,idx_t);
to
Used printTo(navRoot&,bool,menuOut&,idx_t,idx_t,idx_t=0);
this should only affect customized components
inputs are now from class menuIn, derived from Stream but including flag functions for field axis inversion per input class.
- complete revision of menu control system
- menu structure separated in ram objects and flash objects
- using separate navigation control objects navNode
- central navigation control object navRoot
- using event for all menu objects (focus, blur, enter, exit).
- multiple panels
- color enumeration at base level
- multiple output devices in parallel
- define exit as regular option
- limiting text width to prevent overflow
- support for teensy (tested on 3.2)
- new field type SELECT
- reflexivity, fields reflect external changes to values
- store field strings to progmem
- automatic use of RAM on system without PROGMEM
- action functions now need to return bool (only affects menus)
false = continue menu
true = exit menu
- Support for U8GLib screens
- alternative use ClickEncoder
- using flash memory to store menu strings and lists (PROGMEM)
- non-blocking menu main cycle
- Menufields as menu prompts with associated value values can be: numeric withing range list of values toggled on click (for small lists) list of values selected as submenu (for longer lists)
- PCINT now supports Mega/2560 and possibly others
- basic menu functionality