Added e steps for panel
[clinton/Smoothieware.git] / src / modules / utils / panel / screens / MainMenuScreen.cpp
CommitLineData
446deda2 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.
446deda2 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#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"
61134a65
JM
19#include "PublicData.h"
20#include "checksumm.h"
2fa50ca0
JM
21#include "ModifyValuesScreen.h"
22#include "Robot.h"
23#include "Planner.h"
24#include "StepperMotor.h"
35089dc7
JM
25
26#include <string>
27using namespace std;
28
d87968be
JM
29#define extruder_checksum CHECKSUM("extruder")
30
862fc625
JM
31MainMenuScreen::MainMenuScreen()
32{
58d6d841
JM
33 // Children screens
34 this->jog_screen = (new JogScreen() )->set_parent(this);
35 this->watch_screen = (new WatchScreen() )->set_parent(this);
36 this->file_screen = (new FileScreen() )->set_parent(this);
37 this->prepare_screen = (new PrepareScreen() )->set_parent(this);
2fa50ca0
JM
38 this->configure_screen = setupConfigureScreen();
39
58d6d841 40 this->set_parent(this->watch_screen);
35089dc7
JM
41}
42
2fa50ca0
JM
43// setup things here that can be configured
44PanelScreen* MainMenuScreen::setupConfigureScreen()
45{
46 auto mvs= new ModifyValuesScreen();
47 mvs->set_parent(this);
48
49 // acceleration
d87968be 50 mvs->addMenuItem("Acceleration", // menu name
2fa50ca0
JM
51 []() -> float { return THEKERNEL->planner->get_acceleration(); }, // getter
52 [this](float acc) { send_gcode("M204", 'S', acc); }, // setter
53 10.0F, // increment
54 1.0F, // Min
55 10000.0F // Max
56 );
57
58 // steps/mm
59 mvs->addMenuItem("X steps/mm",
60 []() -> float { return THEKERNEL->robot->actuators[0]->get_steps_per_mm(); },
61 [](float v) { THEKERNEL->robot->actuators[0]->change_steps_per_mm(v); },
62 0.1F,
63 1.0F
64 );
65
66 mvs->addMenuItem("Y steps/mm",
67 []() -> float { return THEKERNEL->robot->actuators[1]->get_steps_per_mm(); },
68 [](float v) { THEKERNEL->robot->actuators[1]->change_steps_per_mm(v); },
69 0.1F,
70 1.0F
71 );
72
73 mvs->addMenuItem("Z steps/mm",
74 []() -> float { return THEKERNEL->robot->actuators[2]->get_steps_per_mm(); },
75 [](float v) { THEKERNEL->robot->actuators[2]->change_steps_per_mm(v); },
76 0.1F,
77 1.0F
78 );
79
d87968be
JM
80 mvs->addMenuItem("E steps/mm",
81 // gets steps/mm for currently active extruder
82 []() -> float { void *rd; THEKERNEL->public_data->get_value( extruder_checksum, &rd ); return rd==nullptr ? 0.0F : *((float*)rd); },
83 [this](float v) { send_gcode("M92", 'E', v); },
84 0.1F,
85 1.0F
86 );
87
2fa50ca0
JM
88 return mvs;
89}
90
862fc625
JM
91void MainMenuScreen::on_enter()
92{
35089dc7 93 this->panel->enter_menu_mode();
2fa50ca0 94 this->panel->setup_menu(6);
862fc625 95 this->refresh_menu();
35089dc7
JM
96}
97
862fc625
JM
98void MainMenuScreen::on_refresh()
99{
100 if ( this->panel->menu_change() ) {
101 this->refresh_menu();
35089dc7 102 }
862fc625 103 if ( this->panel->click() ) {
446deda2 104 this->clicked_menu_entry(this->panel->get_menu_current_line());
35089dc7 105 }
35089dc7
JM
106}
107
862fc625
JM
108void MainMenuScreen::display_menu_line(uint16_t line)
109{
110 switch ( line ) {
446deda2
JM
111 case 0: this->panel->lcd->printf("Watch"); break;
112 case 1: this->panel->lcd->printf(panel->is_playing() ? "Abort" : "Play"); break;
113 case 2: this->panel->lcd->printf("Jog"); break;
114 case 3: this->panel->lcd->printf("Prepare"); break;
ca6effd7 115 case 4: this->panel->lcd->printf("Custom"); break;
2fa50ca0 116 case 5: this->panel->lcd->printf("Configure"); break;
862fc625 117 //case 5: this->panel->lcd->printf("Tune"); break;
35089dc7 118 }
35089dc7
JM
119}
120
862fc625
JM
121void MainMenuScreen::clicked_menu_entry(uint16_t line)
122{
123 switch ( line ) {
35089dc7 124 case 0: this->panel->enter_screen(this->watch_screen ); break;
ca6effd7 125 case 1: this->panel->is_playing() ? abort_playing() : this->panel->enter_screen(this->file_screen); break;
35089dc7
JM
126 case 2: this->panel->enter_screen(this->jog_screen ); break;
127 case 3: this->panel->enter_screen(this->prepare_screen ); break;
ca6effd7 128 case 4: this->panel->enter_screen(this->panel->custom_screen ); break;
2fa50ca0 129 case 5: this->panel->enter_screen(this->configure_screen ); break;
35089dc7
JM
130 }
131}
132
862fc625
JM
133void MainMenuScreen::abort_playing()
134{
58d6d841
JM
135 THEKERNEL->public_data->set_value(player_checksum, abort_play_checksum, NULL);
136 this->panel->enter_screen(this->watch_screen);
35089dc7
JM
137}
138