Add halt status to panel and a way to clear it
[clinton/Smoothieware.git] / src / modules / utils / panel / Panel.h
CommitLineData
399cb110 1/*
35089dc7
JM
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.
399cb110 5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
35089dc7
JM
6*/
7
8#ifndef PANEL_H
9#define PANEL_H
10
35089dc7 11#include "Button.h"
fb877329
JM
12#include "Pin.h"
13#include "mbed.h"
e0d0ea84
JM
14#include <string>
15using std::string;
f19a841a 16
35089dc7
JM
17#define MENU_MODE 0
18#define CONTROL_MODE 1
19
cee1bb2d
JM
20#define THEPANEL Panel::instance
21
7af0714f 22class LcdBase;
ca6effd7 23class PanelScreen;
c77d6dae 24class ModifyValuesScreen;
fb877329
JM
25class SDCard;
26class SDFAT;
7af0714f 27
35089dc7
JM
28class Panel : public Module {
29 public:
30 Panel();
31 virtual ~Panel();
cee1bb2d 32 static Panel* instance;
35089dc7
JM
33
34 void on_module_loaded();
35 uint32_t button_tick(uint32_t dummy);
e456d044 36 uint32_t encoder_tick(uint32_t dummy);
35089dc7 37 void on_idle(void* argument);
76217df5 38 void on_halt(void* argument);
35089dc7 39 void on_main_loop(void* argument);
399cb110 40 void on_gcode_received(void* argument);
fb877329 41 void on_second_tick(void* argument);
35089dc7
JM
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);
ab4abea9 49 uint32_t on_select(uint32_t dummy);
52500e58 50 uint32_t on_pause(uint32_t dummy);
35089dc7
JM
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; }
399cb110 56
35089dc7 57 // Menu
5971142d 58 void enter_menu_mode(bool force= false);
35089dc7 59 void setup_menu(uint16_t rows, uint16_t lines);
f65ce58f 60 void setup_menu(uint16_t rows);
35089dc7
JM
61 void menu_update();
62 bool menu_change();
f65ce58f 63 uint16_t max_screen_lines() { return screen_lines; }
446deda2 64 uint16_t get_menu_current_line() { return menu_current_line; }
399cb110 65
35089dc7 66 // Control
1ad23cd3
MM
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();
35089dc7
JM
70 bool control_value_change();
71 void control_value_update();
1ad23cd3
MM
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; }
35089dc7
JM
75
76 // file playing from sd
77 bool is_playing() const;
7aa9fef3
JM
78 void set_playing_file(string f);
79 const char* get_playing_file() { return playing_file; }
399cb110
JM
80
81 string getMessage() { return message; }
82 bool hasMessage() { return message.size() > 0; }
76217df5 83 bool is_halted() const { return halted; }
399cb110 84
f4780d4e
JM
85 uint16_t get_screen_lines() const { return screen_lines; }
86
35089dc7
JM
87 // public as it is directly accessed by screens... not good
88 // TODO pass lcd into ctor of each sub screen
89 LcdBase* lcd;
ca6effd7 90 PanelScreen* custom_screen;
cee1bb2d 91 PanelScreen* temperature_screen;
c77d6dae 92 vector<uint16_t> temperature_modules;
35089dc7
JM
93
94 // as panelscreen accesses private fields in Panel
95 friend class PanelScreen;
399cb110 96
35089dc7 97 private:
cee1bb2d
JM
98 void setup_temperature_screen();
99
fb877329
JM
100 // external SD card
101 bool mount_external_sd(bool on);
102 Pin sdcd_pin;
103 uint8_t extsd_spi_channel;
104 PinName extsd_spi_cs;
105 SDCard *sd;
106 SDFAT *extmounter;
107
35089dc7 108 // Menu
35089dc7
JM
109 int menu_selected_line;
110 int menu_start_line;
111 int menu_rows;
206167cf 112 int panel_lines;
446deda2 113 uint16_t menu_current_line;
f4780d4e 114 char menu_offset;
35089dc7
JM
115
116 // Control
1ad23cd3 117 float normal_increment;
35089dc7 118 int control_normal_counter;
1ad23cd3 119 float control_base_value;
399cb110 120
35089dc7
JM
121 Button up_button;
122 Button down_button;
123 Button back_button;
124 Button click_button;
52500e58 125 Button pause_button;
35089dc7
JM
126
127 int* counter;
f4780d4e
JM
128
129 volatile struct {
130 bool start_up:1;
131 bool menu_changed:1;
132 bool control_value_changed:1;
fb877329 133 bool external_sd_enable:1;
76217df5 134 bool halted:1;
f4780d4e
JM
135 volatile bool counter_changed:1;
136 volatile bool click_changed:1;
137 volatile bool refresh_flag:1;
138 volatile bool do_buttons:1;
139 volatile bool do_encoder:1;
140 };
20e69746 141
35089dc7
JM
142 int idle_time;
143 int encoder_click_resolution;
f65ce58f 144 uint16_t screen_lines;
f4780d4e 145 char mode;
35089dc7 146
ca6effd7 147 PanelScreen* top_screen;
35089dc7
JM
148 PanelScreen* current_screen;
149
1ad23cd3
MM
150 float jogging_speed_mm_min[3];
151 float default_hotend_temperature;
152 float default_bed_temperature;
399cb110 153
7aa9fef3 154 char playing_file[20];
399cb110 155 string message;
35089dc7
JM
156};
157
158#endif