Added new Panel stuff
[clinton/Smoothieware.git] / src / modules / utils / panel / Panel.h
1 /*
2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8 #ifndef PANEL_H
9 #define PANEL_H
10
11 #include "libs/Kernel.h"
12 #include "libs/nuts_bolts.h"
13 #include "libs/utils.h"
14 #include "libs/Pin.h"
15 #include "panels/LcdBase.h"
16 #include "Button.h"
17 #include "PanelScreen.h"
18 #include "screens/MainMenuScreen.h"
19
20 #define panel_checksum CHECKSUM("panel")
21 #define enable_checksum CHECKSUM("enable")
22 #define lcd_checksum CHECKSUM("lcd")
23 #define i2c_lcd_checksum CHECKSUM("i2c_lcd")
24 #define viki_lcd_checksum CHECKSUM("viki_lcd")
25
26 #define jog_x_feedrate_checksum CHECKSUM("alpha_jog_feedrate")
27 #define jog_y_feedrate_checksum CHECKSUM("beta_jog_feedrate")
28 #define jog_z_feedrate_checksum CHECKSUM("gamma_jog_feedrate")
29
30 #define MENU_MODE 0
31 #define CONTROL_MODE 1
32
33
34 class Panel : public Module {
35 public:
36 Panel();
37 virtual ~Panel();
38
39 void on_module_loaded();
40 uint32_t button_tick(uint32_t dummy);
41 void on_idle(void* argument);
42 void on_main_loop(void* argument);
43 void enter_screen(PanelScreen* screen);
44 void reset_counter();
45
46 // Encoder and buttons
47 uint32_t on_up(uint32_t dummy);
48 uint32_t on_down(uint32_t dummy);
49 uint32_t on_back(uint32_t dummy);
50 uint32_t on_click_release(uint32_t dummy);
51 uint32_t refresh_tick(uint32_t dummy);
52 uint32_t encoder_check(uint32_t dummy);
53 bool counter_change();
54 bool click();
55 int get_encoder_resolution() const { return encoder_click_resolution; }
56
57 // Menu
58 void enter_menu_mode();
59 void setup_menu(uint16_t rows, uint16_t lines);
60 void menu_update();
61 bool menu_change();
62 uint16_t menu_current_line();
63
64 // Control
65 bool enter_control_mode(double passed_normal_increment, double passed_pressed_increment);
66 void set_control_value(double value);
67 double get_control_value();
68 bool control_value_change();
69 void control_value_update();
70 double get_jogging_speed(char axis) { return jogging_speed_mm_min[axis-'X']; }
71
72 // file playing from sd
73 bool is_playing() const;
74 void set_playing_file(string f) { playing_file= f; }
75 string get_playing_file() { return playing_file; }
76
77 // public as it is directly accessed by screens... not good
78 // TODO pass lcd into ctor of each sub screen
79 LcdBase* lcd;
80
81 // as panelscreen accesses private fields in Panel
82 friend class PanelScreen;
83
84 private:
85 // Menu
86 char menu_offset;
87 int menu_selected_line;
88 int menu_start_line;
89 int menu_rows;
90 int menu_lines;
91 bool menu_changed;
92 bool control_value_changed;
93
94 // Control
95 double normal_increment;
96 double pressed_increment;
97 int control_normal_counter;
98 int control_pressed_counter;
99 double control_base_value;
100
101 Button up_button;
102 Button down_button;
103 Button back_button;
104 Button click_button;
105
106 int* counter;
107 volatile bool counter_changed;
108 volatile bool click_changed;
109 volatile bool refresh_flag;
110 volatile bool do_buttons;
111 int idle_time;
112 int encoder_click_resolution;
113 char mode;
114
115 MainMenuScreen* top_screen;
116 PanelScreen* current_screen;
117
118 double jogging_speed_mm_min[3];
119
120 string playing_file;
121 };
122
123 #endif