From 84c79d753156a396fca43dd62cd693454efac882 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 13 Apr 2021 15:07:25 -0500 Subject: [PATCH] Followup to sprintf cleanup --- .../lcd/extui/lib/mks_ui/draw_cloud_bind.cpp | 2 +- .../lcd/extui/lib/mks_ui/draw_keyboard.cpp | 2 +- .../lcd/extui/lib/mks_ui/draw_manuaLevel.cpp | 2 +- .../src/lcd/extui/lib/mks_ui/wifi_module.cpp | 54 +++++++++---------- Marlin/src/lcd/extui/lib/mks_ui/wifi_module.h | 14 ++--- .../variants/megaextendedpins/pins_arduino.h | 4 +- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_cloud_bind.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_cloud_bind.cpp index ae8fe3a321..c6752939dd 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_cloud_bind.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_cloud_bind.cpp @@ -190,7 +190,7 @@ void display_qrcode(uint8_t *qrcode_data) { } void cloud_unbind() { - package_to_wifi(WIFI_CLOUD_UNBIND, (uint8_t *)0, 0); + package_to_wifi(WIFI_CLOUD_UNBIND, nullptr, 0); unbinding_flag = 1; } diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp index 1f84ca6f59..a05c558beb 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp @@ -137,7 +137,7 @@ static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) { gCfgItems.wifi_mode_sel = STA_MODEL; - package_to_wifi(WIFI_PARA_SET, (uint8_t *)0, 0); + package_to_wifi(WIFI_PARA_SET, nullptr, 0); public_buf_l[0] = 0xA5; public_buf_l[1] = 0x09; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp index e296a73590..f25c7c0c25 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp @@ -54,7 +54,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { queue.inject_P(G28_STR); } const int ind = obj->mks_obj_id - ID_M_POINT1; - sprintf_P(public_buf_l, PSTR("G1 Z10\nG1 X%d Y%d\nG1 Z0"), gCfgItems.trammingPos[ind].x, gCfgItems.trammingPos[ind].y); + sprintf_P(public_buf_l, PSTR("G1Z10\nG1X%dY%d\nG1Z0"), gCfgItems.trammingPos[ind].x, gCfgItems.trammingPos[ind].y); queue.inject(public_buf_l); } break; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.cpp b/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.cpp index 51c492703e..6c2afeafd3 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.cpp @@ -178,14 +178,14 @@ void changeFlashMode(const bool dmaMode) { } } -static bool longName2DosName(const char *longName, uint8_t *dosName) { +static bool longName2DosName(const char *longName, char *dosName) { uint8_t i; for (i = FILENAME_LENGTH; i--;) dosName[i] = '\0'; while (*longName) { uint8_t c = *longName++; if (c == '.') { // For a dot... if (i == 0) return false; - strcat_P((char *)dosName, PSTR(".GCO")); + strcat_P(dosName, PSTR(".GCO")); break; } else { @@ -196,7 +196,7 @@ static bool longName2DosName(const char *longName, uint8_t *dosName) { dosName[i++] = c + (WITHIN(c, 'a', 'z') ? 'A' - 'a' : 0); // Uppercase required for 8.3 name } if (i >= 5) { - strcat_P((char *)dosName, PSTR("~1.GCO")); + strcat_P(dosName, PSTR("~1.GCO")); break; } } @@ -478,7 +478,7 @@ char wait_ip_back_flag = 0; typedef struct { int write_index; - char saveFileName[30]; + uint8_t saveFileName[30]; uint8_t fileTransfer; uint32_t fileLen; uint32_t tick_begin; @@ -593,7 +593,7 @@ uint8_t Explore_Disk(char *path , uint8_t recu_level) { } static void wifi_gcode_exec(uint8_t *cmd_line) { - char tempBuf[100] = { 0 }; + int8_t tempBuf[100] = { 0 }; uint8_t *tmpStr = 0; int cmd_value; volatile int print_rate; @@ -631,7 +631,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) { while (tmpStr[index] == ' ') index++; if (gCfgItems.wifi_type == ESP_WIFI) { - char *path = tempBuf; + char *path = (char *)tempBuf; if (strlen((char *)&tmpStr[index]) < 80) { send_to_wifi((uint8_t *)"Begin file list\r\n", strlen("Begin file list\r\n")); @@ -680,7 +680,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) { strcat_P((char *)list_file.file_name[sel_id], PSTR("/")); if (file_writer.fileTransfer == 1) { - uint8_t dosName[FILENAME_LENGTH]; + char dosName[FILENAME_LENGTH]; uint8_t fileName[sizeof(list_file.file_name[sel_id])]; fileName[0] = '\0'; if (has_path_selected == 1) { @@ -690,8 +690,8 @@ static void wifi_gcode_exec(uint8_t *cmd_line) { else strcat((char *)fileName, (char *)&tmpStr[index]); if (!longName2DosName((const char *)fileName, dosName)) strcpy_P(list_file.file_name[sel_id], PSTR("notValid")); - strcat((char *)list_file.file_name[sel_id], (char *)dosName); - strcat((char *)list_file.long_name[sel_id], (char *)dosName); + strcat((char *)list_file.file_name[sel_id], dosName); + strcat((char *)list_file.long_name[sel_id], dosName); } else { strcat((char *)list_file.file_name[sel_id], (char *)&tmpStr[index]); @@ -828,8 +828,8 @@ static void wifi_gcode_exec(uint8_t *cmd_line) { if ((uiCfg.print_state == WORKING) || (uiCfg.print_state == PAUSED)|| (uiCfg.print_state == REPRINTING)) { print_rate = uiCfg.totalSend; ZERO(tempBuf); - sprintf_P(tempBuf, PSTR("M27 %d\r\n"), print_rate); - send_to_wifi((uint8_t *)tempBuf, strlen(tempBuf)); + sprintf_P((char *)tempBuf, PSTR("M27 %d\r\n"), print_rate); + send_to_wifi((uint8_t *)tempBuf, strlen((char *)tempBuf)); } break; @@ -841,15 +841,15 @@ static void wifi_gcode_exec(uint8_t *cmd_line) { while (tmpStr[index] == ' ') index++; if (strstr_P((char *)&tmpStr[index], PSTR(".g")) || strstr_P((char *)&tmpStr[index], PSTR(".G"))) { - strcpy(file_writer.saveFileName, (char *)&tmpStr[index]); + strcpy((char *)file_writer.saveFileName, (char *)&tmpStr[index]); if (gCfgItems.fileSysType == FILE_SYS_SD) { ZERO(tempBuf); - sprintf_P(tempBuf, PSTR("%s"), file_writer.saveFileName); + sprintf_P((char *)tempBuf, PSTR("%s"), file_writer.saveFileName); } else if (gCfgItems.fileSysType == FILE_SYS_USB) { ZERO(tempBuf); - sprintf_P(tempBuf, PSTR("%s"), file_writer.saveFileName); + sprintf_P((char *)tempBuf, PSTR("%s"), (char *)file_writer.saveFileName); } mount_file_sys(gCfgItems.fileSysType); @@ -858,11 +858,11 @@ static void wifi_gcode_exec(uint8_t *cmd_line) { card.openFileWrite(cur_name); if (card.isFileOpen()) { ZERO(file_writer.saveFileName); - strcpy(file_writer.saveFileName, (char *)&tmpStr[index]); + strcpy((char *)file_writer.saveFileName, (char *)&tmpStr[index]); ZERO(tempBuf); - sprintf_P(tempBuf, PSTR("Writing to file: %s\r\n"), file_writer.saveFileName); + sprintf_P((char *)tempBuf, PSTR("Writing to file: %s\r\n"), (char *)file_writer.saveFileName); wifi_ret_ack(); - send_to_wifi((uint8_t *)tempBuf, strlen(tempBuf)); + send_to_wifi((uint8_t *)tempBuf, strlen((char *)tempBuf)); wifi_link_state = WIFI_WAIT_TRANS_START; } else { @@ -882,7 +882,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) { SEND_OK_TO_WIFI; - char *outBuf = tempBuf; + char *outBuf = (char *)tempBuf; char tbuf[34]; sprintf_P(tbuf, PSTR("%d /%d"), (int)thermalManager.degHotend(0), (int)thermalManager.degTargetHotend(0)); @@ -917,7 +917,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) { strcat_P(outBuf, PSTR(" @:0 B@:0\r\n")); } else { - sprintf_P(tempBuf, PSTR("T:%d /%d B:%d /%d T0:%d /%d T1:%d /%d @:0 B@:0\r\n"), + sprintf_P((char *)tempBuf, PSTR("T:%d /%d B:%d /%d T0:%d /%d T1:%d /%d @:0 B@:0\r\n"), thermalManager.degHotend(0), thermalManager.degTargetHotend(0), #if HAS_HEATED_BED thermalManager.degBed(), thermalManager.degTargetBed(), @@ -933,16 +933,16 @@ static void wifi_gcode_exec(uint8_t *cmd_line) { ); } - send_to_wifi((uint8_t *)tempBuf, strlen(tempBuf)); + send_to_wifi((uint8_t *)tempBuf, strlen((char *)tempBuf)); queue.enqueue_one_P(PSTR("M105")); break; case 992: if ((uiCfg.print_state == WORKING) || (uiCfg.print_state == PAUSED)) { ZERO(tempBuf); - sprintf_P(tempBuf, PSTR("M992 %d%d:%d%d:%d%d\r\n"), print_time.hours/10, print_time.hours%10, print_time.minutes/10, print_time.minutes%10, print_time.seconds/10, print_time.seconds%10); + sprintf_P((char *)tempBuf, PSTR("M992 %d%d:%d%d:%d%d\r\n"), print_time.hours/10, print_time.hours%10, print_time.minutes/10, print_time.minutes%10, print_time.seconds/10, print_time.seconds%10); wifi_ret_ack(); - send_to_wifi((uint8_t *)tempBuf, strlen(tempBuf)); + send_to_wifi((uint8_t *)tempBuf, strlen((char *)tempBuf)); } break; @@ -950,9 +950,9 @@ static void wifi_gcode_exec(uint8_t *cmd_line) { if ((uiCfg.print_state == WORKING) || (uiCfg.print_state == PAUSED)) { ZERO(tempBuf); if (strlen((char *)list_file.file_name[sel_id]) > (100 - 1)) return; - sprintf_P(tempBuf, PSTR("M994 %s;%d\n"), list_file.file_name[sel_id], (int)gCfgItems.curFilesize); + sprintf_P((char *)tempBuf, PSTR("M994 %s;%d\n"), list_file.file_name[sel_id], (int)gCfgItems.curFilesize); wifi_ret_ack(); - send_to_wifi((uint8_t *)tempBuf, strlen(tempBuf)); + send_to_wifi((uint8_t *)tempBuf, strlen((char *)tempBuf)); } break; @@ -1279,7 +1279,7 @@ static void file_first_msg_handle(uint8_t * msg, uint16_t msgLen) { ZERO(public_buf); - if (strlen(file_writer.saveFileName) > sizeof(saveFilePath)) + if (strlen((const char *)file_writer.saveFileName) > sizeof(saveFilePath)) return; ZERO(saveFilePath); @@ -1305,7 +1305,7 @@ static void file_first_msg_handle(uint8_t * msg, uint16_t msgLen) { char dosName[FILENAME_LENGTH]; - if (!longName2DosName(file_writer.saveFileName, dosName)) { + if (!longName2DosName((const char *)file_writer.saveFileName, dosName)) { clear_cur_ui(); upload_result = 2; wifiTransError.flag = 1; @@ -1313,7 +1313,7 @@ static void file_first_msg_handle(uint8_t * msg, uint16_t msgLen) { lv_draw_dialog(DIALOG_TYPE_UPLOAD_FILE); return; } - strcpy(saveFilePath, dosName); + strcpy((char *)saveFilePath, dosName); card.cdroot(); upload_file.close(); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.h b/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.h index 048996e919..0886641b2d 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.h @@ -178,18 +178,18 @@ extern CLOUD_PARA cloud_para; extern WIFI_GCODE_BUFFER espGcodeFifo; -extern uint32_t getWifiTick(); -extern uint32_t getWifiTickDiff(int32_t lastTick, int32_t curTick); +uint32_t getWifiTick(); +uint32_t getWifiTickDiff(int32_t lastTick, int32_t curTick); void mks_esp_wifi_init(); -extern int cfg_cloud_flag; -extern int send_to_wifi(uint8_t *buf, int len); +extern int cfg_cloud_flag; +int send_to_wifi(uint8_t *buf, int len); void wifi_looping(); -extern int raw_send_to_wifi(uint8_t *buf, int len); -extern int package_to_wifi(WIFI_RET_TYPE type, uint8_t *buf, int len); +int raw_send_to_wifi(uint8_t *buf, int len); +int package_to_wifi(WIFI_RET_TYPE type, uint8_t *buf, int len); void get_wifi_list_command_send(); void get_wifi_commands(); -extern int readWifiBuf(int8_t *buf, int32_t len); +int readWifiBuf(int8_t *buf, int32_t len); void mks_wifi_firmware_update(); #ifdef __cplusplus diff --git a/buildroot/share/PlatformIO/variants/megaextendedpins/pins_arduino.h b/buildroot/share/PlatformIO/variants/megaextendedpins/pins_arduino.h index 81f2ae3e19..dbbb7b4832 100644 --- a/buildroot/share/PlatformIO/variants/megaextendedpins/pins_arduino.h +++ b/buildroot/share/PlatformIO/variants/megaextendedpins/pins_arduino.h @@ -89,7 +89,7 @@ static const uint8_t A15 = PIN_A15; #define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 13)) || \ (((p) >= 50) && ((p) <= 53)) || \ - (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) ) + (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : nullptr ) #define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \ ( (((p) >= 62) && ((p) <= 69)) ? 2 : \ @@ -97,7 +97,7 @@ static const uint8_t A15 = PIN_A15; #define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \ ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \ - ((uint8_t *)0) ) ) + nullptr ) ) #define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \ ( ((p) == 50) ? 3 : \