Skip to content

Commit

Permalink
RRF Compatibility optimization (bigtreetech#1717)
Browse files Browse the repository at this point in the history
* fixed RRF some SD card m21 mounted freeze bug

* Set the firmware to behaves similar to Marlin established firmware

* fix RRF abort printing bug

* rrf notify
  • Loading branch information
Msq001 authored Mar 12, 2021
1 parent 974197a commit b03bff2
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 32 deletions.
9 changes: 5 additions & 4 deletions TFT/src/User/API/Gcode/gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ void clearRequestCommandInfo(void)
*/
bool request_M21(void)
{
const char * sdString = (infoMachineSettings.firmwareType == FW_REPRAPFW) ? "SDHC card " : "SD card ";
const char * sdString = (infoMachineSettings.firmwareType == FW_REPRAPFW) ? "card mounted " : "SD card ";
const char * errString1 = (infoMachineSettings.firmwareType == FW_REPRAPFW) ? "Error" : "No SD card";

resetRequestCommandInfo(sdString, // The magic to identify the start
"ok", // The magic to identify the stop
"No SD card", // The first magic to identify the error response
errString1, // The first magic to identify the error response
"SD init fail", // The second error magic
"volume.init failed"); // The third error magic

Expand Down Expand Up @@ -244,7 +245,7 @@ void send_and_wait_M20(const char* command)
uint32_t timeout = ((uint32_t)0x000FFFFF);
uint32_t waitloops = ((uint32_t)0x00000006);

resetRequestCommandInfo("{", "}", "Error:", "Error:", "Error:");
resetRequestCommandInfo("{", "}", "Error:", NULL, NULL);
mustStoreCmd(command);
while ((strstr(requestCommandInfo.cmd_rev_buf, "dir") == NULL) && (waitloops > 0x00)) //(!find_part("dir"))
{
Expand Down Expand Up @@ -274,7 +275,7 @@ void send_and_wait_M20(const char* command)
if (strstr(requestCommandInfo.cmd_rev_buf, "dir") == NULL)
{
clearRequestCommandInfo();
resetRequestCommandInfo("{", "}", "Error:", "Error:", "Error:");
resetRequestCommandInfo("{", "}", "Error:", NULL, NULL);
mustStoreCmd("\n");
}
}
Expand Down
3 changes: 3 additions & 0 deletions TFT/src/User/API/Printing.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ void abortPrinting(void)
breakAndContinue();
breakAndContinue();
if (infoMachineSettings.firmwareType == FW_REPRAPFW)
{
request_M25(); // Must pause the print before cancel it
request_M0(); // M524 is not supportet in reprap firmware
}
else
request_M524();

Expand Down
5 changes: 5 additions & 0 deletions TFT/src/User/API/Settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ void setupMachine(void)
infoMachineSettings.long_filename_support = DISABLED;
}
mustStoreCmd("M503 S0\n");

if (infoMachineSettings.firmwareType == FW_REPRAPFW)
{
mustStoreCmd("M555 P2\n"); // Set RRF compatibility behaves similar to 2: Marlin
}
}

float flashUsedPercentage(void)
Expand Down
4 changes: 2 additions & 2 deletions TFT/src/User/API/interfaceCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ void sendQueueCmd(void)
switch (cmd)
{
case 0:
if (isPrinting())
if (isPrinting() && infoMachineSettings.firmwareType != FW_REPRAPFW) // Abort printing by "M0" in RepRapFirmware
setPrintPause(true, true);
break;

case 1:
if (isPrinting())
if (isPrinting() && infoMachineSettings.firmwareType != FW_REPRAPFW)
setPrintPause(true, true);
break;

Expand Down
34 changes: 33 additions & 1 deletion TFT/src/User/API/parseACK.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void ackPopupInfo(const char *info)
BUZZER_PLAY(sound_notify);

// set echo message in status screen
if (info == echomagic)
if (info == echomagic || info == messagemagic)
{
//ignore all messages if parameter settings is open
if (infoMenu.menu[infoMenu.cur] == menuParameterSettings)
Expand Down Expand Up @@ -1093,6 +1093,38 @@ void parseACK(void)
ackPopupInfo(echomagic);
}
}

// keep here and parse at lastest
else if (infoMachineSettings.firmwareType == FW_REPRAPFW)
{
if (ack_seen(warningmagic))
{
ackPopupInfo(warningmagic);
}
else if (ack_seen(messagemagic))
{
ackPopupInfo(messagemagic);
}
else if (ack_seen("access point "))
{
uint8_t *string = (uint8_t *)&dmaL2Cache[ack_index];
uint16_t string_start = ack_index;
uint16_t string_end = string_start;
if (ack_seen(",")) //
string_end = ack_index - 1 ;

infoSetAccessPoint(string, string_end - string_start); // Set access poing

if (ack_seen("IP address "))
{
string = (uint8_t *)&dmaL2Cache[ack_index];
string_start = ack_index;
if (ack_seen("\n")) //
string_end = ack_index - 1;
infoSetIPAddress(string, string_end - string_start); // Set IP address
}
}
}
}

