| 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 | #include "PublicData.h" |
| 20 | #include "checksumm.h" |
| 21 | #include "ModifyValuesScreen.h" |
| 22 | #include "Robot.h" |
| 23 | #include "Planner.h" |
| 24 | #include "StepperMotor.h" |
| 25 | |
| 26 | #include <string> |
| 27 | using namespace std; |
| 28 | |
| 29 | #define extruder_checksum CHECKSUM("extruder") |
| 30 | |
| 31 | MainMenuScreen::MainMenuScreen() |
| 32 | { |
| 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); |
| 38 | this->configure_screen = setupConfigureScreen(); |
| 39 | |
| 40 | this->set_parent(this->watch_screen); |
| 41 | } |
| 42 | |
| 43 | // setup things here that can be configured |
| 44 | PanelScreen* MainMenuScreen::setupConfigureScreen() |
| 45 | { |
| 46 | auto mvs= new ModifyValuesScreen(); |
| 47 | mvs->set_parent(this); |
| 48 | |
| 49 | // acceleration |
| 50 | mvs->addMenuItem("Acceleration", // menu name |
| 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 | |
| 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 | |
| 88 | return mvs; |
| 89 | } |
| 90 | |
| 91 | void MainMenuScreen::on_enter() |
| 92 | { |
| 93 | this->panel->enter_menu_mode(); |
| 94 | this->panel->setup_menu(6); |
| 95 | this->refresh_menu(); |
| 96 | } |
| 97 | |
| 98 | void MainMenuScreen::on_refresh() |
| 99 | { |
| 100 | if ( this->panel->menu_change() ) { |
| 101 | this->refresh_menu(); |
| 102 | } |
| 103 | if ( this->panel->click() ) { |
| 104 | this->clicked_menu_entry(this->panel->get_menu_current_line()); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | void MainMenuScreen::display_menu_line(uint16_t line) |
| 109 | { |
| 110 | switch ( line ) { |
| 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; |
| 115 | case 4: this->panel->lcd->printf("Custom"); break; |
| 116 | case 5: this->panel->lcd->printf("Configure"); break; |
| 117 | //case 5: this->panel->lcd->printf("Tune"); break; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | void MainMenuScreen::clicked_menu_entry(uint16_t line) |
| 122 | { |
| 123 | switch ( line ) { |
| 124 | case 0: this->panel->enter_screen(this->watch_screen ); break; |
| 125 | case 1: this->panel->is_playing() ? abort_playing() : this->panel->enter_screen(this->file_screen); break; |
| 126 | case 2: this->panel->enter_screen(this->jog_screen ); break; |
| 127 | case 3: this->panel->enter_screen(this->prepare_screen ); break; |
| 128 | case 4: this->panel->enter_screen(this->panel->custom_screen ); break; |
| 129 | case 5: this->panel->enter_screen(this->configure_screen ); break; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | void MainMenuScreen::abort_playing() |
| 134 | { |
| 135 | THEKERNEL->public_data->set_value(player_checksum, abort_play_checksum, NULL); |
| 136 | this->panel->enter_screen(this->watch_screen); |
| 137 | } |
| 138 | |