Commits

F Malpartida  committed 4bdc104

MMI improvements:
- bargraph for fan speed
- always start the to at least 20% of max capability
- added splash screen
- display position (X, Y) and then (Z, Feed rate).

Improved debug capabilities:
- show used RAM during power up

Cleaned compilation warning and initialized variable to avoid using it un-initialised

Corrected bug when using relative coordinates.

  • Participants
  • Parent commits 8dd91b5
  • Tags V 1.0.5

Comments (0)

Files changed (7)

 #include <lm75.h>
 #endif // _TEMP_CONTROL_ENABLED_
 
+
 // Variable and object declarations
 // ---------------------------------------------------------------------------
 
 #endif // _TEMP_CONTROL_ENABLED_
 
 #ifdef _MMI_ENABLED_
-LiquidCrystal_I2C lcd(0x38);  // Set the LCD I2C address
+LiquidCrystal_I2C lcd(0x38);      // Set the LCD I2C address
 mmi               myMMI;
 #endif // _MMI_ENABLED_
 
-stepperCntrl      machController;
+stepperCntrl      machController; // machine controller
 
+
+// Initialize the system and electronics
+// ----------------------------------------------------------------------------
 void setup()
 {
    // Initialise all the electronics
 #endif // _MMI_ENABLED_
 }
 
+
+// Main application control thread
+// ----------------------------------------------------------------------------
 void loop()
 {
    static int counter = 0;
 #define _CONFIG_ME_H_
 
 
-#define FRMW_VERSION "1.0.4"
+#define FRMW_VERSION (F("1.0.5"))
 
 // FEATURE CONFIGURATION
 // ---------------------------------------------------------------------------
  
  (ENABLE ME) by removing the comment of the define.
  */
-#define _MMI_ENABLED_
+//#define _MMI_ENABLED_
 
 /*!
  @defined    _TEMP_CONTROL_ENABLED_
 
  (ENABLE ME) by removing the comment of the define.
  */
-#define _TEMP_CONTROL_ENABLED_
+//#define _TEMP_CONTROL_ENABLED_
+
+// Define debug capability. Only for debugging
+//#define _DEBUG_
 
 
 // CONTANT DEFINITIONS AND MACROS
 #define MAX(A,B)   ( (A) > (B) ) ? (A) : (B)
 
 
+
 // THREAD CONFIGURATON - machine parameters
 // ---------------------------------------------------------------------------
 #define MM_PER_INCH      (25.4)
 
 // Temperature control constants for fan speed
 // ---------------------------------------------------------------------------
-#define MAX_SPEED      255   // Maximum fan speed
+#define MIN_FAN_SPEED  60    // Minimum fan speed
+#define MAX_FAN_SPEED  255   // Maximum fan speed
 #define MAX_TEMP       35.0  // Maximum temperature for full speed fan speed
 #define START_TEMP     25.0  // Minimum temperature for fan to start control.
 
 #include "tempCntrl.h"
 #include "stepperCntrl.h"
 
+
+extern unsigned int __bss_end;
+extern unsigned int __heap_start;
+extern void *__brkval;
+
+#define CHAR_WIDTH   5
+
+
+
+/*!
+ @function
+ @abstract   Return available RAM memory
+ @discussion This routine returns the ammount of RAM memory available after
+ initialising the C runtime.
+ @param
+ @result     Free RAM available.
+ */
+static int freeMemory()
+{
+   int free_memory;
+   
+   if((int)__brkval == 0)
+      free_memory = ((int)&free_memory) - ((int)&__bss_end);
+   else
+      free_memory = ((int)&free_memory) - ((int)__brkval);
+   
+   return free_memory;
+}
+
+/*!
+ @function
+ @abstract   Load bitmaps into the LCD
+ @discussion This loads into the LCD a predefined set of new characters
+ from position 0.
+ @param      myLCD: LCD object in which to load the character map.
+ @result     Free RAM available.
+ */
+static void loadCharMap ( LCD *myLCD )
+{
+   /*!
+    @const      charBitmap
+    @abstract   Define Character bitmap for the bargraph.
+    @discussion Defines a character bitmap to represent a bargraph on a text
+    display. The bitmap goes from a blank character to full black.
+    */
+   const uint8_t charBitmap[][8] = {
+      { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
+      { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0 },
+      { 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0 },
+      { 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x0 },
+      { 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x0 },
+      { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0 },
+      { 0xe, 0x11, 0x11, 0x11, 0xe, 0, 0, 0 },
+      { 0x6, 0x9, 0x9, 0x6, 0x0, 0, 0, 0}
+   };
+   
+   uint8_t charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));
+   
+   for ( uint8_t i = 0; i < charBitmapSize; i++ )
+   {
+      myLCD->createChar ( i, (uint8_t *)charBitmap[i] );
+   }
+   
+}
+
+/*!
+ @function
+ @abstract   Print splash screen
+ @discussion Prints the powerup splash screen for 2 seconds 
+ @param      myLCD: LCD object where to print the Splash screen.
+ @result
+ */
+static void printSplash ( LCD *lcd )
+{
+   // Print splash screen
+   lcd->setCursor ( 0, 0 );
+   lcd->print ( F("Firmware: ELFCNC") );
+   lcd->setCursor ( 0, 1 );
+   lcd->print ( F("Version: ") );
+   lcd->print ( FRMW_VERSION );
+   delay ( 2000 );
+   lcd->clear ();
+#ifdef _DEBUG_
+   lcd->print ( F("Free mem:"));
+   lcd->print ( freeMemory() );
+   delay ( 2000 );
+#endif
+}
+
+
+static void drawBars ( LCD *myLCD, int value, uint8_t row, uint8_t barLength, char start,
+                       char end )
+{
+   int numBars;
+   
+   // Set initial titles on the display
+   myLCD->setCursor (7, row);
+   myLCD->print ( "Fn" );
+   myLCD->print (start);
+   
+   // Calculate the size of the bar
+   value = map ( value, 0, 255, 0, ( barLength ) * CHAR_WIDTH );
+   numBars = value / CHAR_WIDTH;
+   
+   // Limit the size of the bargraph to barLength
+   if ( numBars > barLength )
+   {
+      numBars = barLength;
+   }
+   myLCD->setCursor ( 8 + 2, row );
+   
+   // Draw the bars
+   while ( numBars-- )
+   {
+      myLCD->print ( char( 5 ) );
+   }
+   
+   // Draw the fractions
+   numBars = value % CHAR_WIDTH;
+   myLCD->print ( char(numBars) );
+   myLCD->setCursor (barLength + 8 + 2, row);
+   myLCD->print (end);
+
+   //@TODO: clean a bit the column position, right now it is a bit of a hack.
+}
+
+
 // CLASS CONSTRUCTORS
 // ---------------------------------------------------------------------------
 // Constructor
    _machCntrl = controller;
    _init      = true;
    
