working Switch module
authorArthur Wolf <wolf.arthur@gmail.com>
Sat, 7 Jul 2012 18:28:07 +0000 (20:28 +0200)
committerArthur Wolf <wolf.arthur@gmail.com>
Sat, 7 Jul 2012 18:28:07 +0000 (20:28 +0200)
src/main.cpp
src/modules/tools/switch/Switch.cpp [new file with mode: 0644]
src/modules/tools/switch/Switch.h [new file with mode: 0644]
src/modules/tools/switch/SwitchPool.cpp [new file with mode: 0644]
src/modules/tools/switch/SwitchPool.h [new file with mode: 0644]

index edbaf5e..cfbb630 100644 (file)
@@ -9,6 +9,7 @@
 #include "modules/tools/laser/Laser.h"
 #include "modules/tools/extruder/Extruder.h"
 #include "modules/tools/temperaturecontrol/TemperatureControlPool.h"
+#include "modules/tools/switch/SwitchPool.h"
 #include "modules/robot/Player.h"
 #include "modules/utils/simpleshell/SimpleShell.h"
 #include "modules/utils/configurator/Configurator.h"
@@ -36,6 +37,7 @@ int main() {
     kernel->add_module( new Configurator() );
     kernel->add_module( new CurrentControl() );
     kernel->add_module( new TemperatureControlPool() );
+    kernel->add_module( new SwitchPool() );
     kernel->add_module( new PauseButton() );   
 
     //kernel->add_module( &cdcmsc );
diff --git a/src/modules/tools/switch/Switch.cpp b/src/modules/tools/switch/Switch.cpp
new file mode 100644 (file)
index 0000000..7c6ff20
--- /dev/null
@@ -0,0 +1,55 @@
+/*  
+      This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
+      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.
+      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.
+      You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. 
+*/
+
+#include "libs/Module.h"
+#include "libs/Kernel.h"
+#include <math.h>
+#include "Switch.h"
+#include "libs/Pin.h"
+
+Switch::Switch(){}
+
+Switch::Switch(uint16_t name){
+    this->name_checksum = name;
+}
+
+void Switch::on_module_loaded(){
+    this->register_for_event(ON_GCODE_EXECUTE);
+    
+    // Settings
+    this->on_config_reload(this);
+
+}
+
+
+// Get config
+void Switch::on_config_reload(void* argument){
+    this->on_m_code                   = this->kernel->config->value(switch_checksum, this->name_checksum, on_m_code_checksum          )->required()->as_number();
+    this->off_m_code                  = this->kernel->config->value(switch_checksum, this->name_checksum, off_m_code_checksum         )->required()->as_number();
+    this->output_pin                  = this->kernel->config->value(switch_checksum, this->name_checksum, output_pin_checksum         )->required()->as_pin()->as_output();
+    this->output_pin->set(              this->kernel->config->value(switch_checksum, this->name_checksum, startup_state_checksum      )->by_default(0)->as_number() );
+}
+
+// Turn pin on and off
+void Switch::on_gcode_execute(void* argument){
+    Gcode* gcode = static_cast<Gcode*>(argument);
+    if( gcode->has_letter('M' )){
+        int code = gcode->get_value('M');
+        if( code == this->on_m_code ){  
+            // Turn pin on
+            this->output_pin->set(1);
+        } 
+        if( code == this->off_m_code ){ 
+            // Turn pin off 
+            this->output_pin->set(0);
+        } 
+    }
+}
+
+
+
+
diff --git a/src/modules/tools/switch/Switch.h b/src/modules/tools/switch/Switch.h
new file mode 100644 (file)
index 0000000..2d3a2e0
--- /dev/null
@@ -0,0 +1,35 @@
+/*  
+      this file is part of smoothie (http://smoothieware.org/). the motion control part is heavily based on grbl (https://github.com/simen/grbl).
+      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.
+      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.
+      you should have received a copy of the gnu general public license along with smoothie. if not, see <http://www.gnu.org/licenses/>. 
+*/
+
+#ifndef SWITCH_H
+#define SWITCH_H
+
+#include "libs/Pin.h"
+#include <math.h>
+
+#define    switch_checksum            15508 
+#define    on_m_code_checksum         29094 
+#define    off_m_code_checksum        14853 
+#define    output_pin_checksum        18779 
+#define    startup_state_checksum     37528 
+
+class Switch : public Module {
+    public:
+        Switch();
+        Switch(uint16_t name);
+        
+        void on_module_loaded();
+        void on_config_reload(void* argument);
+        void on_gcode_execute(void* argument);
+
+        uint16_t name_checksum;
+        uint16_t on_m_code;
+        uint16_t off_m_code;
+        Pin*     output_pin;
+};
+
+#endif
diff --git a/src/modules/tools/switch/SwitchPool.cpp b/src/modules/tools/switch/SwitchPool.cpp
new file mode 100644 (file)
index 0000000..2fbea4e
--- /dev/null
@@ -0,0 +1,37 @@
+/*  
+      This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
+      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.
+      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.
+      You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. 
+*/
+
+#include "libs/Module.h"
+#include "libs/Kernel.h"
+#include <math.h>
+using namespace std;
+#include <vector>
+#include "SwitchPool.h"
+#include "Switch.h"
+
+SwitchPool::SwitchPool(){}
+
+void SwitchPool::on_module_loaded(){
+
+    vector<uint16_t> modules;
+    this->kernel->config->get_module_list( &modules, switch_checksum );
+
+    for( int i = 0; i < modules.size(); i++ ){
+        // If module is enabled
+        if( this->kernel->config->value(switch_checksum, modules[i], enable_checksum )->as_bool() == true ){
+            Switch* controller = new Switch(modules[i]);
+            this->kernel->add_module(controller); 
+            this->controllers.push_back( controller );
+        }
+    }
+
+}
+
+
+
+
+
diff --git a/src/modules/tools/switch/SwitchPool.h b/src/modules/tools/switch/SwitchPool.h
new file mode 100644 (file)
index 0000000..52c4552
--- /dev/null
@@ -0,0 +1,30 @@
+/*  
+      this file is part of smoothie (http://smoothieware.org/). the motion control part is heavily based on grbl (https://github.com/simen/grbl).
+      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.
+      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.
+      you should have received a copy of the gnu general public license along with smoothie. if not, see <http://www.gnu.org/licenses/>. 
+*/
+
+#ifndef SWITCHPOOL_H
+#define SWITCHPOOL_H
+
+#include "Switch.h"
+#include <math.h>
+using namespace std;
+#include <vector>
+
+#define switch_checksum              15508 
+#define enable_checksum              29545
+
+class SwitchPool : public Module {
+    public:
+        SwitchPool();
+
+        void on_module_loaded();
+
+        vector<Switch*> controllers;
+};
+
+
+
+#endif