parse_end:
Expand Down
3 changes: 3 additions & 0 deletions TFT/src/User/API/parseACK.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ extern "C" {

static const char errormagic[] = "Error:";
static const char echomagic[] = "echo:";
static const char warningmagic[] = "Warning:"; // RRF warning
static const char messagemagic[] = "message"; // RRF message in Json format

#define ACK_MAX_SIZE 512

Expand Down Expand Up @@ -47,6 +49,7 @@ typedef struct
const char *const msg;
} ECHO;

bool dmaL1NotEmpty(uint8_t port);
void setCurrentAckSrc(uint8_t src);
void parseACK(void);
void parseRcvGcode(void);
Expand Down
88 changes: 63 additions & 25 deletions TFT/src/User/Menu/SettingsMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ const MENUITEMS settingsItems = {
}
};

const GUI_POINT clocks[] = {
{0 * LCD_WIDTH / 3, 0 * BYTE_HEIGHT},
{1 * LCD_WIDTH / 3, 0 * BYTE_HEIGHT},
{2 * LCD_WIDTH / 3, 0 * BYTE_HEIGHT},
{0 * LCD_WIDTH / 3, 1 * BYTE_HEIGHT},
{1 * LCD_WIDTH / 3, 1 * BYTE_HEIGHT},
{2 * LCD_WIDTH / 3, 1 * BYTE_HEIGHT},};
// const GUI_POINT clocks[] = {
// {0 * LCD_WIDTH / 3, 0 * BYTE_HEIGHT},
// {1 * LCD_WIDTH / 3, 0 * BYTE_HEIGHT},
// {2 * LCD_WIDTH / 3, 0 * BYTE_HEIGHT},
// {0 * LCD_WIDTH / 3, 1 * BYTE_HEIGHT},
// {1 * LCD_WIDTH / 3, 1 * BYTE_HEIGHT},
// {2 * LCD_WIDTH / 3, 1 * BYTE_HEIGHT},};

static uint8_t firmare_name[64] = "Unknow system"; // Marlin firmware version
uint8_t machine_type[64] = "3D Printer"; // Marlin machine type
uint8_t access_point[64] = "Connecting..."; // Access point for RepRapFirmware
uint8_t ip_address[20] = "0.0.0.0"; // IP address for RepRapFirmware

void infoSetFirmwareName(uint8_t *name, uint8_t name_len)
{
Expand All @@ -53,6 +55,30 @@ void infoSetMachineType(uint8_t *machine, uint8_t type_len)
statusScreen_setReady();
}

void infoSetAccessPoint(uint8_t *ssid, uint8_t ssid_len)
{
if (ssid_len > sizeof(access_point) - 1)
ssid_len = sizeof(access_point) - 1;
uint8_t i;
for (i = 0; i < ssid_len; i++)
{
access_point[i] = ssid[i];
}
access_point[i] = 0;
}

void infoSetIPAddress(uint8_t *ip, uint8_t ip_len)
{
if (ip_len > sizeof(ip_address) - 1)
ip_len = sizeof(ip_address) - 1;
uint8_t i;
for (i = 0; i < ip_len; i++)
{
ip_address[i] = ip[i];
}
ip_address[i] = 0;
}

