From e2bf2610b3a72ba06d53cc441e4a96e34f94f0cc Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 7 Dec 2023 13:40:29 +0700 Subject: [PATCH] initial upload implementation draft --- src/espmega_iot_core.cpp | 16 +++++++++++---- src/espmega_iot_lcd.cpp | 39 ++++++++++++++++++++++++------------- src/ota_html/ota-part3.html | 3 +++ 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/espmega_iot_core.cpp b/src/espmega_iot_core.cpp index 713bfbb..7b92f4b 100644 --- a/src/espmega_iot_core.cpp +++ b/src/espmega_iot_core.cpp @@ -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 #include +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); } diff --git a/src/ota_html/ota-part3.html b/src/ota_html/ota-part3.html index b9b4dd4..4c7daee 100644 --- a/src/ota_html/ota-part3.html +++ b/src/ota_html/ota-part3.html @@ -28,6 +28,9 @@ R"=====(