rewrite extruder to handle new core system
[clinton/Smoothieware.git] / src / modules / tools / extruder / ExtruderMaker.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 "ExtruderMaker.h"
9 #include "libs/Module.h"
10 #include "libs/Kernel.h"
11 #include "Extruder.h"
12 #include "Config.h"
13 #include "ToolManager.h"
14 #include "checksumm.h"
15 #include "ConfigValue.h"
16 #include "StreamOutputPool.h"
17
18 #include <math.h>
19 #include <vector>
20 using namespace std;
21
22 #define extruder_checksum CHECKSUM("extruder")
23 #define enable_checksum CHECKSUM("enable")
24
25 void ExtruderMaker::load_tools(){
26
27 // Get every "declared" extruder module
28 vector<uint16_t> modules;
29 THEKERNEL->config->get_module_list( &modules, extruder_checksum );
30
31 if(modules.size() == 0) {
32 THEKERNEL->streams->printf("NOTE: No extruders configured\n");
33 return;
34 }
35
36 // count number of enabled extruders
37 int cnt= 0;
38 for(auto cs : modules) {
39 if( THEKERNEL->config->value(extruder_checksum, cs, enable_checksum )->as_bool() ){
40 cnt++;
41 }
42 }
43
44 if(cnt == 0) {
45 THEKERNEL->streams->printf("NOTE: No extruders enabled\n");
46 return;
47 }
48
49 ToolManager *toolmanager= nullptr;
50 if(cnt > 1) {
51 // ONLY do this if multitool enabled and more than one tool is defined
52 toolmanager= new ToolManager();
53 THEKERNEL->add_module( toolmanager );
54
55 }else{
56 // only one extruder so no tool manager required
57 THEKERNEL->streams->printf("NOTE: One extruder configured and enabled\n");
58 }
59
60
61 // For every extruder found, setup the enabled ones
62 for(auto cs : modules){
63 // If module is enabled
64 if( THEKERNEL->config->value(extruder_checksum, cs, enable_checksum )->as_bool() ){
65
66 // Make a new extruder module
67 Extruder* extruder = new Extruder(cs);
68
69 // Add the Extruder module to the kernel
70 THEKERNEL->add_module( extruder );
71
72 if(toolmanager != nullptr) {
73 // Add the extruder module to the ToolsManager if it was created
74 toolmanager->add_tool( extruder );
75
76 }else{
77 // if not managed by toolmanager we need to enable the one extruder
78 extruder->select();
79 }
80 }
81
82 }
83
84 THEKERNEL->streams->printf("NOTE: %d extruders enabled out of %d\n", cnt, modules.size());
85 }
86
87
88
89
90