Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
New:
- add version number in lib
- add example: initscreen
- add example: hidden menu elements (groups)
- add example: parameters

BugFix:
- redesign LCDML_CONTROL tab
- jumpToElement, active functions are stoped stable before a new
function is called
- goRoot active functions are stoped stable before the old function is
closed

Changes
- update keywords.txt
- update example 001 serial
- update example 002 liquid crystal
  • Loading branch information
Jomelo committed Jan 10, 2016
1 parent a2b6448 commit afe63eb
Show file tree
Hide file tree
Showing 28 changed files with 2,741 additions and 351 deletions.
81 changes: 42 additions & 39 deletions LCDMenuLib/LCDMenuLib.cpp
Expand Up @@ -124,21 +124,27 @@ uint8_t LCDMenuLib::selectElementDirect(LCDMenu &p_m, uint8_t p_search)
void LCDMenuLib::goRoot()
/* ******************************************************************** */
{
//go back to root layer
while(layer > 0)
{
Button_quit();
}
//ends the last aktive function or do nothing
Button_quit();

//reset buttons and cursor position
button = 0;
cursor_pos = 0;
curloc = 0;
scroll = 0;
if(function != _LCDML_NO_FUNC) {
bitSet(control, _LCDML_control_go_root);
Button_quit();
} else {
bitClear(control, _LCDML_control_go_root);
//go back to root layer
while(layer > 0)
{
goBack();
}
cursor_pos = 0;
curloc = 0;
scroll = 0;

//reset buttons and cursor position
button = 0;
}
//display menu
display();
bitSet(control, _LCDML_control_disp_update);

}

