#include "AppendFileStream.h"
#include "stdio.h"
-int AppendFileStream::puts(const char*str)
+int AppendFileStream::puts(const char *str)
{
- FILE *fd= fopen(this->fn.c_str(), "a");
+ FILE *fd= fopen(this->fn, "a");
if(fd == NULL) return 0;
int n= fwrite(str, 1, strlen(str), fd);
#ifndef _APPENDFILESTREAM_H_
#define _APPENDFILESTREAM_H_
-#include <string>
#include "StreamOutput.h"
+#include "string.h"
+#include "stdlib.h"
class AppendFileStream : public StreamOutput {
public:
- AppendFileStream(const char *filename){ fn= filename; }
+ AppendFileStream(const char *filename) { fn= strdup(filename); }
+ virtual ~AppendFileStream(){ free(fn); }
int puts(const char*);
private:
- std::string fn;
+ char *fn;
};
#endif
--- /dev/null
+#ifndef _FILESTREAM_H_
+#define _FILESTREAM_H_
+
+#include "StreamOutput.h"
+#include "stdlib.h"
+
+class FileStream : public StreamOutput {
+ public:
+ FileStream(const char *filename) { fd= fopen(filename, "a"); }
+ virtual ~FileStream(){ close(); }
+ int puts(const char *str){ return (fd == NULL) ? 0 : fwrite(str, 1, strlen(str), fd); }
+ void close() { if(fd != NULL) fclose(fd); fd= NULL; }
+
+ private:
+ FILE *fd;
+};
+
+#endif
#include "modules/robot/Conveyor.h"
#include "libs/SerialMessage.h"
#include "libs/StreamOutput.h"
-#include "libs/AppendFileStream.h"
+#include "libs/FileStream.h"
GcodeDispatch::GcodeDispatch() {}
case 500: // M500 save volatile settings to config-override
// delete the existing file
remove(kernel->config_override_filename());
- // replace stream with one that appends to config-override file
- gcode->stream = new AppendFileStream(kernel->config_override_filename());
+ // replace stream with one that writes to config-override file
+ gcode->stream = new FileStream(kernel->config_override_filename());
// dispatch the M500 here so we can free up the stream when done
this->kernel->call_event(ON_GCODE_RECEIVED, gcode );
delete gcode->stream;
}else if (gcode->m == 500 || gcode->m == 503){// M500 saves some volatile settings to config override file, M503 just prints the settings
gcode->stream->printf(";E Steps per mm:\nM92 E%1.4f\n", this->steps_per_millimeter);
gcode->mark_as_taken();
+ return;
}
}