refactor ON_HALT, add THEKERNEL->is_halted() for modules that just need to test 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
JM
37 void on_idle(void* argument);
38 void on_main_loop(void* argument);
c89338bd 39 void on_set_public_data(void* argument);
fb877329 40 void on_second_tick(void* argument);
35089dc7
JM
41 void enter_screen(PanelScreen* screen);
42 void reset_counter();
43
44 // Encoder and buttons
45 uint32_t on_up(uint32_t dummy);
46 uint32_t on_down(uint32_t dummy);
47 uint32_t on_back(uint32_t dummy);
ab4abea9 48 uint32_t on_select(uint32_t dummy);
52500e58 49 uint32_t on_pause(uint32_t dummy);
35089dc7
JM
50 uint32_t refresh_tick(uint32_t dummy);
51 uint32_t encoder_check(uint32_t dummy);
52 bool counter_change();
53 bool click();
54 int get_encoder_resolution() const { return encoder_click_resolution; }
399cb110 55
35089dc7 56 // Menu
5971142d 57 void enter_menu_mode(bool force= false);
35089dc7 58 void setup_menu(uint16_t rows, uint16_t lines);
f65ce58f 59 void setup_menu(uint16_t rows);
35089dc7
JM
60 void menu_update();
61 bool menu_change();
f65ce58f 62 uint16_t max_screen_lines() { return screen_lines; }
446deda2 63 uint16_t get_menu_current_line() { return menu_current_line; }
399cb110 64
35089dc7 65 // Control
1ad23cd3
MM
66 bool enter_control_mode(float passed_normal_increment, float passed_pressed_increment);
67 void set_control_value(float value);
68 float get_control_value();
35089dc7
JM
69 bool control_value_change();
70 void control_value_update();
1ad23cd3
MM
71 float get_jogging_speed(char axis) { return jogging_speed_mm_min[axis-'X']; }
72 float get_default_hotend_temp() { return default_hotend_temperature; }
73 float get_default_bed_temp() { return default_bed_temperature; }
35089dc7
JM
74
75 // file playing from sd
76 bool is_playing() const;
5f1a896b 77 bool is_suspended() 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; }
83
f4780d4e
JM
84 uint16_t get_screen_lines() const { return screen_lines; }
85
35089dc7
JM
86 // public as it is directly accessed by screens... not good
87 // TODO pass lcd into ctor of each sub screen
88 LcdBase* lcd;
ca6effd7 89 PanelScreen* custom_screen;
35089dc7
JM
90
91 // as panelscreen accesses private fields in Panel
92 friend class PanelScreen;
399cb110 93
35089dc7 94 private:
cee1bb2d 95
fb877329
JM
96 // external SD card
97 bool mount_external_sd(bool on);
98 Pin sdcd_pin;
fb877329
JM
99 PinName extsd_spi_cs;
100 SDCard *sd;
101 SDFAT *extmounter;
102
35089dc7 103 // Menu
35089dc7
JM
104 int menu_selected_line;
105 int menu_start_line;
106 int menu_rows;
206167cf 107 int panel_lines;
35089dc7
JM
108
109 // Control
1ad23cd3 110 float normal_increment;
35089dc7 111 int control_normal_counter;
1ad23cd3 112 float control_base_value;
399cb110 113
35089dc7
JM
114 Button up_button;
115 Button down_button;
116 Button back_button;
117 Button click_button;
52500e58 118 Button pause_button;
35089dc7
JM
119
120 int* counter;
f4780d4e 121
373d0bf1
JM
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
133 uint16_t screen_lines;
134 uint16_t menu_current_line;
135 char playing_file[20];
136 uint8_t extsd_spi_channel;
137
f4780d4e
JM
138 volatile struct {
139 bool start_up:1;
140 bool menu_changed:1;
141 bool control_value_changed:1;
fb877329 142 bool external_sd_enable:1;
f4780d4e
JM
143 volatile bool counter_changed:1;
144 volatile bool click_changed:1;
145 volatile bool refresh_flag:1;
146 volatile bool do_buttons:1;
147 volatile bool do_encoder:1;
373d0bf1
JM
148 char mode:2;
149 char menu_offset:3;
150 int encoder_click_resolution:3;
f4780d4e 151 };
35089dc7
JM
152};
153
154#endif