From 06faad4261b8750e10e0c30537c77925845538ea Mon Sep 17 00:00:00 2001 From: Jay Wilhelm Date: Fri, 19 Oct 2018 21:54:49 -0400 Subject: [PATCH 1/8] Added 3 serial func. Dump calibration, set calibration, and force setup menu start --- .gitignore | 15 +++++--- main.cpp | 79 +++++++++++++++++++++++++++++++++++++++---- permanent_storage.cpp | 18 +--------- permanent_storage.h | 20 +++++++++++ 4 files changed, 104 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index c13749fa..84ae2210 100644 --- a/.gitignore +++ b/.gitignore @@ -4,12 +4,17 @@ /MM-control-01.sln /__vm/.MMU_FW.vsarduino.h -.cproject -.project -.settings -/Debug +.cproject +.project +.settings +/Debug /__vm/.MM-Control.vsarduino.h /.vs/MM-control-01/v14/.suo /main.cpp~RFdf1346e.TMP /__vm/.MM-control-01.vsarduino.h -Doc +Doc +.pioenvs +.piolibdeps +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json diff --git a/main.cpp b/main.cpp index 06efc7ac..0a2d4e6e 100644 --- a/main.cpp +++ b/main.cpp @@ -16,7 +16,7 @@ #include "Buttons.h" #include #include "permanent_storage.h" - +#include "uart.h" int8_t sys_state = 0; uint8_t sys_signals = 0; @@ -25,7 +25,7 @@ int _c = 0; uint8_t tmc2130_mode = NORMAL_MODE; #if (UART_COM == 0) -FILE* uart_com = uart0io; +FILE* uart_com = uart0io;//USB #elif (UART_COM == 1) FILE* uart_com = uart1io; #endif //(UART_COM == 0) @@ -92,7 +92,6 @@ void setup() init_Pulley(); - // if FINDA is sensing filament do not home while (digitalRead(A1) == 1) { @@ -196,9 +195,11 @@ void manual_extruder_selector() //! middle | feed filament //! //! @copydoc manual_extruder_selector() + void loop() { process_commands(uart_com); + process_commands(uart0io); if (!isPrinting) { @@ -220,8 +221,28 @@ extern "C" { void process_commands(FILE* inout) { - static char line[32]; - static int count = 0; + //static char line[32]; + //static int count = 0; + + static char line_usb[32]; + static int count_usb = 0; + + static char line_hw[32]; + static int count_hw = 0; + + char* line; + int count = 0; + if(inout == uart0io) + { + line = line_usb; + count = count_usb; + } + else + { + line = line_hw; + count = count_hw; + } + int c = -1; if (count < 32) { @@ -230,6 +251,8 @@ void process_commands(FILE* inout) if (c == '\r') c = 0; if (c == '\n') c = 0; line[count++] = c; + if(inout == uart0io) + printf_P(PSTR("%c"),c); } } else @@ -243,7 +266,8 @@ void process_commands(FILE* inout) if ((count > 0) && (c == 0)) { //line received - //printf_P(PSTR("line received: '%s' %d\n"), line, count); + if(inout == uart0io) + printf_P(PSTR("\r\nline received: '%s' %d\r\n"), line, count); count = 0; if (sscanf_P(line, PSTR("T%d"), &value) > 0) { @@ -344,10 +368,53 @@ void process_commands(FILE* inout) fprintf_P(inout, PSTR("ok\n")); } } + else if(strcmp_P(line, PSTR("!D")) == 0) + { + fprintf_P(inout, PSTR("DUMPING TUBE LENGTH CALIBRATION\r\n")); + for(int i=0;i<5;i++) + { + uint8_t filament = i; + if (1)//validFilament(filament)) + { + uint16_t bowdenLength = eeprom_read_word(&(eepromBase->eepromBowdenLen[filament])); + + fprintf_P(inout,PSTR("%d:%d\r\n"),i,bowdenLength); + //if (validBowdenLen(bowdenLength)) + // return bowdenLength; + } + } + } + else if(sscanf_P(line,PSTR("!S%d,%d"),&value,&value0) > 0) + { + if(value < 0 || value > 4) + { + fprintf_P(inout, PSTR("Invalid extruder #\r\n")); + } + fprintf_P(inout, PSTR("Storing Extruder Tube Length %d to %d\r\n"),value,value0); + if (validFilament(value)) + eeprom_update_word(&(eepromBase->eepromBowdenLen[value]), value0); + else + { + fprintf_P(inout, PSTR("Invalid length\r\n")); + } + } + else if(strcmp_P(line,PSTR("!CMODE")) == 0) + { + fprintf_P(inout, PSTR("Entering Setup Menu\r\n")); + setupMenu(); + } } else { //nothing received } + if(inout == uart0io) + { + count_usb = count; + } + else + { + count_hw = count; + } } diff --git a/permanent_storage.cpp b/permanent_storage.cpp index 7af1f023..3e1878bd 100644 --- a/permanent_storage.cpp +++ b/permanent_storage.cpp @@ -5,28 +5,12 @@ #include "mmctl.h" #include -//! @brief EEPROM data layout -//! -//! Do not remove, reorder or change size of existing fields. -//! Otherwise values stored with previous version of firmware would be broken. -//! It is possible to add fields in the end of this struct, ensure that erased EEPROM is handled well. -typedef struct -{ - uint8_t eepromLengthCorrection; //!< legacy bowden length correction - uint16_t eepromBowdenLen[5]; //!< Bowden length for each filament -}eeprom_t; -static eeprom_t * const eepromBase = reinterpret_cast(0); //!< First EEPROM address -static const uint16_t eepromEmpty = 0xffff; //!< EEPROM content when erased -static const uint16_t eepromLengthCorrectionBase = 7900u; //!< legacy bowden length correction base -static const uint16_t eepromBowdenLenDefault = 8900u; //!< Default bowden length -static const uint16_t eepromBowdenLenMinimum = 6900u; //!< Minimum bowden length -static const uint16_t eepromBowdenLenMaximum = 10900u; //!< Maximum bowden length //! @brief Is filament number valid? //! @retval true valid //! @retval false invalid -static bool validFilament(uint8_t filament) +bool validFilament(uint8_t filament) { if (filament < (sizeof(eeprom_t::eepromBowdenLen)/sizeof(eeprom_t::eepromBowdenLen[0]))) return true; else return false; diff --git a/permanent_storage.h b/permanent_storage.h index 733fe509..a0cf1132 100644 --- a/permanent_storage.h +++ b/permanent_storage.h @@ -5,6 +5,26 @@ #define PERMANENT_STORAGE_H_ #include +//! @brief EEPROM data layout +//! +//! Do not remove, reorder or change size of existing fields. +//! Otherwise values stored with previous version of firmware would be broken. +//! It is possible to add fields in the end of this struct, ensure that erased EEPROM is handled well. +typedef struct +{ + uint8_t eepromLengthCorrection; //!< legacy bowden length correction + uint16_t eepromBowdenLen[5]; //!< Bowden length for each filament +}eeprom_t; + +static eeprom_t * const eepromBase = reinterpret_cast(0); //!< First EEPROM address +static const uint16_t eepromEmpty = 0xffff; //!< EEPROM content when erased +static const uint16_t eepromLengthCorrectionBase = 7900u; //!< legacy bowden length correction base +static const uint16_t eepromBowdenLenDefault = 8900u; //!< Default bowden length +static const uint16_t eepromBowdenLenMinimum = 6900u; //!< Minimum bowden length +static const uint16_t eepromBowdenLenMaximum = 10900u; //!< Maximum bowden length + +bool validFilament(uint8_t filament); + //! @brief Read manipulate and store bowden length //! From b40245a87a0c11fd0a277bfdc992199accc19f3e Mon Sep 17 00:00:00 2001 From: Jay Wilhelm Date: Fri, 19 Oct 2018 22:57:22 -0400 Subject: [PATCH 2/8] Another cmd for direct calibration and debug output from length calibration --- Buttons.cpp | 27 +++++++++++++++++++++++++-- Buttons.h | 2 +- main.cpp | 7 ++++++- permanent_storage.h | 3 ++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Buttons.cpp b/Buttons.cpp index ef921e76..728c0aef 100644 --- a/Buttons.cpp +++ b/Buttons.cpp @@ -7,6 +7,7 @@ #include "motion.h" #include "permanent_storage.h" #include "main.h" +#include "uart.h" const int ButtonPin = A2; @@ -31,7 +32,8 @@ void settings_select_filament() delay(500); if (Btn::middle == buttonClicked()) { - if (active_extruder < 5) settings_bowden_length(); + if (active_extruder < 5) + settings_bowden_length(); else { select_extruder(4); @@ -76,6 +78,7 @@ void setupMenu() bool eraseLocked = true; + fprintf_P(uart0io,PSTR("\r\nEntered Setup Menu\r\n")); do { @@ -90,32 +93,46 @@ void setupMenu() { case Btn::right: if (_menu > 0) { _menu--; delay(800); } + fprintf_P(uart0io,PSTR("B Right\r\n")); break; case Btn::middle: switch (_menu) { case 1: + fprintf_P(uart0io,PSTR("Selected settings_select_filament\r\n")); settings_select_filament(); _exit = true; break; case 2: if (!eraseLocked) { + fprintf_P(uart0io,PSTR("Erasing BowdenLength\r\n")); BowdenLength::eraseAll(); _exit = true; } + else + { + fprintf_P(uart0io,PSTR("Locked BowdenLength\r\n")); + } break; case 3: //unlock erase + fprintf_P(uart0io,PSTR("Unlocked erase\r\n")); eraseLocked = false; break; case 4: // exit menu + fprintf_P(uart0io,PSTR("Exit Setup\r\n")); _exit = true; break; } break; case Btn::left: - if (_menu < 4) { _menu++; delay(800); } + if (_menu < 4) + { + _menu++; + delay(800); + } + fprintf_P(uart0io,PSTR("B Left\r\n")); break; default: break; @@ -162,6 +179,7 @@ void settings_bowden_length() { BowdenLength bowdenLength; load_filament_withSensor(); + fprintf_P(uart0io,PSTR("Selected #: %d\r\n"),bowdenLength.m_filament); tmc2130_init_axis_current_normal(AX_PUL, 1, 30); do @@ -174,6 +192,7 @@ void settings_bowden_length() { move(0, 0, -bowdenLength.stepSize); delay(400); + fprintf_P(uart0io,PSTR("Dec: %d\r\n"),bowdenLength.m_length); } break; @@ -182,8 +201,10 @@ void settings_bowden_length() { move(0, 0, bowdenLength.stepSize); delay(400); + fprintf_P(uart0io,PSTR("Inc: %d\r\n"),bowdenLength.m_length); } break; + default: break; } @@ -197,6 +218,8 @@ void settings_bowden_length() } while (buttonClicked() != Btn::middle); + + fprintf_P(uart0io,PSTR("Len: %d\r\n"),bowdenLength.m_length); unload_filament_withSensor(); } diff --git a/Buttons.h b/Buttons.h index 3cd8f8ab..43140905 100644 --- a/Buttons.h +++ b/Buttons.h @@ -28,7 +28,7 @@ inline bool operator& (Btn a, Btn b) { return static_cast(a) & static_cast(b); } - +void settings_select_filament(); void setupMenu(); Btn buttonClicked(); diff --git a/main.cpp b/main.cpp index 0a2d4e6e..696b99b2 100644 --- a/main.cpp +++ b/main.cpp @@ -398,7 +398,12 @@ void process_commands(FILE* inout) fprintf_P(inout, PSTR("Invalid length\r\n")); } } - else if(strcmp_P(line,PSTR("!CMODE")) == 0) + else if (strcmp_P(line,PSTR("!CALI")) == 0) + { + fprintf_P(inout, PSTR("Entering Filamint Calibration Mode\r\n")); + settings_select_filament(); + } + else if(strcmp_P(line,PSTR("!SETUP")) == 0) { fprintf_P(inout, PSTR("Entering Setup Menu\r\n")); setupMenu(); diff --git a/permanent_storage.h b/permanent_storage.h index a0cf1132..5a425364 100644 --- a/permanent_storage.h +++ b/permanent_storage.h @@ -40,7 +40,8 @@ class BowdenLength bool increase(); bool decrease(); ~BowdenLength(); -private: + +public: uint8_t m_filament; //!< Selected filament uint16_t m_length; //!< Selected filament bowden length }; From 55496d1913101d4ca243a21a21a18c6728062087 Mon Sep 17 00:00:00 2001 From: Jay Wilhelm Date: Mon, 22 Oct 2018 19:10:12 -0400 Subject: [PATCH 3/8] Added more commands for calibration and stepper disable --- Buttons.cpp | 4 +++- main.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- tmc2130.c | 12 ++++++++---- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/Buttons.cpp b/Buttons.cpp index 728c0aef..bee729ff 100644 --- a/Buttons.cpp +++ b/Buttons.cpp @@ -178,8 +178,10 @@ void settings_bowden_length() if (!isFilamentLoaded) { BowdenLength bowdenLength; - load_filament_withSensor(); fprintf_P(uart0io,PSTR("Selected #: %d\r\n"),bowdenLength.m_filament); + fprintf_P(uart0io,PSTR("Current Len: %d\r\n"),bowdenLength.m_length); + + load_filament_withSensor(); tmc2130_init_axis_current_normal(AX_PUL, 1, 30); do diff --git a/main.cpp b/main.cpp index 696b99b2..a10f0ffe 100644 --- a/main.cpp +++ b/main.cpp @@ -268,11 +268,20 @@ void process_commands(FILE* inout) //line received if(inout == uart0io) printf_P(PSTR("\r\nline received: '%s' %d\r\n"), line, count); + else if(strcmp_P(line,PSTR("P0")) != 0) + fprintf_P(uart0io,PSTR("line received: '%s' %d\r\n"), line, count); count = 0; if (sscanf_P(line, PSTR("T%d"), &value) > 0) { //T-code scanned - if ((value >= 0) && (value < EXTRUDERS)) + if(value == 999) + { + tmc2130_disable_axis(AX_PUL,STEALTH_MODE); + tmc2130_disable_axis(AX_SEL,STEALTH_MODE); + tmc2130_disable_axis(AX_IDL,STEALTH_MODE); + fprintf_P(inout, PSTR("ok\n")); + } + else if ((value >= 0) && (value < EXTRUDERS)) { switch_extruder_withSensor(value); @@ -408,6 +417,38 @@ void process_commands(FILE* inout) fprintf_P(inout, PSTR("Entering Setup Menu\r\n")); setupMenu(); } + else if(strcmp_P(line,PSTR("!DISABLE")) == 0) + { + tmc2130_disable_axis(AX_PUL,STEALTH_MODE); + tmc2130_disable_axis(AX_SEL,STEALTH_MODE); + tmc2130_disable_axis(AX_IDL,STEALTH_MODE); + } + else if(sscanf_P(line,PSTR("!L%d"),&value) > 0) + { + if ((value >= 0) && (value < EXTRUDERS) && !isFilamentLoaded) + { + fprintf_P(inout, PSTR("Loading #%d\r\n"),value); + + select_extruder(value); + //feed_filament(); + load_filament_withSensor(); + + } + else + fprintf_P(inout, PSTR("Load cmd error\r\n")); +// tmc2130_init_axis_current_normal(AX_PUL, 1, 30); + } + else if(strcmp_P(line,PSTR("!U")) == 0) + { + if (isFilamentLoaded) + { + fprintf_P(inout, PSTR("Unloading\r\n")); + + unload_filament_withSensor(); + } + else + fprintf_P(inout, PSTR("Unload cmd error\r\n")); + } } else { //nothing received diff --git a/tmc2130.c b/tmc2130.c index 4509899a..dfe7e3b9 100644 --- a/tmc2130.c +++ b/tmc2130.c @@ -193,14 +193,17 @@ int8_t tmc2130_init_axis(uint8_t axis, uint8_t mode) void tmc2130_disable_axis(uint8_t axis, uint8_t mode) { //temporary solution, use enable pin instead - if (mode == STEALTH_MODE) tmc2130_init_axis_current_stealth(axis, 0, 0); - else tmc2130_init_axis_current_normal(axis, 0, 0); + if (mode == STEALTH_MODE) + tmc2130_init_axis_current_stealth(axis, 0, 0); + else + tmc2130_init_axis_current_normal(axis, 0, 0); } int8_t tmc2130_init_axis_current_stealth(uint8_t axis, uint8_t current_h, uint8_t current_r) { //stealth mode - if (tmc2130_setup_chopper(axis, (uint32_t)__res(axis), current_h, current_r)) return -1; + if (tmc2130_setup_chopper(axis, (uint32_t)__res(axis), current_h, current_r)) + return -1; tmc2130_wr(axis, TMC2130_REG_TPOWERDOWN, 0x00000000); tmc2130_wr(axis, TMC2130_REG_COOLCONF, (((uint32_t)TMC2130_SG_THR) << 16)); tmc2130_wr(axis, TMC2130_REG_TCOOLTHRS, 0); @@ -213,7 +216,8 @@ int8_t tmc2130_init_axis_current_stealth(uint8_t axis, uint8_t current_h, uint8_ int8_t tmc2130_init_axis_current_normal(uint8_t axis, uint8_t current_h, uint8_t current_r) { //normal mode - if (tmc2130_setup_chopper(axis, (uint32_t)__res(axis), current_h, current_r)) return -1; + if (tmc2130_setup_chopper(axis, (uint32_t)__res(axis), current_h, current_r)) + return -1; tmc2130_wr(axis, TMC2130_REG_TPOWERDOWN, 0x00000000); tmc2130_wr(axis, TMC2130_REG_COOLCONF, (((uint32_t)__sg_thr(axis)) << 16)); tmc2130_wr(axis, TMC2130_REG_TCOOLTHRS, __tcoolthrs(axis)); From 7e0b774045e67fb3e58834f4d15d851af3317ebc Mon Sep 17 00:00:00 2001 From: Jay Wilhelm Date: Mon, 22 Oct 2018 20:04:29 -0400 Subject: [PATCH 4/8] Added inc/dec to serial commands with length save --- main.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index a10f0ffe..23266b02 100644 --- a/main.cpp +++ b/main.cpp @@ -223,7 +223,8 @@ void process_commands(FILE* inout) { //static char line[32]; //static int count = 0; - + static BowdenLength *pbowdenLength = 0; + static char line_usb[32]; static int count_usb = 0; @@ -412,6 +413,24 @@ void process_commands(FILE* inout) fprintf_P(inout, PSTR("Entering Filamint Calibration Mode\r\n")); settings_select_filament(); } + else if (strcmp_P(line,PSTR("!INC"))==0) + { + if (pbowdenLength != 0 && pbowdenLength->decrease()) + { + move(0, 0, pbowdenLength->stepSize); + delay(400); + fprintf_P(uart0io,PSTR("Inc: %d\r\n"),pbowdenLength->m_length); + } + } + else if (strcmp_P(line,PSTR("!DEC"))==0) + { + if (pbowdenLength != 0 && pbowdenLength->decrease()) + { + move(0, 0, -pbowdenLength->stepSize); + delay(400); + fprintf_P(uart0io,PSTR("Dec: %d\r\n"),pbowdenLength->m_length); + } + } else if(strcmp_P(line,PSTR("!SETUP")) == 0) { fprintf_P(inout, PSTR("Entering Setup Menu\r\n")); @@ -431,8 +450,9 @@ void process_commands(FILE* inout) select_extruder(value); //feed_filament(); - load_filament_withSensor(); + pbowdenLength = new BowdenLength(); + load_filament_withSensor(); } else fprintf_P(inout, PSTR("Load cmd error\r\n")); @@ -445,6 +465,8 @@ void process_commands(FILE* inout) fprintf_P(inout, PSTR("Unloading\r\n")); unload_filament_withSensor(); + if(pbowdenLength) + delete pbowdenLength; } else fprintf_P(inout, PSTR("Unload cmd error\r\n")); From 7d668ded4d414509db0a0257780621e639db0a29 Mon Sep 17 00:00:00 2001 From: Jay Wilhelm Date: Mon, 29 Oct 2018 19:50:27 -0400 Subject: [PATCH 5/8] inc/dec updated --- main.cpp | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/main.cpp b/main.cpp index 23266b02..a44a3328 100644 --- a/main.cpp +++ b/main.cpp @@ -413,24 +413,7 @@ void process_commands(FILE* inout) fprintf_P(inout, PSTR("Entering Filamint Calibration Mode\r\n")); settings_select_filament(); } - else if (strcmp_P(line,PSTR("!INC"))==0) - { - if (pbowdenLength != 0 && pbowdenLength->decrease()) - { - move(0, 0, pbowdenLength->stepSize); - delay(400); - fprintf_P(uart0io,PSTR("Inc: %d\r\n"),pbowdenLength->m_length); - } - } - else if (strcmp_P(line,PSTR("!DEC"))==0) - { - if (pbowdenLength != 0 && pbowdenLength->decrease()) - { - move(0, 0, -pbowdenLength->stepSize); - delay(400); - fprintf_P(uart0io,PSTR("Dec: %d\r\n"),pbowdenLength->m_length); - } - } + else if(strcmp_P(line,PSTR("!SETUP")) == 0) { fprintf_P(inout, PSTR("Entering Setup Menu\r\n")); @@ -453,6 +436,9 @@ void process_commands(FILE* inout) pbowdenLength = new BowdenLength(); load_filament_withSensor(); + + tmc2130_init_axis_current_normal(AX_PUL, 1, 30); + } else fprintf_P(inout, PSTR("Load cmd error\r\n")); @@ -471,6 +457,29 @@ void process_commands(FILE* inout) else fprintf_P(inout, PSTR("Unload cmd error\r\n")); } + else if (strcmp_P(line,PSTR("!INC"))==0) + { + if (pbowdenLength != 0 && pbowdenLength->increase() && isFilamentLoaded) + { + move(0, 0, 10*pbowdenLength->stepSize); + delay(400); + fprintf_P(uart0io,PSTR("Inc: %d\r\n"),pbowdenLength->m_length); + } + else + fprintf_P(uart0io,PSTR("Cannot increase\r\n"),pbowdenLength->m_length); + + } + else if (strcmp_P(line,PSTR("!DEC"))==0) + { + if (pbowdenLength != 0 && pbowdenLength->decrease() && isFilamentLoaded) + { + move(0, 0, -pbowdenLength->stepSize); + delay(400); + fprintf_P(uart0io,PSTR("Dec: %d\r\n"),pbowdenLength->m_length); + } + else + fprintf_P(uart0io,PSTR("Cannot decrease\r\n"),pbowdenLength->m_length); + } } else { //nothing received From 7cf478614d4875efaba9a21f978686d1d763edc2 Mon Sep 17 00:00:00 2001 From: Jay Wilhelm Date: Sun, 25 Nov 2018 10:06:02 -0500 Subject: [PATCH 6/8] slowed up calibration --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index a44a3328..45fb8849 100644 --- a/main.cpp +++ b/main.cpp @@ -461,7 +461,7 @@ void process_commands(FILE* inout) { if (pbowdenLength != 0 && pbowdenLength->increase() && isFilamentLoaded) { - move(0, 0, 10*pbowdenLength->stepSize); + move(0, 0, pbowdenLength->stepSize); delay(400); fprintf_P(uart0io,PSTR("Inc: %d\r\n"),pbowdenLength->m_length); } From 7675aea0a73500b674b520c42d7c2c473d5bf5da Mon Sep 17 00:00:00 2001 From: Jay Wilhelm Date: Sun, 23 Dec 2018 21:13:36 -0500 Subject: [PATCH 7/8] more conflict resolution for v1.0.3 --- MM-control-01/Buttons.cpp | 11 ++--------- MM-control-01/Buttons.h | 4 ++-- MM-control-01/main.cpp | 3 --- MM-control-01/permanent_storage.cpp | 17 ----------------- 4 files changed, 4 insertions(+), 31 deletions(-) diff --git a/MM-control-01/Buttons.cpp b/MM-control-01/Buttons.cpp index b183c858..93c1cf97 100644 --- a/MM-control-01/Buttons.cpp +++ b/MM-control-01/Buttons.cpp @@ -1,4 +1,3 @@ -<<<<<<< HEAD //! @file #include "Buttons.h" @@ -193,7 +192,7 @@ void settings_bowden_length() switch (buttonClicked()) { case Btn::right: - if (!button_active || (((millis() - saved_millis) > 1000) && button_active)) { + if (!button_active || (((millis() - saved_millis) > 1000) && button_active)) { move(0, 0, -bowdenLength.stepSize); delay(400); @@ -203,7 +202,7 @@ void settings_bowden_length() break; case Btn::left: - if (!button_active || (((millis() - saved_millis) > 1000) && button_active)) { + if (!button_active || (((millis() - saved_millis) > 1000) && button_active)) { move(0, 0, bowdenLength.stepSize); delay(400); @@ -225,25 +224,19 @@ void settings_bowden_length() shr16_set_led(2 << 2 * 1); delay(50); - } while (buttonClicked() != Btn::middle); - fprintf_P(uart0io,PSTR("Len: %d\r\n"),bowdenLength.m_length); - unload_filament_withSensor(); } } - //! @brief Is button pushed? //! //! @return button pushed Btn buttonClicked() { int raw = analogRead(ButtonPin); - if (raw < 50) return Btn::right; if (raw > 80 && raw < 100) return Btn::middle; if (raw > 160 && raw < 180) return Btn::left; - return Btn::none; } \ No newline at end of file diff --git a/MM-control-01/Buttons.h b/MM-control-01/Buttons.h index 5af00374..dc6234af 100644 --- a/MM-control-01/Buttons.h +++ b/MM-control-01/Buttons.h @@ -28,8 +28,8 @@ inline bool operator& (Btn a, Btn b) { return static_cast(a) & static_cast(b); } -void settings_select_filament(); + void setupMenu(); Btn buttonClicked(); - +void settings_select_filament(); #endif //_BUTTONS_h \ No newline at end of file diff --git a/MM-control-01/main.cpp b/MM-control-01/main.cpp index 6a9bfb52..629da479 100644 --- a/MM-control-01/main.cpp +++ b/MM-control-01/main.cpp @@ -271,11 +271,8 @@ void manual_extruder_selector() void loop() { process_commands(uart_com); -<<<<<<< HEAD process_commands(uart0io); -======= filament_presence_signaler(); ->>>>>>> 468aeec76f09dad0d53dfc13702fd74943033b3d if (!isPrinting) { diff --git a/MM-control-01/permanent_storage.cpp b/MM-control-01/permanent_storage.cpp index 42463a74..29af679c 100644 --- a/MM-control-01/permanent_storage.cpp +++ b/MM-control-01/permanent_storage.cpp @@ -6,23 +6,6 @@ -<<<<<<< HEAD -======= -//d = 6.3 mm pulley diameter -//c = pi * d pulley circumference -//FSPR = 200 full steps per revolution (stepper motor constant) (1.8 deg/step) -//mres = 2 pulley microstep resolution (uint8_t __res(AX_PUL)) -//mres = 2 selector microstep resolution (uint8_t __res(AX_SEL)) -//mres = 16 idler microstep resolution (uint8_t __res(AX_IDL)) -//1 pulley ustep = (d*pi)/(mres*FSPR) = 49.48 um - -static eeprom_t * const eepromBase = reinterpret_cast(0); //!< First EEPROM address -static const uint16_t eepromEmpty = 0xffff; //!< EEPROM content when erased -static const uint16_t eepromLengthCorrectionBase = 7900u; //!< legacy bowden length correction base (~391mm) -static const uint16_t eepromBowdenLenDefault = 8900u; //!< Default bowden length (~427 mm) -static const uint16_t eepromBowdenLenMinimum = 6900u; //!< Minimum bowden length (~341 mm) -static const uint16_t eepromBowdenLenMaximum = 16000u; //!< Maximum bowden length (~792 mm) ->>>>>>> 468aeec76f09dad0d53dfc13702fd74943033b3d void permanentStorageInit() { From 983d1379b1a082ce12810a9cf48835d2ed1ef01e Mon Sep 17 00:00:00 2001 From: JW Date: Fri, 29 Mar 2019 21:30:20 -0400 Subject: [PATCH 8/8] merge fixes for compile --- MM-control-01/Buttons.cpp | 264 ++-------------------------- MM-control-01/Buttons.h | 2 +- MM-control-01/main.cpp | 43 +++-- MM-control-01/permanent_storage.cpp | 32 ---- MM-control-01/permanent_storage.h | 18 +- 5 files changed, 52 insertions(+), 307 deletions(-) diff --git a/MM-control-01/Buttons.cpp b/MM-control-01/Buttons.cpp index d6c74260..ee12e911 100644 --- a/MM-control-01/Buttons.cpp +++ b/MM-control-01/Buttons.cpp @@ -1,248 +1,5 @@ //! @file -#include "Buttons.h" -#include "shr16.h" -#include "tmc2130.h" -#include "mmctl.h" -#include "motion.h" -#include "permanent_storage.h" -#include "main.h" -#include "uart.h" - -const int ButtonPin = A2; - -void settings_bowden_length(); - - -//! @brief Select filament for bowden length calibration -//! -//! Filaments are selected by left and right buttons, calibration is activated by middle button. -//! Park position (one behind last filament) can be also selected. -//! Activating calibration in park position exits selector. -//! -void settings_select_filament() -{ - while (1) - { - manual_extruder_selector(); - - if(Btn::middle == buttonClicked()) - { - shr16_set_led(2 << 2 * (4 - active_extruder)); - delay(500); - if (Btn::middle == buttonClicked()) - { - if (!isHomed) { home(); } - if (active_extruder < 5) settings_bowden_length(); - else - { - select_extruder(0); - return; - } - } - } - } -} - -//! @brief Show setup menu -//! -//! Items are selected by left and right buttons, activated by middle button. -//! -//! LED indication of states -//! -//! RG | RG | RG | RG | RG | meaning -//! -- | -- | -- | -- | -- | ------------------------ -//! 11 | 00 | 00 | 00 | 01 | initial state, no action -//! 11 | 00 | 00 | 01 | 00 | setup bowden length -//! 11 | 00 | 01 | 00 | 00 | erase EEPROM if unlocked -//! 11 | 01 | 00 | 00 | 00 | unlock EEPROM erase -//! 11 | 00 | 00 | 00 | 00 | exit setup menu -//! -//! @n R - Red LED -//! @n G - Green LED -//! @n 1 - active -//! @n 0 - inactive -//! -void setupMenu() -{ - shr16_set_led(0x000); - delay(200); - shr16_set_led(0x2aa); - delay(1200); - shr16_set_led(0x000); - delay(600); - - int _menu = 0; - bool _exit = false; - bool eraseLocked = true; - - - fprintf_P(uart0io,PSTR("\r\nEntered Setup Menu\r\n")); - - do - { - shr16_set_led(1 << 2 * 4); - delay(1); - shr16_set_led(2 << 2 * 4); - delay(1); - shr16_set_led(2 << 2 * _menu); - delay(1); - - switch (buttonClicked()) - { - case Btn::right: - if (_menu > 0) { _menu--; delay(800); } - fprintf_P(uart0io,PSTR("B Right\r\n")); - break; - case Btn::middle: - - switch (_menu) - { - case 1: - fprintf_P(uart0io,PSTR("Selected settings_select_filament\r\n")); - settings_select_filament(); - _exit = true; - break; - case 2: - if (!eraseLocked) - { - fprintf_P(uart0io,PSTR("Erasing BowdenLength\r\n")); - eepromEraseAll(); - //BowdenLength::eraseAll(); - _exit = true; - } - else - { - fprintf_P(uart0io,PSTR("Locked BowdenLength\r\n")); - } - break; - case 3: //unlock erase - fprintf_P(uart0io,PSTR("Unlocked erase\r\n")); - eraseLocked = false; - break; - case 4: // exit menu - fprintf_P(uart0io,PSTR("Exit Setup\r\n")); - _exit = true; - break; - } - break; - case Btn::left: - if (_menu < 4) - { - _menu++; - delay(800); - } - fprintf_P(uart0io,PSTR("B Left\r\n")); - break; - default: - break; - } - - } while (!_exit); - - - shr16_set_led(0x000); - delay(400); - shr16_set_led(0x2aa); - delay(400); - shr16_set_led(0x000); - delay(400); - - shr16_set_led(0x000); - shr16_set_led(1 << 2 * (4 - active_extruder)); -} - -//! @brief Set bowden length -//! -//! button | action -//! ------ | ------ -//! left | increase bowden length / feed more filament -//! right | decrease bowden length / feed less filament -//! middle | store bowden length to EEPROM and exit -//! -//! This state is indicated by following LED pattern: -//! -//! RG | RG | RG | RG | RG -//! -- | -- | -- | -- | -- -//! bb | 00 | 00 | 0b | 00 -//! -//! @n R - Red LED -//! @n G - Green LED -//! @n 1 - active -//! @n 0 - inactive -//! @n b - blinking -//! -void settings_bowden_length() -{ - // load filament above Bondtech gears to check correct length of bowden tube - if (!isFilamentLoaded) - { - BowdenLength bowdenLength; - fprintf_P(uart0io,PSTR("Selected #: %d\r\n"),bowdenLength.m_filament); - fprintf_P(uart0io,PSTR("Current Len: %d\r\n"),bowdenLength.m_length); - - load_filament_withSensor(); - - tmc2130_init_axis_current_normal(AX_PUL, 1, 30); - uint32_t saved_millis=millis(); - bool button_active = false; - do - { - - switch (buttonClicked()) - { - case Btn::right: - if (!button_active || (((millis() - saved_millis) > 1000) && button_active)) - { - move(0, 0, -bowdenLength.stepSize); - delay(400); - fprintf_P(uart0io,PSTR("Dec: %d\r\n"),bowdenLength.m_length); - } - button_active = true; - break; - - case Btn::left: - if (!button_active || (((millis() - saved_millis) > 1000) && button_active)) - { - move(0, 0, bowdenLength.stepSize); - delay(400); - fprintf_P(uart0io,PSTR("Inc: %d\r\n"),bowdenLength.m_length); - } - button_active = true; - break; - - default: - button_active = false; - saved_millis = millis(); - break; - } - - shr16_set_led(1 << 2 * 4); - delay(10); - shr16_set_led(2 << 2 * 4); - delay(10); - shr16_set_led(2 << 2 * 1); - delay(50); - - } while (buttonClicked() != Btn::middle); - fprintf_P(uart0io,PSTR("Len: %d\r\n"),bowdenLength.m_length); - unload_filament_withSensor(); - } -} -//! @brief Is button pushed? -//! -//! @return button pushed -Btn buttonClicked() -{ - int raw = analogRead(ButtonPin); - if (raw < 50) return Btn::right; - if (raw > 80 && raw < 100) return Btn::middle; - if (raw > 160 && raw < 180) return Btn::left; - return Btn::none; -} -======= -//! @file - #include "Buttons.h" #include "shr16.h" #include "tmc2130.h" @@ -251,6 +8,7 @@ Btn buttonClicked() #include "permanent_storage.h" #include "main.h" #include "motion.h" +#include "uart.h" const int ButtonPin = A2; @@ -263,8 +21,6 @@ void settings_bowden_length(); //! Park position (one behind last filament) can be also selected. //! Activating calibration in park position exits selector. //! -//! @retval true exit -//! @retval false to be called again bool settings_select_filament() { manual_extruder_selector(); @@ -306,11 +62,9 @@ bool settings_select_filament() //! @n 1 - active //! @n 0 - inactive //! -//! @retval true continue -//! @retval false exit bool setupMenu() { - static bool onEnter = true; + static bool onEnter = true; if (onEnter) { shr16_set_led(0x000); @@ -397,6 +151,7 @@ bool setupMenu() return true; } + //! @brief Set bowden length //! //! button | action @@ -424,7 +179,9 @@ void settings_bowden_length() { BowdenLength bowdenLength; load_filament_withSensor(); - + fprintf_P(uart0io,PSTR("Selected #: %d\r\n"),bowdenLength.m_filament); + fprintf_P(uart0io,PSTR("Current Len: %d\r\n"),bowdenLength.m_length); + tmc2130_init_axis_current_normal(AX_PUL, 1, 30); uint32_t saved_millis=millis(); bool button_active = false; @@ -443,6 +200,8 @@ void settings_bowden_length() delayMicroseconds(1200); do_pulley_step(); } + fprintf_P(uart0io,PSTR("Dec: %d\r\n"),bowdenLength.m_length); + } } button_active = true; @@ -457,6 +216,8 @@ void settings_bowden_length() delayMicroseconds(1200); do_pulley_step(); } + fprintf_P(uart0io,PSTR("Inc: %d\r\n"),bowdenLength.m_length); + } } button_active = true; @@ -476,21 +237,20 @@ void settings_bowden_length() } while (buttonClicked() != Btn::middle); + fprintf_P(uart0io,PSTR("Len: %d\r\n"),bowdenLength.m_length); unload_filament_withSensor(); } } - //! @brief Is button pushed? //! //! @return button pushed Btn buttonClicked() { int raw = analogRead(ButtonPin); - if (raw < 50) return Btn::right; if (raw > 80 && raw < 100) return Btn::middle; if (raw > 160 && raw < 180) return Btn::left; - return Btn::none; } + diff --git a/MM-control-01/Buttons.h b/MM-control-01/Buttons.h index e892575e..52b35913 100644 --- a/MM-control-01/Buttons.h +++ b/MM-control-01/Buttons.h @@ -31,5 +31,5 @@ inline bool operator& (Btn a, Btn b) bool setupMenu(); Btn buttonClicked(); -void settings_select_filament(); +bool settings_select_filament(); #endif //_BUTTONS_h \ No newline at end of file diff --git a/MM-control-01/main.cpp b/MM-control-01/main.cpp index 77a81a9c..200f4d12 100644 --- a/MM-control-01/main.cpp +++ b/MM-control-01/main.cpp @@ -283,23 +283,19 @@ void setup() shr16_set_led(0x000); - init_Pulley(); - - home_idler(true); - - // check if to goto the settings menu - if (buttonClicked() == Btn::middle) - { - state = S::Setup; - } + // check if to goto the settings menu + if (buttonClicked() == Btn::middle) + { + state = S::Setup; + } - tmc2130_init(HOMING_MODE); - tmc2130_read_gstat(); //consume reset after power up - uint8_t filament; - if(FilamentLoaded::get(filament)) - { - motion_set_idler(filament); - } + tmc2130_init(HOMING_MODE); + tmc2130_read_gstat(); //consume reset after power up + uint8_t filament; + if(FilamentLoaded::get(filament)) + { + motion_set_idler(filament); + } if (digitalRead(A1) == 1) isFilamentLoaded = true; @@ -687,7 +683,12 @@ void process_commands(FILE* inout) { if (pbowdenLength != 0 && pbowdenLength->increase() && isFilamentLoaded) { - move(0, 0, pbowdenLength->stepSize); + set_pulley_dir_push(); + for(auto i = pbowdenLength->stepSize; i > 0; --i) + { + delayMicroseconds(1200); + do_pulley_step(); + } delay(400); fprintf_P(uart0io,PSTR("Inc: %d\r\n"),pbowdenLength->m_length); } @@ -699,7 +700,13 @@ void process_commands(FILE* inout) { if (pbowdenLength != 0 && pbowdenLength->decrease() && isFilamentLoaded) { - move(0, 0, -pbowdenLength->stepSize); + set_pulley_dir_pull(); + + for(auto i = pbowdenLength->stepSize; i > 0; --i) + { + delayMicroseconds(1200); + do_pulley_step(); + } delay(400); fprintf_P(uart0io,PSTR("Dec: %d\r\n"),pbowdenLength->m_length); } diff --git a/MM-control-01/permanent_storage.cpp b/MM-control-01/permanent_storage.cpp index 27b63daf..3bb7e697 100644 --- a/MM-control-01/permanent_storage.cpp +++ b/MM-control-01/permanent_storage.cpp @@ -5,38 +5,6 @@ #include "mmctl.h" - -======= -//! @brief EEPROM data layout -//! -//! Do not remove, reorder or change size of existing fields. -//! Otherwise values stored with previous version of firmware would be broken. -//! It is possible to add fields in the end of this struct, ensure that erased EEPROM is handled well. -//! Last byte in EEPROM is reserved for layoutVersion. If some field is repurposed, layoutVersion -//! needs to be changed to force EEPROM erase. -typedef struct __attribute__ ((packed)) -{ - uint8_t eepromLengthCorrection; //!< legacy bowden length correction - uint16_t eepromBowdenLen[5]; //!< Bowden length for each filament - uint8_t eepromFilamentStatus[3];//!< Majority vote status of eepromFilament wear leveling - uint8_t eepromFilament[800]; //!< Top nibble status, bottom nibble last filament loaded - uint8_t eepromDriveErrorCountH; - uint8_t eepromDriveErrorCountL[2]; -}eeprom_t; -static_assert(sizeof(eeprom_t) - 2 <= E2END, "eeprom_t doesn't fit into EEPROM available."); -//! @brief EEPROM layout version -static const uint8_t layoutVersion = 0xff; - -//d = 6.3 mm pulley diameter -//c = pi * d pulley circumference -//FSPR = 200 full steps per revolution (stepper motor constant) (1.8 deg/step) -//mres = 2 pulley microstep resolution (uint8_t __res(AX_PUL)) -//mres = 2 selector microstep resolution (uint8_t __res(AX_SEL)) -//mres = 16 idler microstep resolution (uint8_t __res(AX_IDL)) -//1 pulley ustep = (d*pi)/(mres*FSPR) = 49.48 um - - - void permanentStorageInit() { if (eeprom_read_byte((uint8_t*)E2END) != layoutVersion) eepromEraseAll(); diff --git a/MM-control-01/permanent_storage.h b/MM-control-01/permanent_storage.h index 460e180d..ac948aab 100644 --- a/MM-control-01/permanent_storage.h +++ b/MM-control-01/permanent_storage.h @@ -21,17 +21,27 @@ typedef struct __attribute__ ((packed)) uint16_t eepromBowdenLen[5]; //!< Bowden length for each filament uint8_t eepromFilamentStatus[3];//!< Majority vote status of eepromFilament wear leveling uint8_t eepromFilament[800]; //!< Top nibble status, bottom nibble last filament loaded + uint8_t eepromDriveErrorCountH; + uint8_t eepromDriveErrorCountL[2]; }eeprom_t; static_assert(sizeof(eeprom_t) - 2 <= E2END, "eeprom_t doesn't fit into EEPROM available."); //! @brief EEPROM layout version static const uint8_t layoutVersion = 0xff; +//d = 6.3 mm pulley diameter +//c = pi * d pulley circumference +//FSPR = 200 full steps per revolution (stepper motor constant) (1.8 deg/step) +//mres = 2 pulley microstep resolution (uint8_t __res(AX_PUL)) +//mres = 2 selector microstep resolution (uint8_t __res(AX_SEL)) +//mres = 16 idler microstep resolution (uint8_t __res(AX_IDL)) +//1 pulley ustep = (d*pi)/(mres*FSPR) = 49.48 um + static eeprom_t * const eepromBase = reinterpret_cast(0); //!< First EEPROM address static const uint16_t eepromEmpty = 0xffff; //!< EEPROM content when erased -static const uint16_t eepromLengthCorrectionBase = 7900u; //!< legacy bowden length correction base -static const uint16_t eepromBowdenLenDefault = 8900u; //!< Default bowden length -static const uint16_t eepromBowdenLenMinimum = 6900u; //!< Minimum bowden length -static const uint16_t eepromBowdenLenMaximum = 10900u; //!< Maximum bowden length +static const uint16_t eepromLengthCorrectionBase = 7900u; //!< legacy bowden length correction base (~391mm) +static const uint16_t eepromBowdenLenDefault = 8900u; //!< Default bowden length (~427 mm) +static const uint16_t eepromBowdenLenMinimum = 6900u; //!< Minimum bowden length (~341 mm) +static const uint16_t eepromBowdenLenMaximum = 16000u; //!< Maximum bowden length (~792 mm) void permanentStorageInit(); bool validFilament(uint8_t filament);