get direct step running from encoder
[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 "Button.h"
12 #include "Pin.h"
13 #include "mbed.h"
14 #include <string>
15 #include <functional>
16
17 using std::string;
18
19 #define THEPANEL Panel::instance
20
21 class LcdBase;
22 class PanelScreen;
23 class ModifyValuesScreen;
24 class SDCard;
25 class SDFAT;
26
27 class Panel : public Module {
28 public:
29 Panel();
30 virtual ~Panel();
31 static Panel* instance;
32
33 void on_module_loaded();
34 uint32_t button_tick(uint32_t dummy);
35 uint32_t encoder_tick(uint32_t dummy);
36 void on_idle(void* argument);
37 void on_main_loop(void* argument);
38 void on_set_public_data(void* argument);
39 void on_second_tick(void* argument);
40 void enter_screen(PanelScreen* screen);
41 void reset_counter();
42
43 // Encoder and buttons
44 uint32_t on_up(uint32_t dummy);
45 uint32_t on_down(uint32_t dummy);
46 uint32_t on_back(uint32_t dummy);
47 uint32_t on_select(uint32_t dummy);
48 uint32_t refresh_tick(uint32_t dummy);
49 uint32_t encoder_check(uint32_t dummy);
50 bool counter_change();
51 bool click();
52 int get_encoder_resolution() const { return encoder_click_resolution; }
53
54 // Menu
55 void enter_menu_mode(bool force= false);
56 void setup_menu(uint16_t rows, uint16_t lines);
57 void setup_menu(uint16_t rows);
58 void menu_update();
59 bool menu_change();
60 uint16_t max_screen_lines() { return screen_lines; }
61 uint16_t get_menu_current_line() { return menu_current_line; }
62
63 // Control
64 bool enter_control_mode(float passed_normal_increment, float passed_pressed_increment);
65 void set_control_value(float value);
66 float get_control_value();
67 bool control_value_change();
68 void control_value_update();
69 float get_jogging_speed(char axis) { return jogging_speed_mm_min[axis-'X']; }
70 float get_default_hotend_temp() { return default_hotend_temperature; }
71 float get_default_bed_temp() { return default_bed_temperature; }
72
73 // file playing from sd
74 bool is_playing() const;
75 bool is_suspended() const;
76 void set_playing_file(string f);
77 const char* get_playing_file() { return playing_file; }
78
79 string getMessage() { return message; }
80 bool hasMessage() { return message.size() > 0; }
81
82 uint16_t get_screen_lines() const { return screen_lines; }
83
84 // public as it is directly accessed by screens... not good
85 // TODO pass lcd into ctor of each sub screen
86 LcdBase* lcd;
87 PanelScreen* custom_screen;
88
89 using encoder_cb_t= std::function<void(int ticks)>;
90 bool enter_direct_encoder_mode(encoder_cb_t fnc);
91
92 // as panelscreen accesses private fields in Panel
93 friend class PanelScreen;
94
95 private:
96
97 // external SD card
98 bool mount_external_sd(bool on);
99 Pin sdcd_pin;
100 PinName extsd_spi_cs;
101 SDCard *sd;
102 SDFAT *extmounter;
103
104 // Menu
105 int menu_selected_line;
106 int menu_start_line;
107 int menu_rows;
108 int panel_lines;
109
110 // Control
111 float normal_increment;
112 int control_normal_counter;
113 float control_base_value;
114
115 Button up_button;
116 Button down_button;
117 Button back_button;
118 Button click_button;
119
120 int* counter;
121
122 int idle_time;
123
124 PanelScreen* top_screen;
125 PanelScreen* current_screen;
126
127 float jogging_speed_mm_min[3];
128 float default_hotend_temperature;
129 float default_bed_temperature;
130
131 string message;
132 encoder_cb_t encoder_cb_fnc;
133
134 uint16_t screen_lines;
135 uint16_t menu_current_line;
136 char playing_file[20];
137 uint8_t extsd_spi_channel;
138
139 volatile struct {
140 bool start_up:1;
141 bool menu_changed:1;
142 bool control_value_changed:1;
143 bool external_sd_enable:1;
144 volatile bool counter_changed:1;
145 volatile bool click_changed:1;
146 volatile bool refresh_flag:1;
147 volatile bool do_buttons:1;
148 volatile bool do_encoder:1;
149 char mode:2;
150 char menu_offset:3;
151 int encoder_click_resolution:3;
152 };
153 };
154
155 #endif