1 | #include <Arduino.h>
|
2 | #include "display.h"
|
3 | #include <LiquidCrystal_I2C.h>
|
4 | #include <LCDMenuLib2.h> //https://github.com/Jomelo/LCDMenuLib2
|
5 |
|
6 |
|
7 | displayUtils::displayUtils(){
|
8 | }
|
9 |
|
10 | // =====================================================================
|
11 | //
|
12 | // Output function
|
13 | //
|
14 | // =====================================================================
|
15 |
|
16 | void lcdml_menu_control()
|
17 | {
|
18 | // If something must init, put in in the setup condition
|
19 | if(LCDML.BT_setup()) {
|
20 | // runs only once
|
21 | }
|
22 | /*
|
23 | // check if new serial input is available
|
24 | if (Serial.available()) {
|
25 | // read one char from input buffer,
|
26 | switch (Serial.read())
|
27 | {
|
28 | case _LCDML_CONTROL_serial_enter: LCDML.BT_enter(); break;
|
29 | case _LCDML_CONTROL_serial_up: LCDML.BT_up(); break;
|
30 | case _LCDML_CONTROL_serial_down: LCDML.BT_down(); break;
|
31 | case _LCDML_CONTROL_serial_left: LCDML.BT_left(); break;
|
32 | case _LCDML_CONTROL_serial_right: LCDML.BT_right(); break;
|
33 | case _LCDML_CONTROL_serial_quit: LCDML.BT_quit(); break;
|
34 | default: break;
|
35 | }
|
36 | }*/
|
37 | }
|
38 |
|
39 | /* ******************************************************************** */
|
40 | void lcdml_menu_clear()
|
41 | /* ******************************************************************** */
|
42 | {
|
43 | lcd.clear();
|
44 | lcd.setCursor(0, 0);
|
45 | }
|
46 |
|
47 | /* ******************************************************************** */
|
48 | void lcdml_menu_display()
|
49 | /* ******************************************************************** */
|
50 | {
|
51 | // update content
|
52 | // ***************
|
53 | if (LCDML.DISP_checkMenuUpdate()) {
|
54 | // clear menu
|
55 | // ***************
|
56 | LCDML.DISP_clear();
|
57 |
|
58 | // declaration of some variables
|
59 | // ***************
|
60 | // content variable
|
61 | char content_text[_LCDML_DISP_cols]; // save the content text of every menu element
|
62 | // menu element object
|
63 | LCDMenuLib2_menu *tmp;
|
64 | // some limit values
|
65 | uint8_t i = LCDML.MENU_getScroll();
|
66 | uint8_t maxi = _LCDML_DISP_rows + i;
|
67 | uint8_t n = 0;
|
68 |
|
69 | }
|
70 | }
|
71 |
|
72 |
|
73 | if(LCDML.DISP_checkMenuCursorUpdate())
|
74 | {
|
75 | // init vars
|
76 | uint8_t n_max = (LCDML.MENU_getChilds() >= _LCDML_DISP_rows) ? _LCDML_DISP_rows : (LCDML.MENU_getChilds());
|
77 | uint8_t scrollbar_min = 0;
|
78 | uint8_t scrollbar_max = LCDML.MENU_getChilds();
|
79 | uint8_t scrollbar_cur_pos = LCDML.MENU_getCursorPosAbs();
|
80 | uint8_t scroll_pos = ((1.*n_max * _LCDML_DISP_rows) / (scrollbar_max - 1) * scrollbar_cur_pos);
|
81 |
|
82 | }
|
83 |
|
84 | // display scrollbar
|
85 | if (_LCDML_DISP_cfg_scrollbar == 1) {
|
86 | if (scrollbar_max > n_max) {
|
87 | //set scroll position
|
88 | if (scrollbar_cur_pos == scrollbar_min) {
|
89 | // min pos
|
90 | lcd.setCursor((_LCDML_DISP_cols - 1), 0);
|
91 | lcd.write((uint8_t)1);
|
92 | } else if (scrollbar_cur_pos == (scrollbar_max - 1)) {
|
93 | // max pos
|
94 | lcd.setCursor((_LCDML_DISP_cols - 1), (n_max - 1));
|
95 | lcd.write((uint8_t)4);
|
96 | } else {
|
97 | // between
|
98 | lcd.setCursor((_LCDML_DISP_cols - 1), scroll_pos / n_max);
|
99 | lcd.write((uint8_t)(scroll_pos % n_max) + 1);
|
100 | }
|
101 | }
|
102 | }
|
103 | }
|
104 | }
|
105 |
|
106 | void(* ptr_lcdml_menu_display)() = &lcdml_menu_display;
|
107 | void(* ptr_lcdml_menu_clear)() = &lcdml_menu_clear;
|
108 | void(* ptr_lcdml_menu_control)() = &lcdml_menu_control;
|