// Version infomation
void menuInfo(void)
{
Expand All @@ -64,45 +90,52 @@ void menuInfo(void)
GUI_Clear(infoSettings.bg_color);
GUI_SetColor(GRAY);

sprintf(buf, "SYS:%dMhz", mcuClocks.rccClocks.SYSCLK_Frequency / 1000000);
GUI_DispString(clocks[0].x, clocks[0].y, (uint8_t *)buf);
// sprintf(buf, "SYS:%dMhz", mcuClocks.rccClocks.SYSCLK_Frequency / 1000000);
// GUI_DispString(clocks[0].x, clocks[0].y, (uint8_t *)buf);

sprintf(buf, "APB1:%dMhz", mcuClocks.rccClocks.PCLK1_Frequency / 1000000);
GUI_DispString(clocks[1].x, clocks[1].y, (uint8_t *)buf);
// sprintf(buf, "APB1:%dMhz", mcuClocks.rccClocks.PCLK1_Frequency / 1000000);
// GUI_DispString(clocks[1].x, clocks[1].y, (uint8_t *)buf);

sprintf(buf, "P1Tim:%dMhz", mcuClocks.PCLK1_Timer_Frequency / 1000000);
GUI_DispString(clocks[2].x, clocks[2].y, (uint8_t *)buf);
// sprintf(buf, "P1Tim:%dMhz", mcuClocks.PCLK1_Timer_Frequency / 1000000);
// GUI_DispString(clocks[2].x, clocks[2].y, (uint8_t *)buf);

sprintf(buf, "AHB:%dMhz", mcuClocks.rccClocks.HCLK_Frequency / 1000000);
GUI_DispString(clocks[3].x, clocks[3].y, (uint8_t *)buf);
// sprintf(buf, "AHB:%dMhz", mcuClocks.rccClocks.HCLK_Frequency / 1000000);
// GUI_DispString(clocks[3].x, clocks[3].y, (uint8_t *)buf);

sprintf(buf, "APB2:%dMhz", mcuClocks.rccClocks.PCLK2_Frequency / 1000000);
GUI_DispString(clocks[4].x, clocks[4].y, (uint8_t *)buf);
// sprintf(buf, "APB2:%dMhz", mcuClocks.rccClocks.PCLK2_Frequency / 1000000);
// GUI_DispString(clocks[4].x, clocks[4].y, (uint8_t *)buf);

sprintf(buf, "P2Tim:%dMhz", mcuClocks.PCLK2_Timer_Frequency / 1000000);
GUI_DispString(clocks[5].x, clocks[5].y, (uint8_t *)buf);
// sprintf(buf, "P2Tim:%dMhz", mcuClocks.PCLK2_Timer_Frequency / 1000000);
// GUI_DispString(clocks[5].x, clocks[5].y, (uint8_t *)buf);

GUI_HLine(0, clocks[5].y + BYTE_HEIGHT, LCD_WIDTH);
// GUI_HLine(0, clocks[5].y + BYTE_HEIGHT, LCD_WIDTH);

//spi flash info
float usedMB = (float)FLASH_USED/1048576;
sprintf(buf, "Used %.2f%% (%.2fMB/%uMB)", flashUsedPercentage(), usedMB, (W25Qxx_ReadCapacity()/1048576));

const uint16_t top_y = (LCD_HEIGHT - (7 * BYTE_HEIGHT)) / 2; // 8 firmware info lines + 1 SPI flash info line
const uint16_t top_y = 0; //(LCD_HEIGHT - (7 * BYTE_HEIGHT)) / 2; // 8 firmware info lines + 1 SPI flash info line
const uint16_t start_x = strlen("Firmware:") * BYTE_WIDTH;
const GUI_RECT version[5] = {
const GUI_RECT version[7] = {
{start_x, top_y + 0*BYTE_HEIGHT, LCD_WIDTH, top_y + 2*BYTE_HEIGHT},
{start_x, top_y + 2*BYTE_HEIGHT, LCD_WIDTH, top_y + 4*BYTE_HEIGHT},
{start_x, top_y + 4*BYTE_HEIGHT, LCD_WIDTH, top_y + 6*BYTE_HEIGHT},
{start_x, top_y + 5*BYTE_HEIGHT, LCD_WIDTH, top_y + 8*BYTE_HEIGHT},
{start_x, top_y + 6*BYTE_HEIGHT, LCD_WIDTH, top_y + 9*BYTE_HEIGHT},
{start_x, top_y + 4*BYTE_HEIGHT, LCD_WIDTH, top_y + 5*BYTE_HEIGHT},
{start_x, top_y + 5*BYTE_HEIGHT, LCD_WIDTH, top_y + 6*BYTE_HEIGHT},
{start_x, top_y + 6*BYTE_HEIGHT, LCD_WIDTH, top_y + 7*BYTE_HEIGHT},
{start_x, top_y + 7*BYTE_HEIGHT, LCD_WIDTH, top_y + 8*BYTE_HEIGHT},
{start_x, top_y + 8*BYTE_HEIGHT, LCD_WIDTH, top_y + 9*BYTE_HEIGHT},
};
//draw titles
GUI_DispString(0, version[0].y0, (uint8_t *)"System :");
GUI_DispString(0, version[1].y0, (uint8_t *)"Machine :");
GUI_DispString(0, version[2].y0, (uint8_t *)"Board :");
GUI_DispString(0, version[3].y0, (uint8_t *)"Firmware:");
GUI_DispString(0, version[4].y0, (uint8_t *)"SPIFlash:");
if (infoMachineSettings.firmwareType == FW_REPRAPFW)
{
GUI_DispString(0, version[5].y0, (uint8_t *)"WIFI :");
GUI_DispString(0, version[6].y0, (uint8_t *)"IP :");
}

//draw info
GUI_SetColor(0xDB40);
Expand All @@ -111,6 +144,11 @@ void menuInfo(void)
GUI_DispStringInPrectEOL(&version[2], (uint8_t *)hardware);
GUI_DispStringInPrectEOL(&version[3], (uint8_t *)firmware);
GUI_DispStringInPrectEOL(&version[4], (uint8_t *)buf);
if (infoMachineSettings.firmwareType == FW_REPRAPFW)
{
GUI_DispStringInPrectEOL(&version[5], (uint8_t *)access_point);
GUI_DispStringInPrectEOL(&version[6], (uint8_t *)ip_address);
}

GUI_SetColor(GRAY);

Expand Down
2 changes: 2 additions & 0 deletions TFT/src/User/Menu/SettingsMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ void menuInfo(void);
void menuSettings(void);
void infoSetFirmwareName(uint8_t *name, uint8_t name_len);
void infoSetMachineType(uint8_t *machine, uint8_t type_len);
void infoSetAccessPoint(uint8_t *ssid, uint8_t ssid_len);
void infoSetIPAddress(uint8_t *ip, uint8_t ip_len);

#ifdef __cplusplus
}
Expand Down

0 comments on commit b03bff2

Please sign in to comment.