chane speed changes via panel to issue M220 to avoid skipping issues
authorJim Morris <morris@wolfman.com>
Thu, 1 Aug 2013 07:31:48 +0000 (00:31 -0700)
committerJim Morris <morris@wolfman.com>
Thu, 1 Aug 2013 07:38:07 +0000 (00:38 -0700)
clean up gcode sending and rename command sending

Conflicts:

src/modules/utils/panel/screens/WatchScreen.cpp

src/modules/utils/panel/PanelScreen.cpp
src/modules/utils/panel/PanelScreen.h
src/modules/utils/panel/screens/ControlScreen.cpp
src/modules/utils/panel/screens/ControlScreen.h
src/modules/utils/panel/screens/ExtruderScreen.cpp
src/modules/utils/panel/screens/ExtruderScreen.h
src/modules/utils/panel/screens/PrepareScreen.cpp
src/modules/utils/panel/screens/PrepareScreen.h
src/modules/utils/panel/screens/WatchScreen.cpp
src/modules/utils/panel/screens/WatchScreen.h

index 36bd9bb..a2df7f7 100644 (file)
@@ -49,6 +49,8 @@ PanelScreen* PanelScreen::set_parent(PanelScreen* passed_parent){
     return this;
 }
 
-
-
-
+// Helper for screens to send a gcode
+void PanelScreen::send_gcode(std::string g) {
+    Gcode gcode(g, &(StreamOutput::NullStream));
+    THEKERNEL->call_event(ON_GCODE_RECEIVED, &gcode );
+}
index 8c9a837..3efa1e4 100644 (file)
@@ -32,6 +32,9 @@ class PanelScreen {
 
         Panel* panel;
         PanelScreen* parent;
+
+      protected:
+        void send_gcode(std::string g);
 };
 
 
index 4beecfd..50794c5 100644 (file)
@@ -17,8 +17,6 @@
 #include "modules/robot/RobotPublicAccess.h"
 using namespace std;
 
-#define JOGGING_SPEED_MM_MIN 1200
-
 ControlScreen::ControlScreen(){
     this->control_mode = NULL_CONTROL_MODE;
 }
@@ -124,9 +122,3 @@ void ControlScreen::set_current_pos(char axis, double p){
     string g(buf, n);
     send_gcode(g);
 }
