initial upload implementation draft
This commit is contained in:
parent
0c31060035
commit
e2bf2610b3
|
@ -546,13 +546,21 @@ void ota_begin()
|
|||
otaserver.sendHeader("Connection","close");
|
||||
},[](){
|
||||
HTTPUpload &upload = otaserver.upload();
|
||||
size_t file_size = 0;
|
||||
if(upload.status == UPLOAD_FILE_START) {
|
||||
Serial.println(upload.totalSize);
|
||||
for(int i=0;i<otaserver.headers();i++) {
|
||||
if(!otaserver.headerName(i).compareTo("Content-Length")) {
|
||||
Serial.printf("Content-Length: %s\n",otaserver.header(i).c_str());
|
||||
file_size = otaserver.header(i).toInt();
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println(file_size);
|
||||
lcd_upload_start(file_size);
|
||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||
for(int i = 0; i<upload.currentSize;i++)
|
||||
Serial.print(upload.buf[i],HEX);
|
||||
lcd_upload_write(upload.buf, upload.currentSize);
|
||||
} else if (upload.status == UPLOAD_FILE_END) {
|
||||
Serial.println("Upload End");
|
||||
Serial.println("Upload END.");
|
||||
}
|
||||
});
|
||||
otaserver.begin();
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include <user_code.hpp>
|
||||
#include <espmega_iot_lcd.hpp>
|
||||
|
||||
int lcd_byte_counter = 0;
|
||||
|
||||
/**
|
||||
* @brief Sends stop bit to LCD.
|
||||
*
|
||||
*
|
||||
* This function sends a stop bit to the LCD. It is only enabled if the ENABLE_INTERNAL_LCD macro is defined.
|
||||
*/
|
||||
void lcd_send_stop_bit()
|
||||
|
@ -17,7 +19,7 @@ void lcd_send_stop_bit()
|
|||
|
||||
/**
|
||||
* Sends a command to the LCD display.
|
||||
*
|
||||
*
|
||||
* @param command The command to send to the LCD display.
|
||||
*/
|
||||
void lcd_send_command(String command)
|
||||
|
@ -31,9 +33,9 @@ void lcd_send_command(String command)
|
|||
|
||||
/**
|
||||
* @brief Resets the LCD display.
|
||||
*
|
||||
*
|
||||
* If ENABLE_INTERNAL_LCD is defined, sends a reset command to the LCD display.
|
||||
*
|
||||
*
|
||||
*/
|
||||
void lcd_reset()
|
||||
{
|
||||
|
@ -57,7 +59,7 @@ void lcd_init()
|
|||
|
||||
/**
|
||||
* @brief Starts the upload process to the LCD.
|
||||
*
|
||||
*
|
||||
* @param size The size of the data to be uploaded.
|
||||
* @return true if the upload process started successfully, false otherwise.
|
||||
*/
|
||||
|
@ -70,14 +72,16 @@ bool lcd_upload_start(size_t size)
|
|||
Serial.print("connect");
|
||||
lcd_send_stop_bit();
|
||||
delay(1000);
|
||||
Serial.print("whmi-wri 1024,115200,res0");
|
||||
Serial.print("whmi-wri ");
|
||||
Serial.print(size);
|
||||
Serial.print(",115200,res0");
|
||||
lcd_send_stop_bit();
|
||||
lcd_wait_ack();
|
||||
return lcd_wait_ack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data to the LCD upload buffer.
|
||||
*
|
||||
*
|
||||
* @param data Pointer to the data to be written.
|
||||
* @param size Size of the data to be written.
|
||||
* @return True if the write was successful, false otherwise.
|
||||
|
@ -87,9 +91,15 @@ bool lcd_upload_write(uint8_t *data, size_t size)
|
|||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
Serial.write(data[i]);
|
||||
lcd_byte_counter++;
|
||||
if (lcd_byte_counter == 4096)
|
||||
{
|
||||
lcd_wait_ack();
|
||||
lcd_byte_counter = 0;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for an acknowledgement signal from the LCD.
|
||||
* @return true if acknowledgement signal is received, false otherwise.
|
||||
|
@ -97,12 +107,15 @@ bool lcd_upload_write(uint8_t *data, size_t size)
|
|||
bool lcd_wait_ack()
|
||||
{
|
||||
bool data_ok = false;
|
||||
for (int i; i < 50; i++)
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
if (Serial.read() == 0x05)
|
||||
if (Serial.available())
|
||||
{
|
||||
data_ok = true;
|
||||
break;
|
||||
if (Serial.read() == 0x05)
|
||||
{
|
||||
data_ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
delay(100);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,9 @@ R"=====(<button type="button" class="conf" onclick="window.location.href='config
|
|||
data: data,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
headers: {
|
||||
"Content-Length": data.length
|
||||
},
|
||||
xhr: function () {
|
||||
var xhr = new window.XMLHttpRequest();
|
||||
xhr.upload.addEventListener(
|
||||
|
|
Loading…
Reference in New Issue