From 83e33bdd266e16ffaa322e664f67fdda3471f197 Mon Sep 17 00:00:00 2001 From: Bob Clough Date: Mon, 25 Feb 2013 14:01:48 +0000 Subject: [PATCH 01/31] Added LiquidCrystal_I2C library to ArduinoAddons --- ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal_I2C | 1 + ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal_I2C | 1 + 2 files changed, 2 insertions(+) create mode 160000 ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal_I2C create mode 160000 ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal_I2C diff --git a/ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal_I2C b/ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal_I2C new file mode 160000 index 0000000000..bfb71c8759 --- /dev/null +++ b/ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal_I2C @@ -0,0 +1 @@ +Subproject commit bfb71c87594ab904db9e41d9f57c6e2df89dc632 diff --git a/ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal_I2C b/ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal_I2C new file mode 160000 index 0000000000..bfb71c8759 --- /dev/null +++ b/ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal_I2C @@ -0,0 +1 @@ +Subproject commit bfb71c87594ab904db9e41d9f57c6e2df89dc632 From 06272f463d523a914a972e9b5ec1ef687c3f41c7 Mon Sep 17 00:00:00 2001 From: Bob Clough Date: Mon, 25 Feb 2013 14:14:46 +0000 Subject: [PATCH 02/31] Added Config variables for activating I2C LCDs and setting type and address --- Marlin/Configuration.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 9d1027a0fe..75dcc3cc4f 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -316,9 +316,9 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th // The RepRapDiscount Smart Controller (white PCB) // http://reprap.org/wiki/RepRapDiscount_Smart_Controller //#define REPRAP_DISCOUNT_SMART_CONTROLLER - -// The GADGETS3D G3D LCD/SD Controller (blue PCB) -// http://reprap.org/wiki/RAMPS_1.3/1.4_GADGETS3D_Shield_with_Panel + +// The GADGETS3D G3D LCD/SD Controller (blue PCB) +// http://reprap.org/wiki/RAMPS_1.3/1.4_GADGETS3D_Shield_with_Panel //#define G3D_PANEL //automatic expansion @@ -351,6 +351,15 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #endif #endif +//The LCD is attached via an I2C port expander. +//#define LCD_I2C +#ifdef LCD_I2C + // Port Expander Type - PCF8574 or MCP23008 + #define LCD_I2C_TYPE PCF8574 + // I2C Address of the port expander + #define LCD_I2C_ADDRESS 0x20 +#endif + // Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino //#define FAST_PWM_FAN From 2b567d1df55b9762f79736df7c9eb9f64e22cc73 Mon Sep 17 00:00:00 2001 From: Bob Clough Date: Mon, 25 Feb 2013 14:22:14 +0000 Subject: [PATCH 03/31] Added I2C port expander support to HD44780 --- Marlin/Configuration.h | 4 +-- .../ultralcd_implementation_hitachi_HD44780.h | 26 ++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 75dcc3cc4f..bd0ac931fb 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -354,8 +354,8 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th //The LCD is attached via an I2C port expander. //#define LCD_I2C #ifdef LCD_I2C - // Port Expander Type - PCF8574 or MCP23008 - #define LCD_I2C_TYPE PCF8574 + // Port Expander Type - 0=PCF8574 or 1=MCP23008 + #define LCD_I2C_TYPE 0 // I2C Address of the port expander #define LCD_I2C_ADDRESS 0x20 #endif diff --git a/Marlin/ultralcd_implementation_hitachi_HD44780.h b/Marlin/ultralcd_implementation_hitachi_HD44780.h index 1d19b7718d..526dd8df07 100644 --- a/Marlin/ultralcd_implementation_hitachi_HD44780.h +++ b/Marlin/ultralcd_implementation_hitachi_HD44780.h @@ -7,11 +7,16 @@ **/ #if LANGUAGE_CHOICE == 6 -#include "LiquidCrystalRus.h" -#define LCD_CLASS LiquidCrystalRus + #include "LiquidCrystalRus.h" + #define LCD_CLASS LiquidCrystalRus #else -#include -#define LCD_CLASS LiquidCrystal + #ifdef LCD_I2C + #include + #define LCD_CLASS LiquidCrystal_I2C + #else + #include + #define LCD_CLASS LiquidCrystal + #endif #endif /* Custom characters defined in the first 8 characters of the LCD */ @@ -25,7 +30,12 @@ #define LCD_STR_CLOCK "\x07" #define LCD_STR_ARROW_RIGHT "\x7E" /* from the default character set */ -LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7 +#ifdef LCD_I2C + LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT, LCD_I2C_TYPE); //address, columns, rows, type +#else + LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7 +#endif + static void lcd_implementation_init() { byte bedTemp[8] = @@ -111,7 +121,11 @@ static void lcd_implementation_init() B00000, B00000 }; //thanks Sonny Mounicou - lcd.begin(LCD_WIDTH, LCD_HEIGHT); + #ifdef LCD_I2C + lcd.init(); + #else + lcd.begin(LCD_WIDTH, LCD_HEIGHT); + #endif lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp); lcd.createChar(LCD_STR_DEGREE[0], degree); lcd.createChar(LCD_STR_THERMOMETER[0], thermometer); From b6209c86dd0890970a9bb041755a74dc88d62a0a Mon Sep 17 00:00:00 2001 From: Bob Clough Date: Mon, 25 Feb 2013 15:15:23 +0000 Subject: [PATCH 04/31] Added import of Wire Library to make I2C LCD support compilable --- Marlin/Marlin.pde | 7 ++++++- Marlin/ultralcd_implementation_hitachi_HD44780.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 5cd646e469..6602f6c862 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -34,7 +34,12 @@ #include "pins.h" #ifdef ULTRA_LCD -#include + #ifdef LCD_I2C + #include + #include + #else + #include + #endif #endif #if DIGIPOTSS_PIN > -1 diff --git a/Marlin/ultralcd_implementation_hitachi_HD44780.h b/Marlin/ultralcd_implementation_hitachi_HD44780.h index 526dd8df07..aa94b93ecc 100644 --- a/Marlin/ultralcd_implementation_hitachi_HD44780.h +++ b/Marlin/ultralcd_implementation_hitachi_HD44780.h @@ -11,6 +11,7 @@ #define LCD_CLASS LiquidCrystalRus #else #ifdef LCD_I2C + #include #include #define LCD_CLASS LiquidCrystal_I2C #else From 67710df9f3ac7921502f0444f4cc5621fbd645ce Mon Sep 17 00:00:00 2001 From: MendelMax Date: Tue, 26 Feb 2013 22:22:12 +0000 Subject: [PATCH 05/31] Made i2c mode wok with the hardware I am able to test (ywrobot / sainsmart i2c LCD 2004) Removed incorrect LiquidCrystal_I2C Library --- .../Arduino_0.xx/libraries/LiquidCrystal_I2C | 1 - .../Arduino_1.x.x/libraries/LiquidCrystal_I2C | 1 - Marlin/Configuration.h | 4 ++-- .../ultralcd_implementation_hitachi_HD44780.h | 24 +++++++++++++++---- 4 files changed, 22 insertions(+), 8 deletions(-) delete mode 160000 ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal_I2C delete mode 160000 ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal_I2C diff --git a/ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal_I2C b/ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal_I2C deleted file mode 160000 index bfb71c8759..0000000000 --- a/ArduinoAddons/Arduino_0.xx/libraries/LiquidCrystal_I2C +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bfb71c87594ab904db9e41d9f57c6e2df89dc632 diff --git a/ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal_I2C b/ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal_I2C deleted file mode 160000 index bfb71c8759..0000000000 --- a/ArduinoAddons/Arduino_1.x.x/libraries/LiquidCrystal_I2C +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bfb71c87594ab904db9e41d9f57c6e2df89dc632 diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index bd0ac931fb..d47b24cc46 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -354,10 +354,10 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th //The LCD is attached via an I2C port expander. //#define LCD_I2C #ifdef LCD_I2C - // Port Expander Type - 0=PCF8574 or 1=MCP23008 + // Port Expander Type - 0=PCF8574 sainsmart/ywrobot #define LCD_I2C_TYPE 0 // I2C Address of the port expander - #define LCD_I2C_ADDRESS 0x20 + #define LCD_I2C_ADDRESS 0x27 #endif // Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino diff --git a/Marlin/ultralcd_implementation_hitachi_HD44780.h b/Marlin/ultralcd_implementation_hitachi_HD44780.h index aa94b93ecc..81195d21e5 100644 --- a/Marlin/ultralcd_implementation_hitachi_HD44780.h +++ b/Marlin/ultralcd_implementation_hitachi_HD44780.h @@ -11,7 +11,19 @@ #define LCD_CLASS LiquidCrystalRus #else #ifdef LCD_I2C + #if LCD_I2C_TYPE = 0 + #define LCD_I2C_PIN_BL 3 + #define LCD_I2C_PIN_EN 2 + #define LCD_I2C_PIN_RW 1 + #define LCD_I2C_PIN_RS 0 + #define LCD_I2C_PIN_D4 4 + #define LCD_I2C_PIN_D5 5 + #define LCD_I2C_PIN_D6 6 + #define LCD_I2C_PIN_D7 7 + #endif + #include + #include #include #define LCD_CLASS LiquidCrystal_I2C #else @@ -32,7 +44,7 @@ #define LCD_STR_ARROW_RIGHT "\x7E" /* from the default character set */ #ifdef LCD_I2C - LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT, LCD_I2C_TYPE); //address, columns, rows, type + LCD_CLASS lcd(LCD_I2C_ADDRESS,LCD_I2C_PIN_EN,LCD_I2C_PIN_RW,LCD_I2C_PIN_RS,LCD_I2C_PIN_D4,LCD_I2C_PIN_D5,LCD_I2C_PIN_D6,LCD_I2C_PIN_D7); #else LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7 #endif @@ -122,11 +134,15 @@ static void lcd_implementation_init() B00000, B00000 }; //thanks Sonny Mounicou + #ifdef LCD_I2C - lcd.init(); - #else - lcd.begin(LCD_WIDTH, LCD_HEIGHT); + #ifdef LCD_I2C_PIN_BL + lcd.setBacklightPin(LCD_I2C_PIN_BL,POSITIVE); + lcd.setBacklight(HIGH); + #endif #endif + + lcd.begin(LCD_WIDTH, LCD_HEIGHT); lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp); lcd.createChar(LCD_STR_DEGREE[0], degree); lcd.createChar(LCD_STR_THERMOMETER[0], thermometer); From 1292d735baa8106996d7c2b545e0f4470624375d Mon Sep 17 00:00:00 2001 From: Robert F-C Date: Thu, 28 Feb 2013 02:04:51 +1100 Subject: [PATCH 06/31] Converge all I2C LCD branches (PANELOLU2, VIKI & PCF8575) This includes refactoring the buttons code to remove a large amount of non-pin dependent duplication from pins.h. --- Marlin/Configuration.h | 61 +- Marlin/Marlin.pde | 16 +- Marlin/Marlin_main.cpp | 22 +- Marlin/pins.h | 105 +- Marlin/ultralcd.cpp | 9 + Marlin/ultralcd.h | 21 +- .../ultralcd_implementation_hitachi_HD44780.h | 1205 ++++++++++------- 7 files changed, 765 insertions(+), 674 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index d47b24cc46..e88515b5ec 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -306,12 +306,21 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th // please keep turned on if you can. //#define EEPROM_CHITCHAT +// Preheat Constants +#define PLA_PREHEAT_HOTEND_TEMP 180 +#define PLA_PREHEAT_HPB_TEMP 70 +#define PLA_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + +#define ABS_PREHEAT_HOTEND_TEMP 240 +#define ABS_PREHEAT_HPB_TEMP 100 +#define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 + //LCD and SD support //#define ULTRA_LCD //general lcd support, also 16x2 //#define SDSUPPORT // Enable SD Card Support in Hardware Console //#define ULTIMAKERCONTROLLER //as available from the ultimaker online store. -//#define ULTIPANEL //the ultipanel as on thingiverse +#define ULTIPANEL //the ultipanel as on thingiverse // The RepRapDiscount Smart Controller (white PCB) // http://reprap.org/wiki/RepRapDiscount_Smart_Controller @@ -327,15 +336,42 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #define NEWPANEL #endif -// Preheat Constants -#define PLA_PREHEAT_HOTEND_TEMP 180 -#define PLA_PREHEAT_HPB_TEMP 70 -#define PLA_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 +// I2C PANELS -#define ABS_PREHEAT_HOTEND_TEMP 240 -#define ABS_PREHEAT_HPB_TEMP 100 -#define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 +#define LCD_I2C_SAINSMART_YWROBOT +#ifdef LCD_I2C_SAINSMART_YWROBOT + // This uses the LiquidCrystal_I2C library ( https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home ) + // Make sure it is placed in the Arduino libraries directory. + #define LCD_I2C_TYPE_PCF8575 + #define ULTIPANEL + #define NEWPANEL + #define LCD_I2C_ADDRESS 0x27 // I2C Address of the port expander +#endif +// PANELOLU2 LCD with status LEDs, separate encoder and click inputs +//#define LCD_I2C_PANELOLU2 +#ifdef LCD_I2C_PANELOLU2 + // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 ). + // Make sure it is placed in the Arduino libraries directory. + #define LCD_I2C_TYPE_MCP23017 + #define ULTIPANEL + #define NEWPANEL + #define LCD_I2C_ADDRESS 0x20 + #define LCD_HAS_I2C_BUZZ //comment out to disable buzzer on LCD + #define LCD_HAS_STATUS_INDICATORS +#endif + +// VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs +//#define LCD_I2C_VIKI +#ifdef LCD_I2C_VIKI + // This uses the LiquidTWI2 library (https://github.com/lincomatic/LiquidTWI2). + // Make sure it is placed in the Arduino libraries directory. + #define LCD_I2C_TYPE_MCP23017 + #define ULTIPANEL + #define NEWPANEL + #define LCD_I2C_ADDRESS 0x20 + #define LCD_HAS_STATUS_INDICATORS +#endif #ifdef ULTIPANEL // #define NEWPANEL //enable this if you have a click-encoder panel @@ -351,15 +387,6 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #endif #endif -//The LCD is attached via an I2C port expander. -//#define LCD_I2C -#ifdef LCD_I2C - // Port Expander Type - 0=PCF8574 sainsmart/ywrobot - #define LCD_I2C_TYPE 0 - // I2C Address of the port expander - #define LCD_I2C_ADDRESS 0x27 -#endif - // Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino //#define FAST_PWM_FAN diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 6602f6c862..93a6504cb6 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -36,7 +36,21 @@ #ifdef ULTRA_LCD #ifdef LCD_I2C #include - #include + #if defined(LCD_I2C_TYPE_PCF8575) + #include + #elif defined(LCD_I2C_TYPE_MCP23017) + #ifdef PANELOLU2 + #undef PANELOLU2 + #include + #ifndef PANELOLU2 + #error You must uncomment #define PANELOLU2 in LiquidTWI2.h for LiquidTWI2.cpp to compile correctly + #endif + #else + #include + #endif + #else + #error Unknown I2C LCD type + #endif #else #include #endif diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 39efdf4545..2f2d449c9c 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -124,7 +124,7 @@ // M500 - stores paramters in EEPROM // M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily). // M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to. -// M503 - print the current settings (from memory not from eeprom) +// M503 - print the current settings (from memory not from eeprom) // M540 - Use S[0|1] to enable or disable the stop SD card print on endstop hit (requires ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) // M600 - Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal] // M907 - Set digital trimpot motor current using axis codes. @@ -853,13 +853,13 @@ void process_commands() previous_millis_cmd = millis(); if (codenum > 0){ codenum += millis(); // keep track of when we started waiting - while(millis() < codenum && !LCD_CLICKED){ + while(millis() < codenum && !lcd_clicked()){ manage_heater(); manage_inactivity(); lcd_update(); } }else{ - while(!LCD_CLICKED){ + while(!lcd_clicked()){ manage_heater(); manage_inactivity(); lcd_update(); @@ -1499,13 +1499,13 @@ void process_commands() { Config_PrintSettings(); } - break; - #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED - case 540: - { - if(code_seen('S')) abort_on_endstop_hit = code_value() > 0; - } - break; + break; + #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED + case 540: + { + if(code_seen('S')) abort_on_endstop_hit = code_value() > 0; + } + break; #endif #ifdef FILAMENTCHANGEENABLE case 600: //Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal] @@ -1592,7 +1592,7 @@ void process_commands() delay(100); LCD_ALERTMESSAGEPGM(MSG_FILAMENTCHANGE); uint8_t cnt=0; - while(!LCD_CLICKED){ + while(!lcd_clicked()){ cnt++; manage_heater(); manage_inactivity(); diff --git a/Marlin/pins.h b/Marlin/pins.h index 41aae2e221..d81b3abb60 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -290,15 +290,6 @@ #define BTN_EN1 11 #define BTN_EN2 10 #define BTN_ENC 12 //the click - - #define BLEN_C 2 - #define BLEN_B 1 - #define BLEN_A 0 - - #define encrot0 0 - #define encrot1 2 - #define encrot2 3 - #define encrot3 1 #endif /**************************************************************************************** @@ -384,16 +375,6 @@ #ifdef ULTRA_LCD #ifdef NEWPANEL - //encoder rotation values - #define encrot0 0 - #define encrot1 2 - #define encrot2 3 - #define encrot3 1 - - #define BLEN_A 0 - #define BLEN_B 1 - #define BLEN_C 2 - #define LCD_PINS_RS 16 #define LCD_PINS_ENABLE 17 #define LCD_PINS_D4 23 @@ -427,7 +408,7 @@ #else //old style panel with shift register //arduino pin witch triggers an piezzo beeper - #define BEEPER 33 No Beeper added + #define BEEPER 33 // No Beeper added //buttons are attached to a shift register // Not wired this yet @@ -442,25 +423,6 @@ #define LCD_PINS_D5 25 #define LCD_PINS_D6 27 #define LCD_PINS_D7 29 - - //encoder rotation values - #define encrot0 0 - #define encrot1 2 - #define encrot2 3 - #define encrot3 1 - - - //bits in the shift register that carry the buttons for: - // left up center down right red - #define BL_LE 7 - #define BL_UP 6 - #define BL_MI 5 - #define BL_DW 4 - #define BL_RI 3 - #define BL_ST 2 - - #define BLEN_B 1 - #define BLEN_A 0 #endif #endif //ULTRA_LCD @@ -735,23 +697,12 @@ #define LCD_PINS_D7 27 //The encoder and click button - #define BTN_EN1 11 //must be a hardware interrupt pin - #define BTN_EN2 10 //must be hardware interrupt pin + #define BTN_EN1 11 + #define BTN_EN2 10 #define BTN_ENC 16 //the switch //not connected to a pin - #define SDCARDDETECT -1 - - //from the same bit in the RAMPS Newpanel define - //encoder rotation values - #define encrot0 0 - #define encrot1 2 - #define encrot2 3 - #define encrot3 1 - - #define BLEN_C 2 - #define BLEN_B 1 - #define BLEN_A 0 - + #define SDCARDDETECT -1 + #endif //Newpanel #endif //Ultipanel @@ -834,17 +785,8 @@ #define BTN_EN2 42 #define BTN_ENC 19 //the click - #define BLEN_C 2 - #define BLEN_B 1 - #define BLEN_A 0 - #define SDCARDDETECT 38 - //encoder rotation values - #define encrot0 0 - #define encrot1 2 - #define encrot2 3 - #define encrot3 1 #else //old style panel with shift register //arduino pin witch triggers an piezzo beeper #define BEEPER 18 @@ -861,33 +803,8 @@ #define LCD_PINS_D5 21 #define LCD_PINS_D6 20 #define LCD_PINS_D7 19 - - //encoder rotation values - #ifndef ULTIMAKERCONTROLLER - #define encrot0 0 - #define encrot1 2 - #define encrot2 3 - #define encrot3 1 - #else - #define encrot0 0 - #define encrot1 1 - #define encrot2 3 - #define encrot3 2 - - #endif - + #define SDCARDDETECT -1 - //bits in the shift register that carry the buttons for: - // left up center down right red - #define BL_LE 7 - #define BL_UP 6 - #define BL_MI 5 - #define BL_DW 4 - #define BL_RI 3 - #define BL_ST 2 - - #define BLEN_B 1 - #define BLEN_A 0 #endif #endif //ULTRA_LCD @@ -1455,17 +1372,7 @@ #define BTN_EN2 64 #define BTN_ENC 43 //the click - #define BLEN_C 2 - #define BLEN_B 1 - #define BLEN_A 0 - #define SDCARDDETECT -1 // Ramps does not use this port - - //encoder rotation values - #define encrot0 0 - #define encrot1 2 - #define encrot2 3 - #define encrot3 1 #endif #endif //ULTRA_LCD diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index db2d2766ca..8e223ed00f 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -714,6 +714,10 @@ void lcd_update() lcd_buttons_update(); + #ifdef LCD_HAS_EXTRA_BUTTONS + buttons |= lcd_read_extra_buttons(); // buttons which take too long to read in interrupt context + #endif + #if (SDCARDDETECT > -1) if((IS_SD_INSERTED != lcd_oldcardstatus)) { @@ -858,6 +862,11 @@ void lcd_buttons_update() } #endif//ULTIPANEL +bool lcd_clicked() +{ + return LCD_CLICKED; +} + /********************************/ /** Float conversion utilities **/ /********************************/ diff --git a/Marlin/ultralcd.h b/Marlin/ultralcd.h index df7746a1ab..40116d762b 100644 --- a/Marlin/ultralcd.h +++ b/Marlin/ultralcd.h @@ -20,7 +20,6 @@ #ifdef ULTIPANEL void lcd_buttons_update(); - extern volatile uint8_t buttons; //the last checked buttons in a bit array. #else FORCE_INLINE void lcd_buttons_update() {} #endif @@ -33,25 +32,7 @@ extern int absPreheatHPBTemp; extern int absPreheatFanSpeed; - #ifdef NEWPANEL - #define EN_C (1< - #include - #include - #define LCD_CLASS LiquidCrystal_I2C - #else - #include - #define LCD_CLASS LiquidCrystal - #endif -#endif - -/* Custom characters defined in the first 8 characters of the LCD */ -#define LCD_STR_BEDTEMP "\x00" -#define LCD_STR_DEGREE "\x01" -#define LCD_STR_THERMOMETER "\x02" -#define LCD_STR_UPLEVEL "\x03" -#define LCD_STR_REFRESH "\x04" -#define LCD_STR_FOLDER "\x05" -#define LCD_STR_FEEDRATE "\x06" -#define LCD_STR_CLOCK "\x07" -#define LCD_STR_ARROW_RIGHT "\x7E" /* from the default character set */ - -#ifdef LCD_I2C - LCD_CLASS lcd(LCD_I2C_ADDRESS,LCD_I2C_PIN_EN,LCD_I2C_PIN_RW,LCD_I2C_PIN_RS,LCD_I2C_PIN_D4,LCD_I2C_PIN_D5,LCD_I2C_PIN_D6,LCD_I2C_PIN_D7); -#else - LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7 -#endif - -static void lcd_implementation_init() -{ - byte bedTemp[8] = - { - B00000, - B11111, - B10101, - B10001, - B10101, - B11111, - B00000, - B00000 - }; //thanks Sonny Mounicou - byte degree[8] = - { - B01100, - B10010, - B10010, - B01100, - B00000, - B00000, - B00000, - B00000 - }; - byte thermometer[8] = - { - B00100, - B01010, - B01010, - B01010, - B01010, - B10001, - B10001, - B01110 - }; - byte uplevel[8]={ - B00100, - B01110, - B11111, - B00100, - B11100, - B00000, - B00000, - B00000 - }; //thanks joris - byte refresh[8]={ - B00000, - B00110, - B11001, - B11000, - B00011, - B10011, - B01100, - B00000, - }; //thanks joris - byte folder [8]={ - B00000, - B11100, - B11111, - B10001, - B10001, - B11111, - B00000, - B00000 - }; //thanks joris - byte feedrate [8]={ - B11100, - B10000, - B11000, - B10111, - B00101, - B00110, - B00101, - B00000 - }; //thanks Sonny Mounicou - byte clock [8]={ - B00000, - B01110, - B10011, - B10101, - B10001, - B01110, - B00000, - B00000 - }; //thanks Sonny Mounicou - - #ifdef LCD_I2C - #ifdef LCD_I2C_PIN_BL - lcd.setBacklightPin(LCD_I2C_PIN_BL,POSITIVE); - lcd.setBacklight(HIGH); - #endif - #endif - - lcd.begin(LCD_WIDTH, LCD_HEIGHT); - lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp); - lcd.createChar(LCD_STR_DEGREE[0], degree); - lcd.createChar(LCD_STR_THERMOMETER[0], thermometer); - lcd.createChar(LCD_STR_UPLEVEL[0], uplevel); - lcd.createChar(LCD_STR_REFRESH[0], refresh); - lcd.createChar(LCD_STR_FOLDER[0], folder); - lcd.createChar(LCD_STR_FEEDRATE[0], feedrate); - lcd.createChar(LCD_STR_CLOCK[0], clock); - lcd.clear(); -} -static void lcd_implementation_clear() -{ - lcd.clear(); -} -/* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */ -static void lcd_printPGM(const char* str) -{ - char c; - while((c = pgm_read_byte(str++)) != '\0') - { - lcd.write(c); - } -} -/* -Possible status screens: -16x2 |0123456789012345| - |000/000 B000/000| - |Status line.....| - -16x4 |0123456789012345| - |000/000 B000/000| - |SD100% Z000.0| - |F100% T--:--| - |Status line.....| - -20x2 |01234567890123456789| - |T000/000D B000/000D | - |Status line.........| - -20x4 |01234567890123456789| - |T000/000D B000/000D | - |X+000.0 Y+000.0 Z+000.0| - |F100% SD100% T--:--| - |Status line.........| - -20x4 |01234567890123456789| - |T000/000D B000/000D | - |T000/000D Z000.0| - |F100% SD100% T--:--| - |Status line.........| -*/ -static void lcd_implementation_status_screen() -{ - int tHotend=int(degHotend(0) + 0.5); - int tTarget=int(degTargetHotend(0) + 0.5); - -#if LCD_WIDTH < 20 - lcd.setCursor(0, 0); - lcd.print(itostr3(tHotend)); - lcd.print('/'); - lcd.print(itostr3left(tTarget)); - -# if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0 - //If we have an 2nd extruder or heated bed, show that in the top right corner - lcd.setCursor(8, 0); -# if EXTRUDERS > 1 - tHotend = int(degHotend(1) + 0.5); - tTarget = int(degTargetHotend(1) + 0.5); - lcd.print(LCD_STR_THERMOMETER[0]); -# else//Heated bed - tHotend=int(degBed() + 0.5); - tTarget=int(degTargetBed() + 0.5); - lcd.print(LCD_STR_BEDTEMP[0]); -# endif - lcd.print(itostr3(tHotend)); - lcd.print('/'); - lcd.print(itostr3left(tTarget)); -# endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0 - -#else//LCD_WIDTH > 19 - lcd.setCursor(0, 0); - lcd.print(LCD_STR_THERMOMETER[0]); - lcd.print(itostr3(tHotend)); - lcd.print('/'); - lcd.print(itostr3left(tTarget)); - lcd_printPGM(PSTR(LCD_STR_DEGREE " ")); - if (tTarget < 10) - lcd.print(' '); - -# if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0 - //If we have an 2nd extruder or heated bed, show that in the top right corner - lcd.setCursor(10, 0); -# if EXTRUDERS > 1 - tHotend = int(degHotend(1) + 0.5); - tTarget = int(degTargetHotend(1) + 0.5); - lcd.print(LCD_STR_THERMOMETER[0]); -# else//Heated bed - tHotend=int(degBed() + 0.5); - tTarget=int(degTargetBed() + 0.5); - lcd.print(LCD_STR_BEDTEMP[0]); -# endif - lcd.print(itostr3(tHotend)); - lcd.print('/'); - lcd.print(itostr3left(tTarget)); - lcd_printPGM(PSTR(LCD_STR_DEGREE " ")); - if (tTarget < 10) - lcd.print(' '); -# endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0 -#endif//LCD_WIDTH > 19 - -#if LCD_HEIGHT > 2 -//Lines 2 for 4 line LCD -# if LCD_WIDTH < 20 -# ifdef SDSUPPORT - lcd.setCursor(0, 2); - lcd_printPGM(PSTR("SD")); - if (IS_SD_PRINTING) - lcd.print(itostr3(card.percentDone())); - else - lcd_printPGM(PSTR("---")); - lcd.print('%'); -# endif//SDSUPPORT -# else//LCD_WIDTH > 19 -# if EXTRUDERS > 1 && TEMP_SENSOR_BED != 0 - //If we both have a 2nd extruder and a heated bed, show the heated bed temp on the 2nd line on the left, as the first line is filled with extruder temps - tHotend=int(degBed() + 0.5); - tTarget=int(degTargetBed() + 0.5); - - lcd.setCursor(0, 1); - lcd.print(LCD_STR_BEDTEMP[0]); - lcd.print(itostr3(tHotend)); - lcd.print('/'); - lcd.print(itostr3left(tTarget)); - lcd_printPGM(PSTR(LCD_STR_DEGREE " ")); - if (tTarget < 10) - lcd.print(' '); -# else - lcd.setCursor(0,1); - lcd.print('X'); - lcd.print(ftostr3(current_position[X_AXIS])); - lcd_printPGM(PSTR(" Y")); - lcd.print(ftostr3(current_position[Y_AXIS])); -# endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0 -# endif//LCD_WIDTH > 19 - lcd.setCursor(LCD_WIDTH - 8, 1); - lcd.print('Z'); - lcd.print(ftostr32(current_position[Z_AXIS])); -#endif//LCD_HEIGHT > 2 - -#if LCD_HEIGHT > 3 - lcd.setCursor(0, 2); - lcd.print(LCD_STR_FEEDRATE[0]); - lcd.print(itostr3(feedmultiply)); - lcd.print('%'); -# if LCD_WIDTH > 19 -# ifdef SDSUPPORT - lcd.setCursor(7, 2); - lcd_printPGM(PSTR("SD")); - if (IS_SD_PRINTING) - lcd.print(itostr3(card.percentDone())); - else - lcd_printPGM(PSTR("---")); - lcd.print('%'); -# endif//SDSUPPORT -# endif//LCD_WIDTH > 19 - lcd.setCursor(LCD_WIDTH - 6, 2); - lcd.print(LCD_STR_CLOCK[0]); - if(starttime != 0) - { - uint16_t time = millis()/60000 - starttime/60000; - lcd.print(itostr2(time/60)); - lcd.print(':'); - lcd.print(itostr2(time%60)); - }else{ - lcd_printPGM(PSTR("--:--")); - } -#endif - - //Status message line on the last line - lcd.setCursor(0, LCD_HEIGHT - 1); - lcd.print(lcd_status_message); -} -static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, char pre_char, char post_char) -{ - char c; - //Use all characters in narrow LCDs - #if LCD_WIDTH < 20 - uint8_t n = LCD_WIDTH - 1 - 1; - #else - uint8_t n = LCD_WIDTH - 1 - 2; - #endif - lcd.setCursor(0, row); - lcd.print(pre_char); - while((c = pgm_read_byte(pstr)) != '\0') - { - lcd.print(c); - pstr++; - n--; - } - while(n--) - lcd.print(' '); - lcd.print(post_char); - lcd.print(' '); -} -static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, char* data) -{ - char c; - //Use all characters in narrow LCDs - #if LCD_WIDTH < 20 - uint8_t n = LCD_WIDTH - 1 - 1 - strlen(data); - #else - uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data); - #endif - lcd.setCursor(0, row); - lcd.print(pre_char); - while((c = pgm_read_byte(pstr)) != '\0') - { - lcd.print(c); - pstr++; - n--; - } - lcd.print(':'); - while(n--) - lcd.print(' '); - lcd.print(data); -} -static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, const char* pstr, char pre_char, const char* data) -{ - char c; - //Use all characters in narrow LCDs - #if LCD_WIDTH < 20 - uint8_t n = LCD_WIDTH - 1 - 1 - strlen_P(data); - #else - uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data); - #endif - lcd.setCursor(0, row); - lcd.print(pre_char); - while((c = pgm_read_byte(pstr)) != '\0') - { - lcd.print(c); - pstr++; - n--; - } - lcd.print(':'); - while(n--) - lcd.print(' '); - lcd_printPGM(data); -} -#define lcd_implementation_drawmenu_setting_edit_int3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', itostr3(*(data))) -#define lcd_implementation_drawmenu_setting_edit_int3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', itostr3(*(data))) -#define lcd_implementation_drawmenu_setting_edit_float3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr3(*(data))) -#define lcd_implementation_drawmenu_setting_edit_float3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr3(*(data))) -#define lcd_implementation_drawmenu_setting_edit_float32_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr32(*(data))) -#define lcd_implementation_drawmenu_setting_edit_float32(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr32(*(data))) -#define lcd_implementation_drawmenu_setting_edit_float5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data))) -#define lcd_implementation_drawmenu_setting_edit_float5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data))) -#define lcd_implementation_drawmenu_setting_edit_float52_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr52(*(data))) -#define lcd_implementation_drawmenu_setting_edit_float52(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr52(*(data))) -#define lcd_implementation_drawmenu_setting_edit_float51_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr51(*(data))) -#define lcd_implementation_drawmenu_setting_edit_float51(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr51(*(data))) -#define lcd_implementation_drawmenu_setting_edit_long5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data))) -#define lcd_implementation_drawmenu_setting_edit_long5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data))) -#define lcd_implementation_drawmenu_setting_edit_bool_selected(row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF)) -#define lcd_implementation_drawmenu_setting_edit_bool(row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(row, pstr, ' ', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF)) -void lcd_implementation_drawedit(const char* pstr, char* value) -{ - lcd.setCursor(1, 1); - lcd_printPGM(pstr); - lcd.print(':'); - #if LCD_WIDTH < 20 - lcd.setCursor(LCD_WIDTH - strlen(value), 1); - #else - lcd.setCursor(LCD_WIDTH -1 - strlen(value), 1); - #endif - lcd.print(value); -} -static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename) -{ - char c; - uint8_t n = LCD_WIDTH - 1; - lcd.setCursor(0, row); - lcd.print('>'); - if (longFilename[0] != '\0') - { - filename = longFilename; - longFilename[LCD_WIDTH-1] = '\0'; - } - while((c = *filename) != '\0') - { - lcd.print(c); - filename++; - n--; - } - while(n--) - lcd.print(' '); -} -static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename) -{ - char c; - uint8_t n = LCD_WIDTH - 1; - lcd.setCursor(0, row); - lcd.print(' '); - if (longFilename[0] != '\0') - { - filename = longFilename; - longFilename[LCD_WIDTH-1] = '\0'; - } - while((c = *filename) != '\0') - { - lcd.print(c); - filename++; - n--; - } - while(n--) - lcd.print(' '); -} -static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename) -{ - char c; - uint8_t n = LCD_WIDTH - 2; - lcd.setCursor(0, row); - lcd.print('>'); - lcd.print(LCD_STR_FOLDER[0]); - if (longFilename[0] != '\0') - { - filename = longFilename; - longFilename[LCD_WIDTH-2] = '\0'; - } - while((c = *filename) != '\0') - { - lcd.print(c); - filename++; - n--; - } - while(n--) - lcd.print(' '); -} -static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename) -{ - char c; - uint8_t n = LCD_WIDTH - 2; - lcd.setCursor(0, row); - lcd.print(' '); - lcd.print(LCD_STR_FOLDER[0]); - if (longFilename[0] != '\0') - { - filename = longFilename; - longFilename[LCD_WIDTH-2] = '\0'; - } - while((c = *filename) != '\0') - { - lcd.print(c); - filename++; - n--; - } - while(n--) - lcd.print(' '); -} -#define lcd_implementation_drawmenu_back_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0]) -#define lcd_implementation_drawmenu_back(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_UPLEVEL[0]) -#define lcd_implementation_drawmenu_submenu_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', LCD_STR_ARROW_RIGHT[0]) -#define lcd_implementation_drawmenu_submenu(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_ARROW_RIGHT[0]) -#define lcd_implementation_drawmenu_gcode_selected(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ') -#define lcd_implementation_drawmenu_gcode(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ') -#define lcd_implementation_drawmenu_function_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ') -#define lcd_implementation_drawmenu_function(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ') - -static void lcd_implementation_quick_feedback() -{ -#if BEEPER > -1 - SET_OUTPUT(BEEPER); - for(int8_t i=0;i<10;i++) - { - WRITE(BEEPER,HIGH); - delay(3); - WRITE(BEEPER,LOW); - delay(3); - } -#endif -} -#endif//ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H +#ifndef ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H +#define ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H + +/** +* Implementation of the LCD display routines for a hitachi HD44780 display. These are common LCD character displays. +* When selecting the rusian language, a slightly different LCD implementation is used to handle UTF8 characters. +**/ + +// Declare LCD class to use +#if defined(LCD_I2C_TYPE_PCF8575) + // note: these are virtual pins on the PCF8575 controller not Arduino pins + #define LCD_I2C_PIN_BL 3 + #define LCD_I2C_PIN_EN 2 + #define LCD_I2C_PIN_RW 1 + #define LCD_I2C_PIN_RS 0 + #define LCD_I2C_PIN_D4 4 + #define LCD_I2C_PIN_D5 5 + #define LCD_I2C_PIN_D6 6 + #define LCD_I2C_PIN_D7 7 + + #include + #include + #include + #define LCD_CLASS LiquidCrystal_I2C + LCD_CLASS lcd(LCD_I2C_ADDRESS,LCD_I2C_PIN_EN,LCD_I2C_PIN_RW,LCD_I2C_PIN_RS,LCD_I2C_PIN_D4,LCD_I2C_PIN_D5,LCD_I2C_PIN_D6,LCD_I2C_PIN_D7); +#elif defined(LCD_I2C_TYPE_MCP23017) + //for the LED indicators (which maybe mapped to different things in lcd_implementation_update_indicators()) + #define LED_A 0x04 //100 + #define LED_B 0x02 //010 + #define LED_C 0x01 //001 + + #include + #include + #define LCD_CLASS LiquidTWI2 + LCD_CLASS lcd(LCD_I2C_ADDRESS); //An alternative I2C master address can be used in place of "0" +#elif defined(LCD_I2C_TYPE_MCP23008) + #include + #include + #define LCD_CLASS LiquidTWI2 + LCD_CLASS lcd(LCD_I2C_ADDRESS); //An alternative I2C master address can be used in place of "0" +#else + #if LANGUAGE_CHOICE == 6 + #include "LiquidCrystalRus.h" + #define LCD_CLASS LiquidCrystalRus + #else + #include + #define LCD_CLASS LiquidCrystal + #endif + LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7 +#endif + +extern volatile uint8_t buttons; //the last checked buttons in a bit array. + +// provide default button bitmask and encoder definitions (note this is not pin or motherboard specific) +#ifdef LCD_I2C_VIKI + //encoder rotation values + #define encrot0 0 + #define encrot1 2 + #define encrot2 3 + #define encrot3 1 + + #define BLEN_C 2 + #define BLEN_B 1 + #define BLEN_A 0 + + #define EN_C (1< 1 || TEMP_SENSOR_BED != 0 + //If we have an 2nd extruder or heated bed, show that in the top right corner + lcd.setCursor(8, 0); +# if EXTRUDERS > 1 + tHotend = int(degHotend(1) + 0.5); + tTarget = int(degTargetHotend(1) + 0.5); + lcd.print(LCD_STR_THERMOMETER[0]); +# else//Heated bed + tHotend=int(degBed() + 0.5); + tTarget=int(degTargetBed() + 0.5); + lcd.print(LCD_STR_BEDTEMP[0]); +# endif + lcd.print(itostr3(tHotend)); + lcd.print('/'); + lcd.print(itostr3left(tTarget)); +# endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0 + +#else//LCD_WIDTH > 19 + lcd.setCursor(0, 0); + lcd.print(LCD_STR_THERMOMETER[0]); + lcd.print(itostr3(tHotend)); + lcd.print('/'); + lcd.print(itostr3left(tTarget)); + lcd_printPGM(PSTR(LCD_STR_DEGREE " ")); + if (tTarget < 10) + lcd.print(' '); + +# if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0 + //If we have an 2nd extruder or heated bed, show that in the top right corner + lcd.setCursor(10, 0); +# if EXTRUDERS > 1 + tHotend = int(degHotend(1) + 0.5); + tTarget = int(degTargetHotend(1) + 0.5); + lcd.print(LCD_STR_THERMOMETER[0]); +# else//Heated bed + tHotend=int(degBed() + 0.5); + tTarget=int(degTargetBed() + 0.5); + lcd.print(LCD_STR_BEDTEMP[0]); +# endif + lcd.print(itostr3(tHotend)); + lcd.print('/'); + lcd.print(itostr3left(tTarget)); + lcd_printPGM(PSTR(LCD_STR_DEGREE " ")); + if (tTarget < 10) + lcd.print(' '); +# endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0 +#endif//LCD_WIDTH > 19 + +#if LCD_HEIGHT > 2 +//Lines 2 for 4 line LCD +# if LCD_WIDTH < 20 +# ifdef SDSUPPORT + lcd.setCursor(0, 2); + lcd_printPGM(PSTR("SD")); + if (IS_SD_PRINTING) + lcd.print(itostr3(card.percentDone())); + else + lcd_printPGM(PSTR("---")); + lcd.print('%'); +# endif//SDSUPPORT +# else//LCD_WIDTH > 19 +# if EXTRUDERS > 1 && TEMP_SENSOR_BED != 0 + //If we both have a 2nd extruder and a heated bed, show the heated bed temp on the 2nd line on the left, as the first line is filled with extruder temps + tHotend=int(degBed() + 0.5); + tTarget=int(degTargetBed() + 0.5); + + lcd.setCursor(0, 1); + lcd.print(LCD_STR_BEDTEMP[0]); + lcd.print(itostr3(tHotend)); + lcd.print('/'); + lcd.print(itostr3left(tTarget)); + lcd_printPGM(PSTR(LCD_STR_DEGREE " ")); + if (tTarget < 10) + lcd.print(' '); +# else + lcd.setCursor(0,1); + lcd.print('X'); + lcd.print(ftostr3(current_position[X_AXIS])); + lcd_printPGM(PSTR(" Y")); + lcd.print(ftostr3(current_position[Y_AXIS])); +# endif//EXTRUDERS > 1 || TEMP_SENSOR_BED != 0 +# endif//LCD_WIDTH > 19 + lcd.setCursor(LCD_WIDTH - 8, 1); + lcd.print('Z'); + lcd.print(ftostr32(current_position[Z_AXIS])); +#endif//LCD_HEIGHT > 2 + +#if LCD_HEIGHT > 3 + lcd.setCursor(0, 2); + lcd.print(LCD_STR_FEEDRATE[0]); + lcd.print(itostr3(feedmultiply)); + lcd.print('%'); +# if LCD_WIDTH > 19 +# ifdef SDSUPPORT + lcd.setCursor(7, 2); + lcd_printPGM(PSTR("SD")); + if (IS_SD_PRINTING) + lcd.print(itostr3(card.percentDone())); + else + lcd_printPGM(PSTR("---")); + lcd.print('%'); +# endif//SDSUPPORT +# endif//LCD_WIDTH > 19 + lcd.setCursor(LCD_WIDTH - 6, 2); + lcd.print(LCD_STR_CLOCK[0]); + if(starttime != 0) + { + uint16_t time = millis()/60000 - starttime/60000; + lcd.print(itostr2(time/60)); + lcd.print(':'); + lcd.print(itostr2(time%60)); + }else{ + lcd_printPGM(PSTR("--:--")); + } +#endif + + //Status message line on the last line + lcd.setCursor(0, LCD_HEIGHT - 1); + lcd.print(lcd_status_message); +#ifdef LCD_HAS_STATUS_INDICATORS + lcd_implementation_update_indicators(); +#endif +} +static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, char pre_char, char post_char) +{ + char c; + //Use all characters in narrow LCDs + #if LCD_WIDTH < 20 + uint8_t n = LCD_WIDTH - 1 - 1; + #else + uint8_t n = LCD_WIDTH - 1 - 2; + #endif + lcd.setCursor(0, row); + lcd.print(pre_char); + while((c = pgm_read_byte(pstr)) != '\0') + { + lcd.print(c); + pstr++; + n--; + } + while(n--) + lcd.print(' '); + lcd.print(post_char); + lcd.print(' '); +} +static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char* pstr, char pre_char, char* data) +{ + char c; + //Use all characters in narrow LCDs + #if LCD_WIDTH < 20 + uint8_t n = LCD_WIDTH - 1 - 1 - strlen(data); + #else + uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data); + #endif + lcd.setCursor(0, row); + lcd.print(pre_char); + while((c = pgm_read_byte(pstr)) != '\0') + { + lcd.print(c); + pstr++; + n--; + } + lcd.print(':'); + while(n--) + lcd.print(' '); + lcd.print(data); +} +static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, const char* pstr, char pre_char, const char* data) +{ + char c; + //Use all characters in narrow LCDs + #if LCD_WIDTH < 20 + uint8_t n = LCD_WIDTH - 1 - 1 - strlen_P(data); + #else + uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data); + #endif + lcd.setCursor(0, row); + lcd.print(pre_char); + while((c = pgm_read_byte(pstr)) != '\0') + { + lcd.print(c); + pstr++; + n--; + } + lcd.print(':'); + while(n--) + lcd.print(' '); + lcd_printPGM(data); +} +#define lcd_implementation_drawmenu_setting_edit_int3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', itostr3(*(data))) +#define lcd_implementation_drawmenu_setting_edit_int3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', itostr3(*(data))) +#define lcd_implementation_drawmenu_setting_edit_float3_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr3(*(data))) +#define lcd_implementation_drawmenu_setting_edit_float3(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr3(*(data))) +#define lcd_implementation_drawmenu_setting_edit_float32_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr32(*(data))) +#define lcd_implementation_drawmenu_setting_edit_float32(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr32(*(data))) +#define lcd_implementation_drawmenu_setting_edit_float5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data))) +#define lcd_implementation_drawmenu_setting_edit_float5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data))) +#define lcd_implementation_drawmenu_setting_edit_float52_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr52(*(data))) +#define lcd_implementation_drawmenu_setting_edit_float52(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr52(*(data))) +#define lcd_implementation_drawmenu_setting_edit_float51_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr51(*(data))) +#define lcd_implementation_drawmenu_setting_edit_float51(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr51(*(data))) +#define lcd_implementation_drawmenu_setting_edit_long5_selected(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, '>', ftostr5(*(data))) +#define lcd_implementation_drawmenu_setting_edit_long5(row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(row, pstr, ' ', ftostr5(*(data))) +#define lcd_implementation_drawmenu_setting_edit_bool_selected(row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF)) +#define lcd_implementation_drawmenu_setting_edit_bool(row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(row, pstr, ' ', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF)) +void lcd_implementation_drawedit(const char* pstr, char* value) +{ + lcd.setCursor(1, 1); + lcd_printPGM(pstr); + lcd.print(':'); + #if LCD_WIDTH < 20 + lcd.setCursor(LCD_WIDTH - strlen(value), 1); + #else + lcd.setCursor(LCD_WIDTH -1 - strlen(value), 1); + #endif + lcd.print(value); +} +static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename) +{ + char c; + uint8_t n = LCD_WIDTH - 1; + lcd.setCursor(0, row); + lcd.print('>'); + if (longFilename[0] != '\0') + { + filename = longFilename; + longFilename[LCD_WIDTH-1] = '\0'; + } + while((c = *filename) != '\0') + { + lcd.print(c); + filename++; + n--; + } + while(n--) + lcd.print(' '); +} +static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* pstr, const char* filename, char* longFilename) +{ + char c; + uint8_t n = LCD_WIDTH - 1; + lcd.setCursor(0, row); + lcd.print(' '); + if (longFilename[0] != '\0') + { + filename = longFilename; + longFilename[LCD_WIDTH-1] = '\0'; + } + while((c = *filename) != '\0') + { + lcd.print(c); + filename++; + n--; + } + while(n--) + lcd.print(' '); +} +static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* pstr, const char* filename, char* longFilename) +{ + char c; + uint8_t n = LCD_WIDTH - 2; + lcd.setCursor(0, row); + lcd.print('>'); + lcd.print(LCD_STR_FOLDER[0]); + if (longFilename[0] != '\0') + { + filename = longFilename; + longFilename[LCD_WIDTH-2] = '\0'; + } + while((c = *filename) != '\0') + { + lcd.print(c); + filename++; + n--; + } + while(n--) + lcd.print(' '); +} +static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pstr, const char* filename, char* longFilename) +{ + char c; + uint8_t n = LCD_WIDTH - 2; + lcd.setCursor(0, row); + lcd.print(' '); + lcd.print(LCD_STR_FOLDER[0]); + if (longFilename[0] != '\0') + { + filename = longFilename; + longFilename[LCD_WIDTH-2] = '\0'; + } + while((c = *filename) != '\0') + { + lcd.print(c); + filename++; + n--; + } + while(n--) + lcd.print(' '); +} +#define lcd_implementation_drawmenu_back_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0]) +#define lcd_implementation_drawmenu_back(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_UPLEVEL[0]) +#define lcd_implementation_drawmenu_submenu_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', LCD_STR_ARROW_RIGHT[0]) +#define lcd_implementation_drawmenu_submenu(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', LCD_STR_ARROW_RIGHT[0]) +#define lcd_implementation_drawmenu_gcode_selected(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ') +#define lcd_implementation_drawmenu_gcode(row, pstr, gcode) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ') +#define lcd_implementation_drawmenu_function_selected(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, '>', ' ') +#define lcd_implementation_drawmenu_function(row, pstr, data) lcd_implementation_drawmenu_generic(row, pstr, ' ', ' ') + +static void lcd_implementation_quick_feedback() +{ +#ifdef LCD_HAS_I2C_BUZZ + lcd.buzz(300,4000); +#elif defined(BEEPER) && BEEPER > -1 + SET_OUTPUT(BEEPER); + for(int8_t i=0;i<10;i++) + { + WRITE(BEEPER,HIGH); + delay(3); + WRITE(BEEPER,LOW); + delay(3); + } +#endif +} + +#ifdef LCD_HAS_STATUS_INDICATORS +static void lcd_implementation_update_indicators() +{ + #if defined(LCD_I2C_PANELOLU2) || defined(LCD_I2C_VIKI) + //set the LEDS - referred to as backlights by the LiquidTWI2 library + static uint8_t ledsprev = 0; + uint8_t leds = 0; + if (isHeatingBed()) leds |= LED_A; + if (isHeatingHotend(0)) leds |= LED_B; + if (fanSpeed) leds |= LED_C; + #if EXTRUDERS > 1 + if (isHeatingHotend(1)) leds |= LED_C; + #endif + if (leds != ledsprev) { + lcd.setBacklight(leds); + ledsprev = leds; + } + #endif +} +#endif + +#ifdef LCD_HAS_EXTRA_BUTTONS +static uint8_t lcd_read_extra_buttons() +{ + #ifdef LCD_I2C_TYPE_MCP23017 + // the I2C button bit positions are shifted by three bits from the native LiquidTWI2 position + // this is potentially too slow to call inside interrupt context + return lcd.readButtons() << B_I2C_BTN_OFFSET; + #endif +} +#endif + +#endif//ULTRA_LCD_IMPLEMENTATION_HITACHI_HD44780_H From 839bef6d5d436055c6cef051b6b32a84bd18d05a Mon Sep 17 00:00:00 2001 From: Robert F-C Date: Thu, 28 Feb 2013 02:32:20 +1100 Subject: [PATCH 07/31] Fix Configuration.h file to not define LCDs be default. Also fix compile time check in Marlin.pde --- Marlin/Configuration.h | 7 +++++-- Marlin/Marlin.pde | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index e88515b5ec..2cc80dd30c 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -320,7 +320,7 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th //#define SDSUPPORT // Enable SD Card Support in Hardware Console //#define ULTIMAKERCONTROLLER //as available from the ultimaker online store. -#define ULTIPANEL //the ultipanel as on thingiverse +//#define ULTIPANEL //the ultipanel as on thingiverse // The RepRapDiscount Smart Controller (white PCB) // http://reprap.org/wiki/RepRapDiscount_Smart_Controller @@ -338,11 +338,12 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th // I2C PANELS -#define LCD_I2C_SAINSMART_YWROBOT +//#define LCD_I2C_SAINSMART_YWROBOT #ifdef LCD_I2C_SAINSMART_YWROBOT // This uses the LiquidCrystal_I2C library ( https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home ) // Make sure it is placed in the Arduino libraries directory. #define LCD_I2C_TYPE_PCF8575 + #define LCD_I2C #define ULTIPANEL #define NEWPANEL #define LCD_I2C_ADDRESS 0x27 // I2C Address of the port expander @@ -354,6 +355,7 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 ). // Make sure it is placed in the Arduino libraries directory. #define LCD_I2C_TYPE_MCP23017 + #define LCD_I2C #define ULTIPANEL #define NEWPANEL #define LCD_I2C_ADDRESS 0x20 @@ -367,6 +369,7 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th // This uses the LiquidTWI2 library (https://github.com/lincomatic/LiquidTWI2). // Make sure it is placed in the Arduino libraries directory. #define LCD_I2C_TYPE_MCP23017 + #define LCD_I2C #define ULTIPANEL #define NEWPANEL #define LCD_I2C_ADDRESS 0x20 diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 93a6504cb6..082bb0694f 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -39,8 +39,7 @@ #if defined(LCD_I2C_TYPE_PCF8575) #include #elif defined(LCD_I2C_TYPE_MCP23017) - #ifdef PANELOLU2 - #undef PANELOLU2 + #ifdef LCD_I2C_PANELOLU2 #include #ifndef PANELOLU2 #error You must uncomment #define PANELOLU2 in LiquidTWI2.h for LiquidTWI2.cpp to compile correctly From 6beb42cdf65971aeca93868305ed93ae6ed732eb Mon Sep 17 00:00:00 2001 From: Robert F-C Date: Fri, 1 Mar 2013 01:17:07 +1100 Subject: [PATCH 08/31] Attempt to address Bernhard's comments Refactor configuration to try to make items clearer (what defines a panel vs what is user changeable). --- Marlin/Configuration.h | 27 +-- Marlin/Marlin.pde | 21 +- Marlin/ultralcd.cpp | 14 +- .../ultralcd_implementation_hitachi_HD44780.h | 214 +++++++++--------- 4 files changed, 134 insertions(+), 142 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 2cc80dd30c..492a32361b 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -336,44 +336,39 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #define NEWPANEL #endif -// I2C PANELS +//I2C PANELS //#define LCD_I2C_SAINSMART_YWROBOT #ifdef LCD_I2C_SAINSMART_YWROBOT // This uses the LiquidCrystal_I2C library ( https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home ) // Make sure it is placed in the Arduino libraries directory. #define LCD_I2C_TYPE_PCF8575 - #define LCD_I2C - #define ULTIPANEL - #define NEWPANEL #define LCD_I2C_ADDRESS 0x27 // I2C Address of the port expander + #define NEWPANEL + #define ULTIPANEL #endif -// PANELOLU2 LCD with status LEDs, separate encoder and click inputs +//PANELOLU2 LCD with status LEDs, separate encoder and click inputs //#define LCD_I2C_PANELOLU2 #ifdef LCD_I2C_PANELOLU2 // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 ). // Make sure it is placed in the Arduino libraries directory. #define LCD_I2C_TYPE_MCP23017 - #define LCD_I2C - #define ULTIPANEL + #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander + #define LCD_USE_I2C_BUZZER //comment out to disable buzzer on LCD #define NEWPANEL - #define LCD_I2C_ADDRESS 0x20 - #define LCD_HAS_I2C_BUZZ //comment out to disable buzzer on LCD - #define LCD_HAS_STATUS_INDICATORS + #define ULTIPANEL #endif -// VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs +//VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs //#define LCD_I2C_VIKI #ifdef LCD_I2C_VIKI // This uses the LiquidTWI2 library (https://github.com/lincomatic/LiquidTWI2). // Make sure it is placed in the Arduino libraries directory. - #define LCD_I2C_TYPE_MCP23017 - #define LCD_I2C - #define ULTIPANEL + #define LCD_I2C_TYPE_MCP23017 + #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander #define NEWPANEL - #define LCD_I2C_ADDRESS 0x20 - #define LCD_HAS_STATUS_INDICATORS + #define ULTIPANEL #endif #ifdef ULTIPANEL diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 082bb0694f..a3ebf4756d 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -34,21 +34,14 @@ #include "pins.h" #ifdef ULTRA_LCD - #ifdef LCD_I2C + #if defined(LCD_I2C_TYPE_PCF8575) #include - #if defined(LCD_I2C_TYPE_PCF8575) - #include - #elif defined(LCD_I2C_TYPE_MCP23017) - #ifdef LCD_I2C_PANELOLU2 - #include - #ifndef PANELOLU2 - #error You must uncomment #define PANELOLU2 in LiquidTWI2.h for LiquidTWI2.cpp to compile correctly - #endif - #else - #include - #endif - #else - #error Unknown I2C LCD type + #include + #elif defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008) + #include + #include + #if defined(LCD_I2C_PANELOLU2) && !defined(PANELOLU2) + #error You must uncomment "#define PANELOLU2" in LiquidTWI2.h for LiquidTWI2.cpp to compile correctly #endif #else #include diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 8e223ed00f..ed259196d7 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -705,7 +705,9 @@ void lcd_init() lcd_oldcardstatus = IS_SD_INSERTED; #endif//(SDCARDDETECT > -1) lcd_buttons_update(); +#ifdef ULTIPANEL encoderDiff = 0; +#endif } void lcd_update() @@ -714,8 +716,8 @@ void lcd_update() lcd_buttons_update(); - #ifdef LCD_HAS_EXTRA_BUTTONS - buttons |= lcd_read_extra_buttons(); // buttons which take too long to read in interrupt context + #ifdef LCD_HAS_SLOW_BUTTONS + buttons |= lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context #endif #if (SDCARDDETECT > -1) @@ -751,8 +753,12 @@ void lcd_update() if (LCD_CLICKED) timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS; #endif//ULTIPANEL - (*currentMenu)(); + +#ifdef LCD_HAS_STATUS_INDICATORS + lcd_implementation_update_indicators(); +#endif + #ifdef ULTIPANEL if(timeoutToStatus < millis() && currentMenu != lcd_status_screen) { @@ -860,12 +866,12 @@ void lcd_buttons_update() } lastEncoderBits = enc; } -#endif//ULTIPANEL bool lcd_clicked() { return LCD_CLICKED; } +#endif//ULTIPANEL /********************************/ /** Float conversion utilities **/ diff --git a/Marlin/ultralcd_implementation_hitachi_HD44780.h b/Marlin/ultralcd_implementation_hitachi_HD44780.h index 651b1484cf..a606f642dd 100644 --- a/Marlin/ultralcd_implementation_hitachi_HD44780.h +++ b/Marlin/ultralcd_implementation_hitachi_HD44780.h @@ -6,72 +6,35 @@ * When selecting the rusian language, a slightly different LCD implementation is used to handle UTF8 characters. **/ -// Declare LCD class to use -#if defined(LCD_I2C_TYPE_PCF8575) - // note: these are virtual pins on the PCF8575 controller not Arduino pins - #define LCD_I2C_PIN_BL 3 - #define LCD_I2C_PIN_EN 2 - #define LCD_I2C_PIN_RW 1 - #define LCD_I2C_PIN_RS 0 - #define LCD_I2C_PIN_D4 4 - #define LCD_I2C_PIN_D5 5 - #define LCD_I2C_PIN_D6 6 - #define LCD_I2C_PIN_D7 7 - - #include - #include - #include - #define LCD_CLASS LiquidCrystal_I2C - LCD_CLASS lcd(LCD_I2C_ADDRESS,LCD_I2C_PIN_EN,LCD_I2C_PIN_RW,LCD_I2C_PIN_RS,LCD_I2C_PIN_D4,LCD_I2C_PIN_D5,LCD_I2C_PIN_D6,LCD_I2C_PIN_D7); -#elif defined(LCD_I2C_TYPE_MCP23017) - //for the LED indicators (which maybe mapped to different things in lcd_implementation_update_indicators()) - #define LED_A 0x04 //100 - #define LED_B 0x02 //010 - #define LED_C 0x01 //001 - - #include - #include - #define LCD_CLASS LiquidTWI2 - LCD_CLASS lcd(LCD_I2C_ADDRESS); //An alternative I2C master address can be used in place of "0" -#elif defined(LCD_I2C_TYPE_MCP23008) - #include - #include - #define LCD_CLASS LiquidTWI2 - LCD_CLASS lcd(LCD_I2C_ADDRESS); //An alternative I2C master address can be used in place of "0" -#else - #if LANGUAGE_CHOICE == 6 - #include "LiquidCrystalRus.h" - #define LCD_CLASS LiquidCrystalRus - #else - #include - #define LCD_CLASS LiquidCrystal - #endif - LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7 -#endif - extern volatile uint8_t buttons; //the last checked buttons in a bit array. -// provide default button bitmask and encoder definitions (note this is not pin or motherboard specific) -#ifdef LCD_I2C_VIKI - //encoder rotation values - #define encrot0 0 - #define encrot1 2 - #define encrot2 3 - #define encrot3 1 - - #define BLEN_C 2 - #define BLEN_B 1 - #define BLEN_A 0 - - #define EN_C (1< + #include + #include + #define LCD_CLASS LiquidCrystal_I2C + LCD_CLASS lcd(LCD_I2C_ADDRESS,LCD_I2C_PIN_EN,LCD_I2C_PIN_RW,LCD_I2C_PIN_RS,LCD_I2C_PIN_D4,LCD_I2C_PIN_D5,LCD_I2C_PIN_D6,LCD_I2C_PIN_D7); + +#elif defined(LCD_I2C_TYPE_MCP23017) + //for the LED indicators (which maybe mapped to different things in lcd_implementation_update_indicators()) + #define LED_A 0x04 //100 + #define LED_B 0x02 //010 + #define LED_C 0x01 //001 + + #define LCD_HAS_STATUS_INDICATORS + + #include + #include + #define LCD_CLASS LiquidTWI2 + LCD_CLASS lcd(LCD_I2C_ADDRESS); + +#elif defined(LCD_I2C_TYPE_MCP23008) + #include + #include + #define LCD_CLASS LiquidTWI2 + LCD_CLASS lcd(LCD_I2C_ADDRESS); + +#else + // Standard directly connected LCD implementations + #if LANGUAGE_CHOICE == 6 + #include "LiquidCrystalRus.h" + #define LCD_CLASS LiquidCrystalRus + #else + #include + #define LCD_CLASS LiquidCrystal + #endif + LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7 #endif /* Custom characters defined in the first 8 characters of the LCD */ @@ -247,13 +245,16 @@ static void lcd_implementation_init() lcd.setBacklightPin(LCD_I2C_PIN_BL,POSITIVE); lcd.setBacklight(HIGH); #endif + #elif defined(LCD_I2C_TYPE_MCP23017) lcd.setMCPType(LTI_TYPE_MCP23017); lcd.begin(LCD_WIDTH, LCD_HEIGHT); lcd.setBacklight(0); //set all the LEDs off to begin with + #elif defined(LCD_I2C_TYPE_MCP23008) lcd.setMCPType(LTI_TYPE_MCP23008); lcd.begin(LCD_WIDTH, LCD_HEIGHT); + #else lcd.begin(LCD_WIDTH, LCD_HEIGHT); #endif @@ -439,9 +440,6 @@ static void lcd_implementation_status_screen() //Status message line on the last line lcd.setCursor(0, LCD_HEIGHT - 1); lcd.print(lcd_status_message); -#ifdef LCD_HAS_STATUS_INDICATORS - lcd_implementation_update_indicators(); -#endif } static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, char pre_char, char post_char) { @@ -630,7 +628,7 @@ static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pst static void lcd_implementation_quick_feedback() { -#ifdef LCD_HAS_I2C_BUZZ +#ifdef LCD_USE_I2C_BUZZER lcd.buzz(300,4000); #elif defined(BEEPER) && BEEPER > -1 SET_OUTPUT(BEEPER); @@ -665,12 +663,12 @@ static void lcd_implementation_update_indicators() } #endif -#ifdef LCD_HAS_EXTRA_BUTTONS -static uint8_t lcd_read_extra_buttons() +#ifdef LCD_HAS_SLOW_BUTTONS +static uint8_t lcd_implementation_read_slow_buttons() { #ifdef LCD_I2C_TYPE_MCP23017 - // the I2C button bit positions are shifted by three bits from the native LiquidTWI2 position - // this is potentially too slow to call inside interrupt context + // Reading these buttons this is likely to be too slow to call inside interrupt context + // so they are called during normal lcd_update return lcd.readButtons() << B_I2C_BTN_OFFSET; #endif } From 372e12f83f53704abc002c681c85b08383347c7b Mon Sep 17 00:00:00 2001 From: Robert F-C Date: Fri, 1 Mar 2013 21:57:23 +1100 Subject: [PATCH 09/31] Implement automatic extruder/cold-end fan control based on temperature This change allows fan outputs to automatically turn on/off when the associated nozzle temperature of an extruder is above/below a threshold temperature. Multiple extruders can be assigned to the same pin in which case the fan will turn on when any selected extruder is above the threshold. It also makes the M42 command compatible with the M106/M107 command. The majority of the logic in this change will be evaluated by the compiler at build time (i.e, low code space requirements). --- Marlin/Configuration_adv.h | 18 +- Marlin/Marlin_main.cpp | 14 +- Marlin/temperature.cpp | 54 ++++- README.md | 450 +++++++++++++++++++------------------ 4 files changed, 302 insertions(+), 234 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 7fc95b9979..a65c69dee2 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -71,6 +71,16 @@ // before setting a PWM value. (Does not work with software PWM for fan on Sanguinololu) //#define FAN_KICKSTART_TIME 100 +// Configure fan pin outputs to automatically turn on/off when the associated +// extruder temperature is above/below EXTRUDER_AUTO_FAN_TEMPERATURE. +// Multiple extruders can be assigned to the same pin in which case +// the fan will turn on when any selected extruder is above the threshold. +#define EXTRUDER_0_AUTO_FAN_PIN -1 +#define EXTRUDER_1_AUTO_FAN_PIN -1 +#define EXTRUDER_2_AUTO_FAN_PIN -1 +#define EXTRUDER_AUTO_FAN_TEMPERATURE 50 +#define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed + //=========================================================================== //=============================Mechanical Settings=========================== //=========================================================================== @@ -210,9 +220,9 @@ // However, THIS FEATURE IS UNSAFE!, as it will only work if interrupts are disabled. And the code could hang in an interrupt routine with interrupts disabled. //#define WATCHDOG_RESET_MANUAL #endif - -// Enable the option to stop SD printing when hitting and endstops, needs to be enabled from the LCD menu when this option is enabled. -//#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED + +// Enable the option to stop SD printing when hitting and endstops, needs to be enabled from the LCD menu when this option is enabled. +//#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED // extruder advance constant (s2/mm3) // @@ -276,7 +286,7 @@ const unsigned int dropsegments=5; //everything with less than this number of st #else #define BLOCK_BUFFER_SIZE 16 // maximize block buffer #endif - + //The ASCII buffer for recieving from the serial: #define MAX_CMD_SIZE 96 diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 3725546171..80172c2b13 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -157,12 +157,12 @@ float add_homeing[3]={0,0,0}; float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS }; float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS }; // Extruder offset, only in XY plane -#if EXTRUDERS > 1 +#if EXTRUDERS > 1 float extruder_offset[2][EXTRUDERS] = { #if defined(EXTRUDER_OFFSET_X) && defined(EXTRUDER_OFFSET_Y) EXTRUDER_OFFSET_X, EXTRUDER_OFFSET_Y #endif -}; +}; #endif uint8_t active_extruder = 0; int fanSpeed=0; @@ -982,6 +982,10 @@ void process_commands() break; } } + #if FAN_PIN > -1 + if (pin_number == FAN_PIN) + fanSpeed = pin_status; + #endif if (pin_number > -1) { pinMode(pin_number, OUTPUT); @@ -1380,7 +1384,7 @@ void process_commands() } }break; - #endif // FWRETRACT + #endif // FWRETRACT #if EXTRUDERS > 1 case 218: // M218 - set hotend offset (in mm), T X Y { @@ -1405,7 +1409,7 @@ void process_commands() SERIAL_ECHO(extruder_offset[Y_AXIS][tmp_extruder]); } SERIAL_ECHOLN(""); - }break; + }break; #endif case 220: // M220 S- set speed factor override percentage { @@ -1756,7 +1760,7 @@ void process_commands() if(make_move && Stopped == false) { prepare_move(); } - } + } #endif SERIAL_ECHO_START; SERIAL_ECHO(MSG_ACTIVE_EXTRUDER); diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 6093c99346..75012cff06 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -99,8 +99,9 @@ static volatile bool temp_meas_ready = false; #ifdef FAN_SOFT_PWM static unsigned char soft_pwm_fan; #endif - - +#if EXTRUDER_0_AUTO_FAN_PIN > -1 || EXTRUDER_1_AUTO_FAN_PIN > -1 || EXTRUDER_2_AUTO_FAN_PIN > -1 + static uint8_t extruderAutoFanState = 0; // extruder auto fan state stored as bitmap +#endif #if EXTRUDERS > 3 # error Unsupported number of extruders @@ -399,6 +400,55 @@ void manage_heater() } // End extruder for loop + #if EXTRUDER_0_AUTO_FAN_PIN > -1 + // check the extruder 0 setting (and any ganged auto fan outputs) + bool newFanState = (EXTRUDER_0_AUTO_FAN_PIN > -1 && + (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE || + (EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN && current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) || + (EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE))); + if ((extruderAutoFanState & 1) != newFanState) // store state in first bit + { + int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); + if (EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN) + fanSpeed = newFanSpeed; + pinMode(EXTRUDER_0_AUTO_FAN_PIN, OUTPUT); + digitalWrite(EXTRUDER_0_AUTO_FAN_PIN, newFanSpeed); + analogWrite(EXTRUDER_0_AUTO_FAN_PIN, newFanSpeed); + extruderAutoFanState = newFanState | (extruderAutoFanState & ~1); + } + #endif //EXTRUDER_0_AUTO_FAN_PIN > -1 + #if EXTRUDER_1_AUTO_FAN_PIN > -1 + // check the extruder 1 setting (except when extruder 1 is the same as 0) + newFanState = (EXTRUDER_1_AUTO_FAN_PIN > -1 && EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && + (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE || + (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE))); + if ((extruderAutoFanState & 2) != (newFanState<<1)) // use second bit + { + int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); + if (EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN) + fanSpeed = newFanSpeed; + pinMode(EXTRUDER_1_AUTO_FAN_PIN, OUTPUT); + digitalWrite(EXTRUDER_1_AUTO_FAN_PIN, newFanSpeed); + analogWrite(EXTRUDER_1_AUTO_FAN_PIN, newFanSpeed); + extruderAutoFanState = (newFanState<<1) | (extruderAutoFanState & ~2); + } + #endif //EXTRUDER_1_AUTO_FAN_PIN > -1 + #if EXTRUDER_2_AUTO_FAN_PIN > -1 + // check the extruder 2 setting (except when extruder 2 is the same as 1 or 0) + newFanState = (EXTRUDER_2_AUTO_FAN_PIN > -1 && + EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN && + current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE); + if ((extruderAutoFanState & 4) != (newFanState<<2)) // use third bit + { + int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); + if (EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN) + fanSpeed = newFanSpeed; + pinMode(EXTRUDER_2_AUTO_FAN_PIN, OUTPUT); + digitalWrite(EXTRUDER_2_AUTO_FAN_PIN, newFanSpeed); + analogWrite(EXTRUDER_2_AUTO_FAN_PIN, newFanSpeed); + extruderAutoFanState = (newFanState<<2) | (extruderAutoFanState & ~4); + } + #endif //EXTRUDER_2_AUTO_FAN_PIN > -1 #ifndef PIDTEMPBED if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL) diff --git a/README.md b/README.md index 309fdd1d1d..ada4e83820 100644 --- a/README.md +++ b/README.md @@ -1,223 +1,227 @@ -WARNING: --------- -THIS IS RELEASE CANDIDATE 2 FOR MARLIN 1.0.0 - -The configuration is now split in two files -Configuration.h for the normal settings -Configuration_adv.h for the advanced settings - -Gen7T is not supported. - -Quick Information -=================== -This RepRap firmware is a mashup between Sprinter, grbl and many original parts. - -Derived from Sprinter and Grbl by Erik van der Zalm. -Sprinters lead developers are Kliment and caru. -Grbls lead developer is Simen Svale Skogsrud. Sonney Jeon (Chamnit) improved some parts of grbl -A fork by bkubicek for the Ultimaker was merged, and further development was aided by him. -Some features have been added by: -Lampmaker, Bradley Feldman, and others... - - -Features: - -* Interrupt based movement with real linear acceleration -* High steprate -* Look ahead (Keep the speed high when possible. High cornering speed) -* Interrupt based temperature protection -* preliminary support for Matthew Roberts advance algorithm - For more info see: http://reprap.org/pipermail/reprap-dev/2011-May/003323.html -* Full endstop support -* SD Card support -* SD Card folders (works in pronterface) -* SD Card autostart support -* LCD support (ideally 20x4) -* LCD menu system for autonomous SD card printing, controlled by an click-encoder. -* EEPROM storage of e.g. max-velocity, max-acceleration, and similar variables -* many small but handy things originating from bkubicek's fork. -* Arc support -* Temperature oversampling -* Dynamic Temperature setpointing aka "AutoTemp" -* Support for QTMarlin, a very beta GUI for PID-tuning and velocity-acceleration testing. https://github.com/bkubicek/QTMarlin -* Endstop trigger reporting to the host software. -* Updated sdcardlib -* Heater power reporting. Useful for PID monitoring. -* PID tuning -* CoreXY kinematics (www.corexy.com/theory.html) -* Configurable serial port to support connection of wireless adaptors. - -The default baudrate is 250000. This baudrate has less jitter and hence errors than the usual 115200 baud, but is less supported by drivers and host-environments. - - -Differences and additions to the already good Sprinter firmware: -================================================================ - -*Look-ahead:* - -Marlin has look-ahead. While sprinter has to break and re-accelerate at each corner, -lookahead will only decelerate and accelerate to a velocity, -so that the change in vectorial velocity magnitude is less than the xy_jerk_velocity. -This is only possible, if some future moves are already processed, hence the name. -It leads to less over-deposition at corners, especially at flat angles. - -*Arc support:* - -Slic3r can find curves that, although broken into segments, were ment to describe an arc. -Marlin is able to print those arcs. The advantage is the firmware can choose the resolution, -and can perform the arc with nearly constant velocity, resulting in a nice finish. -Also, less serial communication is needed. - -*Temperature Oversampling:* - -To reduce noise and make the PID-differential term more useful, 16 ADC conversion results are averaged. - -*AutoTemp:* - -If your gcode contains a wide spread of extruder velocities, or you realtime change the building speed, the temperature should be changed accordingly. -Usually, higher speed requires higher temperature. -This can now be performed by the AutoTemp function -By calling M109 S T F you enter the autotemp mode. - -You can leave it by calling M109 without any F. -If active, the maximal extruder stepper rate of all buffered moves will be calculated, and named "maxerate" [steps/sec]. -The wanted temperature then will be set to t=tempmin+factor*maxerate, while being limited between tempmin and tempmax. -If the target temperature is set manually or by gcode to a value less then tempmin, it will be kept without change. -Ideally, your gcode can be completely free of temperature controls, apart from a M109 S T F in the start.gcode, and a M109 S0 in the end.gcode. - -*EEPROM:* - -If you know your PID values, the acceleration and max-velocities of your unique machine, you can set them, and finally store them in the EEPROM. -After each reboot, it will magically load them from EEPROM, independent what your Configuration.h says. - -*LCD Menu:* - -If your hardware supports it, you can build yourself a LCD-CardReader+Click+encoder combination. It will enable you to realtime tune temperatures, -accelerations, velocities, flow rates, select and print files from the SD card, preheat, disable the steppers, and do other fancy stuff. -One working hardware is documented here: http://www.thingiverse.com/thing:12663 -Also, with just a 20x4 or 16x2 display, useful data is shown. - -*SD card folders:* - -If you have an SD card reader attached to your controller, also folders work now. Listing the files in pronterface will show "/path/subpath/file.g". -You can write to file in a subfolder by specifying a similar text using small letters in the path. -Also, backup copies of various operating systems are hidden, as well as files not ending with ".g". - -*SD card folders:* - -If you place a file auto[0-9].g into the root of the sd card, it will be automatically executed if you boot the printer. The same file will be executed by selecting "Autostart" from the menu. -First *0 will be performed, than *1 and so on. That way, you can heat up or even print automatically without user interaction. - -*Endstop trigger reporting:* - -If an endstop is hit while moving towards the endstop, the location at which the firmware thinks that the endstop was triggered is outputed on the serial port. -This is useful, because the user gets a warning message. -However, also tools like QTMarlin can use this for finding acceptable combinations of velocity+acceleration. - -*Coding paradigm:* - -Not relevant from a user side, but Marlin was split into thematic junks, and has tried to partially enforced private variables. -This is intended to make it clearer, what interacts which what, and leads to a higher level of modularization. -We think that this is a useful prestep for porting this firmware to e.g. an ARM platform in the future. -A lot of RAM (with enabled LCD ~2200 bytes) was saved by storing char []="some message" in Program memory. -In the serial communication, a #define based level of abstraction was enforced, so that it is clear that -some transfer is information (usually beginning with "echo:"), an error "error:", or just normal protocol, -necessary for backwards compatibility. - -*Interrupt based temperature measurements:* - -An interrupt is used to manage ADC conversions, and enforce checking for critical temperatures. -This leads to less blocking in the heater management routine. - - -Non-standard M-Codes, different to an old version of sprinter: -============================================================== -Movement: - -* G2 - CW ARC -* G3 - CCW ARC - -General: - -* M17 - Enable/Power all stepper motors. Compatibility to ReplicatorG. -* M18 - Disable all stepper motors; same as M84.Compatibility to ReplicatorG. -* M30 - Print time since last M109 or SD card start to serial -* M42 - Change pin status via gcode -* M80 - Turn on Power Supply -* M81 - Turn off Power Supply -* M114 - Output current position to serial port -* M119 - Output Endstop status to serial port - -Movement variables: - -* M202 - Set max acceleration in units/s^2 for travel moves (M202 X1000 Y1000) Unused in Marlin!! -* M203 - Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in mm/sec -* M204 - Set default acceleration: S normal moves T filament only moves (M204 S3000 T7000) im mm/sec^2 also sets minimum segment time in ms (B20000) to prevent buffer underruns and M20 minimum feedrate -* M206 - set home offsets. This sets the X,Y,Z coordinates of the endstops (and is added to the {X,Y,Z}_HOME_POS configuration options (and is also added to the coordinates, if any, provided to G82, as with earlier firmware) -* M220 - set build speed mulitplying S:factor in percent ; aka "realtime tuneing in the gcode". So you can slow down if you have islands in one height-range, and speed up otherwise. -* M221 - set the extrude multiplying S:factor in percent -* M400 - Finish all buffered moves. - -Temperature variables: -* M301 - Set PID parameters P I and D -* M302 - Allow cold extrudes -* M303 - PID relay autotune S sets the target temperature. (default target temperature = 150C) - -Advance: - -* M200 - Set filament diameter for advance -* M205 - advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk - -EEPROM: - -* M500 - stores paramters in EEPROM. This parameters are stored: axis_steps_per_unit, max_feedrate, max_acceleration ,acceleration,retract_acceleration, - minimumfeedrate,mintravelfeedrate,minsegmenttime, jerk velocities, PID -* M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily). -* M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to. -* M503 - print the current settings (from memory not from eeprom) - -MISC: - -* M240 - Trigger a camera to take a photograph -* M999 - Restart after being stopped by error - -Configuring and compilation: -============================ - -Install the arduino software IDE/toolset v23 (Some configurations also work with 1.x.x) - http://www.arduino.cc/en/Main/Software - -For gen6/gen7 and sanguinololu the Sanguino directory in the Marlin dir needs to be copied to the arduino environment. - copy ArduinoAddons\Arduino_x.x.x\sanguino \hardware\Sanguino - -Install Ultimaker's RepG 25 build - http://software.ultimaker.com -For SD handling and as better substitute (apart from stl manipulation) download -the very nice Kliment's printrun/pronterface https://github.com/kliment/Printrun - -Copy the Ultimaker Marlin firmware - https://github.com/ErikZalm/Marlin/tree/Marlin_v1 - (Use the download button) - -Start the arduino IDE. -Select Tools -> Board -> Arduino Mega 2560 or your microcontroller -Select the correct serial port in Tools ->Serial Port -Open Marlin.pde - -Click the Verify/Compile button - -Click the Upload button -If all goes well the firmware is uploading - -Start Ultimaker's Custom RepG 25 -Make sure Show Experimental Profiles is enabled in Preferences -Select Sprinter as the Driver - -Press the Connect button. - -KNOWN ISSUES: RepG will display: Unknown: marlin x.y.z - -That's ok. Enjoy Silky Smooth Printing. - - - +========================== +Marlin 3D Printer Firmware +========================== + +Notes: +----- + +The configuration is now split in two files: + Configuration.h for the normal settings + Configuration_adv.h for the advanced settings + +Gen7T is not supported. + +Quick Information +=================== +This RepRap firmware is a mashup between Sprinter, grbl and many original parts. + +Derived from Sprinter and Grbl by Erik van der Zalm. +Sprinters lead developers are Kliment and caru. +Grbls lead developer is Simen Svale Skogsrud. Sonney Jeon (Chamnit) improved some parts of grbl +A fork by bkubicek for the Ultimaker was merged, and further development was aided by him. +Some features have been added by: +Lampmaker, Bradley Feldman, and others... + + +Features: + +* Interrupt based movement with real linear acceleration +* High steprate +* Look ahead (Keep the speed high when possible. High cornering speed) +* Interrupt based temperature protection +* preliminary support for Matthew Roberts advance algorithm + For more info see: http://reprap.org/pipermail/reprap-dev/2011-May/003323.html +* Full endstop support +* SD Card support +* SD Card folders (works in pronterface) +* SD Card autostart support +* LCD support (ideally 20x4) +* LCD menu system for autonomous SD card printing, controlled by an click-encoder. +* EEPROM storage of e.g. max-velocity, max-acceleration, and similar variables +* many small but handy things originating from bkubicek's fork. +* Arc support +* Temperature oversampling +* Dynamic Temperature setpointing aka "AutoTemp" +* Support for QTMarlin, a very beta GUI for PID-tuning and velocity-acceleration testing. https://github.com/bkubicek/QTMarlin +* Endstop trigger reporting to the host software. +* Updated sdcardlib +* Heater power reporting. Useful for PID monitoring. +* PID tuning +* CoreXY kinematics (www.corexy.com/theory.html) +* Configurable serial port to support connection of wireless adaptors. +* Automatic operation of extruder/cold-end cooling fans based on nozzle temperature + +The default baudrate is 250000. This baudrate has less jitter and hence errors than the usual 115200 baud, but is less supported by drivers and host-environments. + + +Differences and additions to the already good Sprinter firmware: +================================================================ + +*Look-ahead:* + +Marlin has look-ahead. While sprinter has to break and re-accelerate at each corner, +lookahead will only decelerate and accelerate to a velocity, +so that the change in vectorial velocity magnitude is less than the xy_jerk_velocity. +This is only possible, if some future moves are already processed, hence the name. +It leads to less over-deposition at corners, especially at flat angles. + +*Arc support:* + +Slic3r can find curves that, although broken into segments, were ment to describe an arc. +Marlin is able to print those arcs. The advantage is the firmware can choose the resolution, +and can perform the arc with nearly constant velocity, resulting in a nice finish. +Also, less serial communication is needed. + +*Temperature Oversampling:* + +To reduce noise and make the PID-differential term more useful, 16 ADC conversion results are averaged. + +*AutoTemp:* + +If your gcode contains a wide spread of extruder velocities, or you realtime change the building speed, the temperature should be changed accordingly. +Usually, higher speed requires higher temperature. +This can now be performed by the AutoTemp function +By calling M109 S T F you enter the autotemp mode. + +You can leave it by calling M109 without any F. +If active, the maximal extruder stepper rate of all buffered moves will be calculated, and named "maxerate" [steps/sec]. +The wanted temperature then will be set to t=tempmin+factor*maxerate, while being limited between tempmin and tempmax. +If the target temperature is set manually or by gcode to a value less then tempmin, it will be kept without change. +Ideally, your gcode can be completely free of temperature controls, apart from a M109 S T F in the start.gcode, and a M109 S0 in the end.gcode. + +*EEPROM:* + +If you know your PID values, the acceleration and max-velocities of your unique machine, you can set them, and finally store them in the EEPROM. +After each reboot, it will magically load them from EEPROM, independent what your Configuration.h says. + +*LCD Menu:* + +If your hardware supports it, you can build yourself a LCD-CardReader+Click+encoder combination. It will enable you to realtime tune temperatures, +accelerations, velocities, flow rates, select and print files from the SD card, preheat, disable the steppers, and do other fancy stuff. +One working hardware is documented here: http://www.thingiverse.com/thing:12663 +Also, with just a 20x4 or 16x2 display, useful data is shown. + +*SD card folders:* + +If you have an SD card reader attached to your controller, also folders work now. Listing the files in pronterface will show "/path/subpath/file.g". +You can write to file in a subfolder by specifying a similar text using small letters in the path. +Also, backup copies of various operating systems are hidden, as well as files not ending with ".g". + +*SD card folders:* + +If you place a file auto[0-9].g into the root of the sd card, it will be automatically executed if you boot the printer. The same file will be executed by selecting "Autostart" from the menu. +First *0 will be performed, than *1 and so on. That way, you can heat up or even print automatically without user interaction. + +*Endstop trigger reporting:* + +If an endstop is hit while moving towards the endstop, the location at which the firmware thinks that the endstop was triggered is outputed on the serial port. +This is useful, because the user gets a warning message. +However, also tools like QTMarlin can use this for finding acceptable combinations of velocity+acceleration. + +*Coding paradigm:* + +Not relevant from a user side, but Marlin was split into thematic junks, and has tried to partially enforced private variables. +This is intended to make it clearer, what interacts which what, and leads to a higher level of modularization. +We think that this is a useful prestep for porting this firmware to e.g. an ARM platform in the future. +A lot of RAM (with enabled LCD ~2200 bytes) was saved by storing char []="some message" in Program memory. +In the serial communication, a #define based level of abstraction was enforced, so that it is clear that +some transfer is information (usually beginning with "echo:"), an error "error:", or just normal protocol, +necessary for backwards compatibility. + +*Interrupt based temperature measurements:* + +An interrupt is used to manage ADC conversions, and enforce checking for critical temperatures. +This leads to less blocking in the heater management routine. + + +Non-standard M-Codes, different to an old version of sprinter: +============================================================== +Movement: + +* G2 - CW ARC +* G3 - CCW ARC + +General: + +* M17 - Enable/Power all stepper motors. Compatibility to ReplicatorG. +* M18 - Disable all stepper motors; same as M84.Compatibility to ReplicatorG. +* M30 - Print time since last M109 or SD card start to serial +* M42 - Change pin status via gcode +* M80 - Turn on Power Supply +* M81 - Turn off Power Supply +* M114 - Output current position to serial port +* M119 - Output Endstop status to serial port + +Movement variables: + +* M202 - Set max acceleration in units/s^2 for travel moves (M202 X1000 Y1000) Unused in Marlin!! +* M203 - Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in mm/sec +* M204 - Set default acceleration: S normal moves T filament only moves (M204 S3000 T7000) im mm/sec^2 also sets minimum segment time in ms (B20000) to prevent buffer underruns and M20 minimum feedrate +* M206 - set home offsets. This sets the X,Y,Z coordinates of the endstops (and is added to the {X,Y,Z}_HOME_POS configuration options (and is also added to the coordinates, if any, provided to G82, as with earlier firmware) +* M220 - set build speed mulitplying S:factor in percent ; aka "realtime tuneing in the gcode". So you can slow down if you have islands in one height-range, and speed up otherwise. +* M221 - set the extrude multiplying S:factor in percent +* M400 - Finish all buffered moves. + +Temperature variables: +* M301 - Set PID parameters P I and D +* M302 - Allow cold extrudes +* M303 - PID relay autotune S sets the target temperature. (default target temperature = 150C) + +Advance: + +* M200 - Set filament diameter for advance +* M205 - advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk + +EEPROM: + +* M500 - stores paramters in EEPROM. This parameters are stored: axis_steps_per_unit, max_feedrate, max_acceleration ,acceleration,retract_acceleration, + minimumfeedrate,mintravelfeedrate,minsegmenttime, jerk velocities, PID +* M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily). +* M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to. +* M503 - print the current settings (from memory not from eeprom) + +MISC: + +* M240 - Trigger a camera to take a photograph +* M999 - Restart after being stopped by error + +Configuring and compilation: +============================ + +Install the arduino software IDE/toolset v23 (Some configurations also work with 1.x.x) + http://www.arduino.cc/en/Main/Software + +For gen6/gen7 and sanguinololu the Sanguino directory in the Marlin dir needs to be copied to the arduino environment. + copy ArduinoAddons\Arduino_x.x.x\sanguino \hardware\Sanguino + +Install Ultimaker's RepG 25 build + http://software.ultimaker.com +For SD handling and as better substitute (apart from stl manipulation) download +the very nice Kliment's printrun/pronterface https://github.com/kliment/Printrun + +Copy the Ultimaker Marlin firmware + https://github.com/ErikZalm/Marlin/tree/Marlin_v1 + (Use the download button) + +Start the arduino IDE. +Select Tools -> Board -> Arduino Mega 2560 or your microcontroller +Select the correct serial port in Tools ->Serial Port +Open Marlin.pde + +Click the Verify/Compile button + +Click the Upload button +If all goes well the firmware is uploading + +Start Ultimaker's Custom RepG 25 +Make sure Show Experimental Profiles is enabled in Preferences +Select Sprinter as the Driver + +Press the Connect button. + +KNOWN ISSUES: RepG will display: Unknown: marlin x.y.z + +That's ok. Enjoy Silky Smooth Printing. + + + From f1263d3f88621e115a842184ba5bf7a9a1911c67 Mon Sep 17 00:00:00 2001 From: Robert F-C Date: Sat, 2 Mar 2013 16:12:11 +1100 Subject: [PATCH 10/31] Further reduce code by using precompiler logic --- Marlin/Configuration_adv.h | 2 +- Marlin/temperature.cpp | 29 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index a65c69dee2..a21a7a42f8 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -86,7 +86,7 @@ //=========================================================================== // This defines the number of extruders -#define EXTRUDERS 1 +#define EXTRUDERS 2 #define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 75012cff06..0dc334e09d 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -400,12 +400,13 @@ void manage_heater() } // End extruder for loop - #if EXTRUDER_0_AUTO_FAN_PIN > -1 + #if EXTRUDER_0_AUTO_FAN_PIN > -1 || EXTRUDER_1_AUTO_FAN_PIN > -1 || EXTRUDER_2_AUTO_FAN_PIN > -1 + bool newFanState; + #if EXTRUDER_0_AUTO_FAN_PIN > -1 // check the extruder 0 setting (and any ganged auto fan outputs) - bool newFanState = (EXTRUDER_0_AUTO_FAN_PIN > -1 && - (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE || + newFanState = (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE || (EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN && current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) || - (EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE))); + (EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE)); if ((extruderAutoFanState & 1) != newFanState) // store state in first bit { int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); @@ -416,12 +417,11 @@ void manage_heater() analogWrite(EXTRUDER_0_AUTO_FAN_PIN, newFanSpeed); extruderAutoFanState = newFanState | (extruderAutoFanState & ~1); } - #endif //EXTRUDER_0_AUTO_FAN_PIN > -1 - #if EXTRUDER_1_AUTO_FAN_PIN > -1 + #endif //EXTRUDER_0_AUTO_FAN_PIN > -1 + #if EXTRUDER_1_AUTO_FAN_PIN > -1 && EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN // check the extruder 1 setting (except when extruder 1 is the same as 0) - newFanState = (EXTRUDER_1_AUTO_FAN_PIN > -1 && EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && - (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE || - (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE))); + newFanState = (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE || + (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE)); if ((extruderAutoFanState & 2) != (newFanState<<1)) // use second bit { int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); @@ -432,12 +432,10 @@ void manage_heater() analogWrite(EXTRUDER_1_AUTO_FAN_PIN, newFanSpeed); extruderAutoFanState = (newFanState<<1) | (extruderAutoFanState & ~2); } - #endif //EXTRUDER_1_AUTO_FAN_PIN > -1 - #if EXTRUDER_2_AUTO_FAN_PIN > -1 + #endif //EXTRUDER_1_AUTO_FAN_PIN > -1 + #if EXTRUDER_2_AUTO_FAN_PIN > -1 && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN // check the extruder 2 setting (except when extruder 2 is the same as 1 or 0) - newFanState = (EXTRUDER_2_AUTO_FAN_PIN > -1 && - EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN && - current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE); + newFanState = (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE); if ((extruderAutoFanState & 4) != (newFanState<<2)) // use third bit { int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); @@ -448,7 +446,8 @@ void manage_heater() analogWrite(EXTRUDER_2_AUTO_FAN_PIN, newFanSpeed); extruderAutoFanState = (newFanState<<2) | (extruderAutoFanState & ~4); } - #endif //EXTRUDER_2_AUTO_FAN_PIN > -1 + #endif //EXTRUDER_2_AUTO_FAN_PIN > -1 + #endif // any AUTO_FAN_PIN enabled #ifndef PIDTEMPBED if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL) From 1daf2f325668385a6ea527c770e8f6e663d2a425 Mon Sep 17 00:00:00 2001 From: Robert F-C Date: Sat, 2 Mar 2013 16:14:19 +1100 Subject: [PATCH 11/31] Number of extruders is not an advanced configuration - it is a basic property. --- Marlin/Configuration.h | 9 ++++++--- Marlin/Configuration_adv.h | 3 --- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 0ba908b06e..27922bf717 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -49,6 +49,9 @@ #define MOTHERBOARD 7 #endif +// This defines the number of extruders +#define EXTRUDERS 1 + //// The following define selects which power supply you have. Please choose the one that matches your setup // 1 = ATX // 2 = X-Box 360 203Watts (the blue wire connected to PS_ON and the red wire to VCC) @@ -322,9 +325,9 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th // The RepRapDiscount Smart Controller (white PCB) // http://reprap.org/wiki/RepRapDiscount_Smart_Controller //#define REPRAP_DISCOUNT_SMART_CONTROLLER - -// The GADGETS3D G3D LCD/SD Controller (blue PCB) -// http://reprap.org/wiki/RAMPS_1.3/1.4_GADGETS3D_Shield_with_Panel + +// The GADGETS3D G3D LCD/SD Controller (blue PCB) +// http://reprap.org/wiki/RAMPS_1.3/1.4_GADGETS3D_Shield_with_Panel //#define G3D_PANEL //automatic expansion diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index a21a7a42f8..6d164c4f5c 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -85,9 +85,6 @@ //=============================Mechanical Settings=========================== //=========================================================================== -// This defines the number of extruders -#define EXTRUDERS 2 - #define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing From 7bad72359c5f2c78096810fffbf809bb8c30b58b Mon Sep 17 00:00:00 2001 From: Robert F-C Date: Sun, 3 Mar 2013 18:47:50 +1100 Subject: [PATCH 12/31] Support encoder click on PANELOLU2 being read through I2C This change also handles the case where the pause/stop/restart button on the VIKI is not used. Make LCD I2C buzz sound the same as the normal buzz (300ms is too long for quick feedback). --- Marlin/Configuration.h | 14 ++++--- Marlin/ultralcd.cpp | 6 ++- .../ultralcd_implementation_hitachi_HD44780.h | 42 ++++++++++++++----- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 492a32361b..ba20c6c04b 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -351,8 +351,10 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th //PANELOLU2 LCD with status LEDs, separate encoder and click inputs //#define LCD_I2C_PANELOLU2 #ifdef LCD_I2C_PANELOLU2 - // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 ). - // Make sure it is placed in the Arduino libraries directory. + // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 ) + // Make sure it is placed in the Arduino or Sketchbook libraries directory. + // Note: The PANELOLU2 encoder click input can either be directly connected to a pin + // (if BTN_ENC defined to != -1) or read through I2C (when BTN_ENC == -1). #define LCD_I2C_TYPE_MCP23017 #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander #define LCD_USE_I2C_BUZZER //comment out to disable buzzer on LCD @@ -360,11 +362,13 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #define ULTIPANEL #endif -//VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs +//Panucatt VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs //#define LCD_I2C_VIKI #ifdef LCD_I2C_VIKI - // This uses the LiquidTWI2 library (https://github.com/lincomatic/LiquidTWI2). - // Make sure it is placed in the Arduino libraries directory. + // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 ) + // Make sure it is placed in the Arduino or Sketchbook libraries directory. + // Note: The pause/stop/resume LCD button pin should be connected to the Arduino + // BTN_ENC pin (or set BTN_ENC to -1 if not used) #define LCD_I2C_TYPE_MCP23017 #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander #define NEWPANEL diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index ed259196d7..523fcd4617 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -686,11 +686,13 @@ void lcd_init() #ifdef NEWPANEL pinMode(BTN_EN1,INPUT); pinMode(BTN_EN2,INPUT); - pinMode(BTN_ENC,INPUT); pinMode(SDCARDDETECT,INPUT); WRITE(BTN_EN1,HIGH); WRITE(BTN_EN2,HIGH); + #if defined(BTN_ENC) && BTN_ENC > -1 + pinMode(BTN_ENC,INPUT); WRITE(BTN_ENC,HIGH); + #endif #else pinMode(SHIFT_CLK,OUTPUT); pinMode(SHIFT_LD,OUTPUT); @@ -809,8 +811,10 @@ void lcd_buttons_update() uint8_t newbutton=0; if(READ(BTN_EN1)==0) newbutton|=EN_A; if(READ(BTN_EN2)==0) newbutton|=EN_B; + #if defined(BTN_ENC) && BTN_ENC > -1 if((blocking_enc -1 + // encoder click is directly connected + #define BLEN_C 2 + #define EN_C (1< -1 + // the pause/stop/restart button is connected to BTN_ENC when used + #define B_ST (EN_C) // Map the pause/stop/resume button into its normalized functional name + #define LCD_CLICKED (buttons&(B_MI|B_RI|B_ST)) // pause/stop button also acts as click until we implement proper pause/stop. + #else + #define LCD_CLICKED (buttons&(B_MI|B_RI)) + #endif // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update #define LCD_HAS_SLOW_BUTTONS +#elif defined(LCD_I2C_PANELOLU2) + #if !defined(BTN_ENC) || BTN_ENC == -1 + // encoder click is connected through I2C (rather than directly connected) + #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C) + + #define B_MI (ENCODER_C< -1 SET_OUTPUT(BEEPER); for(int8_t i=0;i<10;i++) From 9322c408c68bc7c5edd88bf674f9f85fa0d2ffc5 Mon Sep 17 00:00:00 2001 From: Robert F-C Date: Sun, 24 Mar 2013 18:19:58 +1100 Subject: [PATCH 13/31] Updated for LiquidTWI2 library version 1.2.3 The new version of the library means that PANELOLU no longer needs to be defined in LiquidTWI.h (the library file can be used as is) and the new version of the library also enables the buzzer on the Panucatt VIKI panel. --- Marlin/Configuration.h | 14 ++++++++------ Marlin/Marlin.pde | 3 --- Marlin/ultralcd_implementation_hitachi_HD44780.h | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index ba20c6c04b..71f0ca4557 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -348,11 +348,12 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #define ULTIPANEL #endif -//PANELOLU2 LCD with status LEDs, separate encoder and click inputs +// PANELOLU2 LCD with status LEDs, separate encoder and click inputs //#define LCD_I2C_PANELOLU2 #ifdef LCD_I2C_PANELOLU2 - // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 ) - // Make sure it is placed in the Arduino or Sketchbook libraries directory. + // This uses the LiquidTWI2 library v1.2.3 or later ( https://github.com/lincomatic/LiquidTWI2 ) + // Make sure the LiquidTWI2 directory is placed in the Arduino or Sketchbook libraries subdirectory. + // (v1.2.3 no longer requires you to define PANELOLU in the LiquidTWI2.h library header file) // Note: The PANELOLU2 encoder click input can either be directly connected to a pin // (if BTN_ENC defined to != -1) or read through I2C (when BTN_ENC == -1). #define LCD_I2C_TYPE_MCP23017 @@ -362,15 +363,16 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #define ULTIPANEL #endif -//Panucatt VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs +// Panucatt VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs //#define LCD_I2C_VIKI #ifdef LCD_I2C_VIKI - // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 ) - // Make sure it is placed in the Arduino or Sketchbook libraries directory. + // This uses the LiquidTWI2 library v1.2.3 or later ( https://github.com/lincomatic/LiquidTWI2 ) + // Make sure the LiquidTWI2 directory is placed in the Arduino or Sketchbook libraries subdirectory. // Note: The pause/stop/resume LCD button pin should be connected to the Arduino // BTN_ENC pin (or set BTN_ENC to -1 if not used) #define LCD_I2C_TYPE_MCP23017 #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander + #define LCD_USE_I2C_BUZZER //comment out to disable buzzer on LCD (requires LiquidTWI2 v1.2.3 or later) #define NEWPANEL #define ULTIPANEL #endif diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index a3ebf4756d..f7442feb7c 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -40,9 +40,6 @@ #elif defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008) #include #include - #if defined(LCD_I2C_PANELOLU2) && !defined(PANELOLU2) - #error You must uncomment "#define PANELOLU2" in LiquidTWI2.h for LiquidTWI2.cpp to compile correctly - #endif #else #include #endif diff --git a/Marlin/ultralcd_implementation_hitachi_HD44780.h b/Marlin/ultralcd_implementation_hitachi_HD44780.h index c5d1e26c27..845cc33df7 100644 --- a/Marlin/ultralcd_implementation_hitachi_HD44780.h +++ b/Marlin/ultralcd_implementation_hitachi_HD44780.h @@ -54,11 +54,11 @@ extern volatile uint8_t buttons; //the last checked buttons in a bit array. #define LCD_HAS_SLOW_BUTTONS #elif defined(LCD_I2C_PANELOLU2) + // encoder click can be read through I2C if not directly connected #if !defined(BTN_ENC) || BTN_ENC == -1 - // encoder click is connected through I2C (rather than directly connected) #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C) - #define B_MI (ENCODER_C< Date: Mon, 29 Apr 2013 21:50:52 +1000 Subject: [PATCH 14/31] Add lcd_buzz function to ultralcd.h so that non-LCD code can make use of lcd's buzzer. Argument order of lcd_buzz was set to mirror that on tone(). Change default M300 frequency to something audible. --- Marlin/Marlin_main.cpp | 20 +++++++++++++------- Marlin/ultralcd.cpp | 7 +++++++ Marlin/ultralcd.h | 3 +++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 875795f7df..abe27d32b3 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1446,16 +1446,20 @@ void process_commands() } break; - #if defined(LARGE_FLASH) && LARGE_FLASH == true && defined(BEEPER) && BEEPER > -1 + #if defined(LARGE_FLASH) && LARGE_FLASH == true case 300: // M300 { - int beepS = 1; + int beepS = 400; int beepP = 1000; if(code_seen('S')) beepS = code_value(); if(code_seen('P')) beepP = code_value(); - tone(BEEPER, beepS); - delay(beepP); - noTone(BEEPER); + #if defined(BEEPER) && BEEPER > -1 + tone(BEEPER, beepS); + delay(beepP); + noTone(BEEPER); + #elif defined(ULTRALCD) + lcd_buzz(beepS, beepP); + #endif } break; #endif // M300 @@ -1672,17 +1676,19 @@ void process_commands() manage_inactivity(); lcd_update(); - #if BEEPER > -1 if(cnt==0) { + #if defined(BEEPER) && BEEPER > -1 SET_OUTPUT(BEEPER); WRITE(BEEPER,HIGH); delay(3); WRITE(BEEPER,LOW); delay(3); - } + #else + lcd_buzz(1000/6,100); #endif + } } //return to normal diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index dafd2502aa..2dae90a5d4 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -946,6 +946,13 @@ void lcd_buttons_update() lastEncoderBits = enc; } +void lcd_buzz(long duration, uint16_t freq) +{ +#ifdef LCD_USE_I2C_BUZZER + lcd.buzz(duration,freq); +#endif +} + bool lcd_clicked() { return LCD_CLICKED; diff --git a/Marlin/ultralcd.h b/Marlin/ultralcd.h index d84c948bbf..ed9c10978a 100644 --- a/Marlin/ultralcd.h +++ b/Marlin/ultralcd.h @@ -34,6 +34,8 @@ extern int absPreheatHPBTemp; extern int absPreheatFanSpeed; + void lcd_buzz(long duration,uint16_t freq); + bool lcd_clicked(); #else //no lcd @@ -42,6 +44,7 @@ FORCE_INLINE void lcd_setstatus(const char* message) {} FORCE_INLINE void lcd_buttons_update() {} FORCE_INLINE void lcd_reset_alert_level() {} + FORCE_INLINE void lcd_buzz(long duration,uint16_t freq) {} #define LCD_MESSAGEPGM(x) #define LCD_ALERTMESSAGEPGM(x) From 1c127217df70ba25d0eb611688063c245fb2c36d Mon Sep 17 00:00:00 2001 From: Robert F-C Date: Mon, 29 Apr 2013 22:03:37 +1000 Subject: [PATCH 15/31] Make DOGLCD merge neater. --- Marlin/Marlin.pde | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 8514216e66..e02803ceb4 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -40,10 +40,7 @@ #elif defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008) #include #include - #else - #include - #endif - #ifdef DOGLCD + #elif defined(DOGLCD) #include // library for graphics LCD by Oli Kraus (https://code.google.com/p/u8glib/) #else #include // library for character LCD From d5ad7a0814aff16b371fbe2c75ff54d66fd9572d Mon Sep 17 00:00:00 2001 From: Robert F-C Date: Tue, 30 Apr 2013 01:08:29 +1000 Subject: [PATCH 16/31] Rework change to incorporate CONTROLLERFAN Also refactor extruder auto fan logic to simplify further and now only check every 2.5 seconds --- Marlin/Configuration_adv.h | 7 +- Marlin/Marlin_main.cpp | 49 +++++--------- Marlin/temperature.cpp | 128 ++++++++++++++++++++++--------------- 3 files changed, 98 insertions(+), 86 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 6d164c4f5c..afdd684415 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -63,14 +63,16 @@ //This is for controlling a fan to cool down the stepper drivers //it will turn on when any driver is enabled //and turn off after the set amount of seconds from last driver being disabled again -//#define CONTROLLERFAN_PIN 23 //Pin used for the fan to cool controller, comment out to disable this function -#define CONTROLLERFAN_SEC 60 //How many seconds, after all motors were disabled, the fan should run +#define CONTROLLERFAN_PIN -1 //Pin used for the fan to cool controller (-1 to disable) +#define CONTROLLERFAN_SECS 60 //How many seconds, after all motors were disabled, the fan should run +#define CONTROLLERFAN_SPEED 255 // == full speed // When first starting the main fan, run it at full speed for the // given number of milliseconds. This gets the fan spinning reliably // before setting a PWM value. (Does not work with software PWM for fan on Sanguinololu) //#define FAN_KICKSTART_TIME 100 +// Extruder cooling fans // Configure fan pin outputs to automatically turn on/off when the associated // extruder temperature is above/below EXTRUDER_AUTO_FAN_TEMPERATURE. // Multiple extruders can be assigned to the same pin in which case @@ -81,6 +83,7 @@ #define EXTRUDER_AUTO_FAN_TEMPERATURE 50 #define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed + //=========================================================================== //=============================Mechanical Settings=========================== //=========================================================================== diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 69f464b296..a3eac5d2ce 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -374,13 +374,9 @@ void setup() lcd_init(); - #ifdef CONTROLLERFAN_PIN + #if CONTROLLERFAN_PIN > 0 SET_OUTPUT(CONTROLLERFAN_PIN); //Set pin used for driver cooling fan - #endif - - #ifdef EXTRUDERFAN_PIN - SET_OUTPUT(EXTRUDERFAN_PIN); //Set pin used for extruder cooling fan - #endif + #endif } @@ -1963,7 +1959,12 @@ void prepare_arc_move(char isclockwise) { previous_millis_cmd = millis(); } -#ifdef CONTROLLERFAN_PIN +#if CONTROLLERFAN_PIN > 0 + +#if CONTROLLERFAN_PIN == FAN_PIN + #error "You cannot set CONTROLLERFAN_PIN equal to FAN_PIN" +#endif + unsigned long lastMotor = 0; //Save the time for when a motor was turned on last unsigned long lastMotorCheck = 0; @@ -1985,34 +1986,16 @@ void controllerFan() lastMotor = millis(); //... set time to NOW so the fan will turn on } - if ((millis() - lastMotor) >= (CONTROLLERFAN_SEC*1000UL) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC... - { - WRITE(CONTROLLERFAN_PIN, LOW); //... turn the fan off - } - else + if ((millis() - lastMotor) >= (CONTROLLERFAN_SECS*1000UL) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC... { - WRITE(CONTROLLERFAN_PIN, HIGH); //... turn the fan on - } - } -} -#endif - -#ifdef EXTRUDERFAN_PIN -unsigned long lastExtruderCheck = 0; - -void extruderFan() -{ - if ((millis() - lastExtruderCheck) >= 2500) //Not a time critical function, so we only check every 2500ms - { - lastExtruderCheck = millis(); - - if (degHotend(active_extruder) < EXTRUDERFAN_DEC) - { - WRITE(EXTRUDERFAN_PIN, LOW); //... turn the fan off + digitalWrite(CONTROLLERFAN_PIN, 0); + analogWrite(CONTROLLERFAN_PIN, 0); } else { - WRITE(EXTRUDERFAN_PIN, HIGH); //... turn the fan on + // allows digital or PWM fan output to be used (see M42 handling) + digitalWrite(CONTROLLERFAN_PIN, CONTROLLERFAN_SPEED); + analogWrite(CONTROLLERFAN_PIN, CONTROLLERFAN_SPEED); } } } @@ -2036,11 +2019,11 @@ void manage_inactivity() } } } - #if( KILL_PIN>-1 ) + #if KILL_PIN > 0 if( 0 == READ(KILL_PIN) ) kill(); #endif - #ifdef CONTROLLERFAN_PIN + #if CONTROLLERFAN_PIN > 0 controllerFan(); //Check if fan should be turned on to cool stepper drivers down #endif #ifdef EXTRUDER_RUNOUT_PREVENT diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 871bb811f2..78f1a6908f 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -99,8 +99,8 @@ static volatile bool temp_meas_ready = false; #ifdef FAN_SOFT_PWM static unsigned char soft_pwm_fan; #endif -#if EXTRUDER_0_AUTO_FAN_PIN > -1 || EXTRUDER_1_AUTO_FAN_PIN > -1 || EXTRUDER_2_AUTO_FAN_PIN > -1 - static uint8_t extruderAutoFanState = 0; // extruder auto fan state stored as bitmap +#if EXTRUDER_0_AUTO_FAN_PIN > 0 || EXTRUDER_1_AUTO_FAN_PIN > 0 || EXTRUDER_2_AUTO_FAN_PIN > 0 + static unsigned long extruder_autofan_last_check; #endif #if EXTRUDERS > 3 @@ -307,6 +307,73 @@ int getHeaterPower(int heater) { return soft_pwm[heater]; } +#if EXTRUDER_0_AUTO_FAN_PIN > 0 || EXTRUDER_1_AUTO_FAN_PIN > 0 || EXTRUDER_2_AUTO_FAN_PIN > 0 + +void setExtruderAutoFanState(int pin, bool state) +{ + unsigned char newFanSpeed = (state != 0) ? EXTRUDER_AUTO_FAN_SPEED : 0; + // this idiom allows both digital and PWM fan outputs (see M42 handling). + pinMode(pin, OUTPUT); + digitalWrite(pin, newFanSpeed); + analogWrite(pin, newFanSpeed); +} + +void checkExtruderAutoFans() +{ + uint8_t fanState = 0; + + // which fan pins need to be turned on? + #if EXTRUDER_0_AUTO_FAN_PIN > 0 + #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN + #error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN" + #endif + if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE) + fanState |= 1; + #endif + #if EXTRUDER_1_AUTO_FAN_PIN > 0 + #if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN + #error "You cannot set EXTRUDER_1_AUTO_FAN_PIN equal to FAN_PIN" + #endif + if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) + { + if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) + fanState |= 1; + else + fanState |= 2; + } + #endif + #if EXTRUDER_2_AUTO_FAN_PIN > 0 + #if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN + #error "You cannot set EXTRUDER_2_AUTO_FAN_PIN equal to FAN_PIN" + #endif + if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE) + { + if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) + fanState |= 1; + else if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN) + fanState |= 2; + else + fanState |= 4; + } + #endif + + // update extruder auto fan states + #if EXTRUDER_0_AUTO_FAN_PIN > 0 + setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0); + #endif + #if EXTRUDER_1_AUTO_FAN_PIN > 0 + if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) + setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0); + #endif + #if EXTRUDER_2_AUTO_FAN_PIN > 0 + if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN + && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN) + setExtruderAutoFanState(EXTRUDER_2_AUTO_FAN_PIN, (fanState & 4) != 0); + #endif +} + +#endif // any extruder auto fan pins set + void manage_heater() { float pid_input; @@ -399,56 +466,15 @@ void manage_heater() #endif } // End extruder for loop - - #if EXTRUDER_0_AUTO_FAN_PIN > -1 || EXTRUDER_1_AUTO_FAN_PIN > -1 || EXTRUDER_2_AUTO_FAN_PIN > -1 - bool newFanState; - #if EXTRUDER_0_AUTO_FAN_PIN > -1 - // check the extruder 0 setting (and any ganged auto fan outputs) - newFanState = (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE || - (EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN && current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) || - (EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE)); - if ((extruderAutoFanState & 1) != newFanState) // store state in first bit - { - int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); - if (EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN) - fanSpeed = newFanSpeed; - pinMode(EXTRUDER_0_AUTO_FAN_PIN, OUTPUT); - digitalWrite(EXTRUDER_0_AUTO_FAN_PIN, newFanSpeed); - analogWrite(EXTRUDER_0_AUTO_FAN_PIN, newFanSpeed); - extruderAutoFanState = newFanState | (extruderAutoFanState & ~1); - } - #endif //EXTRUDER_0_AUTO_FAN_PIN > -1 - #if EXTRUDER_1_AUTO_FAN_PIN > -1 && EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN - // check the extruder 1 setting (except when extruder 1 is the same as 0) - newFanState = (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE || - (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE)); - if ((extruderAutoFanState & 2) != (newFanState<<1)) // use second bit - { - int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); - if (EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN) - fanSpeed = newFanSpeed; - pinMode(EXTRUDER_1_AUTO_FAN_PIN, OUTPUT); - digitalWrite(EXTRUDER_1_AUTO_FAN_PIN, newFanSpeed); - analogWrite(EXTRUDER_1_AUTO_FAN_PIN, newFanSpeed); - extruderAutoFanState = (newFanState<<1) | (extruderAutoFanState & ~2); - } - #endif //EXTRUDER_1_AUTO_FAN_PIN > -1 - #if EXTRUDER_2_AUTO_FAN_PIN > -1 && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN - // check the extruder 2 setting (except when extruder 2 is the same as 1 or 0) - newFanState = (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE); - if ((extruderAutoFanState & 4) != (newFanState<<2)) // use third bit - { - int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); - if (EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN) - fanSpeed = newFanSpeed; - pinMode(EXTRUDER_2_AUTO_FAN_PIN, OUTPUT); - digitalWrite(EXTRUDER_2_AUTO_FAN_PIN, newFanSpeed); - analogWrite(EXTRUDER_2_AUTO_FAN_PIN, newFanSpeed); - extruderAutoFanState = (newFanState<<2) | (extruderAutoFanState & ~4); - } - #endif //EXTRUDER_2_AUTO_FAN_PIN > -1 - #endif // any AUTO_FAN_PIN enabled + #if EXTRUDER_0_AUTO_FAN_PIN > 0 || EXTRUDER_1_AUTO_FAN_PIN > 0 || EXTRUDER_2_AUTO_FAN_PIN > 0 + if(millis() - extruder_autofan_last_check > 2500) // only need to check fan state very infrequently + { + checkExtruderAutoFans(); + extruder_autofan_last_check = millis(); + } + #endif + #ifndef PIDTEMPBED if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL) return; From 289c02eda492ca0d2db860256fd58a9cf4232ad9 Mon Sep 17 00:00:00 2001 From: Robert F-C Date: Tue, 30 Apr 2013 01:11:23 +1000 Subject: [PATCH 17/31] Remove unnecessary pin initialization in stepper.cpp (duplicates initialization in Marlin_main.cpp) --- Marlin/stepper.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 3bc5e9c892..f8d0af9e7c 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -69,9 +69,9 @@ volatile long endstops_stepsTotal,endstops_stepsDone; static volatile bool endstop_x_hit=false; static volatile bool endstop_y_hit=false; static volatile bool endstop_z_hit=false; -#ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED -bool abort_on_endstop_hit = false; -#endif +#ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED +bool abort_on_endstop_hit = false; +#endif static bool old_x_min_endstop=false; static bool old_x_max_endstop=false; @@ -184,20 +184,20 @@ void checkHitEndstops() SERIAL_ECHOPAIR(" Z:",(float)endstops_trigsteps[Z_AXIS]/axis_steps_per_unit[Z_AXIS]); LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "Z"); } - SERIAL_ECHOLN(""); + SERIAL_ECHOLN(""); endstop_x_hit=false; endstop_y_hit=false; - endstop_z_hit=false; -#ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED - if (abort_on_endstop_hit) - { + endstop_z_hit=false; +#ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED + if (abort_on_endstop_hit) + { card.sdprinting = false; card.closefile(); - quickStop(); + quickStop(); setTargetHotend0(0); setTargetHotend1(0); setTargetHotend2(0); - } + } #endif } } @@ -879,10 +879,6 @@ void st_init() disable_e2(); #endif - #ifdef CONTROLLERFAN_PIN - SET_OUTPUT(CONTROLLERFAN_PIN); //Set pin used for driver cooling fan - #endif - // waveform generation = 0100 = CTC TCCR1B &= ~(1< Date: Sun, 12 May 2013 07:51:28 +1000 Subject: [PATCH 18/31] Optimize menu selection for Viki rotary encoder. The Viki LCD rotary encoder uses a different number of steps per rotation. This fixes the seeming "missed" steps when selecting a menu. --- Marlin/ultralcd.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 2dae90a5d4..72404da032 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -76,7 +76,11 @@ static void menu_action_setting_edit_callback_float51(const char* pstr, float* p static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc); static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc); -#define ENCODER_STEPS_PER_MENU_ITEM 5 +#if !defined(LCD_I2C_VIKI) + #define ENCODER_STEPS_PER_MENU_ITEM 5 +#else + #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation +#endif /* Helper macros for menus */ #define START_MENU() do { \ From fbd899a37d2ec36a37119bcbbd3fdde4b3e4b649 Mon Sep 17 00:00:00 2001 From: Jordan Miller Date: Tue, 14 May 2013 16:25:53 -0400 Subject: [PATCH 19/31] Support for BariCUDA Paste Extruder derived from MakerBot Frostruder. Using Ultimachine RAMBo board. M126/M127 and M128/M129. --- Marlin/Marlin.h | 2 ++ Marlin/Marlin_main.cpp | 37 +++++++++++++++++++++++++++++++++++++ Marlin/pins.h | 2 +- Marlin/planner.cpp | 19 +++++++++++++++++++ Marlin/planner.h | 2 ++ 5 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 25c5aca636..af3f517c86 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -186,6 +186,8 @@ extern float add_homeing[3]; extern float min_pos[3]; extern float max_pos[3]; extern int fanSpeed; +extern int ValvePressure; +extern int EtoPPressure; #ifdef FWRETRACT extern bool autoretract_enabled; diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 9f2ba7be17..3d966bf1d7 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -101,6 +101,10 @@ // M115 - Capabilities string // M117 - display message // M119 - Output Endstop status to serial port +// M126 - Solenoid Air Valve Open (BariCUDA support by jmil) +// M127 - Solenoid Air Valve Closed (BariCUDA vent to atmospheric pressure by jmil) +// M128 - EtoP Open (BariCUDA EtoP = electricity to air pressure transducer by jmil) +// M129 - EtoP Closed (BariCUDA EtoP = electricity to air pressure transducer by jmil) // M140 - Set bed target temp // M190 - Wait for bed current temp to reach target temp. // M200 - Set filament diameter @@ -168,6 +172,8 @@ float extruder_offset[2][EXTRUDERS] = { #endif uint8_t active_extruder = 0; int fanSpeed=0; +int ValvePressure=0; +int EtoPPressure=0; #ifdef FWRETRACT bool autoretract_enabled=true; @@ -1169,6 +1175,37 @@ void process_commands() break; #endif //FAN_PIN + // PWM for HEATER_1_PIN + #if HEATER_1_PIN > -1 + case 126: //M126 valve open + if (code_seen('S')){ + ValvePressure=constrain(code_value(),0,255); + } + else { + ValvePressure=255; + } + break; + case 127: //M127 valve closed + ValvePressure = 0; + break; + #endif //HEATER_1_PIN + + // PWM for HEATER_2_PIN + #if HEATER_2_PIN > -1 + case 128: //M128 valve open + if (code_seen('S')){ + EtoPPressure=constrain(code_value(),0,255); + } + else { + EtoPPressure=255; + } + break; + case 129: //M129 valve closed + EtoPPressure = 0; + break; + #endif //HEATER_2_PIN + + #if (PS_ON_PIN > -1) case 80: // M80 - ATX Power On SET_OUTPUT(PS_ON_PIN); //GND diff --git a/Marlin/pins.h b/Marlin/pins.h index 952fa7a9a3..ac25dea4cf 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -1474,7 +1474,7 @@ #define HEATER_1_PIN 7 #define TEMP_1_PIN 1 -#define HEATER_2_PIN -1 +#define HEATER_2_PIN 6 #define TEMP_2_PIN -1 #define E0_STEP_PIN 34 diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 854fd19eec..f7473c6023 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -439,12 +439,18 @@ void check_axes_activity() unsigned char z_active = 0; unsigned char e_active = 0; unsigned char tail_fan_speed = fanSpeed; + unsigned char valve_pressure = 0; + unsigned char e_to_p_pressure = 0; + unsigned char tail_valve_pressure = 0; + unsigned char tail_e_to_p_pressure = 0; block_t *block; if(block_buffer_tail != block_buffer_head) { uint8_t block_index = block_buffer_tail; tail_fan_speed = block_buffer[block_index].fan_speed; + tail_valve_pressure = block_buffer[block_index].valve_pressure; + tail_e_to_p_pressure = block_buffer[block_index].e_to_p_pressure; while(block_index != block_buffer_head) { block = &block_buffer[block_index]; @@ -486,6 +492,17 @@ void check_axes_activity() #ifdef AUTOTEMP getHighESpeed(); #endif + +#if HEATER_1_PIN > -1 + if (ValvePressure != 0){ + analogWrite(HEATER_1_PIN,ValvePressure); // If buffer is empty use current fan speed + } +#endif +#if HEATER_2_PIN > -1 + if (EtoPPressure != 0){ + analogWrite(HEATER_2_PIN,EtoPPressure); // If buffer is empty use current fan speed + } +#endif } @@ -559,6 +576,8 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa } block->fan_speed = fanSpeed; + block->valve_pressure = ValvePressure; + block->e_to_p_pressure = EtoPPressure; // Compute direction bits for this block block->direction_bits = 0; diff --git a/Marlin/planner.h b/Marlin/planner.h index 9a904e5776..4af72a475e 100644 --- a/Marlin/planner.h +++ b/Marlin/planner.h @@ -60,6 +60,8 @@ typedef struct { unsigned long final_rate; // The minimal rate at exit unsigned long acceleration_st; // acceleration steps/sec^2 unsigned long fan_speed; + unsigned long valve_pressure; + unsigned long e_to_p_pressure; volatile char busy; } block_t; From 37f3199df3ad8607caf5cb71158092e28cfce594 Mon Sep 17 00:00:00 2001 From: Jordan Miller Date: Tue, 14 May 2013 17:16:10 -0400 Subject: [PATCH 20/31] fixed problems in planner with solenoids for BariCUDA when set to 0 --- Marlin/planner.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index f7473c6023..0bf59593e1 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -495,12 +495,29 @@ void check_axes_activity() #if HEATER_1_PIN > -1 if (ValvePressure != 0){ - analogWrite(HEATER_1_PIN,ValvePressure); // If buffer is empty use current fan speed + analogWrite(HEATER_1_PIN,ValvePressure); // If buffer is empty use current valve pressure + } + + if((ValvePressure == 0) && (valve_pressure ==0)) { + analogWrite(HEATER_1_PIN, 0); + } + + if (ValvePressure != 0 && tail_valve_pressure !=0) { + analogWrite(HEATER_1_PIN,tail_valve_pressure); } #endif + #if HEATER_2_PIN > -1 if (EtoPPressure != 0){ - analogWrite(HEATER_2_PIN,EtoPPressure); // If buffer is empty use current fan speed + analogWrite(HEATER_2_PIN,EtoPPressure); // If buffer is empty use current EtoP pressure + } + + if((EtoPPressure == 0) && (e_to_p_pressure ==0)) { + analogWrite(HEATER_2_PIN, 0); + } + + if (EtoPPressure != 0 && tail_e_to_p_pressure !=0) { + analogWrite(HEATER_2_PIN,tail_e_to_p_pressure); } #endif } From bd2cd4903e5daedcfebc06b90e7c0e2cf05e5eaa Mon Sep 17 00:00:00 2001 From: Erik van der Zalm Date: Tue, 14 May 2013 23:56:32 +0200 Subject: [PATCH 21/31] Added #ifdef BARICUDA around the BariCUDA changes --- Marlin/Configuration.h | 3 +++ Marlin/Marlin.h | 2 ++ Marlin/Marlin_main.cpp | 60 ++++++++++++++++++++++-------------------- Marlin/pins.h | 4 +++ Marlin/planner.cpp | 14 +++++++--- Marlin/planner.h | 2 ++ 6 files changed, 53 insertions(+), 32 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 83944ab032..3405dfbffe 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -403,6 +403,9 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th // SF send wrong arc g-codes when using Arc Point as fillet procedure //#define SF_ARC_FIX +// Support for the BariCUDA Paste Extruder. +//#define BARICUDA + #include "Configuration_adv.h" #include "thermistortables.h" diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index af3f517c86..551a553907 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -186,8 +186,10 @@ extern float add_homeing[3]; extern float min_pos[3]; extern float max_pos[3]; extern int fanSpeed; +#ifdef BARICUDA extern int ValvePressure; extern int EtoPPressure; +#endif #ifdef FWRETRACT extern bool autoretract_enabled; diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 3d966bf1d7..0a528ea058 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -172,8 +172,10 @@ float extruder_offset[2][EXTRUDERS] = { #endif uint8_t active_extruder = 0; int fanSpeed=0; +#ifdef BARICUDA int ValvePressure=0; int EtoPPressure=0; +#endif #ifdef FWRETRACT bool autoretract_enabled=true; @@ -1174,37 +1176,37 @@ void process_commands() fanSpeed = 0; break; #endif //FAN_PIN - + #ifdef BARICUDA // PWM for HEATER_1_PIN - #if HEATER_1_PIN > -1 - case 126: //M126 valve open - if (code_seen('S')){ - ValvePressure=constrain(code_value(),0,255); - } - else { - ValvePressure=255; - } - break; - case 127: //M127 valve closed - ValvePressure = 0; - break; - #endif //HEATER_1_PIN - - // PWM for HEATER_2_PIN - #if HEATER_2_PIN > -1 - case 128: //M128 valve open - if (code_seen('S')){ - EtoPPressure=constrain(code_value(),0,255); - } - else { - EtoPPressure=255; - } - break; - case 129: //M129 valve closed - EtoPPressure = 0; - break; - #endif //HEATER_2_PIN + #if HEATER_1_PIN > -1 + case 126: //M126 valve open + if (code_seen('S')){ + ValvePressure=constrain(code_value(),0,255); + } + else { + ValvePressure=255; + } + break; + case 127: //M127 valve closed + ValvePressure = 0; + break; + #endif //HEATER_1_PIN + // PWM for HEATER_2_PIN + #if HEATER_2_PIN > -1 + case 128: //M128 valve open + if (code_seen('S')){ + EtoPPressure=constrain(code_value(),0,255); + } + else { + EtoPPressure=255; + } + break; + case 129: //M129 valve closed + EtoPPressure = 0; + break; + #endif //HEATER_2_PIN + #endif #if (PS_ON_PIN > -1) case 80: // M80 - ATX Power On diff --git a/Marlin/pins.h b/Marlin/pins.h index ac25dea4cf..a13c522f71 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -1474,7 +1474,11 @@ #define HEATER_1_PIN 7 #define TEMP_1_PIN 1 +#ifdef BARICUDA #define HEATER_2_PIN 6 +#else +#define HEATER_2_PIN -1 +#endif #define TEMP_2_PIN -1 #define E0_STEP_PIN 34 diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 0bf59593e1..1a37cecb47 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -439,18 +439,22 @@ void check_axes_activity() unsigned char z_active = 0; unsigned char e_active = 0; unsigned char tail_fan_speed = fanSpeed; + #ifdef BARICUDA unsigned char valve_pressure = 0; unsigned char e_to_p_pressure = 0; unsigned char tail_valve_pressure = 0; unsigned char tail_e_to_p_pressure = 0; + #endif block_t *block; if(block_buffer_tail != block_buffer_head) { uint8_t block_index = block_buffer_tail; tail_fan_speed = block_buffer[block_index].fan_speed; + #ifdef BARICUDA tail_valve_pressure = block_buffer[block_index].valve_pressure; tail_e_to_p_pressure = block_buffer[block_index].e_to_p_pressure; + #endif while(block_index != block_buffer_head) { block = &block_buffer[block_index]; @@ -493,7 +497,8 @@ void check_axes_activity() getHighESpeed(); #endif -#if HEATER_1_PIN > -1 +#ifdef BARICUDA + #if HEATER_1_PIN > -1 if (ValvePressure != 0){ analogWrite(HEATER_1_PIN,ValvePressure); // If buffer is empty use current valve pressure } @@ -505,9 +510,9 @@ void check_axes_activity() if (ValvePressure != 0 && tail_valve_pressure !=0) { analogWrite(HEATER_1_PIN,tail_valve_pressure); } -#endif + #endif -#if HEATER_2_PIN > -1 + #if HEATER_2_PIN > -1 if (EtoPPressure != 0){ analogWrite(HEATER_2_PIN,EtoPPressure); // If buffer is empty use current EtoP pressure } @@ -519,6 +524,7 @@ void check_axes_activity() if (EtoPPressure != 0 && tail_e_to_p_pressure !=0) { analogWrite(HEATER_2_PIN,tail_e_to_p_pressure); } + #endif #endif } @@ -593,8 +599,10 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa } block->fan_speed = fanSpeed; + #ifdef BARICUDA block->valve_pressure = ValvePressure; block->e_to_p_pressure = EtoPPressure; + #endif // Compute direction bits for this block block->direction_bits = 0; diff --git a/Marlin/planner.h b/Marlin/planner.h index 4af72a475e..703646eb13 100644 --- a/Marlin/planner.h +++ b/Marlin/planner.h @@ -60,8 +60,10 @@ typedef struct { unsigned long final_rate; // The minimal rate at exit unsigned long acceleration_st; // acceleration steps/sec^2 unsigned long fan_speed; + #ifdef BARICUDA unsigned long valve_pressure; unsigned long e_to_p_pressure; + #endif volatile char busy; } block_t; From 9cc15876be8e2a584fd5ceeee48a751bbda25657 Mon Sep 17 00:00:00 2001 From: MaikStohn Date: Thu, 16 May 2013 01:16:08 +0200 Subject: [PATCH 22/31] Add support for RUMBA thermocouple add on --- Marlin/pins.h | 57 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/Marlin/pins.h b/Marlin/pins.h index a13c522f71..ad88338e87 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -1053,17 +1053,56 @@ #define PS_ON_PIN 45 #define KILL_PIN 46 -#define HEATER_0_PIN 2 // EXTRUDER 1 -#define HEATER_1_PIN 3 // EXTRUDER 2 -#define HEATER_2_PIN 6 // EXTRUDER 3 +#if (TEMP_SENSOR_0==0) + #define TEMP_0_PIN -1 + #define HEATER_0_PIN -1 +#else + #define HEATER_0_PIN 2 // EXTRUDER 1 + #if (TEMP_SENSOR_0==-1) + #define TEMP_0_PIN 6 // ANALOG NUMBERING - connector *K1* on RUMBA thermocouple ADD ON is used + #else + #define TEMP_0_PIN 15 // ANALOG NUMBERING - default connector for thermistor *T0* on rumba board is used + #endif +#endif + +#if (TEMP_SENSOR_1==0) + #define TEMP_1_PIN -1 + #define HEATER_1_PIN -1 +#else + #define HEATER_1_PIN 3 // EXTRUDER 2 + #if (TEMP_SENSOR_1==-1) + #define TEMP_1_PIN 5 // ANALOG NUMBERING - connector *K2* on RUMBA thermocouple ADD ON is used + #else + #define TEMP_1_PIN 14 // ANALOG NUMBERING - default connector for thermistor *T1* on rumba board is used + #endif +#endif + +#if (TEMP_SENSOR_2==0) + #define TEMP_2_PIN -1 + #define HEATER_2_PIN -1 +#else + #define HEATER_2_PIN 6 // EXTRUDER 3 + #if (TEMP_SENSOR_2==-1) + #define TEMP_2_PIN 7 // ANALOG NUMBERING - connector *K3* on RUMBA thermocouple ADD ON is used <-- this can not be used when TEMP_SENSOR_BED is defined as thermocouple + #else + #define TEMP_2_PIN 13 // ANALOG NUMBERING - default connector for thermistor *T2* on rumba board is used + #endif +#endif + +//optional for extruder 4 or chamber: #define TEMP_X_PIN 12 // ANALOG NUMBERING - default connector for thermistor *T3* on rumba board is used //optional FAN1 can be used as 4th heater output: #define HEATER_3_PIN 8 // EXTRUDER 4 -#define HEATER_BED_PIN 9 // BED -#define TEMP_0_PIN 15 // ANALOG NUMBERING -#define TEMP_1_PIN 14 // ANALOG NUMBERING -#define TEMP_2_PIN 13 // ANALOG NUMBERING -//optional for extruder 4 or chamber: #define TEMP_2_PIN 12 // ANALOG NUMBERING -#define TEMP_BED_PIN 11 // ANALOG NUMBERING +#if (TEMP_SENSOR_BED==0) + #define TEMP_BED_PIN -1 + #define HEATER_BED_PIN -1 +#else + #define HEATER_BED_PIN 9 // BED + #if (TEMP_SENSOR_BED==-1) + #define TEMP_BED_PIN 7 // ANALOG NUMBERING - connector *K3* on RUMBA thermocouple ADD ON is used <-- this can not be used when TEMP_SENSOR_2 is defined as thermocouple + #else + #define TEMP_BED_PIN 11 // ANALOG NUMBERING - default connector for thermistor *THB* on rumba board is used + #endif +#endif #define SDPOWER -1 #define SDSS 53 From 61a48cc6626e3b49a56f379ffbb7980adc7e710b Mon Sep 17 00:00:00 2001 From: MaikStohn Date: Thu, 16 May 2013 01:16:33 +0200 Subject: [PATCH 23/31] Add support for RUMBA thermocouple add on --- Marlin/temperature.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 85017750be..665cbe391f 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -571,6 +571,12 @@ static void updateTemperaturesFromRawValues() void tp_init() { +#if (MOTHERBOARD == 80) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1)) + //disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector + MCUCR=(1< Date: Thu, 16 May 2013 01:17:08 +0200 Subject: [PATCH 24/31] fixed wrong pin initialization when using temperature 2 pin input --- Marlin/temperature.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 665cbe391f..6fced65670 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -653,7 +653,7 @@ void tp_init() #if TEMP_2_PIN < 8 DIDR0 |= 1 << TEMP_2_PIN; #else - DIDR2 = 1<<(TEMP_2_PIN - 8); + DIDR2 |= 1<<(TEMP_2_PIN - 8); #endif #endif #if (TEMP_BED_PIN > -1) From 95dff34b734d3b43857ab6b3feaa95a8e5b97fea Mon Sep 17 00:00:00 2001 From: MaikStohn Date: Thu, 16 May 2013 01:17:38 +0200 Subject: [PATCH 25/31] fixed wrong compare for min temp check of heater 1 and heater 2 --- Marlin/temperature.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 6fced65670..18cdec65fc 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -695,7 +695,7 @@ void tp_init() #if (EXTRUDERS > 1) && defined(HEATER_1_MINTEMP) minttemp[1] = HEATER_1_MINTEMP; - while(analog2temp(minttemp_raw[1], 1) > HEATER_1_MINTEMP) { + while(analog2temp(minttemp_raw[1], 1) < HEATER_1_MINTEMP) { #if HEATER_1_RAW_LO_TEMP < HEATER_1_RAW_HI_TEMP minttemp_raw[1] += OVERSAMPLENR; #else @@ -716,7 +716,7 @@ void tp_init() #if (EXTRUDERS > 2) && defined(HEATER_2_MINTEMP) minttemp[2] = HEATER_2_MINTEMP; - while(analog2temp(minttemp_raw[2], 2) > HEATER_2_MINTEMP) { + while(analog2temp(minttemp_raw[2], 2) < HEATER_2_MINTEMP) { #if HEATER_2_RAW_LO_TEMP < HEATER_2_RAW_HI_TEMP minttemp_raw[2] += OVERSAMPLENR; #else From b668cb051693758a9b1919fbb162ef298bb3d704 Mon Sep 17 00:00:00 2001 From: Gord Christmas Date: Thu, 16 May 2013 06:47:42 -0700 Subject: [PATCH 26/31] Adding in clean copies of Servo library from Arduino 1.0.4 --- Marlin/Servo.cpp | 337 +++++++++++++++++++++++++++++++++++++++++++++++ Marlin/Servo.h | 126 ++++++++++++++++++ 2 files changed, 463 insertions(+) create mode 100644 Marlin/Servo.cpp create mode 100644 Marlin/Servo.h diff --git a/Marlin/Servo.cpp b/Marlin/Servo.cpp new file mode 100644 index 0000000000..02138b5825 --- /dev/null +++ b/Marlin/Servo.cpp @@ -0,0 +1,337 @@ +/* + Servo.cpp - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2 + Copyright (c) 2009 Michael Margolis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + + A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method. + The servos are pulsed in the background using the value most recently written using the write() method + + Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached. + Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four. + + The methods are: + + Servo - Class for manipulating servo motors connected to Arduino pins. + + attach(pin ) - Attaches a servo motor to an i/o pin. + attach(pin, min, max ) - Attaches to a pin setting min and max values in microseconds + default min is 544, max is 2400 + + write() - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds) + writeMicroseconds() - Sets the servo pulse width in microseconds + read() - Gets the last written servo pulse width as an angle between 0 and 180. + readMicroseconds() - Gets the last written servo pulse width in microseconds. (was read_us() in first release) + attached() - Returns true if there is a servo attached. + detach() - Stops an attached servos from pulsing its i/o pin. + +*/ + +#include +#include + +#include "Servo.h" + +#define usToTicks(_us) (( clockCyclesPerMicrosecond()* _us) / 8) // converts microseconds to tick (assumes prescale of 8) // 12 Aug 2009 +#define ticksToUs(_ticks) (( (unsigned)_ticks * 8)/ clockCyclesPerMicrosecond() ) // converts from ticks back to microseconds + + +#define TRIM_DURATION 2 // compensation ticks to trim adjust for digitalWrite delays // 12 August 2009 + +//#define NBR_TIMERS (MAX_SERVOS / SERVOS_PER_TIMER) + +static servo_t servos[MAX_SERVOS]; // static array of servo structures +static volatile int8_t Channel[_Nbr_16timers ]; // counter for the servo being pulsed for each timer (or -1 if refresh interval) + +uint8_t ServoCount = 0; // the total number of attached servos + + +// convenience macros +#define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / SERVOS_PER_TIMER)) // returns the timer controlling this servo +#define SERVO_INDEX_TO_CHANNEL(_servo_nbr) (_servo_nbr % SERVOS_PER_TIMER) // returns the index of the servo on this timer +#define SERVO_INDEX(_timer,_channel) ((_timer*SERVOS_PER_TIMER) + _channel) // macro to access servo index by timer and channel +#define SERVO(_timer,_channel) (servos[SERVO_INDEX(_timer,_channel)]) // macro to access servo class by timer and channel + +#define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4) // minimum value in uS for this servo +#define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4) // maximum value in uS for this servo + +/************ static functions common to all instances ***********************/ + +static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t *TCNTn, volatile uint16_t* OCRnA) +{ + if( Channel[timer] < 0 ) + *TCNTn = 0; // channel set to -1 indicated that refresh interval completed so reset the timer + else{ + if( SERVO_INDEX(timer,Channel[timer]) < ServoCount && SERVO(timer,Channel[timer]).Pin.isActive == true ) + digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,LOW); // pulse this channel low if activated + } + + Channel[timer]++; // increment to the next channel + if( SERVO_INDEX(timer,Channel[timer]) < ServoCount && Channel[timer] < SERVOS_PER_TIMER) { + *OCRnA = *TCNTn + SERVO(timer,Channel[timer]).ticks; + if(SERVO(timer,Channel[timer]).Pin.isActive == true) // check if activated + digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,HIGH); // its an active channel so pulse it high + } + else { + // finished all channels so wait for the refresh period to expire before starting over + if( ((unsigned)*TCNTn) + 4 < usToTicks(REFRESH_INTERVAL) ) // allow a few ticks to ensure the next OCR1A not missed + *OCRnA = (unsigned int)usToTicks(REFRESH_INTERVAL); + else + *OCRnA = *TCNTn + 4; // at least REFRESH_INTERVAL has elapsed + Channel[timer] = -1; // this will get incremented at the end of the refresh period to start again at the first channel + } +} + +#ifndef WIRING // Wiring pre-defines signal handlers so don't define any if compiling for the Wiring platform +// Interrupt handlers for Arduino +#if defined(_useTimer1) +SIGNAL (TIMER1_COMPA_vect) +{ + handle_interrupts(_timer1, &TCNT1, &OCR1A); +} +#endif + +#if defined(_useTimer3) +SIGNAL (TIMER3_COMPA_vect) +{ + handle_interrupts(_timer3, &TCNT3, &OCR3A); +} +#endif + +#if defined(_useTimer4) +SIGNAL (TIMER4_COMPA_vect) +{ + handle_interrupts(_timer4, &TCNT4, &OCR4A); +} +#endif + +#if defined(_useTimer5) +SIGNAL (TIMER5_COMPA_vect) +{ + handle_interrupts(_timer5, &TCNT5, &OCR5A); +} +#endif + +#elif defined WIRING +// Interrupt handlers for Wiring +#if defined(_useTimer1) +void Timer1Service() +{ + handle_interrupts(_timer1, &TCNT1, &OCR1A); +} +#endif +#if defined(_useTimer3) +void Timer3Service() +{ + handle_interrupts(_timer3, &TCNT3, &OCR3A); +} +#endif +#endif + + +static void initISR(timer16_Sequence_t timer) +{ +#if defined (_useTimer1) + if(timer == _timer1) { + TCCR1A = 0; // normal counting mode + TCCR1B = _BV(CS11); // set prescaler of 8 + TCNT1 = 0; // clear the timer count +#if defined(__AVR_ATmega8__)|| defined(__AVR_ATmega128__) + TIFR |= _BV(OCF1A); // clear any pending interrupts; + TIMSK |= _BV(OCIE1A) ; // enable the output compare interrupt +#else + // here if not ATmega8 or ATmega128 + TIFR1 |= _BV(OCF1A); // clear any pending interrupts; + TIMSK1 |= _BV(OCIE1A) ; // enable the output compare interrupt +#endif +#if defined(WIRING) + timerAttach(TIMER1OUTCOMPAREA_INT, Timer1Service); +#endif + } +#endif + +#if defined (_useTimer3) + if(timer == _timer3) { + TCCR3A = 0; // normal counting mode + TCCR3B = _BV(CS31); // set prescaler of 8 + TCNT3 = 0; // clear the timer count +#if defined(__AVR_ATmega128__) + TIFR |= _BV(OCF3A); // clear any pending interrupts; + ETIMSK |= _BV(OCIE3A); // enable the output compare interrupt +#else + TIFR3 = _BV(OCF3A); // clear any pending interrupts; + TIMSK3 = _BV(OCIE3A) ; // enable the output compare interrupt +#endif +#if defined(WIRING) + timerAttach(TIMER3OUTCOMPAREA_INT, Timer3Service); // for Wiring platform only +#endif + } +#endif + +#if defined (_useTimer4) + if(timer == _timer4) { + TCCR4A = 0; // normal counting mode + TCCR4B = _BV(CS41); // set prescaler of 8 + TCNT4 = 0; // clear the timer count + TIFR4 = _BV(OCF4A); // clear any pending interrupts; + TIMSK4 = _BV(OCIE4A) ; // enable the output compare interrupt + } +#endif + +#if defined (_useTimer5) + if(timer == _timer5) { + TCCR5A = 0; // normal counting mode + TCCR5B = _BV(CS51); // set prescaler of 8 + TCNT5 = 0; // clear the timer count + TIFR5 = _BV(OCF5A); // clear any pending interrupts; + TIMSK5 = _BV(OCIE5A) ; // enable the output compare interrupt + } +#endif +} + +static void finISR(timer16_Sequence_t timer) +{ + //disable use of the given timer +#if defined WIRING // Wiring + if(timer == _timer1) { + #if defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) + TIMSK1 &= ~_BV(OCIE1A) ; // disable timer 1 output compare interrupt + #else + TIMSK &= ~_BV(OCIE1A) ; // disable timer 1 output compare interrupt + #endif + timerDetach(TIMER1OUTCOMPAREA_INT); + } + else if(timer == _timer3) { + #if defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) + TIMSK3 &= ~_BV(OCIE3A); // disable the timer3 output compare A interrupt + #else + ETIMSK &= ~_BV(OCIE3A); // disable the timer3 output compare A interrupt + #endif + timerDetach(TIMER3OUTCOMPAREA_INT); + } +#else + //For arduino - in future: call here to a currently undefined function to reset the timer +#endif +} + +static boolean isTimerActive(timer16_Sequence_t timer) +{ + // returns true if any servo is active on this timer + for(uint8_t channel=0; channel < SERVOS_PER_TIMER; channel++) { + if(SERVO(timer,channel).Pin.isActive == true) + return true; + } + return false; +} + + +/****************** end of static functions ******************************/ + +Servo::Servo() +{ + if( ServoCount < MAX_SERVOS) { + this->servoIndex = ServoCount++; // assign a servo index to this instance + servos[this->servoIndex].ticks = usToTicks(DEFAULT_PULSE_WIDTH); // store default values - 12 Aug 2009 + } + else + this->servoIndex = INVALID_SERVO ; // too many servos +} + +uint8_t Servo::attach(int pin) +{ + return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH); +} + +uint8_t Servo::attach(int pin, int min, int max) +{ + if(this->servoIndex < MAX_SERVOS ) { + pinMode( pin, OUTPUT) ; // set servo pin to output + servos[this->servoIndex].Pin.nbr = pin; + // todo min/max check: abs(min - MIN_PULSE_WIDTH) /4 < 128 + this->min = (MIN_PULSE_WIDTH - min)/4; //resolution of min/max is 4 uS + this->max = (MAX_PULSE_WIDTH - max)/4; + // initialize the timer if it has not already been initialized + timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex); + if(isTimerActive(timer) == false) + initISR(timer); + servos[this->servoIndex].Pin.isActive = true; // this must be set after the check for isTimerActive + } + return this->servoIndex ; +} + +void Servo::detach() +{ + servos[this->servoIndex].Pin.isActive = false; + timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex); + if(isTimerActive(timer) == false) { + finISR(timer); + } +} + +void Servo::write(int value) +{ + if(value < MIN_PULSE_WIDTH) + { // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds) + if(value < 0) value = 0; + if(value > 180) value = 180; + value = map(value, 0, 180, SERVO_MIN(), SERVO_MAX()); + } + this->writeMicroseconds(value); +} + +void Servo::writeMicroseconds(int value) +{ + // calculate and store the values for the given channel + byte channel = this->servoIndex; + if( (channel < MAX_SERVOS) ) // ensure channel is valid + { + if( value < SERVO_MIN() ) // ensure pulse width is valid + value = SERVO_MIN(); + else if( value > SERVO_MAX() ) + value = SERVO_MAX(); + + value = value - TRIM_DURATION; + value = usToTicks(value); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009 + + uint8_t oldSREG = SREG; + cli(); + servos[channel].ticks = value; + SREG = oldSREG; + } +} + +int Servo::read() // return the value as degrees +{ + return map( this->readMicroseconds()+1, SERVO_MIN(), SERVO_MAX(), 0, 180); +} + +int Servo::readMicroseconds() +{ + unsigned int pulsewidth; + if( this->servoIndex != INVALID_SERVO ) + pulsewidth = ticksToUs(servos[this->servoIndex].ticks) + TRIM_DURATION ; // 12 aug 2009 + else + pulsewidth = 0; + + return pulsewidth; +} + +bool Servo::attached() +{ + return servos[this->servoIndex].Pin.isActive ; +} diff --git a/Marlin/Servo.h b/Marlin/Servo.h new file mode 100644 index 0000000000..a76954a06f --- /dev/null +++ b/Marlin/Servo.h @@ -0,0 +1,126 @@ +/* + Servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2 + Copyright (c) 2009 Michael Margolis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* + + A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method. + The servos are pulsed in the background using the value most recently written using the write() method + + Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached. + Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four. + The sequence used to sieze timers is defined in timers.h + + The methods are: + + Servo - Class for manipulating servo motors connected to Arduino pins. + + attach(pin ) - Attaches a servo motor to an i/o pin. + attach(pin, min, max ) - Attaches to a pin setting min and max values in microseconds + default min is 544, max is 2400 + + write() - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds) + writeMicroseconds() - Sets the servo pulse width in microseconds + read() - Gets the last written servo pulse width as an angle between 0 and 180. + readMicroseconds() - Gets the last written servo pulse width in microseconds. (was read_us() in first release) + attached() - Returns true if there is a servo attached. + detach() - Stops an attached servos from pulsing its i/o pin. + */ + +#ifndef Servo_h +#define Servo_h + +#include + +/* + * Defines for 16 bit timers used with Servo library + * + * If _useTimerX is defined then TimerX is a 16 bit timer on the curent board + * timer16_Sequence_t enumerates the sequence that the timers should be allocated + * _Nbr_16timers indicates how many 16 bit timers are available. + * + */ + +// Say which 16 bit timers can be used and in what order +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +#define _useTimer5 +#define _useTimer1 +#define _useTimer3 +#define _useTimer4 +typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ; + +#elif defined(__AVR_ATmega32U4__) +#define _useTimer1 +typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ; + +#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) +#define _useTimer3 +#define _useTimer1 +typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; + +#elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) +#define _useTimer3 +#define _useTimer1 +typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; + +#else // everything else +#define _useTimer1 +typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ; +#endif + +#define Servo_VERSION 2 // software version of this library + +#define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo +#define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo +#define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached +#define REFRESH_INTERVAL 20000 // minumim time to refresh servos in microseconds + +#define SERVOS_PER_TIMER 12 // the maximum number of servos controlled by one timer +#define MAX_SERVOS (_Nbr_16timers * SERVOS_PER_TIMER) + +#define INVALID_SERVO 255 // flag indicating an invalid servo index + +typedef struct { + uint8_t nbr :6 ; // a pin number from 0 to 63 + uint8_t isActive :1 ; // true if this channel is enabled, pin not pulsed if false +} ServoPin_t ; + +typedef struct { + ServoPin_t Pin; + unsigned int ticks; +} servo_t; + +class Servo +{ +public: + Servo(); + uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure + uint8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes. + void detach(); + void write(int value); // if value is < 200 its treated as an angle, otherwise as pulse width in microseconds + void writeMicroseconds(int value); // Write pulse width in microseconds + int read(); // returns current pulse width as an angle between 0 and 180 degrees + int readMicroseconds(); // returns current pulse width in microseconds for this servo (was read_us() in first release) + bool attached(); // return true if this servo is attached, otherwise false +private: + uint8_t servoIndex; // index into the channel data for this servo + int8_t min; // minimum is this value times 4 added to MIN_PULSE_WIDTH + int8_t max; // maximum is this value times 4 added to MAX_PULSE_WIDTH +}; + +#endif From dc59f07d240119f3031dc905b21232f581f3e11b Mon Sep 17 00:00:00 2001 From: Gord Christmas Date: Thu, 16 May 2013 07:03:01 -0700 Subject: [PATCH 27/31] First attempt at refactoring of original servo code. Only adding servo support as a start to keep things simple. --- Marlin/Configuration.h | 61 ++++-- Marlin/Marlin_main.cpp | 444 +++++++++++++++++++++++------------------ Marlin/Servo.h | 26 ++- Marlin/pins.h | 171 ++++++++-------- 4 files changed, 395 insertions(+), 307 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 3405dfbffe..e22c83cae0 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2,7 +2,7 @@ #define CONFIGURATION_H // This configurtion file contains the basic settings. -// Advanced settings can be found in Configuration_adv.h +// Advanced settings can be found in Configuration_adv.h // BASIC SETTINGS: select your board type, temperature sensor type, axis scaling, and endstop configuration //User specified version info of this build to display in [Pronterface, etc] terminal window during startup. @@ -78,7 +78,7 @@ // 9 is 100k GE Sensing AL03006-58.2K-97-G1 (4.7k pullup) // 10 is 100k RS thermistor 198-961 (4.7k pullup) // -// 1k ohm pullup tables - This is not normal, you would have to have changed out your 4.7k for 1k +// 1k ohm pullup tables - This is not normal, you would have to have changed out your 4.7k for 1k // (but gives greater accuracy and more stable PID) // 51 is 100k thermistor - EPCOS (1k pullup) // 52 is 200k thermistor - ATC Semitec 204GT-2 (1k pullup) @@ -95,7 +95,7 @@ #define TEMP_WINDOW 1 // (degC) Window around target to start the recidency timer x degC early. // The minimal temperature defines the temperature below which the heater will not be enabled It is used -// to check that the wiring to the thermistor is not broken. +// to check that the wiring to the thermistor is not broken. // Otherwise this would lead to the heater being powered on all the time. #define HEATER_0_MINTEMP 5 #define HEATER_1_MINTEMP 5 @@ -121,7 +121,7 @@ #define BANG_MAX 256 // limits current to nozzle while in bang-bang mode; 256=full current #define PID_MAX 256 // limits current to nozzle while PID is active (see PID_FUNCTIONAL_RANGE below); 256=full current #ifdef PIDTEMP - //#define PID_DEBUG // Sends debug data to the serial port. + //#define PID_DEBUG // Sends debug data to the serial port. //#define PID_OPENLOOP 1 // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX #define PID_FUNCTIONAL_RANGE 10 // If the temperature difference between the target temperature and the actual temperature // is more then PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max. @@ -132,15 +132,15 @@ // If you are using a preconfigured hotend then you can use one of the value sets by uncommenting it // Ultimaker #define DEFAULT_Kp 22.2 - #define DEFAULT_Ki 1.08 - #define DEFAULT_Kd 114 + #define DEFAULT_Ki 1.08 + #define DEFAULT_Kd 114 // Makergear // #define DEFAULT_Kp 7.0 -// #define DEFAULT_Ki 0.1 -// #define DEFAULT_Kd 12 +// #define DEFAULT_Ki 0.1 +// #define DEFAULT_Kd 12 -// Mendel Parts V9 on 12V +// Mendel Parts V9 on 12V // #define DEFAULT_Kp 63.0 // #define DEFAULT_Ki 2.25 // #define DEFAULT_Kd 440 @@ -149,11 +149,11 @@ // Bed Temperature Control // Select PID or bang-bang with PIDTEMPBED. If bang-bang, BED_LIMIT_SWITCHING will enable hysteresis // -// uncomment this to enable PID on the bed. It uses the same ferquency PWM as the extruder. +// uncomment this to enable PID on the bed. It uses the same ferquency PWM as the extruder. // If your PID_dT above is the default, and correct for your hardware/configuration, that means 7.689Hz, // which is fine for driving a square wave into a resistive load and does not significantly impact you FET heating. -// This also works fine on a Fotek SSR-10DA Solid State Relay into a 250W heater. -// If your configuration is significantly different than this and you don't understand the issues involved, you proabaly +// This also works fine on a Fotek SSR-10DA Solid State Relay into a 250W heater. +// If your configuration is significantly different than this and you don't understand the issues involved, you proabaly // shouldn't use bed PID until someone else verifies your hardware works. // If this is enabled, find your own PID constants below. //#define PIDTEMPBED @@ -223,9 +223,9 @@ #endif // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins. -const bool X_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. -const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. -const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. +const bool X_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. +const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. +const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. //#define DISABLE_MAX_ENDSTOPS // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 @@ -280,13 +280,13 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E #define HOMING_FEEDRATE {50*60, 50*60, 4*60, 0} // set the homing speeds (mm/min) -// default settings +// default settings #define DEFAULT_AXIS_STEPS_PER_UNIT {78.7402,78.7402,200.0*8/3,760*1.1} // default steps per unit for ultimaker #define DEFAULT_MAX_FEEDRATE {500, 500, 5, 25} // (mm/sec) #define DEFAULT_MAX_ACCELERATION {9000,9000,100,10000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. -#define DEFAULT_ACCELERATION 3000 // X, Y, Z and E max acceleration in mm/s^2 for printing moves +#define DEFAULT_ACCELERATION 3000 // X, Y, Z and E max acceleration in mm/s^2 for printing moves #define DEFAULT_RETRACT_ACCELERATION 3000 // X, Y, Z and E max acceleration in mm/s^2 for r retracts // Offset of the extruders (uncomment if using more than one and relying on firmware to position when changing). @@ -307,7 +307,7 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th // EEPROM // the microcontroller can store settings in the EEPROM, e.g. max velocity... // M500 - stores paramters in EEPROM -// M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily). +// M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily). // M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to. //define this to enable eeprom support //#define EEPROM_SETTINGS @@ -353,7 +353,7 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #if defined(ULTIMAKERCONTROLLER) || defined(REPRAP_DISCOUNT_SMART_CONTROLLER) || defined(G3D_PANEL) #define ULTIPANEL #define NEWPANEL -#endif +#endif #if defined(REPRAPWORLD_KEYPAD) #define NEWPANEL @@ -361,7 +361,7 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #endif // Preheat Constants -#define PLA_PREHEAT_HOTEND_TEMP 180 +#define PLA_PREHEAT_HOTEND_TEMP 180 #define PLA_PREHEAT_HPB_TEMP 70 #define PLA_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255 @@ -381,7 +381,7 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #define LCD_WIDTH 20 #define LCD_HEIGHT 4 #endif -#else //no panel but just lcd +#else //no panel but just lcd #ifdef ULTRA_LCD #ifdef DOGLCD // Change number of lines to match the 128x64 graphics display #define LCD_WIDTH 20 @@ -389,7 +389,7 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #else #define LCD_WIDTH 16 #define LCD_HEIGHT 2 - #endif + #endif #endif #endif @@ -406,6 +406,23 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th // Support for the BariCUDA Paste Extruder. //#define BARICUDA +/*********************************************************************\ +* +* R/C SERVO support +* +* Sponsored by TrinityLabs, Reworked by codexmas +* +**********************************************************************/ + +// Number of servos +// +// If you select a configuration below, this will receive a default value and does not need to be set manually +// set it manually if you have more servos than extruders and wish to manually control some +// leaving it undefined or defining as 0 will disable the servo subsystem +// If unsure, leave commented / disabled +// +// #define NUM_SERVOS 3 + #include "Configuration_adv.h" #include "thermistortables.h" diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 0a528ea058..0ff34605c3 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -3,17 +3,17 @@ /* Reprap firmware based on Sprinter and grbl. Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm - + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -22,8 +22,8 @@ This firmware is a mashup between Sprinter and grbl. (https://github.com/kliment/Sprinter) (https://github.com/simen/grbl/tree) - - It has preliminary support for Matthew Roberts advance algorithm + + It has preliminary support for Matthew Roberts advance algorithm http://reprap.org/pipermail/reprap-dev/2011-May/003323.html */ @@ -40,6 +40,10 @@ #include "language.h" #include "pins_arduino.h" +#if (defined NUM_SERVOS) && (NUM_SERVOS > 0) +#include "Servo.h" +#endif + #if DIGIPOTSS_PIN > -1 #include #endif @@ -93,11 +97,11 @@ // M81 - Turn off Power Supply // M82 - Set E codes absolute (default) // M83 - Set E codes relative while in Absolute Coordinates (G90) mode -// M84 - Disable steppers until next move, +// M84 - Disable steppers until next move, // or use S to specify an inactivity timeout, after which the steppers will be disabled. S0 to disable the timeout. // M85 - Set inactivity shutdown timer with parameter S. To disable set zero (default) // M92 - Set axis_steps_per_unit - same syntax as G92 -// M114 - Output current position to serial port +// M114 - Output current position to serial port // M115 - Capabilities string // M117 - display message // M119 - Output Endstop status to serial port @@ -121,6 +125,7 @@ // M220 S- set speed factor override percentage // M221 S- set extrude factor override percentage // M240 - Trigger a camera to take a photograph +// M280 - set servo position absolute. P: servo index, S: angle or microseconds // M300 - Play beepsound S P // M301 - Set PID parameters P I and D // M302 - Allow cold extrudes @@ -128,7 +133,7 @@ // M304 - Set bed PID parameters P I and D // M400 - Finish all moves // M500 - stores paramters in EEPROM -// M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily). +// M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily). // M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to. // M503 - print the current settings (from memory not from eeprom) // M540 - Use S[0|1] to enable or disable the stop SD card print on endstop hit (requires ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) @@ -164,11 +169,11 @@ float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS }; float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS }; // Extruder offset, only in XY plane #if EXTRUDERS > 1 -float extruder_offset[2][EXTRUDERS] = { +float extruder_offset[2][EXTRUDERS] = { #if defined(EXTRUDER_OFFSET_X) && defined(EXTRUDER_OFFSET_Y) - EXTRUDER_OFFSET_X, EXTRUDER_OFFSET_Y + EXTRUDER_OFFSET_X, EXTRUDER_OFFSET_Y #endif -}; +}; #endif uint8_t active_extruder = 0; int fanSpeed=0; @@ -225,6 +230,10 @@ static uint8_t tmp_extruder; bool Stopped=false; +#if (defined NUM_SERVOS) && (NUM_SERVOS > 0) + Servo servos[NUM_SERVOS]; +#endif + //=========================================================================== //=============================ROUTINES============================= //=========================================================================== @@ -296,7 +305,7 @@ void setup_killpin() WRITE(KILL_PIN,HIGH); #endif } - + void setup_photpin() { #ifdef PHOTOGRAPH_PIN @@ -304,7 +313,7 @@ void setup_photpin() SET_OUTPUT(PHOTOGRAPH_PIN); WRITE(PHOTOGRAPH_PIN, LOW); #endif - #endif + #endif } void setup_powerhold() @@ -324,16 +333,35 @@ void setup_powerhold() void suicide() { #ifdef SUICIDE_PIN - #if (SUICIDE_PIN> -1) + #if (SUICIDE_PIN> -1) SET_OUTPUT(SUICIDE_PIN); WRITE(SUICIDE_PIN, LOW); #endif #endif } +void servo_init() +{ + #if (NUM_SERVOS >= 1) && defined (SERVO0_PIN) && (SERVO0_PIN > -1) + servos[0].attach(SERVO0_PIN); + #endif + #if (NUM_SERVOS >= 2) && defined (SERVO1_PIN) && (SERVO1_PIN > -1) + servos[1].attach(SERVO1_PIN); + #endif + #if (NUM_SERVOS >= 3) && defined (SERVO2_PIN) && (SERVO2_PIN > -1) + servos[2].attach(SERVO2_PIN); + #endif + #if (NUM_SERVOS >= 4) && defined (SERVO3_PIN) && (SERVO3_PIN > -1) + servos[3].attach(SERVO3_PIN); + #endif + #if (NUM_SERVOS >= 5) + #error "TODO: enter initalisation code for more servos" + #endif +} + void setup() { - setup_killpin(); + setup_killpin(); setup_powerhold(); MYSERIAL.begin(BAUDRATE); SERIAL_PROTOCOLLNPGM("start"); @@ -370,22 +398,23 @@ void setup() { fromsd[i] = false; } - + // loads data from EEPROM if available else uses defaults (and resets step acceleration rate) - Config_RetrieveSettings(); + Config_RetrieveSettings(); - tp_init(); // Initialize temperature loop + tp_init(); // Initialize temperature loop plan_init(); // Initialize planner; watchdog_init(); st_init(); // Initialize stepper, this enables interrupts! setup_photpin(); - + servo_init(); + lcd_init(); - + #ifdef CONTROLLERFAN_PIN SET_OUTPUT(CONTROLLERFAN_PIN); //Set pin used for driver cooling fan #endif - + #ifdef EXTRUDERFAN_PIN SET_OUTPUT(EXTRUDERFAN_PIN); //Set pin used for extruder cooling fan #endif @@ -439,14 +468,14 @@ void loop() lcd_update(); } -void get_command() -{ +void get_command() +{ while( MYSERIAL.available() > 0 && buflen < BUFSIZE) { serial_char = MYSERIAL.read(); - if(serial_char == '\n' || - serial_char == '\r' || - (serial_char == ':' && comment_mode == false) || - serial_count >= (MAX_CMD_SIZE - 1) ) + if(serial_char == '\n' || + serial_char == '\r' || + (serial_char == ':' && comment_mode == false) || + serial_count >= (MAX_CMD_SIZE - 1) ) { if(!serial_count) { //if empty line comment_mode = false; //for new command @@ -487,7 +516,7 @@ void get_command() } //if no errors, continue parsing } - else + else { SERIAL_ERROR_START; SERIAL_ERRORPGM(MSG_ERR_NO_CHECKSUM); @@ -523,7 +552,7 @@ void get_command() if(card.saving) break; #endif //SDSUPPORT - SERIAL_PROTOCOLLNPGM(MSG_OK); + SERIAL_PROTOCOLLNPGM(MSG_OK); } else { SERIAL_ERRORLNPGM(MSG_ERR_STOPPED); @@ -553,10 +582,10 @@ void get_command() while( !card.eof() && buflen < BUFSIZE) { int16_t n=card.get(); serial_char = (char)n; - if(serial_char == '\n' || - serial_char == '\r' || - (serial_char == ':' && comment_mode == false) || - serial_count >= (MAX_CMD_SIZE - 1)||n==-1) + if(serial_char == '\n' || + serial_char == '\r' || + (serial_char == ':' && comment_mode == false) || + serial_count >= (MAX_CMD_SIZE - 1)||n==-1) { if(card.eof()){ SERIAL_PROTOCOLLNPGM(MSG_FILE_PRINTED); @@ -572,7 +601,7 @@ void get_command() lcd_setstatus(time); card.printingHasFinished(); card.checkautostart(true); - + } if(!serial_count) { @@ -584,7 +613,7 @@ void get_command() fromsd[bufindw] = true; buflen += 1; bufindw = (bufindw + 1)%BUFSIZE; -// } +// } comment_mode = false; //for new command serial_count = 0; //clear buffer } @@ -594,20 +623,20 @@ void get_command() if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char; } } - + #endif //SDSUPPORT } -float code_value() -{ - return (strtod(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL)); +float code_value() +{ + return (strtod(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL)); } -long code_value_long() -{ - return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10)); +long code_value_long() +{ + return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10)); } bool code_seen(char code) @@ -656,19 +685,19 @@ static void homeaxis(int axis) { feedrate = homing_feedrate[axis]; plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); - + current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); destination[axis] = -home_retract_mm(axis) * home_dir(axis); plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); - + destination[axis] = 2*home_retract_mm(axis) * home_dir(axis); - feedrate = homing_feedrate[axis]/2 ; + feedrate = homing_feedrate[axis]/2 ; plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); - - axis_is_at_home(axis); + + axis_is_at_home(axis); destination[axis] = current_position[axis]; feedrate = 0.0; endstops_hit_on_purpose(); @@ -711,7 +740,7 @@ void process_commands() codenum = 0; if(code_seen('P')) codenum = code_value(); // milliseconds to wait if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait - + st_synchronize(); codenum += millis(); // keep track of when we started waiting previous_millis_cmd = millis(); @@ -721,30 +750,30 @@ void process_commands() lcd_update(); } break; - #ifdef FWRETRACT + #ifdef FWRETRACT case 10: // G10 retract - if(!retracted) + if(!retracted) { destination[X_AXIS]=current_position[X_AXIS]; destination[Y_AXIS]=current_position[Y_AXIS]; - destination[Z_AXIS]=current_position[Z_AXIS]; + destination[Z_AXIS]=current_position[Z_AXIS]; current_position[Z_AXIS]+=-retract_zlift; - destination[E_AXIS]=current_position[E_AXIS]-retract_length; + destination[E_AXIS]=current_position[E_AXIS]-retract_length; feedrate=retract_feedrate; retracted=true; prepare_move(); } - + break; case 11: // G10 retract_recover - if(!retracted) + if(!retracted) { destination[X_AXIS]=current_position[X_AXIS]; destination[Y_AXIS]=current_position[Y_AXIS]; - destination[Z_AXIS]=current_position[Z_AXIS]; - + destination[Z_AXIS]=current_position[Z_AXIS]; + current_position[Z_AXIS]+=retract_zlift; - current_position[E_AXIS]+=-retract_recover_length; + current_position[E_AXIS]+=-retract_recover_length; feedrate=retract_recover_feedrate; retracted=false; prepare_move(); @@ -756,34 +785,34 @@ void process_commands() saved_feedmultiply = feedmultiply; feedmultiply = 100; previous_millis_cmd = millis(); - + enable_endstops(true); - + for(int8_t i=0; i < NUM_AXIS; i++) { destination[i] = current_position[i]; } feedrate = 0.0; home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2]))); - + #if Z_HOME_DIR > 0 // If homing away from BED do Z first if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) { HOMEAXIS(Z); } #endif - + #ifdef QUICK_HOME if((home_all_axis)||( code_seen(axis_codes[X_AXIS]) && code_seen(axis_codes[Y_AXIS])) ) //first diagonal move { - current_position[X_AXIS] = 0;current_position[Y_AXIS] = 0; + current_position[X_AXIS] = 0;current_position[Y_AXIS] = 0; - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR;destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR; - feedrate = homing_feedrate[X_AXIS]; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR;destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR; + feedrate = homing_feedrate[X_AXIS]; if(homing_feedrate[Y_AXIS] 0){ @@ -900,12 +929,12 @@ void process_commands() #endif case 17: LCD_MESSAGEPGM(MSG_NO_MOVE); - enable_x(); - enable_y(); - enable_z(); - enable_e0(); - enable_e1(); - enable_e2(); + enable_x(); + enable_y(); + enable_z(); + enable_e0(); + enable_e1(); + enable_e2(); break; #ifdef SDSUPPORT @@ -915,9 +944,9 @@ void process_commands() SERIAL_PROTOCOLLNPGM(MSG_END_FILE_LIST); break; case 21: // M21 - init SD card - + card.initsd(); - + break; case 22: //M22 - release SD card card.release(); @@ -957,7 +986,7 @@ void process_commands() //processed in write to file routine above //card,saving = false; break; - case 30: //M30 Delete File + case 30: //M30 Delete File if (card.cardOK){ card.closefile(); starpos = (strchr(strchr_pointer + 4,'*')); @@ -978,7 +1007,7 @@ void process_commands() } card.openLogFile(strchr_pointer+5); break; - + #endif //SDSUPPORT case 31: //M31 take time since the start of the SD print or an M109 command @@ -1035,11 +1064,11 @@ void process_commands() } #if (TEMP_0_PIN > -1) SERIAL_PROTOCOLPGM("ok T:"); - SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1); + SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1); SERIAL_PROTOCOLPGM(" /"); - SERIAL_PROTOCOL_F(degTargetHotend(tmp_extruder),1); + SERIAL_PROTOCOL_F(degTargetHotend(tmp_extruder),1); #if TEMP_BED_PIN > -1 - SERIAL_PROTOCOLPGM(" B:"); + SERIAL_PROTOCOLPGM(" B:"); SERIAL_PROTOCOL_F(degBed(),1); SERIAL_PROTOCOLPGM(" /"); SERIAL_PROTOCOL_F(degTargetBed(),1); @@ -1050,20 +1079,20 @@ void process_commands() #endif SERIAL_PROTOCOLPGM(" @:"); - SERIAL_PROTOCOL(getHeaterPower(tmp_extruder)); + SERIAL_PROTOCOL(getHeaterPower(tmp_extruder)); SERIAL_PROTOCOLPGM(" B@:"); - SERIAL_PROTOCOL(getHeaterPower(-1)); + SERIAL_PROTOCOL(getHeaterPower(-1)); SERIAL_PROTOCOLLN(""); return; break; - case 109: + case 109: {// M109 - Wait for extruder heater to reach target. if(setTargetedHotend(109)){ break; } - LCD_MESSAGEPGM(MSG_HEATING); + LCD_MESSAGEPGM(MSG_HEATING); #ifdef AUTOTEMP autotemp_enabled=false; #endif @@ -1071,15 +1100,15 @@ void process_commands() #ifdef AUTOTEMP if (code_seen('S')) autotemp_min=code_value(); if (code_seen('B')) autotemp_max=code_value(); - if (code_seen('F')) + if (code_seen('F')) { autotemp_factor=code_value(); autotemp_enabled=true; } #endif - + setWatch(); - codenum = millis(); + codenum = millis(); /* See if we are heating up or cooling down */ bool target_direction = isHeatingHotend(tmp_extruder); // true if heating, false if cooling @@ -1087,7 +1116,7 @@ void process_commands() #ifdef TEMP_RESIDENCY_TIME long residencyStart; residencyStart = -1; - /* continue to loop until we have reached the target temp + /* continue to loop until we have reached the target temp _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */ while((residencyStart == -1) || (residencyStart >= 0 && (((unsigned int) (millis() - residencyStart)) < (TEMP_RESIDENCY_TIME * 1000UL))) ) { @@ -1097,9 +1126,9 @@ void process_commands() if( (millis() - codenum) > 1000UL ) { //Print Temp Reading and remaining time every 1 second while heating up/cooling down SERIAL_PROTOCOLPGM("T:"); - SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1); + SERIAL_PROTOCOL_F(degHotend(tmp_extruder),1); SERIAL_PROTOCOLPGM(" E:"); - SERIAL_PROTOCOL((int)tmp_extruder); + SERIAL_PROTOCOL((int)tmp_extruder); #ifdef TEMP_RESIDENCY_TIME SERIAL_PROTOCOLPGM(" W:"); if(residencyStart > -1) @@ -1107,7 +1136,7 @@ void process_commands() codenum = ((TEMP_RESIDENCY_TIME * 1000UL) - (millis() - residencyStart)) / 1000UL; SERIAL_PROTOCOLLN( codenum ); } - else + else { SERIAL_PROTOCOLLN( "?" ); } @@ -1124,7 +1153,7 @@ void process_commands() or when current temp falls outside the hysteresis after target temp was reached */ if ((residencyStart == -1 && target_direction && (degHotend(tmp_extruder) >= (degTargetHotend(tmp_extruder)-TEMP_WINDOW))) || (residencyStart == -1 && !target_direction && (degHotend(tmp_extruder) <= (degTargetHotend(tmp_extruder)+TEMP_WINDOW))) || - (residencyStart > -1 && labs(degHotend(tmp_extruder) - degTargetHotend(tmp_extruder)) > TEMP_HYSTERESIS) ) + (residencyStart > -1 && labs(degHotend(tmp_extruder) - degTargetHotend(tmp_extruder)) > TEMP_HYSTERESIS) ) { residencyStart = millis(); } @@ -1139,8 +1168,8 @@ void process_commands() #if TEMP_BED_PIN > -1 LCD_MESSAGEPGM(MSG_BED_HEATING); if (code_seen('S')) setTargetBed(code_value()); - codenum = millis(); - while(isHeatingBed()) + codenum = millis(); + while(isHeatingBed()) { if(( millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up. { @@ -1148,11 +1177,11 @@ void process_commands() SERIAL_PROTOCOLPGM("T:"); SERIAL_PROTOCOL(tt); SERIAL_PROTOCOLPGM(" E:"); - SERIAL_PROTOCOL((int)active_extruder); + SERIAL_PROTOCOL((int)active_extruder); SERIAL_PROTOCOLPGM(" B:"); - SERIAL_PROTOCOL_F(degBed(),1); - SERIAL_PROTOCOLLN(""); - codenum = millis(); + SERIAL_PROTOCOL_F(degBed(),1); + SERIAL_PROTOCOLLN(""); + codenum = millis(); } manage_heater(); manage_inactivity(); @@ -1169,7 +1198,7 @@ void process_commands() fanSpeed=constrain(code_value(),0,255); } else { - fanSpeed=255; + fanSpeed=255; } break; case 107: //M107 Fan Off @@ -1184,7 +1213,7 @@ void process_commands() ValvePressure=constrain(code_value(),0,255); } else { - ValvePressure=255; + ValvePressure=255; } break; case 127: //M127 valve closed @@ -1199,7 +1228,7 @@ void process_commands() EtoPPressure=constrain(code_value(),0,255); } else { - EtoPPressure=255; + EtoPPressure=255; } break; case 129: //M129 valve closed @@ -1214,18 +1243,18 @@ void process_commands() WRITE(PS_ON_PIN, PS_ON_AWAKE); break; #endif - + case 81: // M81 - ATX Power Off - + #if defined SUICIDE_PIN && SUICIDE_PIN > -1 st_synchronize(); suicide(); #elif (PS_ON_PIN > -1) - SET_OUTPUT(PS_ON_PIN); + SET_OUTPUT(PS_ON_PIN); WRITE(PS_ON_PIN, PS_ON_ASLEEP); #endif break; - + case 82: axis_relative_modes[3] = false; break; @@ -1234,11 +1263,11 @@ void process_commands() break; case 18: //compatibility case 84: // M84 - if(code_seen('S')){ - stepper_inactive_time = code_value() * 1000; + if(code_seen('S')){ + stepper_inactive_time = code_value() * 1000; } else - { + { bool all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2]))|| (code_seen(axis_codes[3]))); if(all_axis) { @@ -1260,18 +1289,18 @@ void process_commands() disable_e1(); disable_e2(); } - #endif + #endif } } break; case 85: // M85 code_seen('S'); - max_inactive_time = code_value() * 1000; + max_inactive_time = code_value() * 1000; break; case 92: // M92 - for(int8_t i=0; i < NUM_AXIS; i++) + for(int8_t i=0; i < NUM_AXIS; i++) { - if(code_seen(axis_codes[i])) + if(code_seen(axis_codes[i])) { if(i == 3) { // E float value = code_value(); @@ -1305,16 +1334,16 @@ void process_commands() SERIAL_PROTOCOL(current_position[Y_AXIS]); SERIAL_PROTOCOLPGM("Z:"); SERIAL_PROTOCOL(current_position[Z_AXIS]); - SERIAL_PROTOCOLPGM("E:"); + SERIAL_PROTOCOLPGM("E:"); SERIAL_PROTOCOL(current_position[E_AXIS]); - + SERIAL_PROTOCOLPGM(MSG_COUNT_X); SERIAL_PROTOCOL(float(st_get_position(X_AXIS))/axis_steps_per_unit[X_AXIS]); SERIAL_PROTOCOLPGM("Y:"); SERIAL_PROTOCOL(float(st_get_position(Y_AXIS))/axis_steps_per_unit[Y_AXIS]); SERIAL_PROTOCOLPGM("Z:"); SERIAL_PROTOCOL(float(st_get_position(Z_AXIS))/axis_steps_per_unit[Z_AXIS]); - + SERIAL_PROTOCOLLN(""); break; case 120: // M120 @@ -1352,7 +1381,7 @@ void process_commands() break; //TODO: update for all axis, use for loop case 201: // M201 - for(int8_t i=0; i < NUM_AXIS; i++) + for(int8_t i=0; i < NUM_AXIS; i++) { if(code_seen(axis_codes[i])) { @@ -1391,7 +1420,7 @@ void process_commands() } break; case 206: // M206 additional homeing offset - for(int8_t i=0; i < 3; i++) + for(int8_t i=0; i < 3; i++) { if(code_seen(axis_codes[i])) add_homeing[i] = code_value(); } @@ -1399,47 +1428,47 @@ void process_commands() #ifdef FWRETRACT case 207: //M207 - set retract length S[positive mm] F[feedrate mm/sec] Z[additional zlift/hop] { - if(code_seen('S')) + if(code_seen('S')) { retract_length = code_value() ; } - if(code_seen('F')) + if(code_seen('F')) { retract_feedrate = code_value() ; } - if(code_seen('Z')) + if(code_seen('Z')) { retract_zlift = code_value() ; } }break; case 208: // M208 - set retract recover length S[positive mm surplus to the M207 S*] F[feedrate mm/sec] { - if(code_seen('S')) + if(code_seen('S')) { retract_recover_length = code_value() ; } - if(code_seen('F')) + if(code_seen('F')) { retract_recover_feedrate = code_value() ; } }break; case 209: // M209 - S<1=true/0=false> enable automatic retract detect if the slicer did not support G10/11: every normal extrude-only move will be classified as retract depending on the direction. { - if(code_seen('S')) + if(code_seen('S')) { int t= code_value() ; switch(t) { case 0: autoretract_enabled=false;retracted=false;break; case 1: autoretract_enabled=true;retracted=false;break; - default: + default: SERIAL_ECHO_START; SERIAL_ECHOPGM(MSG_UNKNOWN_COMMAND); SERIAL_ECHO(cmdbuffer[bufindr]); SERIAL_ECHOLNPGM("\""); } } - + }break; #endif // FWRETRACT #if EXTRUDERS > 1 @@ -1448,7 +1477,7 @@ void process_commands() if(setTargetedHotend(218)){ break; } - if(code_seen('X')) + if(code_seen('X')) { extruder_offset[X_AXIS][tmp_extruder] = code_value(); } @@ -1458,7 +1487,7 @@ void process_commands() } SERIAL_ECHO_START; SERIAL_ECHOPGM(MSG_HOTEND_OFFSET); - for(tmp_extruder = 0; tmp_extruder < EXTRUDERS; tmp_extruder++) + for(tmp_extruder = 0; tmp_extruder < EXTRUDERS; tmp_extruder++) { SERIAL_ECHO(" "); SERIAL_ECHO(extruder_offset[X_AXIS][tmp_extruder]); @@ -1470,7 +1499,7 @@ void process_commands() #endif case 220: // M220 S- set speed factor override percentage { - if(code_seen('S')) + if(code_seen('S')) { feedmultiply = code_value() ; } @@ -1478,13 +1507,44 @@ void process_commands() break; case 221: // M221 S- set extrude factor override percentage { - if(code_seen('S')) + if(code_seen('S')) { extrudemultiply = code_value() ; } } break; - + + #if (defined NUM_SERVOS) && (NUM_SERVOS > 0) + case 280: // M280 - set servo position absolute. P: servo index, S: angle or microseconds + { + int servo_index = -1; + int servo_position = 0; + if (code_seen('P')) + servo_index = code_value(); + if (code_seen('S')) { + servo_position = code_value(); + if ((servo_index >= 0) && (servo_index < NUM_SERVOS)) { + servos[servo_index].write(servo_position); + } + else { + SERIAL_ECHO_START; + SERIAL_ECHO("Servo "); + SERIAL_ECHO(servo_index); + SERIAL_ECHOLN(" out of range"); + } + } + else if (servo_index >= 0) { + SERIAL_PROTOCOL(MSG_OK); + SERIAL_PROTOCOL(" Servo "); + SERIAL_PROTOCOL(servo_index); + SERIAL_PROTOCOL(": "); + SERIAL_PROTOCOL(servos[servo_index].read()); + SERIAL_PROTOCOLLN(""); + } + } + break; + #endif // NUM_SERVOS > 0 + #if defined(LARGE_FLASH) && LARGE_FLASH == true && defined(BEEPER) && BEEPER > -1 case 300: // M300 { @@ -1509,7 +1569,7 @@ void process_commands() #ifdef PID_ADD_EXTRUSION_RATE if(code_seen('C')) Kc = code_value(); #endif - + updatePID(); SERIAL_PROTOCOL(MSG_OK); SERIAL_PROTOCOL(" p:"); @@ -1569,7 +1629,7 @@ void process_commands() #endif } break; - + case 302: // allow cold extrudes { allow_cold_extrudes(true); @@ -1634,7 +1694,7 @@ void process_commands() lastpos[Z_AXIS]=current_position[Z_AXIS]; lastpos[E_AXIS]=current_position[E_AXIS]; //retract by E - if(code_seen('E')) + if(code_seen('E')) { target[E_AXIS]+= code_value(); } @@ -1645,9 +1705,9 @@ void process_commands() #endif } plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder); - + //lift Z - if(code_seen('Z')) + if(code_seen('Z')) { target[Z_AXIS]+= code_value(); } @@ -1658,9 +1718,9 @@ void process_commands() #endif } plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder); - + //move xy - if(code_seen('X')) + if(code_seen('X')) { target[X_AXIS]+= code_value(); } @@ -1670,7 +1730,7 @@ void process_commands() target[X_AXIS]= FILAMENTCHANGE_XPOS ; #endif } - if(code_seen('Y')) + if(code_seen('Y')) { target[Y_AXIS]= code_value(); } @@ -1680,9 +1740,9 @@ void process_commands() target[Y_AXIS]= FILAMENTCHANGE_YPOS ; #endif } - + plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder); - + if(code_seen('L')) { target[E_AXIS]+= code_value(); @@ -1693,9 +1753,9 @@ void process_commands() target[E_AXIS]+= FILAMENTCHANGE_FINALRETRACT ; #endif } - + plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feedrate/60, active_extruder); - + //finish moves st_synchronize(); //disable extruder steppers so filament can be removed @@ -1710,12 +1770,12 @@ void process_commands() manage_heater(); manage_inactivity(); lcd_update(); - + #if BEEPER > -1 if(cnt==0) { SET_OUTPUT(BEEPER); - + WRITE(BEEPER,HIGH); delay(3); WRITE(BEEPER,LOW); @@ -1723,9 +1783,9 @@ void process_commands() } #endif } - + //return to normal - if(code_seen('L')) + if(code_seen('L')) { target[E_AXIS]+= -code_value(); } @@ -1743,7 +1803,7 @@ void process_commands() plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], lastpos[E_AXIS], feedrate/60, active_extruder); //final untretract } break; - #endif //FILAMENTCHANGEENABLE + #endif //FILAMENTCHANGEENABLE case 907: // M907 Set digital trimpot motor current using axis codes. { #if DIGIPOTSS_PIN > -1 @@ -1766,7 +1826,7 @@ void process_commands() case 350: // M350 Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers. { #if X_MS1_PIN > -1 - if(code_seen('S')) for(int i=0;i<=4;i++) microstep_mode(i,code_value()); + if(code_seen('S')) for(int i=0;i<=4;i++) microstep_mode(i,code_value()); for(int i=0;i= EXTRUDERS) { @@ -1825,7 +1885,7 @@ void process_commands() // Offset extruder (only by XY) int i; for(i = 0; i < 2; i++) { - current_position[i] = current_position[i] - + current_position[i] = current_position[i] - extruder_offset[i][active_extruder] + extruder_offset[i][tmp_extruder]; } @@ -1871,14 +1931,14 @@ void ClearToSend() if(fromsd[bufindr]) return; #endif //SDSUPPORT - SERIAL_PROTOCOLLNPGM(MSG_OK); + SERIAL_PROTOCOLLNPGM(MSG_OK); } void get_coordinates() { bool seen[4]={false,false,false,false}; for(int8_t i=0; i < NUM_AXIS; i++) { - if(code_seen(axis_codes[i])) + if(code_seen(axis_codes[i])) { destination[i] = (float)code_value() + (axis_relative_modes[i] || relative_mode)*current_position[i]; seen[i]=true; @@ -1896,23 +1956,23 @@ void get_coordinates() float echange=destination[E_AXIS]-current_position[E_AXIS]; if(echange<-MIN_RETRACT) //retract { - if(!retracted) + if(!retracted) { - + destination[Z_AXIS]+=retract_zlift; //not sure why chaninging current_position negatively does not work. //if slicer retracted by echange=-1mm and you want to retract 3mm, corrrectede=-2mm additionally float correctede=-echange-retract_length; //to generate the additional steps, not the destination is changed, but inversely the current position - current_position[E_AXIS]+=-correctede; + current_position[E_AXIS]+=-correctede; feedrate=retract_feedrate; retracted=true; } - + } - else + else if(echange>MIN_RETRACT) //retract_recover { - if(retracted) + if(retracted) { //current_position[Z_AXIS]+=-retract_zlift; //if slicer retracted_recovered by echange=+1mm and you want to retract_recover 3mm, corrrectede=2mm additionally @@ -1922,7 +1982,7 @@ void get_coordinates() retracted=false; } } - + } #endif //FWRETRACT } @@ -1940,7 +2000,7 @@ void get_arc_coordinates() if(code_seen('I')) { offset[0] = code_value(); - } + } else { offset[0] = 0.0; } @@ -1971,7 +2031,7 @@ void prepare_move() { clamp_to_software_endstops(destination); - previous_millis_cmd = millis(); + previous_millis_cmd = millis(); // Do not use feedmultiply for E or Z only moves if( (current_position[X_AXIS] == destination [X_AXIS]) && (current_position[Y_AXIS] == destination [Y_AXIS])) { plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); @@ -1989,7 +2049,7 @@ void prepare_arc_move(char isclockwise) { // Trace the arc mc_arc(current_position, destination, offset, X_AXIS, Y_AXIS, Z_AXIS, feedrate*feedmultiply/60/100.0, r, isclockwise, active_extruder); - + // As far as the parser is concerned, the position is now == target. In reality the // motion control system might still be processing the action and the real tool position // in any intermediate location. @@ -2008,7 +2068,7 @@ void controllerFan() if ((millis() - lastMotorCheck) >= 2500) //Not a time critical function, so we only check every 2500ms { lastMotorCheck = millis(); - + if(!READ(X_ENABLE_PIN) || !READ(Y_ENABLE_PIN) || !READ(Z_ENABLE_PIN) #if EXTRUDERS > 2 || !READ(E2_ENABLE_PIN) @@ -2016,12 +2076,12 @@ void controllerFan() #if EXTRUDER > 1 || !READ(E1_ENABLE_PIN) #endif - || !READ(E0_ENABLE_PIN)) //If any of the drivers are enabled... + || !READ(E0_ENABLE_PIN)) //If any of the drivers are enabled... { lastMotor = millis(); //... set time to NOW so the fan will turn on } - - if ((millis() - lastMotor) >= (CONTROLLERFAN_SEC*1000UL) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC... + + if ((millis() - lastMotor) >= (CONTROLLERFAN_SEC*1000UL) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC... { WRITE(CONTROLLERFAN_PIN, LOW); //... turn the fan off } @@ -2041,7 +2101,7 @@ void extruderFan() if ((millis() - lastExtruderCheck) >= 2500) //Not a time critical function, so we only check every 2500ms { lastExtruderCheck = millis(); - + if (degHotend(active_extruder) < EXTRUDERFAN_DEC) { WRITE(EXTRUDERFAN_PIN, LOW); //... turn the fan off @@ -2054,13 +2114,13 @@ void extruderFan() } #endif -void manage_inactivity() -{ - if( (millis() - previous_millis_cmd) > max_inactive_time ) - if(max_inactive_time) - kill(); +void manage_inactivity() +{ + if( (millis() - previous_millis_cmd) > max_inactive_time ) + if(max_inactive_time) + kill(); if(stepper_inactive_time) { - if( (millis() - previous_millis_cmd) > stepper_inactive_time ) + if( (millis() - previous_millis_cmd) > stepper_inactive_time ) { if(blocks_queued() == false) { disable_x(); @@ -2080,15 +2140,15 @@ void manage_inactivity() controllerFan(); //Check if fan should be turned on to cool stepper drivers down #endif #ifdef EXTRUDER_RUNOUT_PREVENT - if( (millis() - previous_millis_cmd) > EXTRUDER_RUNOUT_SECONDS*1000 ) + if( (millis() - previous_millis_cmd) > EXTRUDER_RUNOUT_SECONDS*1000 ) if(degHotend(active_extruder)>EXTRUDER_RUNOUT_MINTEMP) { bool oldstatus=READ(E0_ENABLE_PIN); enable_e0(); float oldepos=current_position[E_AXIS]; float oldedes=destination[E_AXIS]; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], - current_position[E_AXIS]+EXTRUDER_RUNOUT_EXTRUDE*EXTRUDER_RUNOUT_ESTEPS/axis_steps_per_unit[E_AXIS], + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], + current_position[E_AXIS]+EXTRUDER_RUNOUT_EXTRUDE*EXTRUDER_RUNOUT_ESTEPS/axis_steps_per_unit[E_AXIS], EXTRUDER_RUNOUT_SPEED/60.*EXTRUDER_RUNOUT_ESTEPS/axis_steps_per_unit[E_AXIS], active_extruder); current_position[E_AXIS]=oldepos; destination[E_AXIS]=oldedes; @@ -2112,7 +2172,7 @@ void kill() disable_e0(); disable_e1(); disable_e2(); - + if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT); SERIAL_ERROR_START; SERIAL_ERRORLNPGM(MSG_ERR_KILLED); @@ -2141,7 +2201,7 @@ void setPwmFrequency(uint8_t pin, int val) val &= 0x07; switch(digitalPinToTimer(pin)) { - + #if defined(TCCR0A) case TIMER0A: case TIMER0B: @@ -2183,7 +2243,7 @@ void setPwmFrequency(uint8_t pin, int val) break; #endif - #if defined(TCCR4A) + #if defined(TCCR4A) case TIMER4A: case TIMER4B: case TIMER4C: @@ -2192,7 +2252,7 @@ void setPwmFrequency(uint8_t pin, int val) break; #endif - #if defined(TCCR5A) + #if defined(TCCR5A) case TIMER5A: case TIMER5B: case TIMER5C: diff --git a/Marlin/Servo.h b/Marlin/Servo.h index a76954a06f..17c99f7974 100644 --- a/Marlin/Servo.h +++ b/Marlin/Servo.h @@ -59,28 +59,34 @@ // Say which 16 bit timers can be used and in what order #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #define _useTimer5 -#define _useTimer1 +//#define _useTimer1 #define _useTimer3 #define _useTimer4 -typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ; +//typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ; +typedef enum { _timer5, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ; #elif defined(__AVR_ATmega32U4__) -#define _useTimer1 -typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ; +//#define _useTimer1 +#define _useTimer3 +//typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ; +typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ; #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) #define _useTimer3 -#define _useTimer1 -typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; +//#define _useTimer1 +//typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; +typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ; #elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) #define _useTimer3 -#define _useTimer1 -typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; +//#define _useTimer1 +//typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; +typedef enum { _timer3, _Nbr_16timers } timer16_Sequence_t ; #else // everything else -#define _useTimer1 -typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ; +//#define _useTimer1 +//typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ; +typedef enum { _Nbr_16timers } timer16_Sequence_t ; #endif #define Servo_VERSION 2 // software version of this library diff --git a/Marlin/pins.h b/Marlin/pins.h index a13c522f71..52310f100e 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -248,14 +248,14 @@ #define E0_STEP_PIN 28 #define E0_DIR_PIN 27 #define E0_ENABLE_PIN 24 - + #define TEMP_0_PIN 2 #define TEMP_1_PIN -1 #define TEMP_2_PIN -1 #define TEMP_BED_PIN 1 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! (pin 34 bed) - + #define HEATER_0_PIN 4 - #define HEATER_1_PIN -1 + #define HEATER_1_PIN -1 #define HEATER_2_PIN -1 #define HEATER_BED_PIN 3 // (bed) @@ -272,25 +272,25 @@ //our RS485 pins //#define TX_ENABLE_PIN 12 //#define RX_ENABLE_PIN 13 - - #define BEEPER -1 - #define SDCARDDETECT -1 + + #define BEEPER -1 + #define SDCARDDETECT -1 #define SUICIDE_PIN -1 //has to be defined; otherwise Power_off doesn't work - + #define KILL_PIN -1 - //Pins for 4bit LCD Support - #define LCD_PINS_RS 18 + //Pins for 4bit LCD Support + #define LCD_PINS_RS 18 #define LCD_PINS_ENABLE 17 #define LCD_PINS_D4 16 - #define LCD_PINS_D5 15 + #define LCD_PINS_D5 15 #define LCD_PINS_D6 13 #define LCD_PINS_D7 14 - + //buttons are directly attached #define BTN_EN1 11 #define BTN_EN2 10 #define BTN_ENC 12 //the click - + #define BLEN_C 2 #define BLEN_B 1 #define BLEN_A 0 @@ -376,13 +376,18 @@ #else #define HEATER_1_PIN 9 // EXTRUDER 2 (FAN On Sprinter) #endif -#define HEATER_2_PIN -1 +#define HEATER_2_PIN -1 #define TEMP_0_PIN 13 // ANALOG NUMBERING #define TEMP_1_PIN 15 // ANALOG NUMBERING #define TEMP_2_PIN -1 // ANALOG NUMBERING #define HEATER_BED_PIN 8 // BED #define TEMP_BED_PIN 14 // ANALOG NUMBERING +#define SERVO0_PIN 11 +#define SERVO1_PIN 6 +#define SERVO2_PIN 5 +#define SERVO3_PIN 4 + #ifdef ULTRA_LCD #ifdef NEWPANEL @@ -396,13 +401,13 @@ #define BLEN_B 1 #define BLEN_C 2 - #define LCD_PINS_RS 16 + #define LCD_PINS_RS 16 #define LCD_PINS_ENABLE 17 #define LCD_PINS_D4 23 - #define LCD_PINS_D5 25 + #define LCD_PINS_D5 25 #define LCD_PINS_D6 27 #define LCD_PINS_D7 29 - + #ifdef REPRAP_DISCOUNT_SMART_CONTROLLER #define BEEPER 37 @@ -455,21 +460,21 @@ //#define SHIFT_LD 42 //#define SHIFT_OUT 40 //#define SHIFT_EN 17 - - #define LCD_PINS_RS 16 + + #define LCD_PINS_RS 16 #define LCD_PINS_ENABLE 17 #define LCD_PINS_D4 23 - #define LCD_PINS_D5 25 + #define LCD_PINS_D5 25 #define LCD_PINS_D6 27 #define LCD_PINS_D7 29 - + //encoder rotation values #define encrot0 0 #define encrot1 2 #define encrot2 3 #define encrot3 1 - + //bits in the shift register that carry the buttons for: // left up center down right red #define BL_LE 7 @@ -481,7 +486,7 @@ #define BLEN_B 1 #define BLEN_A 0 - #endif + #endif #endif //ULTRA_LCD #else // RAMPS_V_1_1 or RAMPS_V_1_2 as default (MOTHERBOARD == 3) @@ -526,15 +531,15 @@ #define HEATER_1_PIN -1 #define HEATER_2_PIN -1 #define TEMP_0_PIN 2 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! -#define TEMP_1_PIN -1 -#define TEMP_2_PIN -1 +#define TEMP_1_PIN -1 +#define TEMP_2_PIN -1 #define TEMP_BED_PIN 1 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! #endif// MOTHERBOARD == 33 || MOTHERBOARD == 34 -// SPI for Max6675 Thermocouple +// SPI for Max6675 Thermocouple #ifndef SDSUPPORT -// these pins are defined in the SD library if building with SD support +// these pins are defined in the SD library if building with SD support #define MAX_SCK_PIN 52 #define MAX_MISO_PIN 50 #define MAX_MOSI_PIN 51 @@ -586,8 +591,8 @@ #define HEATER_1_PIN -1 #define HEATER_2_PIN -1 #define TEMP_0_PIN 0 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! -#define TEMP_1_PIN -1 -#define TEMP_2_PIN -1 +#define TEMP_1_PIN -1 +#define TEMP_2_PIN -1 #define HEATER_BED_PIN -1 #define TEMP_BED_PIN -1 @@ -650,14 +655,14 @@ #define PS_ON_PIN -1 //changed @ rkoeppl 20110410 #define KILL_PIN -1 //changed @ drakelive 20120830 //our pin for debugging. - + #define DEBUG_PIN 0 - + //our RS485 pins #define TX_ENABLE_PIN 12 #define RX_ENABLE_PIN 13 - + #endif /**************************************************************************************** @@ -673,7 +678,7 @@ #if MOTHERBOARD == 62 || MOTHERBOARD == 63 || MOTHERBOARD == 64 #undef MOTHERBOARD #define MOTHERBOARD 6 -#define SANGUINOLOLU_V_1_2 +#define SANGUINOLOLU_V_1_2 #endif #if MOTHERBOARD == 6 #define KNOWN_BOARD 1 @@ -700,7 +705,7 @@ #define LED_PIN -1 -#define FAN_PIN -1 +#define FAN_PIN -1 #if FAN_PIN == 12 || FAN_PIN ==13 #define FAN_SOFT_PWM #endif @@ -779,21 +784,21 @@ #define BTN_ENC 16 //the switch //not connected to a pin #define SDCARDDETECT -1 - + //from the same bit in the RAMPS Newpanel define //encoder rotation values #define encrot0 0 #define encrot1 2 #define encrot2 3 #define encrot3 1 - + #define BLEN_C 2 #define BLEN_B 1 #define BLEN_A 0 - + #endif //Newpanel #endif //Ultipanel - + #endif @@ -823,17 +828,17 @@ #define Y_MAX_PIN 28 #define Y_ENABLE_PIN 29 -#define Z_STEP_PIN 37 +#define Z_STEP_PIN 37 #define Z_DIR_PIN 39 #define Z_MIN_PIN 30 #define Z_MAX_PIN 32 #define Z_ENABLE_PIN 35 -#define HEATER_BED_PIN 4 -#define TEMP_BED_PIN 10 +#define HEATER_BED_PIN 4 +#define TEMP_BED_PIN 10 #define HEATER_0_PIN 2 -#define TEMP_0_PIN 8 +#define TEMP_0_PIN 8 #define HEATER_1_PIN 3 #define TEMP_1_PIN 9 @@ -863,24 +868,24 @@ //arduino pin witch triggers an piezzo beeper #define BEEPER 18 - #define LCD_PINS_RS 20 + #define LCD_PINS_RS 20 #define LCD_PINS_ENABLE 17 #define LCD_PINS_D4 16 - #define LCD_PINS_D5 21 + #define LCD_PINS_D5 21 #define LCD_PINS_D6 5 #define LCD_PINS_D7 6 - + //buttons are directly attached #define BTN_EN1 40 #define BTN_EN2 42 #define BTN_ENC 19 //the click - + #define BLEN_C 2 #define BLEN_B 1 #define BLEN_A 0 - + #define SDCARDDETECT 38 - + //encoder rotation values #define encrot0 0 #define encrot1 2 @@ -895,14 +900,14 @@ #define SHIFT_LD 42 #define SHIFT_OUT 40 #define SHIFT_EN 17 - - #define LCD_PINS_RS 16 + + #define LCD_PINS_RS 16 #define LCD_PINS_ENABLE 5 #define LCD_PINS_D4 6 - #define LCD_PINS_D5 21 + #define LCD_PINS_D5 21 #define LCD_PINS_D6 20 #define LCD_PINS_D7 19 - + //encoder rotation values #ifndef ULTIMAKERCONTROLLER #define encrot0 0 @@ -929,7 +934,7 @@ #define BLEN_B 1 #define BLEN_A 0 - #endif + #endif #endif //ULTRA_LCD #endif @@ -960,17 +965,17 @@ #define Y_MAX_PIN 16 #define Y_ENABLE_PIN 29 -#define Z_STEP_PIN 37 +#define Z_STEP_PIN 37 #define Z_DIR_PIN 39 #define Z_MIN_PIN 19 #define Z_MAX_PIN 18 #define Z_ENABLE_PIN 35 -#define HEATER_BED_PIN -1 -#define TEMP_BED_PIN -1 +#define HEATER_BED_PIN -1 +#define TEMP_BED_PIN -1 #define HEATER_0_PIN 2 -#define TEMP_0_PIN 8 +#define TEMP_0_PIN 8 #define HEATER_1_PIN 1 #define TEMP_1_PIN 1 @@ -994,10 +999,10 @@ #define KILL_PIN -1 #define SUICIDE_PIN -1 //PIN that has to be turned on right after start, to keep power flowing. -#define LCD_PINS_RS 24 +#define LCD_PINS_RS 24 #define LCD_PINS_ENABLE 22 #define LCD_PINS_D4 36 -#define LCD_PINS_D5 34 +#define LCD_PINS_D5 34 #define LCD_PINS_D6 32 #define LCD_PINS_D7 30 @@ -1019,17 +1024,17 @@ #define X_DIR_PIN 16 #define X_ENABLE_PIN 48 #define X_MIN_PIN 37 -#define X_MAX_PIN 36 +#define X_MAX_PIN 36 #define Y_STEP_PIN 54 -#define Y_DIR_PIN 47 +#define Y_DIR_PIN 47 #define Y_ENABLE_PIN 55 #define Y_MIN_PIN 35 -#define Y_MAX_PIN 34 +#define Y_MAX_PIN 34 -#define Z_STEP_PIN 57 +#define Z_STEP_PIN 57 #define Z_DIR_PIN 56 -#define Z_ENABLE_PIN 62 +#define Z_ENABLE_PIN 62 #define Z_MIN_PIN 33 #define Z_MAX_PIN 32 @@ -1047,7 +1052,7 @@ #define LED_PIN 13 -#define FAN_PIN 7 +#define FAN_PIN 7 //additional FAN1 PIN (e.g. useful for electronics fan or light on/off) on PIN 8 #define PS_ON_PIN 45 @@ -1069,10 +1074,10 @@ #define SDSS 53 #define SDCARDDETECT 49 #define BEEPER 44 -#define LCD_PINS_RS 19 +#define LCD_PINS_RS 19 #define LCD_PINS_ENABLE 42 #define LCD_PINS_D4 18 -#define LCD_PINS_D5 38 +#define LCD_PINS_D5 38 #define LCD_PINS_D6 41 #define LCD_PINS_D7 40 #define BTN_EN1 11 @@ -1256,7 +1261,7 @@ #define LED_PIN -1 -#define FAN_PIN -1 +#define FAN_PIN -1 #define PS_ON_PIN 14 #define KILL_PIN -1 @@ -1295,7 +1300,7 @@ * MISO (D 6) PB6 7| |34 PA6 (AI 6 / D25) * SCK (D 7) PB7 8| |33 PA7 (AI 7 / D24) * RST 9| |32 AREF -* VCC 10| |31 GND +* VCC 10| |31 GND * GND 11| |30 AVCC * XTAL2 12| |29 PC7 (D 23) * XTAL1 13| |28 PC6 (D 22) @@ -1352,7 +1357,7 @@ #define KILL_PIN -1 #define HEATER_0_PIN 4 -#define HEATER_1_PIN -1 // 12 +#define HEATER_1_PIN -1 // 12 #define HEATER_2_PIN -1 // 13 #define TEMP_0_PIN 0 //D27 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! #define TEMP_1_PIN -1 // 1 @@ -1414,11 +1419,11 @@ #define KILL_PIN -1 #define HEATER_0_PIN 3 /*DONE PWM on RIGHT connector */ -#define HEATER_1_PIN -1 +#define HEATER_1_PIN -1 #define HEATER_2_PIN -1 -#define HEATER_1_PIN -1 +#define HEATER_1_PIN -1 #define HEATER_2_PIN -1 -#define TEMP_0_PIN 0 // ANALOG INPUT NUMBERING +#define TEMP_0_PIN 0 // ANALOG INPUT NUMBERING #define TEMP_1_PIN 1 // ANALOG #define TEMP_2_PIN -1 // 2 #define HEATER_BED_PIN 4 @@ -1466,7 +1471,7 @@ #define Z_MS2_PIN 67 #define HEATER_BED_PIN 3 -#define TEMP_BED_PIN 2 +#define TEMP_BED_PIN 2 #define HEATER_0_PIN 9 #define TEMP_0_PIN 0 @@ -1559,9 +1564,9 @@ #define HEATER_0_PIN 9 // EXTRUDER 1 #define HEATER_1_PIN 8 // EXTRUDER 2 (FAN On Sprinter) -#define HEATER_2_PIN -1 +#define HEATER_2_PIN -1 -#if TEMP_SENSOR_0 == -1 +#if TEMP_SENSOR_0 == -1 #define TEMP_0_PIN 8 // ANALOG NUMBERING #else #define TEMP_0_PIN 13 // ANALOG NUMBERING @@ -1580,25 +1585,25 @@ #ifdef NEWPANEL //arduino pin which triggers an piezzo beeper - - #define LCD_PINS_RS 16 + + #define LCD_PINS_RS 16 #define LCD_PINS_ENABLE 17 #define LCD_PINS_D4 23 - #define LCD_PINS_D5 25 + #define LCD_PINS_D5 25 #define LCD_PINS_D6 27 #define LCD_PINS_D7 29 - + //buttons are directly attached using AUX-2 #define BTN_EN1 59 #define BTN_EN2 64 #define BTN_ENC 43 //the click - + #define BLEN_C 2 #define BLEN_B 1 #define BLEN_A 0 - + #define SDCARDDETECT -1 // Ramps does not use this port - + //encoder rotation values #define encrot0 0 #define encrot1 2 @@ -1614,7 +1619,7 @@ #endif //List of pins which to ignore when asked to change by gcode, 0 and 1 are RX and TX, do not mess with those! -#define _E0_PINS E0_STEP_PIN, E0_DIR_PIN, E0_ENABLE_PIN, HEATER_0_PIN, +#define _E0_PINS E0_STEP_PIN, E0_DIR_PIN, E0_ENABLE_PIN, HEATER_0_PIN, #if EXTRUDERS > 1 #define _E1_PINS E1_STEP_PIN, E1_DIR_PIN, E1_ENABLE_PIN, HEATER_1_PIN, #else From 96624f0f3174363fc740a125480f6f72042cc963 Mon Sep 17 00:00:00 2001 From: Gord Christmas Date: Thu, 16 May 2013 08:25:20 -0700 Subject: [PATCH 28/31] Forgot to include reference to Servo in makefile --- Marlin/Makefile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Marlin/Makefile b/Marlin/Makefile index e09d15f067..c231735255 100644 --- a/Marlin/Makefile +++ b/Marlin/Makefile @@ -1,12 +1,12 @@ # Sprinter Arduino Project Makefile -# +# # Makefile Based on: # Arduino 0011 Makefile # Arduino adaptation by mellis, eighthave, oli.keller # Marlin adaption by Daid # # This has been tested with Arduino 0022. -# +# # This makefile allows you to build sketches from the command line # without the Arduino environment (or Java). # @@ -21,7 +21,7 @@ # (e.g. UPLOAD_PORT = /dev/tty.USB0). If the exact name of this file # changes, you can use * as a wildcard (e.g. UPLOAD_PORT = /dev/tty.usb*). # -# 3. Set the line containing "MCU" to match your board's processor. +# 3. Set the line containing "MCU" to match your board's processor. # Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth # or Diecimila have the atmega168. If you're using a LilyPad Arduino, # change F_CPU to 8000000. If you are using Gen7 electronics, you @@ -44,7 +44,7 @@ ARDUINO_INSTALL_DIR ?= ../../arduino-0022 ARDUINO_VERSION ?= 22 # You can optionally set a path to the avr-gcc tools. Requires a trailing slash. (ex: /usr/local/avr-gcc/bin) -AVR_TOOLS_PATH ?= +AVR_TOOLS_PATH ?= #Programmer configuration UPLOAD_RATE ?= 115200 @@ -213,7 +213,7 @@ CXXSRC = WMath.cpp WString.cpp Print.cpp Marlin_main.cpp \ SdFile.cpp SdVolume.cpp motion_control.cpp planner.cpp \ stepper.cpp temperature.cpp cardreader.cpp ConfigurationStore.cpp \ watchdog.cpp -CXXSRC += LiquidCrystal.cpp ultralcd.cpp SPI.cpp +CXXSRC += LiquidCrystal.cpp ultralcd.cpp SPI.cpp Servo.cpp #Check for Arduino 1.0.0 or higher and use the correct sourcefiles for that version ifeq ($(shell [ $(ARDUINO_VERSION) -ge 100 ] && echo true), true) @@ -317,19 +317,19 @@ endif # Default target. all: sizeafter -build: $(BUILD_DIR) elf hex +build: $(BUILD_DIR) elf hex # Creates the object directory -$(BUILD_DIR): +$(BUILD_DIR): $P mkdir -p $(BUILD_DIR) elf: $(BUILD_DIR)/$(TARGET).elf hex: $(BUILD_DIR)/$(TARGET).hex eep: $(BUILD_DIR)/$(TARGET).eep -lss: $(BUILD_DIR)/$(TARGET).lss +lss: $(BUILD_DIR)/$(TARGET).lss sym: $(BUILD_DIR)/$(TARGET).sym -# Program the device. +# Program the device. # Do not try to reset an arduino if it's not one upload: $(BUILD_DIR)/$(TARGET).hex ifeq (${AVRDUDE_PROGRAMMER}, arduino) @@ -356,7 +356,7 @@ COFFCONVERT=$(OBJCOPY) --debugging \ --change-section-address .data-0x800000 \ --change-section-address .bss-0x800000 \ --change-section-address .noinit-0x800000 \ - --change-section-address .eeprom-0x810000 + --change-section-address .eeprom-0x810000 coff: $(BUILD_DIR)/$(TARGET).elf From 6c45c3f4e70d3d9e71d03bba73bb85136238415f Mon Sep 17 00:00:00 2001 From: Erik van der Zalm Date: Thu, 16 May 2013 19:00:57 +0200 Subject: [PATCH 29/31] BariCUDA changes --- Marlin/planner.cpp | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 1a37cecb47..35bda428f7 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -440,10 +440,8 @@ void check_axes_activity() unsigned char e_active = 0; unsigned char tail_fan_speed = fanSpeed; #ifdef BARICUDA - unsigned char valve_pressure = 0; - unsigned char e_to_p_pressure = 0; - unsigned char tail_valve_pressure = 0; - unsigned char tail_e_to_p_pressure = 0; + unsigned char tail_valve_pressure = ValvePressure; + unsigned char tail_e_to_p_pressure = EtoPPressure; #endif block_t *block; @@ -499,31 +497,11 @@ void check_axes_activity() #ifdef BARICUDA #if HEATER_1_PIN > -1 - if (ValvePressure != 0){ - analogWrite(HEATER_1_PIN,ValvePressure); // If buffer is empty use current valve pressure - } - - if((ValvePressure == 0) && (valve_pressure ==0)) { - analogWrite(HEATER_1_PIN, 0); - } - - if (ValvePressure != 0 && tail_valve_pressure !=0) { analogWrite(HEATER_1_PIN,tail_valve_pressure); - } #endif #if HEATER_2_PIN > -1 - if (EtoPPressure != 0){ - analogWrite(HEATER_2_PIN,EtoPPressure); // If buffer is empty use current EtoP pressure - } - - if((EtoPPressure == 0) && (e_to_p_pressure ==0)) { - analogWrite(HEATER_2_PIN, 0); - } - - if (EtoPPressure != 0 && tail_e_to_p_pressure !=0) { analogWrite(HEATER_2_PIN,tail_e_to_p_pressure); - } #endif #endif } From 4121311b9d13dc2d0c26f4b4c767c6b6952029c3 Mon Sep 17 00:00:00 2001 From: Robert F-C Date: Sat, 18 May 2013 22:30:42 +1000 Subject: [PATCH 30/31] Change to LCD status indicators The I2C LCD status indicators now indicate when the hotends or bed are turned on at all (rather than just when they are in their heating phase) --- .../ultralcd_implementation_hitachi_HD44780.h | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Marlin/ultralcd_implementation_hitachi_HD44780.h b/Marlin/ultralcd_implementation_hitachi_HD44780.h index 23fa8b4215..d4e9967414 100644 --- a/Marlin/ultralcd_implementation_hitachi_HD44780.h +++ b/Marlin/ultralcd_implementation_hitachi_HD44780.h @@ -298,12 +298,12 @@ static void lcd_implementation_init() #endif #elif defined(LCD_I2C_TYPE_MCP23017) - lcd.setMCPType(LTI_TYPE_MCP23017); + lcd.setMCPType(LTI_TYPE_MCP23017); lcd.begin(LCD_WIDTH, LCD_HEIGHT); lcd.setBacklight(0); //set all the LEDs off to begin with #elif defined(LCD_I2C_TYPE_MCP23008) - lcd.setMCPType(LTI_TYPE_MCP23008); + lcd.setMCPType(LTI_TYPE_MCP23008); lcd.begin(LCD_WIDTH, LCD_HEIGHT); #else @@ -497,9 +497,9 @@ static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, c char c; //Use all characters in narrow LCDs #if LCD_WIDTH < 20 - uint8_t n = LCD_WIDTH - 1 - 1; + uint8_t n = LCD_WIDTH - 1 - 1; #else - uint8_t n = LCD_WIDTH - 1 - 2; + uint8_t n = LCD_WIDTH - 1 - 2; #endif lcd.setCursor(0, row); lcd.print(pre_char); @@ -519,9 +519,9 @@ static void lcd_implementation_drawmenu_setting_edit_generic(uint8_t row, const char c; //Use all characters in narrow LCDs #if LCD_WIDTH < 20 - uint8_t n = LCD_WIDTH - 1 - 1 - strlen(data); + uint8_t n = LCD_WIDTH - 1 - 1 - strlen(data); #else - uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data); + uint8_t n = LCD_WIDTH - 1 - 2 - strlen(data); #endif lcd.setCursor(0, row); lcd.print(pre_char); @@ -541,9 +541,9 @@ static void lcd_implementation_drawmenu_setting_edit_generic_P(uint8_t row, cons char c; //Use all characters in narrow LCDs #if LCD_WIDTH < 20 - uint8_t n = LCD_WIDTH - 1 - 1 - strlen_P(data); + uint8_t n = LCD_WIDTH - 1 - 1 - strlen_P(data); #else - uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data); + uint8_t n = LCD_WIDTH - 1 - 2 - strlen_P(data); #endif lcd.setCursor(0, row); lcd.print(pre_char); @@ -600,9 +600,9 @@ void lcd_implementation_drawedit(const char* pstr, char* value) lcd_printPGM(pstr); lcd.print(':'); #if LCD_WIDTH < 20 - lcd.setCursor(LCD_WIDTH - strlen(value), 1); + lcd.setCursor(LCD_WIDTH - strlen(value), 1); #else - lcd.setCursor(LCD_WIDTH -1 - strlen(value), 1); + lcd.setCursor(LCD_WIDTH -1 - strlen(value), 1); #endif lcd.print(value); } @@ -720,11 +720,11 @@ static void lcd_implementation_update_indicators() //set the LEDS - referred to as backlights by the LiquidTWI2 library static uint8_t ledsprev = 0; uint8_t leds = 0; - if (isHeatingBed()) leds |= LED_A; - if (isHeatingHotend(0)) leds |= LED_B; + if (target_temperature_bed > 0) leds |= LED_A; + if (target_temperature[0] > 0) leds |= LED_B; if (fanSpeed) leds |= LED_C; #if EXTRUDERS > 1 - if (isHeatingHotend(1)) leds |= LED_C; + if (target_temperature[1] > 0) leds |= LED_C; #endif if (leds != ledsprev) { lcd.setBacklight(leds); From 86cce025f4c771ee085eea855220ba39147798c3 Mon Sep 17 00:00:00 2001 From: Erik van der Zalm Date: Sat, 18 May 2013 23:12:28 +0200 Subject: [PATCH 31/31] Added #ifdef NUM_SERVOS to servo.cpp --- Marlin/Servo.cpp | 676 ++++++++++++++++++++++++----------------------- 1 file changed, 339 insertions(+), 337 deletions(-) diff --git a/Marlin/Servo.cpp b/Marlin/Servo.cpp index 02138b5825..1b42ce0b04 100644 --- a/Marlin/Servo.cpp +++ b/Marlin/Servo.cpp @@ -1,337 +1,339 @@ -/* - Servo.cpp - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2 - Copyright (c) 2009 Michael Margolis. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - - A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method. - The servos are pulsed in the background using the value most recently written using the write() method - - Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached. - Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four. - - The methods are: - - Servo - Class for manipulating servo motors connected to Arduino pins. - - attach(pin ) - Attaches a servo motor to an i/o pin. - attach(pin, min, max ) - Attaches to a pin setting min and max values in microseconds - default min is 544, max is 2400 - - write() - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds) - writeMicroseconds() - Sets the servo pulse width in microseconds - read() - Gets the last written servo pulse width as an angle between 0 and 180. - readMicroseconds() - Gets the last written servo pulse width in microseconds. (was read_us() in first release) - attached() - Returns true if there is a servo attached. - detach() - Stops an attached servos from pulsing its i/o pin. - -*/ - -#include -#include - -#include "Servo.h" - -#define usToTicks(_us) (( clockCyclesPerMicrosecond()* _us) / 8) // converts microseconds to tick (assumes prescale of 8) // 12 Aug 2009 -#define ticksToUs(_ticks) (( (unsigned)_ticks * 8)/ clockCyclesPerMicrosecond() ) // converts from ticks back to microseconds - - -#define TRIM_DURATION 2 // compensation ticks to trim adjust for digitalWrite delays // 12 August 2009 - -//#define NBR_TIMERS (MAX_SERVOS / SERVOS_PER_TIMER) - -static servo_t servos[MAX_SERVOS]; // static array of servo structures -static volatile int8_t Channel[_Nbr_16timers ]; // counter for the servo being pulsed for each timer (or -1 if refresh interval) - -uint8_t ServoCount = 0; // the total number of attached servos - - -// convenience macros -#define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / SERVOS_PER_TIMER)) // returns the timer controlling this servo -#define SERVO_INDEX_TO_CHANNEL(_servo_nbr) (_servo_nbr % SERVOS_PER_TIMER) // returns the index of the servo on this timer -#define SERVO_INDEX(_timer,_channel) ((_timer*SERVOS_PER_TIMER) + _channel) // macro to access servo index by timer and channel -#define SERVO(_timer,_channel) (servos[SERVO_INDEX(_timer,_channel)]) // macro to access servo class by timer and channel - -#define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4) // minimum value in uS for this servo -#define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4) // maximum value in uS for this servo - -/************ static functions common to all instances ***********************/ - -static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t *TCNTn, volatile uint16_t* OCRnA) -{ - if( Channel[timer] < 0 ) - *TCNTn = 0; // channel set to -1 indicated that refresh interval completed so reset the timer - else{ - if( SERVO_INDEX(timer,Channel[timer]) < ServoCount && SERVO(timer,Channel[timer]).Pin.isActive == true ) - digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,LOW); // pulse this channel low if activated - } - - Channel[timer]++; // increment to the next channel - if( SERVO_INDEX(timer,Channel[timer]) < ServoCount && Channel[timer] < SERVOS_PER_TIMER) { - *OCRnA = *TCNTn + SERVO(timer,Channel[timer]).ticks; - if(SERVO(timer,Channel[timer]).Pin.isActive == true) // check if activated - digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,HIGH); // its an active channel so pulse it high - } - else { - // finished all channels so wait for the refresh period to expire before starting over - if( ((unsigned)*TCNTn) + 4 < usToTicks(REFRESH_INTERVAL) ) // allow a few ticks to ensure the next OCR1A not missed - *OCRnA = (unsigned int)usToTicks(REFRESH_INTERVAL); - else - *OCRnA = *TCNTn + 4; // at least REFRESH_INTERVAL has elapsed - Channel[timer] = -1; // this will get incremented at the end of the refresh period to start again at the first channel - } -} - -#ifndef WIRING // Wiring pre-defines signal handlers so don't define any if compiling for the Wiring platform -// Interrupt handlers for Arduino -#if defined(_useTimer1) -SIGNAL (TIMER1_COMPA_vect) -{ - handle_interrupts(_timer1, &TCNT1, &OCR1A); -} -#endif - -#if defined(_useTimer3) -SIGNAL (TIMER3_COMPA_vect) -{ - handle_interrupts(_timer3, &TCNT3, &OCR3A); -} -#endif - -#if defined(_useTimer4) -SIGNAL (TIMER4_COMPA_vect) -{ - handle_interrupts(_timer4, &TCNT4, &OCR4A); -} -#endif - -#if defined(_useTimer5) -SIGNAL (TIMER5_COMPA_vect) -{ - handle_interrupts(_timer5, &TCNT5, &OCR5A); -} -#endif - -#elif defined WIRING -// Interrupt handlers for Wiring -#if defined(_useTimer1) -void Timer1Service() -{ - handle_interrupts(_timer1, &TCNT1, &OCR1A); -} -#endif -#if defined(_useTimer3) -void Timer3Service() -{ - handle_interrupts(_timer3, &TCNT3, &OCR3A); -} -#endif -#endif - - -static void initISR(timer16_Sequence_t timer) -{ -#if defined (_useTimer1) - if(timer == _timer1) { - TCCR1A = 0; // normal counting mode - TCCR1B = _BV(CS11); // set prescaler of 8 - TCNT1 = 0; // clear the timer count -#if defined(__AVR_ATmega8__)|| defined(__AVR_ATmega128__) - TIFR |= _BV(OCF1A); // clear any pending interrupts; - TIMSK |= _BV(OCIE1A) ; // enable the output compare interrupt -#else - // here if not ATmega8 or ATmega128 - TIFR1 |= _BV(OCF1A); // clear any pending interrupts; - TIMSK1 |= _BV(OCIE1A) ; // enable the output compare interrupt -#endif -#if defined(WIRING) - timerAttach(TIMER1OUTCOMPAREA_INT, Timer1Service); -#endif - } -#endif - -#if defined (_useTimer3) - if(timer == _timer3) { - TCCR3A = 0; // normal counting mode - TCCR3B = _BV(CS31); // set prescaler of 8 - TCNT3 = 0; // clear the timer count -#if defined(__AVR_ATmega128__) - TIFR |= _BV(OCF3A); // clear any pending interrupts; - ETIMSK |= _BV(OCIE3A); // enable the output compare interrupt -#else - TIFR3 = _BV(OCF3A); // clear any pending interrupts; - TIMSK3 = _BV(OCIE3A) ; // enable the output compare interrupt -#endif -#if defined(WIRING) - timerAttach(TIMER3OUTCOMPAREA_INT, Timer3Service); // for Wiring platform only -#endif - } -#endif - -#if defined (_useTimer4) - if(timer == _timer4) { - TCCR4A = 0; // normal counting mode - TCCR4B = _BV(CS41); // set prescaler of 8 - TCNT4 = 0; // clear the timer count - TIFR4 = _BV(OCF4A); // clear any pending interrupts; - TIMSK4 = _BV(OCIE4A) ; // enable the output compare interrupt - } -#endif - -#if defined (_useTimer5) - if(timer == _timer5) { - TCCR5A = 0; // normal counting mode - TCCR5B = _BV(CS51); // set prescaler of 8 - TCNT5 = 0; // clear the timer count - TIFR5 = _BV(OCF5A); // clear any pending interrupts; - TIMSK5 = _BV(OCIE5A) ; // enable the output compare interrupt - } -#endif -} - -static void finISR(timer16_Sequence_t timer) -{ - //disable use of the given timer -#if defined WIRING // Wiring - if(timer == _timer1) { - #if defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) - TIMSK1 &= ~_BV(OCIE1A) ; // disable timer 1 output compare interrupt - #else - TIMSK &= ~_BV(OCIE1A) ; // disable timer 1 output compare interrupt - #endif - timerDetach(TIMER1OUTCOMPAREA_INT); - } - else if(timer == _timer3) { - #if defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) - TIMSK3 &= ~_BV(OCIE3A); // disable the timer3 output compare A interrupt - #else - ETIMSK &= ~_BV(OCIE3A); // disable the timer3 output compare A interrupt - #endif - timerDetach(TIMER3OUTCOMPAREA_INT); - } -#else - //For arduino - in future: call here to a currently undefined function to reset the timer -#endif -} - -static boolean isTimerActive(timer16_Sequence_t timer) -{ - // returns true if any servo is active on this timer - for(uint8_t channel=0; channel < SERVOS_PER_TIMER; channel++) { - if(SERVO(timer,channel).Pin.isActive == true) - return true; - } - return false; -} - - -/****************** end of static functions ******************************/ - -Servo::Servo() -{ - if( ServoCount < MAX_SERVOS) { - this->servoIndex = ServoCount++; // assign a servo index to this instance - servos[this->servoIndex].ticks = usToTicks(DEFAULT_PULSE_WIDTH); // store default values - 12 Aug 2009 - } - else - this->servoIndex = INVALID_SERVO ; // too many servos -} - -uint8_t Servo::attach(int pin) -{ - return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH); -} - -uint8_t Servo::attach(int pin, int min, int max) -{ - if(this->servoIndex < MAX_SERVOS ) { - pinMode( pin, OUTPUT) ; // set servo pin to output - servos[this->servoIndex].Pin.nbr = pin; - // todo min/max check: abs(min - MIN_PULSE_WIDTH) /4 < 128 - this->min = (MIN_PULSE_WIDTH - min)/4; //resolution of min/max is 4 uS - this->max = (MAX_PULSE_WIDTH - max)/4; - // initialize the timer if it has not already been initialized - timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex); - if(isTimerActive(timer) == false) - initISR(timer); - servos[this->servoIndex].Pin.isActive = true; // this must be set after the check for isTimerActive - } - return this->servoIndex ; -} - -void Servo::detach() -{ - servos[this->servoIndex].Pin.isActive = false; - timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex); - if(isTimerActive(timer) == false) { - finISR(timer); - } -} - -void Servo::write(int value) -{ - if(value < MIN_PULSE_WIDTH) - { // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds) - if(value < 0) value = 0; - if(value > 180) value = 180; - value = map(value, 0, 180, SERVO_MIN(), SERVO_MAX()); - } - this->writeMicroseconds(value); -} - -void Servo::writeMicroseconds(int value) -{ - // calculate and store the values for the given channel - byte channel = this->servoIndex; - if( (channel < MAX_SERVOS) ) // ensure channel is valid - { - if( value < SERVO_MIN() ) // ensure pulse width is valid - value = SERVO_MIN(); - else if( value > SERVO_MAX() ) - value = SERVO_MAX(); - - value = value - TRIM_DURATION; - value = usToTicks(value); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009 - - uint8_t oldSREG = SREG; - cli(); - servos[channel].ticks = value; - SREG = oldSREG; - } -} - -int Servo::read() // return the value as degrees -{ - return map( this->readMicroseconds()+1, SERVO_MIN(), SERVO_MAX(), 0, 180); -} - -int Servo::readMicroseconds() -{ - unsigned int pulsewidth; - if( this->servoIndex != INVALID_SERVO ) - pulsewidth = ticksToUs(servos[this->servoIndex].ticks) + TRIM_DURATION ; // 12 aug 2009 - else - pulsewidth = 0; - - return pulsewidth; -} - -bool Servo::attached() -{ - return servos[this->servoIndex].Pin.isActive ; -} +/* + Servo.cpp - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2 + Copyright (c) 2009 Michael Margolis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + + A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method. + The servos are pulsed in the background using the value most recently written using the write() method + + Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached. + Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four. + + The methods are: + + Servo - Class for manipulating servo motors connected to Arduino pins. + + attach(pin ) - Attaches a servo motor to an i/o pin. + attach(pin, min, max ) - Attaches to a pin setting min and max values in microseconds + default min is 544, max is 2400 + + write() - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds) + writeMicroseconds() - Sets the servo pulse width in microseconds + read() - Gets the last written servo pulse width as an angle between 0 and 180. + readMicroseconds() - Gets the last written servo pulse width in microseconds. (was read_us() in first release) + attached() - Returns true if there is a servo attached. + detach() - Stops an attached servos from pulsing its i/o pin. + +*/ +#ifdef NUM_SERVOS +#include +#include + +#include "Servo.h" + +#define usToTicks(_us) (( clockCyclesPerMicrosecond()* _us) / 8) // converts microseconds to tick (assumes prescale of 8) // 12 Aug 2009 +#define ticksToUs(_ticks) (( (unsigned)_ticks * 8)/ clockCyclesPerMicrosecond() ) // converts from ticks back to microseconds + + +#define TRIM_DURATION 2 // compensation ticks to trim adjust for digitalWrite delays // 12 August 2009 + +//#define NBR_TIMERS (MAX_SERVOS / SERVOS_PER_TIMER) + +static servo_t servos[MAX_SERVOS]; // static array of servo structures +static volatile int8_t Channel[_Nbr_16timers ]; // counter for the servo being pulsed for each timer (or -1 if refresh interval) + +uint8_t ServoCount = 0; // the total number of attached servos + + +// convenience macros +#define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / SERVOS_PER_TIMER)) // returns the timer controlling this servo +#define SERVO_INDEX_TO_CHANNEL(_servo_nbr) (_servo_nbr % SERVOS_PER_TIMER) // returns the index of the servo on this timer +#define SERVO_INDEX(_timer,_channel) ((_timer*SERVOS_PER_TIMER) + _channel) // macro to access servo index by timer and channel +#define SERVO(_timer,_channel) (servos[SERVO_INDEX(_timer,_channel)]) // macro to access servo class by timer and channel + +#define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4) // minimum value in uS for this servo +#define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4) // maximum value in uS for this servo + +/************ static functions common to all instances ***********************/ + +static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t *TCNTn, volatile uint16_t* OCRnA) +{ + if( Channel[timer] < 0 ) + *TCNTn = 0; // channel set to -1 indicated that refresh interval completed so reset the timer + else{ + if( SERVO_INDEX(timer,Channel[timer]) < ServoCount && SERVO(timer,Channel[timer]).Pin.isActive == true ) + digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,LOW); // pulse this channel low if activated + } + + Channel[timer]++; // increment to the next channel + if( SERVO_INDEX(timer,Channel[timer]) < ServoCount && Channel[timer] < SERVOS_PER_TIMER) { + *OCRnA = *TCNTn + SERVO(timer,Channel[timer]).ticks; + if(SERVO(timer,Channel[timer]).Pin.isActive == true) // check if activated + digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,HIGH); // its an active channel so pulse it high + } + else { + // finished all channels so wait for the refresh period to expire before starting over + if( ((unsigned)*TCNTn) + 4 < usToTicks(REFRESH_INTERVAL) ) // allow a few ticks to ensure the next OCR1A not missed + *OCRnA = (unsigned int)usToTicks(REFRESH_INTERVAL); + else + *OCRnA = *TCNTn + 4; // at least REFRESH_INTERVAL has elapsed + Channel[timer] = -1; // this will get incremented at the end of the refresh period to start again at the first channel + } +} + +#ifndef WIRING // Wiring pre-defines signal handlers so don't define any if compiling for the Wiring platform +// Interrupt handlers for Arduino +#if defined(_useTimer1) +SIGNAL (TIMER1_COMPA_vect) +{ + handle_interrupts(_timer1, &TCNT1, &OCR1A); +} +#endif + +#if defined(_useTimer3) +SIGNAL (TIMER3_COMPA_vect) +{ + handle_interrupts(_timer3, &TCNT3, &OCR3A); +} +#endif + +#if defined(_useTimer4) +SIGNAL (TIMER4_COMPA_vect) +{ + handle_interrupts(_timer4, &TCNT4, &OCR4A); +} +#endif + +#if defined(_useTimer5) +SIGNAL (TIMER5_COMPA_vect) +{ + handle_interrupts(_timer5, &TCNT5, &OCR5A); +} +#endif + +#elif defined WIRING +// Interrupt handlers for Wiring +#if defined(_useTimer1) +void Timer1Service() +{ + handle_interrupts(_timer1, &TCNT1, &OCR1A); +} +#endif +#if defined(_useTimer3) +void Timer3Service() +{ + handle_interrupts(_timer3, &TCNT3, &OCR3A); +} +#endif +#endif + + +static void initISR(timer16_Sequence_t timer) +{ +#if defined (_useTimer1) + if(timer == _timer1) { + TCCR1A = 0; // normal counting mode + TCCR1B = _BV(CS11); // set prescaler of 8 + TCNT1 = 0; // clear the timer count +#if defined(__AVR_ATmega8__)|| defined(__AVR_ATmega128__) + TIFR |= _BV(OCF1A); // clear any pending interrupts; + TIMSK |= _BV(OCIE1A) ; // enable the output compare interrupt +#else + // here if not ATmega8 or ATmega128 + TIFR1 |= _BV(OCF1A); // clear any pending interrupts; + TIMSK1 |= _BV(OCIE1A) ; // enable the output compare interrupt +#endif +#if defined(WIRING) + timerAttach(TIMER1OUTCOMPAREA_INT, Timer1Service); +#endif + } +#endif + +#if defined (_useTimer3) + if(timer == _timer3) { + TCCR3A = 0; // normal counting mode + TCCR3B = _BV(CS31); // set prescaler of 8 + TCNT3 = 0; // clear the timer count +#if defined(__AVR_ATmega128__) + TIFR |= _BV(OCF3A); // clear any pending interrupts; + ETIMSK |= _BV(OCIE3A); // enable the output compare interrupt +#else + TIFR3 = _BV(OCF3A); // clear any pending interrupts; + TIMSK3 = _BV(OCIE3A) ; // enable the output compare interrupt +#endif +#if defined(WIRING) + timerAttach(TIMER3OUTCOMPAREA_INT, Timer3Service); // for Wiring platform only +#endif + } +#endif + +#if defined (_useTimer4) + if(timer == _timer4) { + TCCR4A = 0; // normal counting mode + TCCR4B = _BV(CS41); // set prescaler of 8 + TCNT4 = 0; // clear the timer count + TIFR4 = _BV(OCF4A); // clear any pending interrupts; + TIMSK4 = _BV(OCIE4A) ; // enable the output compare interrupt + } +#endif + +#if defined (_useTimer5) + if(timer == _timer5) { + TCCR5A = 0; // normal counting mode + TCCR5B = _BV(CS51); // set prescaler of 8 + TCNT5 = 0; // clear the timer count + TIFR5 = _BV(OCF5A); // clear any pending interrupts; + TIMSK5 = _BV(OCIE5A) ; // enable the output compare interrupt + } +#endif +} + +static void finISR(timer16_Sequence_t timer) +{ + //disable use of the given timer +#if defined WIRING // Wiring + if(timer == _timer1) { + #if defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) + TIMSK1 &= ~_BV(OCIE1A) ; // disable timer 1 output compare interrupt + #else + TIMSK &= ~_BV(OCIE1A) ; // disable timer 1 output compare interrupt + #endif + timerDetach(TIMER1OUTCOMPAREA_INT); + } + else if(timer == _timer3) { + #if defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) + TIMSK3 &= ~_BV(OCIE3A); // disable the timer3 output compare A interrupt + #else + ETIMSK &= ~_BV(OCIE3A); // disable the timer3 output compare A interrupt + #endif + timerDetach(TIMER3OUTCOMPAREA_INT); + } +#else + //For arduino - in future: call here to a currently undefined function to reset the timer +#endif +} + +static boolean isTimerActive(timer16_Sequence_t timer) +{ + // returns true if any servo is active on this timer + for(uint8_t channel=0; channel < SERVOS_PER_TIMER; channel++) { + if(SERVO(timer,channel).Pin.isActive == true) + return true; + } + return false; +} + + +/****************** end of static functions ******************************/ + +Servo::Servo() +{ + if( ServoCount < MAX_SERVOS) { + this->servoIndex = ServoCount++; // assign a servo index to this instance + servos[this->servoIndex].ticks = usToTicks(DEFAULT_PULSE_WIDTH); // store default values - 12 Aug 2009 + } + else + this->servoIndex = INVALID_SERVO ; // too many servos +} + +uint8_t Servo::attach(int pin) +{ + return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH); +} + +uint8_t Servo::attach(int pin, int min, int max) +{ + if(this->servoIndex < MAX_SERVOS ) { + pinMode( pin, OUTPUT) ; // set servo pin to output + servos[this->servoIndex].Pin.nbr = pin; + // todo min/max check: abs(min - MIN_PULSE_WIDTH) /4 < 128 + this->min = (MIN_PULSE_WIDTH - min)/4; //resolution of min/max is 4 uS + this->max = (MAX_PULSE_WIDTH - max)/4; + // initialize the timer if it has not already been initialized + timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex); + if(isTimerActive(timer) == false) + initISR(timer); + servos[this->servoIndex].Pin.isActive = true; // this must be set after the check for isTimerActive + } + return this->servoIndex ; +} + +void Servo::detach() +{ + servos[this->servoIndex].Pin.isActive = false; + timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex); + if(isTimerActive(timer) == false) { + finISR(timer); + } +} + +void Servo::write(int value) +{ + if(value < MIN_PULSE_WIDTH) + { // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds) + if(value < 0) value = 0; + if(value > 180) value = 180; + value = map(value, 0, 180, SERVO_MIN(), SERVO_MAX()); + } + this->writeMicroseconds(value); +} + +void Servo::writeMicroseconds(int value) +{ + // calculate and store the values for the given channel + byte channel = this->servoIndex; + if( (channel < MAX_SERVOS) ) // ensure channel is valid + { + if( value < SERVO_MIN() ) // ensure pulse width is valid + value = SERVO_MIN(); + else if( value > SERVO_MAX() ) + value = SERVO_MAX(); + + value = value - TRIM_DURATION; + value = usToTicks(value); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009 + + uint8_t oldSREG = SREG; + cli(); + servos[channel].ticks = value; + SREG = oldSREG; + } +} + +int Servo::read() // return the value as degrees +{ + return map( this->readMicroseconds()+1, SERVO_MIN(), SERVO_MAX(), 0, 180); +} + +int Servo::readMicroseconds() +{ + unsigned int pulsewidth; + if( this->servoIndex != INVALID_SERVO ) + pulsewidth = ticksToUs(servos[this->servoIndex].ticks) + TRIM_DURATION ; // 12 aug 2009 + else + pulsewidth = 0; + + return pulsewidth; +} + +bool Servo::attached() +{ + return servos[this->servoIndex].Pin.isActive ; +} + +#endif