/* ******************************************************************** *
Expand All @@ -149,8 +155,9 @@ void LCDMenuLib::goRoot()
* ******************************************************************** */
void LCDMenuLib::jumpToElement(uint8_t p_element)
/* ******************************************************************** */
{
{
Button_quit();
function = _LCDML_NO_FUNC;
goRoot();

bitSet(control, _LCDML_control_disable_hidden);
Expand Down Expand Up @@ -306,15 +313,20 @@ uint8_t LCDMenuLib::countChilds()
uint8_t j = 0;

//check if element has childs
if ((tmp = curMenu->getChild(0)) != NULL) {
while ((tmp = tmp->getSibling(1)) != NULL)
{
if ((tmp = curMenu->getChild(0)) != NULL) {
do
{
if (bitRead(group_en, tmp->disp) || bitRead(control, _LCDML_control_disable_hidden)) {
j++;
}
}
}
} while ((tmp = tmp->getSibling(1)) != NULL);
}
return j;

if(j == 0) {
return 0;
} else {
return --j;
}
}

/* ******************************************************************** *
Expand All @@ -323,8 +335,7 @@ uint8_t LCDMenuLib::countChilds()
* @return
* ******************************************************************** */
void LCDMenuLib::display_clear()
{

{
for(uint8_t n=0; n<_LCDML_DISP_cfg_max_rows;n++) {
for(uint8_t nc=0; nc<_LCDML_DISP_cfg_max_string_length;nc++) {
content[n][nc] = ' ';
Expand All @@ -333,10 +344,6 @@ void LCDMenuLib::display_clear()
}






/* ******************************************************************** *
* public: display the current menu
* @param
Expand All @@ -353,19 +360,16 @@ void LCDMenuLib::display()
char buffer[_LCDML_DISP_cfg_max_string_length];

child_cnt = countChilds();

//check children
if ((tmp = curMenu->getChild(i))) {
if (!bitRead(control, _LCDML_control_search_display)) {
//clear lcd
display_clear();

display_clear();
//show menu structure
do
{
if (bitRead(group_en, tmp->disp)) {
// reset cursor
strcpy_P(content[i-scroll], (char*)pgm_read_word(&(flash_table[tmp->name])));
if (bitRead(group_en, tmp->disp)) {
strcpy_P(content[i-scroll], (char*)pgm_read_word(&(flash_table[tmp->name])));
i++;
}

Expand Down Expand Up @@ -412,7 +416,7 @@ void LCDMenuLib::setCursor()
* ******************************************************************** */
void LCDMenuLib::doScroll()
/* ******************************************************************** */
{
{
//only allow it to go up to menu element
while (curloc>0 && !curMenu->getChild(curloc))
{
Expand Down Expand Up @@ -482,15 +486,14 @@ void LCDMenuLib::Button_quit()
* ******************************************************************** */
void LCDMenuLib::Button_udlr(uint8_t but)
/* ******************************************************************** */
{
{
if (function == _LCDML_NO_FUNC) { //check menu lock
//enable up and down button for menu mode and scroll
switch(but)
{
case _LCDML_button_up: if(curloc > 0) { curloc--; } break;
case _LCDML_button_down: if (curloc < child_cnt) { curloc++; } break;
}
doScroll();
case _LCDML_button_up: if (curloc > 0) { curloc--; doScroll();} break;
case _LCDML_button_down: if (curloc < child_cnt) { curloc++; doScroll();} break;
}
}
else {
bitSet(button, but);
Expand Down Expand Up @@ -534,7 +537,7 @@ uint8_t LCDMenuLib::getLayer()
* ******************************************************************** */
uint8_t LCDMenuLib::getCursorPos()
/* ******************************************************************** */
{
{
return (cursor_pos); //return the current cursor position
}

Expand Down
8 changes: 6 additions & 2 deletions LCDMenuLib/LCDMenuLib.h
Expand Up @@ -5,7 +5,7 @@
/* ******************************************************************** */
/* Autor: Nils Feldkämper */
/* Create: 03.02.2008 */
/* Edit: 05.01.2016 */
/* Edit: 08.01.2016 */
/* ******************************************************************** */
/* error reporting (english / german) */
/* https://github.com/Jomelo/LCDMenuLib/issues */
Expand All @@ -16,12 +16,16 @@
#ifndef LCDMenuLib_h
# define LCDMenuLib_h

# define _LCDML_VERSION "LCDML v2.1.0 beta 2"

/* config */
# define _LCDML_DISP_cfg_cursor_deep 6 // save the last position of the cursor until layer xx
# define _LCDML_DISP_cfg_max_string_length 20 // max string length witch can be display
# define _LCDML_DISP_cfg_max_rows 4






/* include arduino ios */
Expand Down Expand Up @@ -52,7 +56,7 @@
# define _LCDML_control_menu_back 7
# define _LCDML_control_disp_update 6
# define _LCDML_control_cursor_update 5
# define _LCDML_control_free4 4
# define _LCDML_control_go_root 4
# define _LCDML_control_free3 3
# define _LCDML_control_search_display 2
# define _LCDML_control_funcend 1
Expand Down
56 changes: 40 additions & 16 deletions LCDMenuLib/LCDMenuLib_makros.h
Expand Up @@ -92,6 +92,9 @@
LCDML_BACK_dynamic_setLoopTime(LCDML_BACKEND_control, time);\
LCDML_BACK_start(LCDML_BACKEND_control)




# define LCDML_DISP_init(N)\
typedef void(* LCDML_FuncPtr)();\
LCDML_FuncPtr g_LCDML_DISP_functions_loop_setup[(N+1)];\
Expand All @@ -104,24 +107,28 @@
unsigned long g_lcdml_initscreen = millis();\
LCDMenu LCDML_Item (0, true);\
void LCDML_lcd_menu_display(); \
void LCDML_lcd_menu_clear()
void LCDML_lcd_menu_clear();\
uint8_t g_lcdml_jump_func = _LCDML_NO_FUNC


# define LCDML_DISP_initParam(N)\
uint8_t param[(N + 1)]; \
typedef void(*LCDML_FuncPtr)(); \
LCDML_FuncPtr g_LCDML_DISP_functions_loop_setup[(N + 1)]; \
LCDML_FuncPtr g_LCDML_DISP_functions_loop[(N + 1)]; \
LCDML_FuncPtr g_LCDML_DISP_functions_loop_end[(N + 1)]; \
uint8_t g_lcdml_param[(N + 1)]; \
typedef void(* LCDML_FuncPtr)();\
LCDML_FuncPtr g_LCDML_DISP_functions_loop_setup[(N+1)];\
LCDML_FuncPtr g_LCDML_DISP_functions_loop[(N+1)];\
LCDML_FuncPtr g_LCDML_DISP_functions_loop_end[(N+1)];\
void LCDML_FUNC_loop_setup(){}\
void LCDML_FUNC_loop(){}\
void LCDML_FUNC_loop_end(){}\
unsigned long g_LCDML_DISP_press_time = 0; \
unsigned long g_lcdml_initscreen = millis(); \
LCDMenu LCDML_Item(0, true);\
unsigned long g_LCDML_DISP_press_time = 0;\
unsigned long g_lcdml_initscreen = millis();\
LCDMenu LCDML_Item (0, true);\
void LCDML_lcd_menu_display(); \
void LCDML_lcd_menu_clear()

void LCDML_lcd_menu_clear();\
uint8_t g_lcdml_jump_func = _LCDML_NO_FUNC




# define LCDML_DISP_add(name, disp, item_parent, item_child, content, function)\
const char g_LCDML_DISP_lang_ ## name ##_var[] PROGMEM = {content};\
Expand All @@ -137,11 +144,11 @@
void function ## _loop(); \
void function ## _loop_end(); \
LCDMenu item_parent ## _ ## item_child(name, disp); \
void LCDML_DISP_##name##_function() { g_LCDML_DISP_functions_loop_setup[name] = function##_loop_setup; g_LCDML_DISP_functions_loop[name] = function##_loop; g_LCDML_DISP_functions_loop_end[name] = function##_loop_end; item_parent.addChild(item_parent ## _ ## item_child); param[name] = para; }
void LCDML_DISP_##name##_function() { g_LCDML_DISP_functions_loop_setup[name] = function##_loop_setup; g_LCDML_DISP_functions_loop[name] = function##_loop; g_LCDML_DISP_functions_loop_end[name] = function##_loop_end; item_parent.addChild(item_parent ## _ ## item_child); g_lcdml_param[name] = para; }


# define LCDML_DISP_getParameter()\
param[LCDML.getFunction()]
g_lcdml_param[LCDML.getFunction()]


# define LCDML_DISP_initSetup(N)\
Expand All @@ -156,8 +163,13 @@
# define LCDML_DISP_jumpToFunc(name)\
for(uint8_t i=0; i<=254;i++) {\
if (name##_loop_setup == g_LCDML_DISP_functions_loop_setup[i]) { \
LCDML.jumpToElement(i);\
LCDML_DISP_update_menu(); \
if(LCDML.getFunction() != _LCDML_NO_FUNC) {\
bitSet(LCDML.control, _LCDML_control_funcend);\
g_lcdml_jump_func = i;\
} else {\
LCDML.jumpToElement(i);\
LCDML_DISP_update_menu(); \
}\
break;\
}\
}\
Expand Down Expand Up @@ -213,6 +225,16 @@
LCDML_BUTTON_resetAll(); \
LCDML.function = _LCDML_NO_FUNC; \
bitClear(LCDML.control, _LCDML_control_funcend); \
if(g_lcdml_jump_func != _LCDML_NO_FUNC) { \
LCDML.jumpToElement(g_lcdml_jump_func); \
LCDML_DISP_update_menu(); \
g_lcdml_jump_func = _LCDML_NO_FUNC; \
} \
if(bitRead(LCDML.control, _LCDML_control_go_root)) { \
LCDML.goRoot(); \
LCDML.display(); \
LCDML_lcd_menu_display(); \
} \
} \
}

Expand Down Expand Up @@ -254,7 +276,9 @@
uint8_t g_LCDML_BACK_reset[((cnt+1)/7)+1];\
uint8_t g_LCDML_BACK_loop_status = true;\
uint8_t g_LCDML_BACK_lastFunc = _LCDML_NO_FUNC;\
unsigned long g_LCDML_BACK_timer[(cnt+1)];
unsigned long g_LCDML_BACK_timer[(cnt+1)];\
void LCDML_CONTROL_setup();\
void LCDML_CONTROL_loop()
// macro: loop function
# define LCDML_run(mode)\
if (bitRead(LCDML.control, _LCDML_control_funcend)) {\
Expand Down
19 changes: 11 additions & 8 deletions LCDMenuLib/examples/LCDML_001_serial/LCDML_001_serial.ino
@@ -1,17 +1,19 @@
// ============================================================
//
// Example: easy_02_lcd_test
// Example: LCDML_001_serial menu
//
// ============================================================
// This example shows how the menu works without any LCD.
// The output is print in serial console. This example can be
// extended with network functions to print this menu with telnet
// or other protocols.
// ============================================================

// include libs
#include <LCDMenuLib.h>

// lib config
#define _LCDML_DISP_cfg_button_press_time 200 // button press time in ms
#define _LCDML_DISP_cfg_initscreen 0 // this screen is not implemented in this example
#define _LCDML_DISP_cfg_initscreen_time 30000 // has in this example no effekt
#define _LCDML_DISP_cfg_scrollbar 1 // enable a scrollbar
#define _LCDML_DISP_cfg_cursor 0x7E // cursor Symbol

// *********************************************************************
Expand Down Expand Up @@ -61,7 +63,7 @@
#define _LCDML_BACK_cnt 1 // last backend function id

LCDML_BACK_init(_LCDML_BACK_cnt);
LCDML_BACK_new_timebased_static (0 , ( 20UL ) , _LCDML_start , LCDML_BACKEND_control);
LCDML_BACK_new_timebased_dynamic (0 , ( 20UL ) , _LCDML_start , LCDML_BACKEND_control);
LCDML_BACK_new_timebased_dynamic (1 , ( 10000000UL ) , _LCDML_stop , LCDML_BACKEND_menu);
LCDML_BACK_create();

Expand All @@ -71,9 +73,10 @@
// *********************************************************************
void setup()
{
// serial init; only be needed if seriel control is used
while(!Serial);
Serial.begin(9600); // start serial
// serial init; only be needed if serial control is used
while(!Serial); // wait until serial ready
Serial.begin(9600); // start serial
Serial.println(F(_LCDML_VERSION)); // only for examples

// Enable all items with _LCDML_G1
LCDML_DISP_groupEnable(_LCDML_G1); // enable group 1
Expand Down

0 comments on commit afe63eb

Please sign in to comment.