added Pauser module
[clinton/Smoothieware.git] / src / libs / Kernel.h
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 #ifndef KERNEL_H
9 #define KERNEL_H
10 #include "libs/Module.h"
11 #include "libs/Config.h"
12 #include "modules/communication/SerialConsole.h"
13 #include "modules/communication/GcodeDispatch.h"
14 #include "modules/robot/Planner.h"
15 #include "modules/robot/Robot.h"
16 #include "modules/robot/Stepper.h"
17 #include "mbed.h"
18
19 // See : http://smoothieware.org/listofevents
20 #define NUMBER_OF_DEFINED_EVENTS 11
21 #define ON_MAIN_LOOP 0
22 #define ON_CONSOLE_LINE_RECEIVED 1
23 #define ON_GCODE_RECEIVED 2
24 #define ON_STEPPER_WAKE_UP 3 //TODO : Remove the need for this event, then this event itself eg: have planner call stepper directly
25 #define ON_GCODE_EXECUTE 4
26 #define ON_SPEED_CHANGE 5
27 #define ON_BLOCK_BEGIN 6
28 #define ON_BLOCK_END 7
29 #define ON_CONFIG_RELOAD 8
30 #define ON_PLAY 9
31 #define ON_PAUSE 10
32
33
34 using namespace std;
35 #include <vector>
36
37 typedef void (Module::*ModuleCallback)(void * argument);
38
39 //Module manager
40 class Module;
41 class Kernel {
42 public:
43 Kernel();
44 void add_module(Module* module);
45 void register_for_event(unsigned int id_event, Module* module);
46 void call_event(unsigned int id_event);
47 void call_event(unsigned int id_event, void * argument);
48
49 // These modules are aviable to all other modules
50 SerialConsole* serial;
51 GcodeDispatch* gcode_dispatch;
52 Robot* robot;
53 Stepper* stepper;
54 Planner* planner;
55 Config* config;
56
57 private:
58 vector<Module*> hooks[NUMBER_OF_DEFINED_EVENTS]; // When a module asks to be called for a specific event ( a hook ), this is where that request is remembered
59
60 };
61
62 #endif