-
-void ControlScreen::send_gcode(std::string g) {
-    Gcode gcode(g, &(StreamOutput::NullStream));
-    THEKERNEL->call_event(ON_GCODE_RECEIVED, &gcode );
-}
-
index 93ae5d7..a0cdeed 100644 (file)
@@ -33,7 +33,6 @@ class ControlScreen : public PanelScreen {
     private:
         void clicked_menu_entry(uint16_t line);
         void display_axis_line(char axis);
-        void send_gcode(std::string msg);
         void enter_axis_control(char axis);
         void enter_menu_control();
         void get_current_pos(double *p);
index 4451988..291debc 100644 (file)
@@ -50,15 +50,15 @@ void ExtruderScreen::display_menu_line(uint16_t line){
 void ExtruderScreen::clicked_menu_entry(uint16_t line){
     switch( line ){
         case 0: this->panel->enter_screen(this->parent); return;
-        case 1: send_gcode("G91"); send_gcode("G1 E5");  send_gcode("G90"); break;
-        case 2: send_gcode("G91"); send_gcode("G1 E-5"); send_gcode("G90"); break;
+        case 1: send_command("G91"); send_command("G1 E5");  send_command("G90"); break;
+        case 2: send_command("G91"); send_command("G1 E-5"); send_command("G90"); break;
     }
 }
 
-void ExtruderScreen::send_gcode(const char* gcstr) {
-    string gcode(gcstr);
+void ExtruderScreen::send_command(const char* gcstr) {
+    string cmd(gcstr);
     struct SerialMessage message;
-    message.message = gcode;
+    message.message = cmd;
     message.stream = &(StreamOutput::NullStream);
     THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message );
 }
index b32f884..5250dfb 100644 (file)
@@ -27,7 +27,7 @@ class ExtruderScreen : public PanelScreen {
         void clicked_menu_entry(uint16_t line);
 
     private:
-        void send_gcode(const char* gcstr);
+        void send_command(const char* gcstr);
 };
 
 #endif
index 4cabb74..6e46d2c 100644 (file)
@@ -60,12 +60,12 @@ void PrepareScreen::display_menu_line(uint16_t line){
 void PrepareScreen::clicked_menu_entry(uint16_t line){
     switch( line ){
         case 0: this->panel->enter_screen(this->parent); break;
-        case 1: send_gcode("G28"); break;
-        case 2: send_gcode("G92 X0 Y0 Z0"); break;
+        case 1: send_command("G28"); break;
+        case 2: send_command("G92 X0 Y0 Z0"); break;
         case 3: this->preheat(); break;
         case 4: this->cooldown(); break;
         case 5: this->panel->enter_screen(this->extruder_screen); break;
-        case 6: send_gcode("M84"); break;
+        case 6: send_command("M84"); break;
         //case 7: this->panel->enter_screen(this->temp_screen      ); break;
     }
 
@@ -84,10 +84,10 @@ void PrepareScreen::cooldown() {
     THEKERNEL->public_data->set_value( temperature_control_checksum, bed_checksum, &t );
 }
 
-void PrepareScreen::send_gcode(const char* gcstr) {
-    string gcode(gcstr);
+void PrepareScreen::send_command(const char* gcstr) {
+    string cmd(gcstr);
     struct SerialMessage message;
-    message.message = gcode;
+    message.message = cmd;
     message.stream = &(StreamOutput::NullStream);
     THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message );
 }
index 07489c2..517a1a8 100644 (file)
@@ -31,7 +31,7 @@ class PrepareScreen : public PanelScreen {
         PanelScreen* temp_screen;
         void preheat();
         void cooldown();
-        void send_gcode(const char* gcstr);
+        void send_command(const char* gcstr);
 };
 
 #endif
index 7b18cb6..667f22a 100644 (file)
@@ -19,7 +19,9 @@
 #include <string>
 using namespace std;
 
-WatchScreen::WatchScreen(){}
+WatchScreen::WatchScreen(){
+    speed_changed= false;
+}
 
 void WatchScreen::on_enter(){
     this->panel->lcd->clear();
@@ -43,13 +45,13 @@ void WatchScreen::on_refresh(){
     // see if speed is being changed
     if(this->panel->control_value_change()) {
         this->current_speed= this->panel->get_control_value();
-        if(this->current_speed <= 1.0) {
+        if(this->current_speed < 1.0) {
             this->current_speed= 1.0;
             this->panel->set_control_value(this->current_speed);
             this->panel->reset_counter();
         }else{
             // change actual speed
-            set_current_speed();
+            this->speed_changed= true; // flag main loop to isseu g code
             this->refresh_screen(false);
         }
     }
@@ -75,6 +77,13 @@ void WatchScreen::on_refresh(){
     }
 }
 
+// queuing gcodes needs to be done from main loop
+void WatchScreen::on_main_loop() {
+    if(!this->speed_changed) return;
+    this->speed_changed= false;
+    set_speed();
+}
+
 // fetch the data we are displaying
 void WatchScreen::get_temp_data() {
     void *returned_data;
@@ -119,12 +128,6 @@ double WatchScreen::get_current_speed() {
     return 0.0;
 }
 
-void WatchScreen::set_current_speed() {
-    bool ok= THEKERNEL->public_data->set_value( robot_checksum, speed_override_percent_checksum, &this->current_speed );
-    if(!ok) this->current_speed= 0;
-        
-}
-
 void WatchScreen::get_current_pos(double *cp){
     void *returned_data;
 
@@ -169,3 +172,11 @@ const char* WatchScreen::get_status(){
 
     return "Smoothie ready";
 }
+
+void WatchScreen::set_speed(){    
+    // change pos by issuing a M220 Snnn
+    char buf[32];
+    int n= snprintf(buf, sizeof(buf), "M220 S%f", this->current_speed);
+    string g(buf, n);
+    send_gcode(g);
+}
index 5792c29..7689bde 100644 (file)
@@ -21,16 +21,18 @@ class WatchScreen : public PanelScreen {
         WatchScreen();
         void on_refresh(); 
         void on_enter();
+        void on_main_loop();
         void display_menu_line(uint16_t line);
 
     private:
         void get_temp_data();
         double get_current_speed();
-        void set_current_speed();
+        void set_speed();
         void get_current_pos(double *cp);
         void get_sd_play_info();
         const char* get_status();
         
+        bool speed_changed;
         int hotendtemp;
         int hotendtarget;
         int bedtemp;