Fix positive trim values for delta M666
authorJim Morris <morris@wolfman.com>
Wed, 2 Apr 2014 04:58:55 +0000 (21:58 -0700)
committerJim Morris <morris@wolfman.com>
Wed, 2 Apr 2014 05:00:23 +0000 (22:00 -0700)
Cleanup includes in PID autotuner
use fgets in play rather than reading one character at a time, optimization

src/main.cpp
src/modules/tools/endstops/Endstops.cpp
src/modules/tools/temperaturecontrol/PID_Autotuner.cpp
src/modules/tools/temperaturecontrol/PID_Autotuner.h
src/modules/tools/temperaturecontrol/TemperatureControl.h
src/modules/utils/player/Player.cpp
src/modules/utils/player/Player.h

index ca1eb04..6be92d7 100644 (file)
@@ -6,7 +6,6 @@
 */
 
 #include "libs/Kernel.h"
-\
 #include "modules/tools/laser/Laser.h"
 #include "modules/tools/extruder/ExtruderMaker.h"
 #include "modules/tools/temperaturecontrol/TemperatureControlPool.h"
index 2e67cae..f484b12 100644 (file)
@@ -276,7 +276,7 @@ void Endstops::do_homing(char axes_to_move)
                 if (this->trim[c - 'X'] < 0) inverted_dir = !inverted_dir;
                 this->feed_rate[c - 'X']= this->slow_rates[c - 'X'];
                 this->steppers[c - 'X']->set_speed(0);
-                this->steppers[c - 'X']->move(inverted_dir, this->trim[c - 'X']);
+                this->steppers[c - 'X']->move(inverted_dir, abs(this->trim[c - 'X']));
             }
         }
 
@@ -513,7 +513,7 @@ void Endstops::on_gcode_received(void *argument)
             break;
 
 
-            case 666: { // M666 - set trim for each axis in mm
+            case 666: { // M666 - set trim for each axis in mm, NB negative mm and positive steps trim is down
                 float mm[3];
                 trim2mm(mm);
 
index 368f53e..3349102 100644 (file)
@@ -1,10 +1,13 @@
 #include "PID_Autotuner.h"
 #include "Kernel.h"
-#include <cmath>        // std::abs
 #include "SlowTicker.h"
 #include "Gcode.h"
+#include "TemperatureControl.h"
+
+#include <cmath>        // std::abs
 
-#define DEBUG_PRINTF s->printf
+//#define DEBUG_PRINTF s->printf
+#define DEBUG_PRINTF(...)
 
 PID_Autotuner::PID_Autotuner()
 {
index fd22651..1729cc3 100644 (file)
@@ -8,8 +8,9 @@
 #include <stdint.h>
 
 #include "Module.h"
-#include "TemperatureControl.h"
-#include "StreamOutput.h"
+
+class TemperatureControl;
+class StreamOutput;
 
 class PID_Autotuner : public Module
 {
index 7d41283..e5b729e 100644 (file)
@@ -15,6 +15,7 @@
 
 #define QUEUE_LEN 8
 
+class Module;
 class TemperatureControlPool;
 
 class TemperatureControl : public Module {
index 43381f2..4da4c7e 100644 (file)
@@ -5,9 +5,9 @@
     You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include "Player.h"
 
 #include "libs/Kernel.h"
-#include "Player.h"
 #include "libs/nuts_bolts.h"
 #include "libs/utils.h"
 #include "SerialConsole.h"
@@ -280,36 +280,32 @@ void Player::on_main_loop(void* argument){
     }
 
     if( this->playing_file ){
-        string buffer;
+        char buf[130]; // lines upto 128 characters are allowed, anything longer is discarded
         bool discard= false;
-        int c;
-        buffer.reserve(20);
-        // Print each line of the file
-        while ((c = fgetc(this->current_file_handler)) != EOF){
-            if (c == '\n'){
-                if(discard) {
-                    // we hit a long line and discarded it
+
+        while(fgets(buf, sizeof(buf), this->current_file_handler) != NULL) {
+            int len= strlen(buf);
+            if(len == 0) continue; // empty line? should not be possible
+            if(buf[len-1] == '\n') {
+                if(discard) { // we are discarding a long line
                     discard= false;
-                    buffer.clear();
-                    this->current_stream->printf("Warning: Discarded long line\n");
-                    return;
+                    continue;
                 }
-                this->current_stream->printf("%s\n", buffer.c_str());
+                if(len == 1) continue; // empty line
+
+                this->current_stream->printf("%s", buf);
                 struct SerialMessage message;
-                message.message = buffer;
+                message.message = buf;
                 message.stream = &(StreamOutput::NullStream); // we don't really need to see the ok
                 // wait for the queue to have enough room that a serial message could still be received before sending
                 THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message);
-                played_cnt += buffer.size();
-                buffer.clear();
-                return;
-
-            }else if(buffer.size() > 128) {
-                // discard rest of line
-                discard= true;
+                played_cnt += len;
+                return; // we feed one line per main loop
 
             }else{
-                buffer += c;
+                // discard long line
+                this->current_stream->printf("Warning: Discarded long line\n");
+                discard= true;
             }
         }
 
index 256d0e4..c03269d 100644 (file)
@@ -9,11 +9,13 @@
 #ifndef PLAYER_H
 #define PLAYER_H
 
-#include "libs/Kernel.h"
-#include "libs/nuts_bolts.h"
-#include "libs/utils.h"
-#include "libs/StreamOutput.h"
+#include "Module.h"
 
+#include <stdio.h>
+#include <string>
+using std::string;
+
+class StreamOutput;
 
 class Player : public Module {
     public: