Skip to content

Commit

Permalink
improve RRF (bigtreetech#1962)
Browse files Browse the repository at this point in the history
  • Loading branch information
Msq001 authored Jun 15, 2021
1 parent 1c578c1 commit ef37035
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 6 deletions.
20 changes: 19 additions & 1 deletion TFT/src/User/API/FanControl.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "FanControl.h"
#include "includes.h"

#define RRF_FAN_QUERY_MS 3000
#define NEXT_FAN_WAIT 500 // 1 second is 1000

const char* fanID[MAX_FAN_COUNT] = FAN_DISPLAY_ID;
Expand Down Expand Up @@ -76,7 +77,7 @@ void loopFan(void)
{
if (storeCmd(fanCmd[i], setFanSpeed[i]))
lastSetFanSpeed[i] = setFanSpeed[i];

nextCtrlFanTime = OS_GetTimeMs() + NEXT_FAN_WAIT; // avoid rapid fire, clogging the queue
}
}
Expand All @@ -95,3 +96,20 @@ void ctrlFanQuery(void)
ctrlFanQueryWait = storeCmd("M710\n");
}
}

void fanQuery(void)
{
if (!infoHost.connected)
return;

if (infoMachineSettings.firmwareType == FW_REPRAPFW)
{
static uint32_t rrf_next_fan_time = 0;

if (OS_GetTimeMs() > rrf_next_fan_time)
{
rrf_next_fan_time = OS_GetTimeMs() + RRF_FAN_QUERY_MS;
storeCmd("M408 S0\n");
}
}
}
1 change: 1 addition & 0 deletions TFT/src/User/API/FanControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void fanBuildList(void);
void loopFan(void);
void ctrlFanQuery(void);
void ctrlFanQuerySetWait(bool wait);
void fanQuery(void);

#ifdef __cplusplus
}
Expand Down
2 changes: 2 additions & 0 deletions TFT/src/User/API/Settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ void setupMachine(void)
{
mustStoreCmd("M555 P2\n"); // Set RRF compatibility behaves similar to 2: Marlin
}
mustStoreCmd("M82\n"); // Set extruder to absolute mode
mustStoreCmd("G90\n"); // Set to Absolute Positioning
}

float flashUsedPercentage(void)
Expand Down
7 changes: 5 additions & 2 deletions TFT/src/User/API/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,13 +892,16 @@ void loopBackEnd(void)
{
loopCaseLight();
}

// Query fan speed, only for RRF now
fanQuery();
} // loopBackEnd

void loopFrontEnd(void)
{
// Check if volume source(SD/U disk) insert
loopVolumeSource();
// loop to check and run toast messages
// Loop to check and run toast messages
loopToast();
// If there is a message in the status bar, timed clear
loopReminderClear();
Expand All @@ -913,7 +916,7 @@ void loopFrontEnd(void)
loopFrontEndFILRunoutDetect();
#endif

// loop for popup menu
// Loop for popup menu
loopPopup();
}

Expand Down
19 changes: 19 additions & 0 deletions TFT/src/User/API/parseACK.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,15 @@ void parseACK(void)
fanSetCurSpeed(i, ack_value());
}
}
// parse and store flow rate percentage in case of RepRapFirmware
else if ((infoMachineSettings.firmwareType == FW_REPRAPFW) && ack_seen("fanPercent\":["))
{
for (uint8_t i = 0; i < infoSettings.fan_count; i++)
{
fanSetPercent(i, ack_value() + 0.5f);
ack_continue_seen(",");
}
}
// parse and store M710, controller fan
else if (ack_seen("M710"))
{
Expand Down Expand Up @@ -732,6 +741,16 @@ void parseACK(void)
{
pidUpdateStatus(false);
}
// parse M303, PID Autotune completed message in case of RRF
else if ((infoMachineSettings.firmwareType == FW_REPRAPFW) && ack_seen("Auto tuning heater") && ack_seen("completed"))
{
pidUpdateStatus(true);
}
// parse M303, PID Autotune failed message in case of RRF
else if ((infoMachineSettings.firmwareType == FW_REPRAPFW) && (ack_seen("Error: M303") || (ack_seen("Auto tune of heater") && ack_seen("failed"))))
{
pidUpdateStatus(false);
}
// parse and store M355, Case light message
else if (ack_seen("Case light: OFF"))
{
Expand Down
3 changes: 2 additions & 1 deletion TFT/src/User/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@
#define AUTO_SAVE_LOAD_BL_VALUE 1 // Default: 1

// PID autotune
#define PID_CMD {"M303 U1 C8 E0", "M303 U1 C8 E1", "M303 U1 C8 E2", "M303 U1 C8 E3", "M303 U1 C8 E4", "M303 U1 C8 E5", "M303 U1 C8 E-1", ""}
#define PID_CMD_MARLIN {"M303 U1 C8 E0", "M303 U1 C8 E1", "M303 U1 C8 E2", "M303 U1 C8 E3", "M303 U1 C8 E4", "M303 U1 C8 E5", "M303 U1 C8 E-1", ""}
#define PID_CMD_RRF {"M303 T0", "M303 T1", "M303 T2", "M303 T3", "M303 T4", "M303 T5", "M303 H0", ""}
#define PID_PROCESS_TIMEOUT (15 * 60000) // (MilliSeconds, 1 minute = 60000 MilliSeconds)

/**
Expand Down
9 changes: 7 additions & 2 deletions TFT/src/User/Menu/Pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const MENUITEMS pidWaitItems = {
}
};

const char *const pidCmd[] = PID_CMD;
const char *const pidCmdMarlin[] = PID_CMD_MARLIN;
const char *const pidCmdRRF[] = PID_CMD_RRF;
static int16_t pidHeaterTarget[MAX_HEATER_COUNT] = {0};
static uint8_t curTool_index = NOZZLE0;
static uint8_t degreeSteps_index = 1;
Expand Down Expand Up @@ -150,14 +151,18 @@ void menuPidWait(void)

static inline void pidStart(void)
{
const char *const *pidCmd = (infoMachineSettings.firmwareType == FW_REPRAPFW) ? pidCmdRRF : pidCmdMarlin;
pidRunning = true;
pidSucceeded = true;

pidUpdateCounter(); // update the number of set temperatures (number of PID processes to execute)
pidTimeout = OS_GetTimeMs() + PID_PROCESS_TIMEOUT; // set timeout for overall PID process

mustStoreCmd("M150 R255 U0 B0\n"); // set LED light to RED
mustStoreCmd("M106 S255\n"); // set fan speed to max
if (infoMachineSettings.firmwareType != FW_REPRAPFW)
{
mustStoreCmd("M106 S255\n"); // set fan speed to max
}
mustStoreCmd("G4 S1\n"); // wait 1 sec

for (uint8_t i = 0; i < MAX_HEATER_COUNT; i++) // hotends + bed + chamber
Expand Down

0 comments on commit ef37035

Please sign in to comment.