Fix some bugs
authorJim Morris <morris@wolfman.com>
Thu, 10 Apr 2014 08:55:58 +0000 (01:55 -0700)
committerJim Morris <morris@wolfman.com>
Thu, 10 Apr 2014 08:55:58 +0000 (01:55 -0700)
regain 4k by not using fstream
shorten lines in config example
max config line is now 132, it is truncated if longer

ConfigSamples/Smoothieboard/config
src/libs/ConfigSource.h
src/libs/ConfigSources/FileConfigSource.cpp
src/libs/ConfigSources/FileConfigSource.h
src/libs/Kernel.cpp

index d77a3f9..aee2fb3 100644 (file)
@@ -1,8 +1,12 @@
+# NOTE Lines must not exceed 132 characters
 # Robot module configurations : general handling of movement G-codes and slicing into moves
 default_feed_rate                            4000             # Default rate ( mm/minute ) for G1/G2/G3 moves
 default_seek_rate                            4000             # Default rate ( mm/minute ) for G0 moves
-mm_per_arc_segment                           0.5              # Arcs are cut into segments ( lines ), this is the length for these segments.  Smaller values mean more resolution, higher values mean faster computation
-mm_per_line_segment                          5                # Lines can be cut into segments ( not usefull with cartesian coordinates robots ).
+mm_per_arc_segment                           0.5              # Arcs are cut into segments ( lines ), this is the length for 
+                                                              # these segments.  Smaller values mean more resolution, 
+                                                              # higher values mean faster computation
+mm_per_line_segment                          5                # Lines can be cut into segments ( not usefull with cartesian
+                                                              # coordinates robots ).
 
 # Arm solution configuration : Cartesian robot. Translates mm positions into stepper positions
 alpha_steps_per_mm                           80               # Steps per mm for alpha stepper
@@ -10,11 +14,14 @@ beta_steps_per_mm                            80               # Steps per mm for
 gamma_steps_per_mm                           1600             # Steps per mm for gamma stepper
 
 # Planner module configuration : Look-ahead and acceleration configuration
-planner_queue_size                           32               # Size of the planning queue DO NOT CHANGE THIS UNLESS YOU KNOW EXACLTY WHAT YOU ARE DOING
+planner_queue_size                           32               # DO NOT CHANGE THIS UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING
 acceleration                                 3000             # Acceleration in mm/second/second.
 acceleration_ticks_per_second                1000             # Number of times per second the speed is updated
-junction_deviation                           0.05             # Similar to the old "max_jerk", in millimeters, see : https://github.com/grbl/grbl/blob/master/planner.c#L409
-                                                              # and https://github.com/grbl/grbl/wiki/Configuring-Grbl-v0.8 . Lower values mean being more careful, higher values means being faster and have more jerk
+junction_deviation                           0.05             # Similar to the old "max_jerk", in millimeters, 
+                                                              # see https://github.com/grbl/grbl/blob/master/planner.c#L409
+                                                              # and https://github.com/grbl/grbl/wiki/Configuring-Grbl-v0.8
+                                                              # Lower values mean being more careful, higher values means being
+                                                              # faster and have more jerk
 #minimum_planner_speed                       0.0              # sets the minimum planner speed in mm/sec
 
 # Stepper module configuration
@@ -48,12 +55,14 @@ gamma_max_rate                               300.0            # mm/min
 
 # Serial communications configuration ( baud rate default to 9600 if undefined )
 uart0.baud_rate                              115200           # Baud rate for the default hardware serial port
-second_usb_serial_enable                     false            # This enables a second usb serial port (to have both pronterface and a terminal connected)
+second_usb_serial_enable                     false            # This enables a second usb serial port (to have both pronterface 
+                                                              # and a terminal connected)
 #leds_disable                                true             # disable using leds after config loaded
 
 
 # Extruder module configuration
-extruder_module_enable                       true             # Whether to activate the extruder module at all. All configuration is ignored if false
+extruder_module_enable                       true             # Whether to activate the extruder module at all. All configuration
+                                                              # is ignored if false
 extruder_steps_per_mm                        140              # Steps per mm for extruder stepper
 extruder_default_feed_rate                   600              # Default rate ( mm/minute ) for moves where only the extruder moves
 extruder_acceleration                        50               # Acceleration for the stepper motor, as of 0.6, arbitrary ratio
@@ -65,17 +74,22 @@ extruder_en_pin                              0.21             # Pin for extruder
 delta_current                                1.5              # Extruder stepper motor current
 
 # Laser module configuration
