FIx suspend/pause and saving/restoring Extruder state, this is complex due to possibl...
[clinton/Smoothieware.git] / src / modules / tools / extruder / Extruder.h
dissimilarity index 65%
index 2560a2f..9bddf93 100644 (file)
@@ -1,67 +1,66 @@
-/*
-      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 EXTURDER_MODULE_H
-#define EXTRUDER_MODULE_H
-
-#include "Tool.h"
-#include "Pin.h"
-
-class StepperMotor;
-class Block;
-
-// NOTE Tool is also a module, no need for multiple inheritance here
-class Extruder : public Tool {
-    public:
-        Extruder(uint16_t config_identifier, bool single= false);
-        virtual ~Extruder() {}
-
-        void     on_module_loaded();
-        void     on_config_reload(void* argument);
-        void     on_gcode_received(void*);
-        void     on_gcode_execute(void* argument);
-        void     on_block_begin(void* argument);
-        void     on_block_end(void* argument);
-        void     on_play(void* argument);
-        void     on_pause(void* argument);
-        void     on_speed_change(void* argument);
-        uint32_t acceleration_tick(uint32_t dummy);
-        uint32_t stepper_motor_finished_move(uint32_t dummy);
-        Block*   append_empty_block();
-
-    private:
-        void on_get_public_data(void* argument);
-
-        Pin             step_pin;                     // Step pin for the stepper driver
-        Pin             dir_pin;                      // Dir pin for the stepper driver
-        Pin             en_pin;
-
-        float          target_position;              // End point ( in mm ) for the current move
-        float          current_position;             // Current point ( in mm ) for the current move, incremented every time a move is executed
-        float          unstepped_distance;           // overflow buffer for requested moves that are less than 1 step
-        Block*         current_block;                // Current block we are stepping, same as Stepper's one
-        float          steps_per_millimeter;         // Steps to travel one millimeter
-        float          steps_per_millimeter_setting; // original steps to travel one millimeter saved while in volumetric mode
-        float          feed_rate;                    //
-        float          acceleration;                 //
-        float          max_speed;
-
-        float          travel_ratio;
-        float          travel_distance;
-
-        char mode;                                    // extruder motion mode,  OFF, SOLO, or FOLLOW
-        bool absolute_mode;                           // absolute/relative coordinate mode switch
-        bool paused;
-        bool single_config;
-
-        StepperMotor* stepper_motor;
-
-};
-
-#endif
+/*
+      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/>.
+*/
+
+
+
+#pragma once
+
+#include "Tool.h"
+#include "Pin.h"
+
+#include <tuple>
+
+class StepperMotor;
+
+// NOTE Tool is also a module, no need for multiple inheritance here
+class Extruder : public Tool {
+    public:
+        Extruder(uint16_t config_identifier);
+        virtual ~Extruder();
+
+        void     on_module_loaded();
+        void     on_gcode_received(void*);
+
+        void select();
+        void deselect();
+
+    private:
+        void config_load();
+        void on_get_public_data(void* argument);
+        void on_set_public_data(void* argument);
+        float check_max_speeds(float target, float isecs);
+
+        StepperMotor *stepper_motor;
+
+        // kept together so they can be passed as public data
+        struct {
+            float filament_diameter;            // filament diameter
+            float extruder_multiplier;          // flow rate 1.0 == 100%
+            float retract_length;               // firmware retract length
+        };
+
+        float volumetric_multiplier;
+        float max_volumetric_rate;      // used for calculating volumetric rate in mm³/sec
+
+        // for firmware retract
+        float retract_feedrate;
+        float retract_recover_feedrate;
+        float retract_recover_length;
+        float retract_zlift_length;
+        float retract_zlift_feedrate;
+
+        // for saving and restoring extruder position
+        std::tuple<float, float, int32_t> saved_position;
+
+        struct {
+            uint8_t motor_id:8;
+            bool retracted:1;
+            bool cancel_zlift_restore:1; // hack to stop a G11 zlift restore from overring an absolute Z setting
+            bool selected:1;
+            bool saved_selected:1;
+        };
+};