8d7c8bb4626dafe6d81c524310a17cb6ae5095b6
[clinton/Smoothieware.git] / src / modules / utils / panel / screens / MainMenuScreen.cpp
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 #include "libs/Kernel.h"
9 #include "Panel.h"
10 #include "PanelScreen.h"
11 #include "MainMenuScreen.h"
12 #include "WatchScreen.h"
13 #include "FileScreen.h"
14 #include "ControlScreen.h"
15 #include "PrepareScreen.h"
16 #include "libs/nuts_bolts.h"
17 #include "libs/utils.h"
18 #include "modules/utils/player/PlayerPublicAccess.h"
19
20
21 #include <string>
22 using namespace std;
23
24 MainMenuScreen::MainMenuScreen()
25 {
26 // Children screens
27 this->jog_screen = (new JogScreen() )->set_parent(this);
28 this->watch_screen = (new WatchScreen() )->set_parent(this);
29 this->file_screen = (new FileScreen() )->set_parent(this);
30 this->prepare_screen = (new PrepareScreen() )->set_parent(this);
31 this->set_parent(this->watch_screen);
32 }
33
34 void MainMenuScreen::on_enter()
35 {
36 this->panel->enter_menu_mode();
37 this->panel->setup_menu(5);
38 this->refresh_menu();
39 }
40
41 void MainMenuScreen::on_refresh()
42 {
43 if ( this->panel->menu_change() ) {
44 this->refresh_menu();
45 }
46 if ( this->panel->click() ) {
47 this->clicked_menu_entry(this->panel->get_menu_current_line());
48 }
49 }
50
51 void MainMenuScreen::display_menu_line(uint16_t line)
52 {
53 switch ( line ) {
54 case 0: this->panel->lcd->printf("Watch"); break;
55 case 1: this->panel->lcd->printf(panel->is_playing() ? "Abort" : "Play"); break;
56 case 2: this->panel->lcd->printf("Jog"); break;
57 case 3: this->panel->lcd->printf("Prepare"); break;
58 case 4: this->panel->lcd->printf("Custom"); break;
59 //case 4: this->panel->lcd->printf("Configure"); break;
60 //case 5: this->panel->lcd->printf("Tune"); break;
61 }
62 }
63
64 void MainMenuScreen::clicked_menu_entry(uint16_t line)
65 {
66 switch ( line ) {
67 case 0: this->panel->enter_screen(this->watch_screen ); break;
68 case 1: this->panel->is_playing() ? abort_playing() : this->panel->enter_screen(this->file_screen); break;
69 case 2: this->panel->enter_screen(this->jog_screen ); break;
70 case 3: this->panel->enter_screen(this->prepare_screen ); break;
71 case 4: this->panel->enter_screen(this->panel->custom_screen ); break;
72 }
73 }
74
75 void MainMenuScreen::abort_playing()
76 {
77 THEKERNEL->public_data->set_value(player_checksum, abort_play_checksum, NULL);
78 this->panel->enter_screen(this->watch_screen);
79 }
80