+   loadCharMap ( lcd );
+   printSplash ( lcd );
+   
 }
 #else
 void mmi::init ( LCD *lcd, stepperCntrl *controller )
    _machCntrl = controller;
    _init      = true;
    
+   loadCharMap ( lcd );
+   printSplash ( lcd );
 }
 #endif // _TEMP_CONTROL_ENABLED_
 
 // LCD rendering
 void mmi::display ( void )
 {
-   uint8_t speed;
+   uint8_t                    speed;
    stepperCntrl::t_floatPoint pos;
+   static uint8_t             counter = 0;
+   
+   _lcd->clear();
    
 #ifdef _TEMP_CONTROL_ENABLED_  
    speed = _tempCont->speedGet();
    _lcd->setCursor ( 0,0 );
    _lcd->print ( "T:" );
    _lcd->print ( _tempCont->tempGet(), 1 );
-   _lcd->print ("    S:");
-   _lcd->print ( speed/100 );
-   _lcd->print ( (speed % 100)/10 );
-   _lcd->print ( (speed % 10) );
+   
+   drawBars ( _lcd, speed, 0, 5, '[', ']' );
 #endif
    
    pos = _machCntrl->getPosition ();
+
    _lcd->setCursor ( 0, 1 );
-   _lcd->print (pos.x, 2);
-   _lcd->print (" ");
-   _lcd->print (pos.y, 2);
-   _lcd->print (" ");
-   _lcd->print (pos.z, 1);
-   _lcd->print (" ");
+   if ( counter % 4 )
+   {
+      _lcd->print ("X:");
+      _lcd->print (pos.x, 2);
+      _lcd->print (" ");
+      _lcd->print ("Y:");
+      _lcd->print (pos.y, 2);
+   }
+   else
+   {
+      _lcd->print ("Z:");
+      _lcd->print (pos.z, 2);
+      _lcd->print (" ");
+      _lcd->print ("FR:");
+      _lcd->print (_machCntrl->getFeedRate());
+   }
+   counter++;
    
 #ifdef _DEBUG_
+#ifdef _TEMP_CONTROL_ENABLED_
    Serial.print ( _tempCont->tempGet(), 1 );
    Serial.println ( speed  );
-   
+#endif // _TEMP_CONTROL_ENABLED_
+   Serial.print ( freeMemory() );
    Serial.print (pos.x, 1);
    Serial.print (" ");
    Serial.print (pos.y, 1);
    Serial.print (" ");
    Serial.println (pos.z, 1);
-#endif
+#endif // _DEBUG_
 }
 #endif // _MMI_ENABLED_

