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