-laser_module_enable                          false            # Whether to activate the laser module at all. All configuration is ignored if false.
-#laser_module_pin                             2.5              # this pin will be PWMed to control the laser. Only P2.0 - P2.5 can be used since laser requires hardware PWM
-#laser_module_max_power                       0.8              # this is the maximum duty cycle that will be applied to the laser
-#laser_module_tickle_power                    0.0              # this duty cycle will be used for travel moves to keep the laser active without actually burning
-#laser_module_pwm_period                      20               # this sets the pwm frequency, the value is the period in microseconds
+laser_module_enable                          false            # Whether to activate the laser module at all. All configuration is 
+                                                              # ignored if false.
+#laser_module_pin                             2.5             # this pin will be PWMed to control the laser. Only P2.0 - P2.5 
+                                                              # can be used since laser requires hardware PWM
+#laser_module_max_power                       0.8             # this is the maximum duty cycle that will be applied to the laser
+#laser_module_tickle_power                    0.0             # this duty cycle will be used for travel moves to keep the laser 
+                                                              # active without actually burning
+#laser_module_pwm_period                      20              # this sets the pwm frequency as the period in microseconds
 
 # Hotend temperature control configuration
-temperature_control.hotend.enable            true             # Whether to activate this ( "hotend" ) module at all. All configuration is ignored if false.
+temperature_control.hotend.enable            true             # Whether to activate this ( "hotend" ) module at all. 
+                                                              # All configuration is ignored if false.
 temperature_control.hotend.thermistor_pin    0.23             # Pin for the thermistor to read
 temperature_control.hotend.heater_pin        2.7              # Pin that controls the heater
-temperature_control.hotend.thermistor        EPCOS100K        # see src/modules/tools/temperaturecontrol/TemperatureControl.cpp:64 for a list of valid thermistor names
+temperature_control.hotend.thermistor        EPCOS100K        # see src/modules/tools/temperaturecontrol/TemperatureControl.cpp:64
+                                                              # for a list of valid thermistor names
 temperature_control.hotend.set_m_code        104              #
 temperature_control.hotend.set_and_wait_m_code 109            #
 temperature_control.hotend.designator        T                #
@@ -84,18 +98,20 @@ temperature_control.hotend.designator        T                #
 #temperature_control.hotend.i_factor         0.097            #
 #temperature_control.hotend.d_factor         24               #
 
-#temperature_control.hotend.max_pwm          64               # override max pwm, 64 is a good value if driving a 12v resistor with 24v.
+#temperature_control.hotend.max_pwm          64               # max pwm, 64 is a good value if driving a 12v resistor with 24v.
 
 temperature_control.bed.enable               true             #
 temperature_control.bed.thermistor_pin       0.24             #
 temperature_control.bed.heater_pin           2.5              #
-temperature_control.bed.thermistor           Honeywell100K    # see src/modules/tools/temperaturecontrol/TemperatureControl.cpp:64 for a list of valid thermistor names
+temperature_control.bed.thermistor           Honeywell100K    # see src/modules/tools/temperaturecontrol/TemperatureControl.cpp:64
+                                                              # for a list of valid thermistor names
 temperature_control.bed.set_m_code           140              #
 temperature_control.bed.set_and_wait_m_code  190              #
 temperature_control.bed.designator           B                #
 
-#temperature_control.bed.bang_bang            false            # set to true to use bang bang control rather than PID
-#temperature_control.bed.hysteresis           2.0              # set to the temperature in degrees C to use as hysteresis when using bang bang
+#temperature_control.bed.bang_bang            false           # set to true to use bang bang control rather than PID
+#temperature_control.bed.hysteresis           2.0             # set to the temperature in degrees C to use as hysteresis
+                                                              # when using bang bang
 
 # Switch module for fan control
 switch.fan.enable                            true             #
@@ -151,7 +167,7 @@ pause_button_enable                          true             #
 
 # Panel
 panel.enable                                 false             # set to true to enable the panel code
-panel.lcd                                    smoothiepanel     # set type of panel also viki_lcd, i2c_lcd is a generic i2c panel, panelolu2
+panel.lcd                                    smoothiepanel     # set type of panel 
 panel.encoder_a_pin                          3.25!^            # encoder pin
 panel.encoder_b_pin                          3.26!^            # encoder pin
 
