MKS WiFi for TFT_LVGL_UI (#20191)
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "draw_ui.h"
|
||||
#include "wifi_module.h"
|
||||
#include "wifi_upload.h"
|
||||
#include "SPI_TFT.h"
|
||||
|
||||
#if ENABLED(MKS_WIFI_MODULE)
|
||||
|
||||
@@ -36,6 +37,8 @@
|
||||
#include "../../../../lcd/marlinui.h"
|
||||
#include "../../../../sd/cardreader.h"
|
||||
#include "../../../../module/planner.h"
|
||||
#include "../../../../module/servo.h"
|
||||
#include "../../../../module/probe.h"
|
||||
#if ENABLED(POWER_LOSS_RECOVERY)
|
||||
#include "../../../../feature/powerloss.h"
|
||||
#endif
|
||||
@@ -109,10 +112,9 @@ extern IP_PARA ipPara;
|
||||
extern CLOUD_PARA cloud_para;
|
||||
|
||||
extern bool once_flag, flash_preview_begin, default_preview_flg, gcode_preview_over;
|
||||
extern bool flash_dma_mode;
|
||||
|
||||
uint32_t getWifiTick() {
|
||||
return millis();
|
||||
}
|
||||
uint32_t getWifiTick() { return millis(); }
|
||||
|
||||
uint32_t getWifiTickDiff(int32_t lastTick, int32_t curTick) {
|
||||
if (lastTick <= curTick)
|
||||
@@ -149,40 +151,123 @@ void mount_file_sys(uint8_t disk_type) {
|
||||
}
|
||||
}
|
||||
|
||||
static void dma_init() {
|
||||
#if 0
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||
#include <libmaple/timer.h>
|
||||
#include <libmaple/util.h>
|
||||
#include <libmaple/rcc.h>
|
||||
|
||||
//HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
|
||||
HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 4, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
|
||||
#include <boards.h>
|
||||
#include <wirish.h>
|
||||
|
||||
hdma_usart1_rx.Instance = DMA1_Channel5;
|
||||
//hdma_usart1_rx.Init.Channel = DMA_CHANNEL_4;
|
||||
hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
||||
hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
hdma_usart1_rx.Init.MemDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
hdma_usart1_rx.Init.Mode = DMA_NORMAL;
|
||||
hdma_usart1_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
|
||||
if (HAL_DMA_Init((DMA_HandleTypeDef *)&hdma_usart1_rx) != HAL_OK) {
|
||||
Error_Handler();
|
||||
#include <libmaple/dma.h>
|
||||
#include <libmaple/bitband.h>
|
||||
|
||||
#include <libmaple/libmaple.h>
|
||||
#include <libmaple/gpio.h>
|
||||
#include <libmaple/usart.h>
|
||||
#include <libmaple/ring_buffer.h>
|
||||
|
||||
void changeFlashMode(const bool dmaMode) {
|
||||
if (flash_dma_mode != dmaMode) {
|
||||
flash_dma_mode = dmaMode;
|
||||
if (!flash_dma_mode) {
|
||||
dma_disable(DMA1, DMA_CH5);
|
||||
dma_clear_isr_bits(DMA1, DMA_CH4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool longName2DosName(const char *longName, uint8_t *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((char *)dosName, ".GCO");
|
||||
break;
|
||||
}
|
||||
else {
|
||||
if (c < 0x21 || c == 0x7F) return false; // Check size, non-printable characters
|
||||
// Fail for illegal characters
|
||||
PGM_P p = PSTR("|<>^+=?/[];,*\"\\");
|
||||
while (const uint8_t b = pgm_read_byte(p++)) if (b == c) return false;
|
||||
dosName[i++] = c + (WITHIN(c, 'a', 'z') ? 'A' - 'a' : 0); // Uppercase required for 8.3 name
|
||||
}
|
||||
if (i >= 5) {
|
||||
strcat((char *)dosName, "~1.GCO");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return dosName[0] != '\0'; // Return true if any name was set
|
||||
}
|
||||
|
||||
static int storeRcvData(volatile uint8_t *bufToCpy, int32_t len) {
|
||||
unsigned char tmpW = wifiDmaRcvFifo.write_cur;
|
||||
|
||||
if (len > UDISKBUFLEN) return 0;
|
||||
|
||||
if (wifiDmaRcvFifo.state[tmpW] == udisk_buf_empty) {
|
||||
memcpy((unsigned char *) wifiDmaRcvFifo.bufferAddr[tmpW], (uint8_t *)bufToCpy, len);
|
||||
wifiDmaRcvFifo.state[tmpW] = udisk_buf_full;
|
||||
wifiDmaRcvFifo.write_cur = (tmpW + 1) % TRANS_RCV_FIFO_BLOCK_NUM;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
HAL_DMA_Start_IT((DMA_HandleTypeDef *)&hdma_usart1_rx,
|
||||
(uint32_t)&huart1.Instance->DR,
|
||||
(uint32_t)(&WifiRxFifo.uartTxBuffer[0]),
|
||||
UART_RX_BUFFER_SIZE);
|
||||
static void esp_dma_pre() {
|
||||
dma_channel_reg_map *channel_regs = dma_tube_regs(DMA1, DMA_CH5);
|
||||
|
||||
//HAL_UART_Receive_DMA(&huart1,(uint8_t*)&WifiRxFifo.uartTxBuffer[0], UART_RX_BUFFER_SIZE);
|
||||
CBI32(channel_regs->CCR, 0);
|
||||
channel_regs->CMAR = (uint32_t)WIFISERIAL.usart_device->rb->buf;
|
||||
channel_regs->CNDTR = 0x0000;
|
||||
channel_regs->CNDTR = UART_RX_BUFFER_SIZE;
|
||||
DMA1->regs->IFCR = 0xF0000;
|
||||
SBI32(channel_regs->CCR, 0);
|
||||
}
|
||||
|
||||
/* Enable the DMA transfer for the receiver request by setting the DMAR bit
|
||||
in the UART CR3 register */
|
||||
SET_BIT(huart1.Instance->CR3, USART_CR3_DMAR);
|
||||
static void dma_ch5_irq_handle() {
|
||||
uint8 status_bits = dma_get_isr_bits(DMA1, DMA_CH5);
|
||||
dma_clear_isr_bits(DMA1, DMA_CH5);
|
||||
if (status_bits & 0x8) {
|
||||
// DMA transmit Error
|
||||
}
|
||||
else if (status_bits & 0x2) {
|
||||
// DMA transmit complete
|
||||
if (esp_state == TRANSFER_IDLE)
|
||||
esp_state = TRANSFERING;
|
||||
|
||||
if (storeRcvData(WIFISERIAL.usart_device->rb->buf, UART_RX_BUFFER_SIZE)) {
|
||||
esp_dma_pre();
|
||||
if (wifiTransError.flag != 0x1)
|
||||
WIFI_IO1_RESET();
|
||||
}
|
||||
else {
|
||||
WIFI_IO1_SET();
|
||||
esp_state = TRANSFER_STORE;
|
||||
}
|
||||
}
|
||||
else if (status_bits & 0x4) {
|
||||
// DMA transmit half
|
||||
WIFI_IO1_SET();
|
||||
}
|
||||
}
|
||||
static void wifi_usart_dma_init() {
|
||||
dma_init(DMA1);
|
||||
uint32_t flags = ( DMA_MINC_MODE | DMA_TRNS_CMPLT | DMA_HALF_TRNS | DMA_TRNS_ERR);
|
||||
dma_xfer_size dma_bit_size = DMA_SIZE_8BITS;
|
||||
dma_setup_transfer(DMA1, DMA_CH5, &USART1_BASE->DR, dma_bit_size,
|
||||
(volatile void*)WIFISERIAL.usart_device->rb->buf, dma_bit_size, flags);// Transmit buffer DMA
|
||||
dma_set_priority(DMA1, DMA_CH5, DMA_PRIORITY_LOW);
|
||||
dma_attach_interrupt(DMA1, DMA_CH5, &dma_ch5_irq_handle);
|
||||
|
||||
dma_clear_isr_bits(DMA1, DMA_CH5);
|
||||
dma_set_num_transfers(DMA1, DMA_CH5, UART_RX_BUFFER_SIZE);
|
||||
|
||||
bb_peri_set_bit(&USART1_BASE->CR3, USART_CR3_DMAR_BIT, 1);
|
||||
dma_enable(DMA1, DMA_CH5); // enable transmit
|
||||
|
||||
#endif
|
||||
for (uint8_t i = 0; i < TRANS_RCV_FIFO_BLOCK_NUM; i++) {
|
||||
wifiDmaRcvFifo.bufferAddr[i] = &bmp_public_buf[1024 * i];
|
||||
wifiDmaRcvFifo.state[i] = udisk_buf_empty;
|
||||
@@ -193,113 +278,39 @@ static void dma_init() {
|
||||
wifiDmaRcvFifo.write_cur = 0;
|
||||
}
|
||||
|
||||
static void wifi_deInit() {
|
||||
#if 0
|
||||
HAL_DMA_Abort((DMA_HandleTypeDef *)&hdma_usart1_rx);
|
||||
HAL_DMA_DeInit((DMA_HandleTypeDef *)&hdma_usart1_rx);
|
||||
__HAL_DMA_DISABLE((DMA_HandleTypeDef *)&hdma_usart1_rx);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern uint8_t mksUsart1Rx;
|
||||
|
||||
void esp_port_begin(uint8_t interrupt) {
|
||||
WifiRxFifo.uart_read_point = 0;
|
||||
WifiRxFifo.uart_write_point = 0;
|
||||
#if 0
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
#if 1
|
||||
|
||||
WifiRxFifo.uart_read_point = 0;
|
||||
WifiRxFifo.uart_write_point = 0;
|
||||
memset((uint8_t*)WifiRxFifo.uartTxBuffer, 0, sizeof(WifiRxFifo.uartTxBuffer));
|
||||
|
||||
if (interrupt) {
|
||||
#if TAN
|
||||
wifi_deInit ();
|
||||
|
||||
//SZ_STM32_COMInit(COM1, 115200);
|
||||
__HAL_UART_ENABLE_IT(USART1, USART_IT_RXNE);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = 115200; //<2F><><EFBFBD>ڵIJ<DAB5><C4B2><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD>115200 <20><>ߴ<EFBFBD>4.5Mbits/s
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //<2F><><EFBFBD><EFBFBD><EFBFBD>ֳ<EFBFBD><D6B3><EFBFBD>(8λ<38><CEBB>9λ)
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1; //<2F><><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ֹͣλ-֧<><D6A7>1<EFBFBD><31>2<EFBFBD><32>ֹͣλ
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No; //<2F><><EFBFBD><EFBFBD>żУ<C5BC><D0A3>
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //<2F><>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //˫<><CBAB>ģʽ<C4A3><CABD>ʹ<EFBFBD>ܷ<EFBFBD><DCB7>ͺͽ<CDBA><CDBD><EFBFBD>
|
||||
|
||||
__HAL_RCC_USART1_CLK_ENABLE();
|
||||
|
||||
GPIO_InitStruct.Pin = TFT_WIFI_TX_Pin|TFT_WIFI_RX_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pin = TFT_WIFI_RX_Pin;
|
||||
HAL_GPIO_Init(GPIOA,&GPIO_InitStruct);
|
||||
|
||||
USART_Init(USART1, &USART_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
#else
|
||||
HAL_UART_DeInit(&huart1);
|
||||
MX_USART1_UART_Init(3);
|
||||
//__HAL_UART_ENABLE_IT(&huart1, UART_IT_RXNE);
|
||||
HAL_UART_Receive_IT(&huart1,&mksUsart1Rx,1);
|
||||
#if ENABLED(MKS_WIFI_MODULE)
|
||||
WIFISERIAL.end();
|
||||
if (interrupt) {
|
||||
for (uint16_t i = 0; i < 65535; i++) { /*nada*/ }
|
||||
WIFISERIAL.begin(WIFI_BAUDRATE);
|
||||
uint32_t serial_connect_timeout = millis() + 1000UL;
|
||||
while (PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
|
||||
}
|
||||
else {
|
||||
WIFISERIAL.usart_device->regs->CR1 &= ~USART_CR1_RXNEIE;
|
||||
WIFISERIAL.begin(WIFI_UPLOAD_BAUDRATE);
|
||||
wifi_usart_dma_init();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else{
|
||||
#if 0
|
||||
NVIC_DisableIRQ(SZ_STM32_COM1_IRQn);
|
||||
|
||||
USART_Cmd(SZ_STM32_COM1, DISABLE);
|
||||
#else
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, DISABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||
|
||||
SZ_STM32_COMInit(COM1, 1958400);
|
||||
|
||||
USART_Cmd(SZ_STM32_COM1, ENABLE);
|
||||
|
||||
wifi_delay(10);
|
||||
|
||||
dma_init();
|
||||
#if MKS_WIFI_MODULE
|
||||
WIFISERIAL.end();
|
||||
for (uint16_t i = 0; i < 65535; i++) { /*nada*/ }
|
||||
WIFISERIAL.begin(interrupt ? WIFI_BAUDRATE : WIFI_UPLOAD_BAUDRATE);
|
||||
uint32_t serial_connect_timeout = millis() + 1000UL;
|
||||
while (PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
|
||||
#endif
|
||||
HAL_UART_DeInit(&huart1);
|
||||
MX_USART1_UART_Init(5);
|
||||
//dma1_5_IRQ_sel = 1;
|
||||
dma_init();
|
||||
}
|
||||
if (!interrupt) wifi_usart_dma_init();
|
||||
|
||||
#endif
|
||||
|
||||
#if ENABLED(MKS_WIFI_MODULE)
|
||||
WIFISERIAL.end();
|
||||
for (uint16_t i = 0; i < 65535; i++) { /*nada*/ }
|
||||
WIFISERIAL.begin(interrupt ? WIFI_BAUDRATE : WIFI_UPLOAD_BAUDRATE);
|
||||
|
||||
const millis_t serial_connect_timeout = millis() + 1000UL;
|
||||
while (/*!WIFISERIAL && */PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
|
||||
|
||||
if (interrupt) {
|
||||
//for (uint8_t i=0;i<100;i++) WIFISERIAL.write(0x33);
|
||||
}
|
||||
else {
|
||||
//for (uint16_t i=0;i<65535;i++); //WIFISERIAL.write(0x33);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!interrupt) dma_init();
|
||||
}
|
||||
|
||||
#if ENABLED(MKS_WIFI_MODULE)
|
||||
@@ -441,10 +452,12 @@ int package_to_wifi(WIFI_RET_TYPE type, uint8_t *buf, int len) {
|
||||
ZERO(buf_to_wifi);
|
||||
index_to_wifi = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int send_to_wifi(char *buf, int len) { return package_to_wifi(WIFI_TRANS_INF, buf, len); }
|
||||
#define SEND_OK_TO_WIFI send_to_wifi((uint8_t *)"ok\r\n", strlen("ok\r\n"))
|
||||
int send_to_wifi(uint8_t *buf, int len) { return package_to_wifi(WIFI_TRANS_INF, buf, len); }
|
||||
|
||||
void set_cur_file_sys(int fileType) { gCfgItems.fileSysType = fileType; }
|
||||
|
||||
@@ -463,9 +476,9 @@ void get_file_list(char *path) {
|
||||
char wait_ip_back_flag = 0;
|
||||
|
||||
typedef struct {
|
||||
char write_buf[513];
|
||||
int write_index;
|
||||
uint8_t saveFileName[30];
|
||||
uint8_t fileTransfer;
|
||||
uint32_t fileLen;
|
||||
uint32_t tick_begin;
|
||||
uint32_t tick_end;
|
||||
@@ -475,22 +488,43 @@ FILE_WRITER file_writer;
|
||||
|
||||
int32_t lastFragment = 0;
|
||||
|
||||
char lastBinaryCmd[50] = { 0 };
|
||||
char saveFilePath[50];
|
||||
|
||||
int total_write = 0;
|
||||
char binary_head[2] = { 0, 0 };
|
||||
unsigned char binary_data_len = 0;
|
||||
static SdFile upload_file, *upload_curDir;
|
||||
static filepos_t pos;
|
||||
|
||||
int write_to_file(char *buf, int len) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
file_writer.write_buf[file_writer.write_index++] = buf[i];
|
||||
int i;
|
||||
int res = 0;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
public_buf[file_writer.write_index++] = buf[i];
|
||||
if (file_writer.write_index >= 512) {
|
||||
int res = card.write(file_writer.write_buf, file_writer.write_index);
|
||||
if (res == -1) return -1;
|
||||
ZERO(file_writer.write_buf);
|
||||
res = upload_file.write(public_buf, file_writer.write_index);
|
||||
|
||||
if (res == -1) {
|
||||
upload_file.close();
|
||||
const char * const fname = card.diveToFile(true, upload_curDir, saveFilePath);
|
||||
|
||||
if (upload_file.open(upload_curDir, fname, O_WRITE)) {
|
||||
upload_file.setpos(&pos);
|
||||
res = upload_file.write(public_buf, file_writer.write_index);
|
||||
}
|
||||
}
|
||||
if (res == -1) {
|
||||
return -1;
|
||||
}
|
||||
upload_file.getpos(&pos);
|
||||
file_writer.write_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (res == -1) {
|
||||
memset(public_buf, 0, sizeof(public_buf));
|
||||
file_writer.write_index = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -543,10 +577,8 @@ uint8_t Explore_Disk(char* path , uint8_t recu_level) {
|
||||
for (uint8_t i = 0; i < fileCnt; i++) {
|
||||
card.getfilename_sorted(SD_ORDER(i, fileCnt));
|
||||
|
||||
//if (card.longFilename[0] == 0)
|
||||
strcpy(tmp, card.filename);
|
||||
//else
|
||||
// strcpy(tmp, card.longFilename);
|
||||
memset(tmp, 0, sizeof(tmp));
|
||||
strcpy(tmp, card.filename);
|
||||
|
||||
ZERO(Fstream);
|
||||
strcpy(Fstream, tmp);
|
||||
@@ -584,6 +616,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
switch (cmd_value) {
|
||||
|
||||
case 20: // M20: Print SD / µdisk file
|
||||
file_writer.fileTransfer = 0;
|
||||
if (uiCfg.print_state == IDLE) {
|
||||
int index = 0;
|
||||
|
||||
@@ -591,8 +624,8 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
gCfgItems.fileSysType = FILE_SYS_SD;
|
||||
send_to_wifi((uint8_t *)"Begin file list\r\n", strlen("Begin file list\r\n"));
|
||||
get_file_list((char *)"0:/");
|
||||
send_to_wifi((char *)"End file list\r\n", strlen("End file list\r\n"));
|
||||
send_to_wifi((char *)"ok\r\n", strlen("ok\r\n"));
|
||||
send_to_wifi((uint8_t *)"End file list\r\n", strlen("End file list\r\n"));
|
||||
SEND_OK_TO_WIFI;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -613,14 +646,14 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
get_file_list(path);
|
||||
send_to_wifi((uint8_t *)"End file list\r\n", strlen("End file list\r\n"));
|
||||
}
|
||||
send_to_wifi((char *)"ok\r\n", strlen("ok\r\n"));
|
||||
SEND_OK_TO_WIFI;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 21:
|
||||
/*init sd card*/
|
||||
send_to_wifi((char *)"ok\r\n", strlen("ok\r\n"));
|
||||
SEND_OK_TO_WIFI;
|
||||
break;
|
||||
|
||||
case 23:
|
||||
@@ -632,15 +665,40 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
if (strstr((char *)&tmpStr[index], ".g") || strstr((char *)&tmpStr[index], ".G")) {
|
||||
if (strlen((char *)&tmpStr[index]) < 80) {
|
||||
ZERO(list_file.file_name[sel_id]);
|
||||
ZERO(list_file.long_name[sel_id]);
|
||||
uint8_t has_path_selected = 0;
|
||||
|
||||
if (gCfgItems.wifi_type == ESP_WIFI) {
|
||||
if (strncmp((char *)&tmpStr[index], "1:", 2) == 0)
|
||||
if (strncmp((char *)&tmpStr[index], "1:", 2) == 0) {
|
||||
gCfgItems.fileSysType = FILE_SYS_SD;
|
||||
else if (strncmp((char *)&tmpStr[index], "0:", 2) == 0)
|
||||
has_path_selected = 1;
|
||||
}
|
||||
else if (strncmp((char *)&tmpStr[index], "0:", 2) == 0) {
|
||||
gCfgItems.fileSysType = FILE_SYS_USB;
|
||||
has_path_selected = 1;
|
||||
}
|
||||
else if (tmpStr[index] != '/')
|
||||
strcat((char *)list_file.file_name[0], "/");
|
||||
strcat((char *)list_file.file_name[sel_id], (char *)&tmpStr[index]);
|
||||
strcat((char *)list_file.file_name[sel_id], "/");
|
||||
|
||||
if (file_writer.fileTransfer == 1) {
|
||||
uint8_t dosName[FILENAME_LENGTH];
|
||||
uint8_t fileName[sizeof(list_file.file_name[sel_id])];
|
||||
fileName[0] = '\0';
|
||||
if (has_path_selected == 1) {
|
||||
strcat((char *)fileName, (char *)&tmpStr[index + 3]);
|
||||
strcat((char *)list_file.file_name[sel_id], "/");
|
||||
}
|
||||
else strcat((char *)fileName, (char *)&tmpStr[index]);
|
||||
if (!longName2DosName((const char *)fileName, dosName)) {
|
||||
strcpy(list_file.file_name[sel_id], "notValid");
|
||||
}
|
||||
strcat((char *)list_file.file_name[sel_id], (char *)dosName);
|
||||
strcat((char *)list_file.long_name[sel_id], (char *)dosName);
|
||||
}
|
||||
else {
|
||||
strcat((char *)list_file.file_name[sel_id], (char *)&tmpStr[index]);
|
||||
strcat((char *)list_file.long_name[sel_id], (char *)&tmpStr[index]);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
@@ -656,7 +714,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
send_to_wifi((uint8_t *)"file.open failed\r\n", strlen("file.open failed\r\n"));
|
||||
strcpy(list_file.file_name[sel_id], "notValid");
|
||||
}
|
||||
send_to_wifi((char *)"ok\r\n", strlen("ok\r\n"));
|
||||
SEND_OK_TO_WIFI;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -680,6 +738,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
|
||||
SdFile file;
|
||||
SdFile *curDir;
|
||||
card.endFilePrint();
|
||||
const char * const fname = card.diveToFile(true, curDir, cur_name);
|
||||
if (!fname) return;
|
||||
if (file.open(curDir, fname, O_READ)) {
|
||||
@@ -726,7 +785,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
lv_draw_printing();
|
||||
}
|
||||
}
|
||||
send_to_wifi((char *)"ok\r\n", strlen("ok\r\n"));
|
||||
SEND_OK_TO_WIFI;
|
||||
break;
|
||||
|
||||
case 25:
|
||||
@@ -745,7 +804,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
else
|
||||
default_preview_flg = true;
|
||||
lv_draw_printing();
|
||||
send_to_wifi((char *)"ok\r\n", strlen("ok\r\n"));
|
||||
SEND_OK_TO_WIFI;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -762,7 +821,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
|
||||
lv_draw_ready_print();
|
||||
|
||||
send_to_wifi((char *)"ok\r\n", strlen("ok\r\n"));
|
||||
SEND_OK_TO_WIFI;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -805,8 +864,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
ZERO(tempBuf);
|
||||
sprintf((char *)tempBuf, "Writing to file: %s\r\n", (char *)file_writer.saveFileName);
|
||||
wifi_ret_ack();
|
||||
send_to_wifi((char *)tempBuf, strlen((char *)tempBuf));
|
||||
total_write = 0;
|
||||
send_to_wifi((uint8_t *)tempBuf, strlen((char *)tempBuf));
|
||||
wifi_link_state = WIFI_WAIT_TRANS_START;
|
||||
}
|
||||
else {
|
||||
@@ -822,7 +880,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
case 991:
|
||||
ZERO(tempBuf);
|
||||
if (cmd_value == 105) {
|
||||
send_to_wifi((char *)"ok\r\n", strlen("ok\r\n"));
|
||||
SEND_OK_TO_WIFI;
|
||||
sprintf((char *)tempBuf,"T:%.1f /%.1f B:%.1f /%.1f T0:%.1f /%.1f T1:%.1f /%.1f @:0 B@:0\r\n",
|
||||
|
||||
(float)thermalManager.temp_hotend[0].celsius, (float)thermalManager.temp_hotend[0].target,
|
||||
@@ -891,7 +949,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
}
|
||||
else if (uiCfg.print_state == PAUSED) {
|
||||
wifi_ret_ack();
|
||||
send_to_wifi((char *)"M997 PAUSE\r\n", strlen("M997 PAUSE\r\n"));
|
||||
send_to_wifi((uint8_t *)"M997 PAUSE\r\n", strlen("M997 PAUSE\r\n"));
|
||||
}
|
||||
else if (uiCfg.print_state == REPRINTING) {
|
||||
wifi_ret_ack();
|
||||
@@ -913,8 +971,8 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
|
||||
case 115:
|
||||
ZERO(tempBuf);
|
||||
send_to_wifi((char *)"ok\r\n", strlen("ok\r\n"));
|
||||
send_to_wifi((char *)"FIRMWARE_NAME:Robin_nano\r\n", strlen("FIRMWARE_NAME:Robin_nano\r\n"));
|
||||
SEND_OK_TO_WIFI;
|
||||
send_to_wifi((uint8_t *)"FIRMWARE_NAME:Robin_nano\r\n", strlen("FIRMWARE_NAME:Robin_nano\r\n"));
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -935,7 +993,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
index++;
|
||||
}
|
||||
if (left - WIFI_GCODE_BUFFER_LEAST_SIZE >= strlen((const char *)cmd_line))
|
||||
send_to_wifi((char *)"ok\r\n", strlen("ok\r\n"));
|
||||
SEND_OK_TO_WIFI;
|
||||
else
|
||||
need_ok_later = true;
|
||||
}
|
||||
@@ -961,7 +1019,7 @@ static void wifi_gcode_exec(uint8_t *cmd_line) {
|
||||
index++;
|
||||
}
|
||||
if (left_g - WIFI_GCODE_BUFFER_LEAST_SIZE >= strlen((const char *)cmd_line))
|
||||
send_to_wifi((char *)"ok\r\n", strlen("ok\r\n"));
|
||||
SEND_OK_TO_WIFI;
|
||||
else
|
||||
need_ok_later = true;
|
||||
}
|
||||
@@ -1191,29 +1249,6 @@ void utf8_2_unicode(uint8_t *source,uint8_t Len) {
|
||||
COPY(source, FileName_unicode);
|
||||
}
|
||||
|
||||
char saveFilePath[50];
|
||||
|
||||
static bool longName2DosName(const char* longName, uint8_t* dosName) {
|
||||
uint8_t i = 11;
|
||||
while (i--) dosName[i] = '\0';
|
||||
while (*longName) {
|
||||
uint8_t c = *longName++;
|
||||
if (c == '.') { // For a dot...
|
||||
if (i == 0) return false;
|
||||
else { strcat((char *)dosName,".GCO"); return dosName[0] != '\0'; }
|
||||
}
|
||||
else {
|
||||
// Fail for illegal characters
|
||||
PGM_P p = PSTR("|<>^+=?/[];,*\"\\");
|
||||
while (uint8_t b = pgm_read_byte(p++)) if (b == c) return false;
|
||||
if (c < 0x21 || c == 0x7F) return false; // Check size, non-printable characters
|
||||
dosName[i++] = (c < 'a' || c > 'z') ? (c) : (c + ('A' - 'a')); // Uppercase required for 8.3 name
|
||||
}
|
||||
if (i >= 5) strcat((char *)dosName,"~1.GCO");
|
||||
}
|
||||
return dosName[0] != '\0'; // Return true if any name was set
|
||||
}
|
||||
|
||||
static void file_first_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
||||
uint8_t fileNameLen = *msg;
|
||||
|
||||
@@ -1226,7 +1261,7 @@ static void file_first_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
||||
|
||||
utf8_2_unicode(file_writer.saveFileName,fileNameLen);
|
||||
|
||||
ZERO(file_writer.write_buf);
|
||||
ZERO(public_buf);
|
||||
|
||||
if (strlen((const char *)file_writer.saveFileName) > sizeof(saveFilePath))
|
||||
return;
|
||||
@@ -1234,11 +1269,7 @@ static void file_first_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
||||
ZERO(saveFilePath);
|
||||
|
||||
if (gCfgItems.fileSysType == FILE_SYS_SD) {
|
||||
//sprintf((char *)saveFilePath, "/%s", file_writer.saveFileName);
|
||||
card.mount();
|
||||
|
||||
//ZERO(list_file.long_name[sel_id]);
|
||||
//memcpy(list_file.long_name[sel_id],file_writer.saveFileName,sizeof(list_file.long_name[sel_id]));
|
||||
TERN_(SDSUPPORT, card.mount());
|
||||
}
|
||||
else if (gCfgItems.fileSysType == FILE_SYS_USB) {
|
||||
|
||||
@@ -1266,26 +1297,19 @@ static void file_first_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
||||
lv_draw_dialog(DIALOG_TYPE_UPLOAD_FILE);
|
||||
return;
|
||||
}
|
||||
sprintf((char *)saveFilePath, "/%s", dosName);
|
||||
sprintf((char *)saveFilePath, "%s", dosName);
|
||||
|
||||
ZERO(list_file.long_name[sel_id]);
|
||||
memcpy(list_file.long_name[sel_id], dosName, sizeof(dosName));
|
||||
card.cdroot();
|
||||
upload_file.close();
|
||||
const char * const fname = card.diveToFile(true, upload_curDir, saveFilePath);
|
||||
|
||||
char *cur_name=strrchr((const char *)saveFilePath,'/');
|
||||
|
||||
SdFile file;
|
||||
SdFile *curDir;
|
||||
card.endFilePrint();
|
||||
const char * const fname = card.diveToFile(true, curDir, cur_name);
|
||||
if (!fname) return;
|
||||
if (file.open(curDir, fname, O_CREAT | O_APPEND | O_WRITE | O_TRUNC)) {
|
||||
gCfgItems.curFilesize = file.fileSize();
|
||||
}
|
||||
else {
|
||||
if (!upload_file.open(upload_curDir, fname, O_CREAT | O_APPEND | O_WRITE | O_TRUNC)) {
|
||||
clear_cur_ui();
|
||||
upload_result = 2;
|
||||
|
||||
wifiTransError.flag = 1;
|
||||
wifiTransError.start_tick = getWifiTick();
|
||||
|
||||
lv_draw_dialog(DIALOG_TYPE_UPLOAD_FILE);
|
||||
return;
|
||||
}
|
||||
@@ -1302,22 +1326,23 @@ static void file_first_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
||||
lv_task_handler();
|
||||
|
||||
file_writer.tick_begin = getWifiTick();
|
||||
|
||||
file_writer.fileTransfer = 1;
|
||||
}
|
||||
|
||||
#define FRAG_MASK _BV32(31)
|
||||
#define FRAG_MASK ~_BV32(31)
|
||||
|
||||
static void file_fragment_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
||||
uint32_t frag = *((uint32_t *)msg);
|
||||
|
||||
if ((frag & FRAG_MASK) != (uint32_t)(lastFragment + 1)) {
|
||||
ZERO(file_writer.write_buf);
|
||||
ZERO(public_buf);
|
||||
file_writer.write_index = 0;
|
||||
wifi_link_state = WIFI_CONNECTED;
|
||||
upload_result = 2;
|
||||
}
|
||||
else {
|
||||
if (write_to_file((char *)msg + 4, msgLen - 4) < 0) {
|
||||
ZERO(file_writer.write_buf);
|
||||
ZERO(public_buf);
|
||||
file_writer.write_index = 0;
|
||||
wifi_link_state = WIFI_CONNECTED;
|
||||
upload_result = 2;
|
||||
@@ -1325,16 +1350,31 @@ static void file_fragment_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
||||
}
|
||||
lastFragment = frag;
|
||||
|
||||
if ((frag & (~FRAG_MASK))) {
|
||||
int res = card.write(file_writer.write_buf, file_writer.write_index);
|
||||
if ((frag & (~FRAG_MASK)) != 0) {
|
||||
int res = upload_file.write(public_buf, file_writer.write_index);
|
||||
if (res == -1) {
|
||||
ZERO(file_writer.write_buf);
|
||||
upload_file.close();
|
||||
const char * const fname = card.diveToFile(true, upload_curDir, saveFilePath);
|
||||
if (upload_file.open(upload_curDir, fname, O_WRITE)) {
|
||||
upload_file.setpos(&pos);
|
||||
res = upload_file.write(public_buf, file_writer.write_index);
|
||||
}
|
||||
}
|
||||
upload_file.close();
|
||||
SdFile file, *curDir;
|
||||
const char * const fname = card.diveToFile(true, curDir, saveFilePath);
|
||||
if (file.open(curDir, fname, O_RDWR)) {
|
||||
gCfgItems.curFilesize = file.fileSize();
|
||||
file.close();
|
||||
}
|
||||
else {
|
||||
ZERO(public_buf);
|
||||
file_writer.write_index = 0;
|
||||
wifi_link_state = WIFI_CONNECTED;
|
||||
upload_result = 2;
|
||||
return;
|
||||
}
|
||||
ZERO(file_writer.write_buf);
|
||||
ZERO(public_buf);
|
||||
file_writer.write_index = 0;
|
||||
file_writer.tick_end = getWifiTick();
|
||||
upload_time = getWifiTickDiff(file_writer.tick_begin, file_writer.tick_end) / 1000;
|
||||
@@ -1342,7 +1382,6 @@ static void file_fragment_msg_handle(uint8_t * msg, uint16_t msgLen) {
|
||||
wifi_link_state = WIFI_CONNECTED;
|
||||
upload_result = 3;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1453,7 +1492,6 @@ void esp_data_parser(char *cmdRxBuf, int len) {
|
||||
esp_msg_index = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((charAtArray(esp_msg_buf, esp_msg_index, ESP_PROTOC_HEAD) != -1) && (charAtArray(esp_msg_buf, esp_msg_index, ESP_PROTOC_TAIL) != -1))
|
||||
loop_again = true;
|
||||
}
|
||||
@@ -1461,19 +1499,6 @@ void esp_data_parser(char *cmdRxBuf, int len) {
|
||||
}
|
||||
|
||||
int32_t tick_net_time1, tick_net_time2;
|
||||
|
||||
int storeRcvData(int32_t len) {
|
||||
unsigned char tmpW = wifiDmaRcvFifo.write_cur;
|
||||
if (len <= UDISKBUFLEN && wifiDmaRcvFifo.state[tmpW] == udisk_buf_empty) {
|
||||
for (uint16_t i = 0; i < len; i++)
|
||||
wifiDmaRcvFifo.bufferAddr[tmpW][i] = WIFISERIAL.read();
|
||||
wifiDmaRcvFifo.state[tmpW] = udisk_buf_full;
|
||||
wifiDmaRcvFifo.write_cur = (tmpW + 1) % TRANS_RCV_FIFO_BLOCK_NUM;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t readWifiFifo(uint8_t *retBuf, uint32_t bufLen) {
|
||||
unsigned char tmpR = wifiDmaRcvFifo.read_cur;
|
||||
if (bufLen >= UDISKBUFLEN && wifiDmaRcvFifo.state[tmpR] == udisk_buf_full) {
|
||||
@@ -1496,20 +1521,33 @@ void stopEspTransfer() {
|
||||
wifiTransError.start_tick = getWifiTick();
|
||||
card.removeFile((const char *)saveFilePath);
|
||||
}
|
||||
else {
|
||||
}
|
||||
|
||||
wifi_delay(200);
|
||||
WIFI_IO1_SET();
|
||||
//exchangeFlashMode(1); //change spi flash to use dma mode
|
||||
|
||||
// disable dma
|
||||
dma_clear_isr_bits(DMA1, DMA_CH5);
|
||||
bb_peri_set_bit(&USART1_BASE->CR3, USART_CR3_DMAR_BIT, 0);
|
||||
dma_disable(DMA1, DMA_CH5);
|
||||
|
||||
wifi_delay(200);
|
||||
changeFlashMode(true); // Set SPI flash to use DMA mode
|
||||
esp_port_begin(1);
|
||||
wifi_delay(200);
|
||||
|
||||
W25QXX.init(SPI_QUARTER_SPEED);
|
||||
|
||||
TERN_(HAS_TFT_LVGL_UI_SPI, SPI_TFT.spi_init(SPI_FULL_SPEED));
|
||||
TERN_(HAS_SERVOS, servo_init());
|
||||
TERN_(HAS_Z_SERVO_PROBE, probe.servo_probe_init());
|
||||
|
||||
if (wifiTransError.flag != 0x1) WIFI_IO1_RESET();
|
||||
}
|
||||
|
||||
void wifi_rcv_handle() {
|
||||
int32_t len = 0;
|
||||
uint8_t ucStr[(UART_RX_BUFFER_SIZE) + 1] = { 0 };
|
||||
uint8_t ucStr[(UART_RX_BUFFER_SIZE) + 1] = {0};
|
||||
int8_t getDataF = 0;
|
||||
|
||||
if (wifi_link_state == WIFI_TRANS_FILE) {
|
||||
#if 0
|
||||
if (WIFISERIAL.available() == UART_RX_BUFFER_SIZE) {
|
||||
@@ -1531,9 +1569,9 @@ void wifi_rcv_handle() {
|
||||
getDataF = 1;
|
||||
}
|
||||
if (esp_state == TRANSFER_STORE) {
|
||||
if (storeRcvData(UART_RX_BUFFER_SIZE)) {
|
||||
if (storeRcvData(WIFISERIAL.usart_device->rb->buf, UART_RX_BUFFER_SIZE)) {
|
||||
esp_state = TRANSFERING;
|
||||
//esp_dma_pre();
|
||||
esp_dma_pre();
|
||||
if (wifiTransError.flag != 0x1) WIFI_IO1_RESET();
|
||||
}
|
||||
else
|
||||
@@ -1541,13 +1579,11 @@ void wifi_rcv_handle() {
|
||||
}
|
||||
}
|
||||
else {
|
||||
//len = readUsartFifo((SZ_USART_FIFO *)&WifiRxFifo, (int8_t *)ucStr, UART_RX_BUFFER_SIZE);
|
||||
len = readWifiBuf((int8_t *)ucStr, UART_RX_BUFFER_SIZE);
|
||||
if (len > 0) {
|
||||
esp_data_parser((char *)ucStr, len);
|
||||
|
||||
if (wifi_link_state == WIFI_TRANS_FILE) {
|
||||
//exchangeFlashMode(0); //change spi flash not use dma mode
|
||||
changeFlashMode(false); // Set SPI flash to use non-DMA mode
|
||||
wifi_delay(10);
|
||||
esp_port_begin(0);
|
||||
wifi_delay(10);
|
||||
@@ -1558,7 +1594,7 @@ void wifi_rcv_handle() {
|
||||
}
|
||||
if (need_ok_later && (queue.length < BUFSIZE)) {
|
||||
need_ok_later = false;
|
||||
send_to_wifi((char *)"ok\r\n", strlen("ok\r\n"));
|
||||
send_to_wifi((uint8_t *)"ok\r\n", strlen("ok\r\n"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1569,7 +1605,7 @@ void wifi_rcv_handle() {
|
||||
tick_net_time2 = getWifiTick();
|
||||
|
||||
if (wifi_link_state == WIFI_TRANS_FILE) {
|
||||
if ((tick_net_time1 != 0) && (getWifiTickDiff(tick_net_time1, tick_net_time2) > 4500)) {
|
||||
if (tick_net_time1 && getWifiTickDiff(tick_net_time1, tick_net_time2) > 8000) {
|
||||
wifi_link_state = WIFI_CONNECTED;
|
||||
upload_result = 2;
|
||||
clear_cur_ui();
|
||||
@@ -1577,11 +1613,10 @@ void wifi_rcv_handle() {
|
||||
lv_draw_dialog(DIALOG_TYPE_UPLOAD_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
if ((tick_net_time1 != 0) && (getWifiTickDiff(tick_net_time1, tick_net_time2) > 10000))
|
||||
if (tick_net_time1 && getWifiTickDiff(tick_net_time1, tick_net_time2) > 10000)
|
||||
wifi_link_state = WIFI_NOT_CONFIG;
|
||||
|
||||
if ((tick_net_time1 != 0) && (getWifiTickDiff(tick_net_time1, tick_net_time2) > 120000)) {
|
||||
if (tick_net_time1 && getWifiTickDiff(tick_net_time1, tick_net_time2) > 120000) {
|
||||
wifi_link_state = WIFI_NOT_CONFIG;
|
||||
wifi_reset();
|
||||
tick_net_time1 = getWifiTick();
|
||||
@@ -1598,7 +1633,10 @@ void wifi_rcv_handle() {
|
||||
}
|
||||
|
||||
void wifi_looping() {
|
||||
do { wifi_rcv_handle(); } while (wifi_link_state == WIFI_TRANS_FILE);
|
||||
do {
|
||||
wifi_rcv_handle();
|
||||
watchdog_refresh();
|
||||
} while (wifi_link_state == WIFI_TRANS_FILE);
|
||||
}
|
||||
|
||||
void mks_esp_wifi_init() {
|
||||
@@ -1616,32 +1654,8 @@ void mks_esp_wifi_init() {
|
||||
wifi_reset();
|
||||
|
||||
#if 0
|
||||
res = f_open(&esp_upload.uploadFile, ESP_FIRMWARE_FILE, FA_OPEN_EXISTING | FA_READ);
|
||||
|
||||
if (res == FR_OK) {
|
||||
f_close(&esp_upload.uploadFile);
|
||||
|
||||
wifi_delay(2000);
|
||||
|
||||
if (usartFifoAvailable((SZ_USART_FIFO *)&WifiRxFifo) < 20) {
|
||||
return;
|
||||
}
|
||||
|
||||
clear_cur_ui();
|
||||
|
||||
draw_dialog(DIALOG_TYPE_UPDATE_ESP_FIRMARE);
|
||||
|
||||
if (wifi_upload(0) >= 0) {
|
||||
|
||||
f_unlink("1:/MKS_WIFI_CUR");
|
||||
f_rename(ESP_FIRMWARE_FILE,"/MKS_WIFI_CUR");
|
||||
}
|
||||
draw_return_ui();
|
||||
|
||||
update_flag = 1;
|
||||
}
|
||||
if (update_flag == 0) {
|
||||
res = f_open(&esp_upload.uploadFile, ESP_WEB_FIRMWARE_FILE, FA_OPEN_EXISTING | FA_READ);
|
||||
if (update_flag == 0) {
|
||||
res = f_open(&esp_upload.uploadFile, ESP_WEB_FIRMWARE_FILE, FA_OPEN_EXISTING | FA_READ);
|
||||
|
||||
if (res == FR_OK) {
|
||||
f_close(&esp_upload.uploadFile);
|
||||
@@ -1694,32 +1708,42 @@ void mks_esp_wifi_init() {
|
||||
wifi_link_state = WIFI_NOT_CONFIG;
|
||||
}
|
||||
|
||||
#define BUF_INC_POINTER(p) ((p + 1 == UART_FIFO_BUFFER_SIZE) ? 0 : (p + 1))
|
||||
|
||||
void mks_wifi_firmware_update() {
|
||||
card.openFileRead((char *)ESP_FIRMWARE_FILE);
|
||||
|
||||
if (card.isFileOpen()) {
|
||||
card.closefile();
|
||||
|
||||
wifi_delay(2000);
|
||||
|
||||
if (usartFifoAvailable((SZ_USART_FIFO *)&WifiRxFifo) < 20)
|
||||
return;
|
||||
|
||||
clear_cur_ui();
|
||||
|
||||
lv_draw_dialog(DIALOG_TYPE_UPDATE_ESP_FIRMARE);
|
||||
|
||||
lv_task_handler();
|
||||
watchdog_refresh();
|
||||
|
||||
if (wifi_upload(0) >= 0) {
|
||||
card.removeFile((char *)ESP_FIRMWARE_FILE_RENAME);
|
||||
SdFile file, *curDir;
|
||||
const char * const fname = card.diveToFile(true, curDir, ESP_FIRMWARE_FILE);
|
||||
if (file.open(curDir, fname, O_READ)) {
|
||||
file.rename(curDir, (char *)ESP_FIRMWARE_FILE_RENAME);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
clear_cur_ui();
|
||||
}
|
||||
}
|
||||
|
||||
#define BUF_INC_POINTER(p) ((p + 1 == UART_FIFO_BUFFER_SIZE) ? 0:(p + 1))
|
||||
|
||||
int usartFifoAvailable(SZ_USART_FIFO *fifo) {
|
||||
int diff = fifo->uart_write_point - fifo->uart_read_point;
|
||||
if (diff < 0) diff += UART_FIFO_BUFFER_SIZE;
|
||||
return diff;
|
||||
}
|
||||
|
||||
int readUsartFifo(SZ_USART_FIFO *fifo, int8_t *buf, int32_t len) {
|
||||
int i = 0 ;
|
||||
while (i < len && fifo->uart_read_point != fifo->uart_write_point) {
|
||||
buf[i++] = fifo->uartTxBuffer[fifo->uart_read_point];
|
||||
fifo->uart_read_point = BUF_INC_POINTER(fifo->uart_read_point);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int writeUsartFifo(SZ_USART_FIFO *fifo, int8_t *buf, int32_t len) {
|
||||
if (buf == 0 || len <= 0) return -1;
|
||||
|
||||
int i = 0 ;
|
||||
while (i < len && fifo->uart_read_point != BUF_INC_POINTER(fifo->uart_write_point)) {
|
||||
fifo->uartTxBuffer[fifo->uart_write_point] = buf[i++];
|
||||
fifo->uart_write_point = BUF_INC_POINTER(fifo->uart_write_point);
|
||||
}
|
||||
return i;
|
||||
return WIFISERIAL.available();
|
||||
}
|
||||
|
||||
void get_wifi_commands() {
|
||||
@@ -1791,10 +1815,9 @@ void get_wifi_commands() {
|
||||
if (!wifi_comment_mode) wifi_line_buffer[wifi_read_count++] = wifi_char;
|
||||
}
|
||||
}
|
||||
}// queue has space, serial has data
|
||||
else {
|
||||
} // queue has space, serial has data
|
||||
else
|
||||
espGcodeFifo.wait_tick++;
|
||||
}
|
||||
}
|
||||
|
||||
int readWifiBuf(int8_t *buf, int32_t len) {
|
||||
|
Reference in New Issue
Block a user