File processGcode.cpp

 // processGcode
 void processGcode ( void )
 {
-   char c;
+   char       c = 0;
    static int no_data = 0;
    
    // read in characters if they are available on serial line.
                myController->setFeedRate(search_string('F', instruction, size));
             }
             
-            fp = myController->getPosition();
+            // If in absolute coordinates get the current position and get the
+            // new coordinates
+            // ---------------------------------------------------------------
+            if ( myController->absoluteCoord () )
+            {
+               fp = myController->getPosition();
+            }
             
             // Extract the new coordinates received to get the new position
             // the controller should handle the coordinate reference.

File stepperCntrl.cpp

 
 void stepperCntrl::setTarget(float x, float y, float z)
 {
+   // Set new position based on configuration
+   // ---------------------------------------
    if ( _absMode )
    {
       _target_units.x = x;
    _feedRate = feedrate;
 }
 
+long stepperCntrl::getFeedRate ( void )
+{
+   return ( _feedRate );
+}
+
 // Setters and getters.
 void stepperCntrl::setCurveSection ( float curveSection )
 {

File stepperCntrl.h

     @abstract   Returns the machine maximum speed in mm per minute.
     @result     Returns the machine's maximum speed capabibility in mm per min.
     */
-   long  getMaxSpeed();
+   long  getMaxSpeed( void );
    
    /*!
     @function
-    @abstract   Set the maching feed rate (movement speed)
+    @abstract   Set the machine feed rate (movement speed)
     @param      Speed rate at which the machine will move in mm per minute.
     */
    void  setFeedRate ( long feedDelay );
    
+   /*!
+    @function
+    @abstract   Get the machine feed rate (movement speed)
+    @param      Speed rate at which the machine will move in mm per minute.
+    */
+   long getFeedRate ( void );
+   
    // Machine movement methods
    /*!
     @function

File tempCntrl.cpp

  @abstract   Proportional speed increment around temperature control window
  @discussion Fan speed increments based on temperature control window. 
  */
-#define TEMP_SPEED_INC (MAX_SPEED/(MAX_TEMP - START_TEMP))
+#define TEMP_SPEED_INC (MAX_FAN_SPEED/(MAX_TEMP - START_TEMP))
 
 // CLASS CONSTRUCTORS
 // ---------------------------------------------------------------------------
    // Temperature reading hight than maximum threshold
    if ( avrTemp > MAX_TEMP )
    {
-      _speed = MAX_SPEED;
+      _speed = MAX_FAN_SPEED;
       analogWrite ( FAN_PIN, _speed );
    }
    
    else if ( avrTemp > START_TEMP )
    {
       _speed = (avrTemp - START_TEMP) * TEMP_SPEED_INC;
+      
+      if ( _speed < MIN_FAN_SPEED )
+      {
+         _speed = MIN_FAN_SPEED;
+      }
       analogWrite ( FAN_PIN, _speed );
    }