index b5f9a9c..134b487 100644 (file)
@@ -25,11 +25,10 @@ class ConfigSource {
         virtual void write( string setting, string value ) = 0;
         virtual string read( uint16_t check_sums[3] ) = 0;
 
-        uint16_t name_checksum;
-
     protected:
         virtual string process_line_from_ascii_config(const string& line, ConfigCache* cache);
         virtual string process_line_from_ascii_config(const string& line, uint16_t line_checksums[3]);
+        uint16_t name_checksum;
 
     private:
         ConfigValue* process_line(const string &buffer);
index 997d55a..df4b27f 100644 (file)
@@ -14,8 +14,7 @@
 
 using namespace std;
 #include <string>
-#include <fstream>
-#include <stdio.h>
+#include <string.h>
 
 FileConfigSource::FileConfigSource(string config_file, const char *name)
 {
@@ -24,22 +23,42 @@ FileConfigSource::FileConfigSource(string config_file, const char *name)
     this->config_file_found = false;
 }
 
+bool FileConfigSource::readLine(string& line, FILE *fp)
+{
+    char buf[132];
+    char *l= fgets(buf, sizeof(buf)-1, fp);
+    if(l != NULL) {
+        if(buf[strlen(l)-1] != '\n') {
+            // truncate long lines
+            printf("Truncated long line in: %s\n", config_file.c_str());
+            // read until the next \n or eof
+            int c;
+            while((c=fgetc(fp)) != '\n' && c != EOF) /* discard */;
+        }
+        line.assign(buf);
+        return true;
+    }
+
+    return false;
+}
+
 // Transfer all values found in the file to the passed cache
 void FileConfigSource::transfer_values_to_cache( ConfigCache *cache )
 {
-
     if( !this->has_config_file() ) {
         return;
     }
     // Open the config file ( find it if we haven't already found it )
-    std::ifstream ifs(this->get_config_file().c_str(), std::ifstream::in);
+    FILE *lp = fopen(this->get_config_file().c_str(), "r");
+
     // For each line
-    string line;
-    while(ifs.good()) {
-        std::getline(ifs, line);
-        process_line_from_ascii_config(line, cache);
+    while(!feof(lp)) {
+        string line;
+        if(readLine(line, lp)) {
+            process_line_from_ascii_config(line, cache);
+        }else break;
     }
-    ifs.close();
+    fclose(lp);
 }
 
 // Return true if the check_sums match
@@ -111,15 +130,16 @@ string FileConfigSource::read( uint16_t check_sums[3] )
     }
 
     // Open the config file ( find it if we haven't already found it )
-    std::ifstream ifs(this->get_config_file().c_str(), std::ifstream::in);
+    FILE *lp = fopen(this->get_config_file().c_str(), "r");
     // For each line
-    string line;
-    while(ifs.good()) {
-        std::getline(ifs, line);
-        value = process_line_from_ascii_config(line, check_sums);
-        if(!value.empty()) break; // found it
+    while(!feof(lp)) {
+        string line;
+         if(readLine(line, lp)) {
+            value = process_line_from_ascii_config(line, check_sums);
+            if(!value.empty()) break; // found it
+        }else break;
     }
-    ifs.close();
+    fclose(lp);
 
     return value;
 }
index a535e96..c799ecd 100644 (file)
@@ -14,6 +14,7 @@ class ConfigCache;
 
 using namespace std;
 #include <string>
+#include <stdio.h>
 
 class FileConfigSource : public ConfigSource
 {
@@ -28,6 +29,7 @@ public:
     string get_config_file();
 
 private:
+    bool readLine(string& line, FILE *fp);
     string config_file;         // Path to the config file
     bool   config_file_found;   // Wether or not the config file's location is known
 };
index 2fa961e..c105410 100644 (file)
@@ -43,11 +43,12 @@ Kernel::Kernel(){
     instance= this; // setup the Singleton instance of the kernel
 
     // serial first at fixed baud rate (MRI_BAUD) so config can report errors to serial
-    this->serial = new SerialConsole(USBTX, USBRX, 115200); // TODO set to whatver MRI is
+    this->serial = new SerialConsole(USBTX, USBRX, 115200); // TODO set to whatever MRI is
 
     // Config next, but does not load cache yet
     this->config         = new Config();
-    // Pre-load the config cache, do after ssetting up serial so we can report errors to serial
+
+    // Pre-load the config cache, do after setting up serial so we can report errors to serial
     this->config->config_cache_load();
 
     // now config is loaded we can do normal setup for serial and the rest