Skip to content

Commit

Permalink
PRINT:Add hardware mos abnormal processing
Browse files Browse the repository at this point in the history
Signed-off-by: winter.tian <winter.tian@anker-in.com>
  • Loading branch information
WinterAnker committed Mar 7, 2023
1 parent b7e605e commit 863545e
Show file tree
Hide file tree
Showing 15 changed files with 402 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@
#define HEATER_5_MAXTEMP 275
#define HEATER_6_MAXTEMP 275
#define HEATER_7_MAXTEMP 275
#define BED_MAXTEMP 150
#define BED_MAXTEMP 110
#define CHAMBER_MAXTEMP 60

/**
Expand Down
8 changes: 4 additions & 4 deletions release_marlin2.0/maincode/Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,10 @@ void idle(bool no_stepper_sleep/*=false*/) {
*/
void kill(PGM_P const lcd_error/*=nullptr*/, PGM_P const lcd_component/*=nullptr*/, const bool steppers_off/*=false*/) {
thermalManager.disable_all_heaters();

#if ENABLED(ANKER_NOZZLE_BOARD)
get_anker_nozzle_board_info()->power_off();
#endif

TERN_(HAS_CUTTER, cutter.kill()); // Full cutter shutdown including ISR control

Expand All @@ -966,10 +970,6 @@ void kill(PGM_P const lcd_error/*=nullptr*/, PGM_P const lcd_component/*=nullptr
TERN_(HAS_TFT_LVGL_UI, lv_draw_error_message(lcd_error));

TERN_(ANKER_MAKE_API,SERIAL_ECHOLN(lcd_error));

#ifdef NOZZLE_BOARD_PWR_PIN
OUT_WRITE(NOZZLE_BOARD_PWR_PIN, !NOZZLE_BOARD_PWR_STATE);
#endif

// "Error:Printer halted. kill() called!"
SERIAL_ERROR_MSG(STR_ERR_KILLED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
* @Author : winter
* @Date : 2022-05-12 20:30:21
* @LastEditors: winter.tian
* @LastEditTime: 2022-11-30 18:51:50
* @LastEditTime: 2022-12-16 12:02:56
* @Description :
*/
#include "anker_nozzle_board.h"
#include "../../gcode/gcode.h"
#include "../../module/planner.h"
#include "../../module/temperature.h"

#if ENABLED(ANKER_MAKE_API)

Expand Down Expand Up @@ -45,6 +46,19 @@ static unsigned char crc8(unsigned char *pdat, unsigned int len)
return crc;
}

static void anker_nozzle_board_power_off(void)
{
anker_nozzle_board_info_t *p_info = get_anker_nozzle_board_info();
p_info->tx_init_flag = 0;
p_info->tx_deal_step = 0;
p_info->heartbeat_deal_step = 0;
#ifdef NOZZLE_BOARD_PWR_PIN
OUT_WRITE(NOZZLE_BOARD_PWR_PIN, !NOZZLE_BOARD_PWR_STATE);
#endif
#if ENABLED(PROVE_CONTROL)
OUT_WRITE(PROVE_CONTROL_PIN, !PROVE_CONTROL_STATE);
#endif
}
static void anker_nozzle_board_power_reset(void)
{
anker_nozzle_board_info_t *p_info = get_anker_nozzle_board_info();
Expand Down Expand Up @@ -172,6 +186,31 @@ static void anker_nozzle_board_heartbeat_deal(void)
p_info->heartbeat_deal_step = 0;
}
}
static void anker_nozzle_board_tx_error_deal(void)
{
anker_nozzle_board_info_t *p_info = get_anker_nozzle_board_info();
static millis_t tx_error_timeout = millis() + 10000UL;
static uint8_t tmp_abnormal_flag = 0;

if (p_info->com_abnormal_flag == 1)
{
if (!PENDING(millis(), tx_error_timeout))
{
tmp_abnormal_flag = 1;
SERIAL_ECHOPAIR("echo:M3005,", p_info->com_abnormal_flag, "\r\n");
tx_error_timeout = millis() + 10000UL;
}
}
else
{
if (tmp_abnormal_flag == 1)
{
tmp_abnormal_flag = 0;
SERIAL_ECHOPAIR("echo:M3005,", p_info->com_abnormal_flag, "\r\n");
}
tx_error_timeout = millis() + 10000UL;
}
}
static uint8_t anker_nozzle_board_tx_cmd_ring_buf_available(void)
{
anker_nozzle_board_info_t *p_info = get_anker_nozzle_board_info();
Expand Down Expand Up @@ -282,29 +321,26 @@ static void anker_nozzle_board_tx_deal(void)
{
anker_nozzle_board_info_t *p_info = get_anker_nozzle_board_info();
char tmp_buf[ANKER_NOZZLE_BOARD_TX_BUF_SIZE] = {0};
static uint8_t tmp_com_abnormal_pre_flag = 0;
static millis_t tmp_timeout = 0;
static uint8_t tmp_tx_retry_count = 0;
static uint8_t add_cmd_fail_count = 0;

if (tmp_com_abnormal_pre_flag != p_info->com_abnormal_flag)
{
tmp_com_abnormal_pre_flag = p_info->com_abnormal_flag;
// SERIAL_ECHOPAIR("echo:M3006,", p_info->com_abnormal_flag, "\r\n");
}
anker_nozzle_board_tx_error_deal();

switch (p_info->tx_deal_step)
{
case 0:
{
if (p_info->tx_init_flag == 0)
{
memset(p_info->tx_buf, 0, sizeof(p_info->tx_buf));
memset(&p_info->tx_cmd_ring_buf, 0, sizeof(p_info->tx_cmd_ring_buf));
memset(tmp_buf, 0, sizeof(tmp_buf));
snprintf(tmp_buf, sizeof(tmp_buf), "M3003 %d", p_info->threshold);
if (p_info->tx_ring_buf_add(tmp_buf) == 0)
{
p_info->power_reset();
// p_info->tx_deal_step++;
p_info->serial_begin();
add_cmd_fail_count = 0;
p_info->tx_deal_step = 3;
}
Expand Down Expand Up @@ -425,6 +461,7 @@ static void anker_nozzle_board_tx_deal(void)
memset(p_info->tx_buf, 0, sizeof(p_info->tx_buf));
p_info->com_abnormal_flag = 0;
p_info->tx_deal_step = 10;
thermalManager.temp_watch_mos2_stop_flag = false;
}
else
{
Expand All @@ -447,11 +484,10 @@ static void anker_nozzle_board_tx_deal(void)
p_info->tx_state = TX_ERROR_STATE;
p_info->tx_error_times++;
p_info->com_abnormal_flag = 1;
memset(p_info->tx_buf, 0, sizeof(p_info->tx_buf));
p_info->tx_init_flag = 0;
p_info->tx_deal_step = 0;
memset(&p_info->tx_cmd_ring_buf, 0, sizeof(p_info->tx_cmd_ring_buf));
debug_log_printf("[nozzle-%d]:step %d TX_ERROR_TIMES: %d\r\n", __LINE__, p_info->tx_deal_step, p_info->tx_error_times);
thermalManager.temp_watch_mos2_stop_flag = true;
debug_log_printf("[nozzle-%d]:TX_ERROR_TIMES: %d\r\n", __LINE__, p_info->tx_error_times);
}
else
{
Expand Down Expand Up @@ -773,6 +809,13 @@ static void anker_nozzle_board_deal(void)
{
anker_nozzle_board_info_t *p_info = get_anker_nozzle_board_info();

#if ENABLED(ANKER_TEMP_WATCH)
if (thermalManager.temp_watch_is_error() || thermalManager.temp_watch_is_mos2_self_test())
{
p_info->power_off();
return;
}
#endif
p_info->rx_deal();
p_info->tx_deal();
p_info->heartbeat_deal();
Expand All @@ -789,6 +832,7 @@ void anker_nozzle_board_init(void)
{
anker_nozzle_board_info_t *p_info = get_anker_nozzle_board_info();

p_info->power_off = anker_nozzle_board_power_off;
p_info->power_reset = anker_nozzle_board_power_reset;
p_info->serial_begin = anker_nozzle_board_serial_begin;
p_info->serial_end = anker_nozzle_board_serial_end;
Expand All @@ -803,6 +847,9 @@ void anker_nozzle_board_init(void)
p_info->nozzle_board_deal = anker_nozzle_board_deal;

p_info->serial_begin();
p_info->tx_init_flag = 0;
p_info->tx_deal_step = 0;
p_info->heartbeat_deal_step = 0;
}

void set_anker_z_sensorless_probe_value(int value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* @Author : winter
* @Date : 2022-05-12 20:32:54
* @LastEditors: winter.tian winter.tian@anker-in.com
* @LastEditTime: 2022-09-16 16:57:38
* @LastEditors: winter.tian
* @LastEditTime: 2022-12-03 20:35:08
* @Description :
*/
#include "../../inc/MarlinConfig.h"
Expand Down Expand Up @@ -90,6 +90,7 @@ typedef struct
uint8_t heartbeat_abnormal_flag;
uint8_t heartbeat_deal_step;

void (*power_off)(void);
void (*power_reset)(void);
void (*serial_begin)(void);
void (*serial_end)(void);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author : winter
* @Date : 2022-04-02 10:50:23
* @LastEditors: winter.tian
* @LastEditTime: 2023-03-06 20:38:22
* @LastEditTime: 2023-03-07 09:44:25
* @Description :
*/
#include "anker_pause.h"
Expand Down Expand Up @@ -187,10 +187,10 @@ static void anker_pause_deal(void)
memcpy(&(p_info->save_block_buf), &(p_info->cur_block_buf), sizeof(anker_block_buffer_t));

memset(p_info->tmp_cmd_buf, 0, sizeof(p_info->tmp_cmd_buf));
sprintf(p_info->tmp_cmd_buf, "<== %d ==> : block_length = %d\r\n", __LINE__, p_info->save_block_buf.block_length);
snprintf(p_info->tmp_cmd_buf, sizeof(p_info->tmp_cmd_buf), "<== %d ==> : block_length = %d\r\n", __LINE__, p_info->save_block_buf.block_length);
MYSERIAL1.printf(p_info->tmp_cmd_buf);
memset(p_info->tmp_cmd_buf, 0, sizeof(p_info->tmp_cmd_buf));
sprintf(p_info->tmp_cmd_buf, "<== %d ==> : x = %f y = %f z = %f e = %f fr = %f\r\n", __LINE__,
snprintf(p_info->tmp_cmd_buf, sizeof(p_info->tmp_cmd_buf), "<== %d ==> : x = %f y = %f z = %f e = %f fr = %f\r\n", __LINE__,
p_info->save_block_buf.cur_pos.x,
p_info->save_block_buf.cur_pos.y,
p_info->save_block_buf.cur_pos.z,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* @Author : winter
* @Date : 2022-04-02 10:50:38
* @LastEditors : winter
* @LastEditTime : 2022-05-20 14:01:53
* @LastEditors: winter.tian
* @LastEditTime: 2022-12-02 09:50:05
* @Description :
*/
#include "../../inc/MarlinConfig.h"
Expand Down Expand Up @@ -90,7 +90,7 @@ typedef struct
int pause_queue_state;
int pause_block_state;
int pause_deal_step;
char tmp_cmd_buf[64];
char tmp_cmd_buf[256];
uint8_t tmp_block_tail;
uint8_t tmp_block_length;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* @Author : winter
* @Date : 2022-05-24 14:08:20
* @LastEditors: winter.tian winter.tian@anker-in.com
* @LastEditTime: 2022-10-11 16:53:33
* @LastEditors: winter.tian
* @LastEditTime: 2022-12-16 11:36:44
* @Description :
*/
#include "../../inc/MarlinConfig.h"
Expand Down Expand Up @@ -290,6 +290,14 @@ void GcodeSuite::M3009()
}
}

#if ENABLED(ANKER_TEMP_WATCH)
// M3008 MOS2 self-test
void GcodeSuite::M3008()
{
MYSERIAL2.printf("Mos2:Start\r\n");
MYSERIAL2.printf("Mos2:End\r\n");
}
#endif
#if 0
static bool flash_sector_read(uint32_t addr, uint32_t *data)
{
Expand Down
3 changes: 3 additions & 0 deletions release_marlin2.0/maincode/Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,9 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 3005: M3005(); break;
case 3009: M3009(); break;
#endif
#if ENABLED(ANKER_TEMP_WATCH)
case 3008: M3008(); break;
#endif
#if ENABLED(EVT_HOMING_5X)
case 89: M89(); break;
case 2004:M2004(); break;
Expand Down
3 changes: 3 additions & 0 deletions release_marlin2.0/maincode/Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,9 @@ class GcodeSuite {
static void M3005();
static void M3009();
#endif
#if ENABLED(ANKER_TEMP_WATCH)
static void M3008();
#endif
#endif

static void T(const int8_t tool_index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ void GcodeSuite::M104_M109(const bool isM109) {

if (DEBUGGING(DRYRUN)) return;

#if ENABLED(ANKER_TEMP_WATCH)
if(thermalManager.temp_watch_is_error())
{
return;
}
#endif

#if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
constexpr int8_t target_extruder = 0;
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ void GcodeSuite::M140_M190(const bool isM190) {

if (DEBUGGING(DRYRUN)) return;

#if ENABLED(ANKER_TEMP_WATCH)
if(thermalManager.temp_watch_is_error())
{
return;
}
#endif

bool got_temp = false;
celsius_t temp = 0;

Expand Down
5 changes: 3 additions & 2 deletions release_marlin2.0/maincode/Marlin/src/inc/ANKER_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
/*******************************Functional API Configuration****************************/
#if MACCHINE == MOTOR_5X_DVT
#ifndef SHORT_BUILD_VERSION
#define SHORT_BUILD_VERSION "V8111_V2.0.41"
#define SHORT_BUILD_VERSION "V8111_V2.0.42"
#endif
#define ANKER_MAKE_API 1 //gcode
#define ANKER_GCODE_CHECK 0
Expand Down Expand Up @@ -84,7 +84,8 @@
#define TMC_AUTO_CONFIG 0// Enable TMC2209 silent mode auto-configuration function
#define ANKER_NOZZLE_PROBE_OFFSET 1 //
#define ANKER_PRINT_SLOWDOWN 0 //this is for the machine to prevent to print slowdown
#define ANKER_LIN_PARAMETER 1 //this is for lin_advance
#define ANKER_LIN_PARAMETER 1 //this is for lin_advance
#define ANKER_TEMP_WATCH 1
#endif

/*******************************Error detection****************************/
Expand Down
29 changes: 19 additions & 10 deletions release_marlin2.0/maincode/Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,9 +1046,12 @@ void MarlinSettings::postprocess() {
// LCD Contrast
//
{
_FIELD_TEST(lcd_contrast);
const int16_t lcd_contrast = TERN(HAS_LCD_CONTRAST, ui.contrast, 127);
EEPROM_WRITE(lcd_contrast);
// _FIELD_TEST(lcd_contrast);
// const int16_t lcd_contrast = TERN(HAS_LCD_CONTRAST, ui.contrast, 127);
// EEPROM_WRITE(lcd_contrast);
#if ENABLED(ANKER_TEMP_WATCH)
EEPROM_WRITE(thermalManager.temp_watch_error_flag);
#endif
}

//
Expand Down Expand Up @@ -1920,12 +1923,15 @@ void MarlinSettings::postprocess() {
// LCD Contrast
//
{
_FIELD_TEST(lcd_contrast);
int16_t lcd_contrast;
EEPROM_READ(lcd_contrast);
if (!validating) {
TERN_(HAS_LCD_CONTRAST, ui.set_contrast(lcd_contrast));
}
// _FIELD_TEST(lcd_contrast);
// int16_t lcd_contrast;
// EEPROM_READ(lcd_contrast);
// if (!validating) {
// TERN_(HAS_LCD_CONTRAST, ui.set_contrast(lcd_contrast));
// }
#if ENABLED(ANKER_TEMP_WATCH)
EEPROM_READ(thermalManager.temp_watch_error_flag);
#endif
}

//
Expand Down Expand Up @@ -2958,7 +2964,10 @@ void MarlinSettings::reset() {
//
// LCD Contrast
//
TERN_(HAS_LCD_CONTRAST, ui.set_contrast(DEFAULT_LCD_CONTRAST));
// TERN_(HAS_LCD_CONTRAST, ui.set_contrast(DEFAULT_LCD_CONTRAST));
#if ENABLED(ANKER_TEMP_WATCH)
thermalManager.temp_watch_error_flag = 0;
#endif

//
// LCD Brightness
Expand Down

0 comments on commit 863545e

Please sign in to comment.