From 91fb96f5966ad7b999c2a262a0cc01a4d4758acd Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Mon, 13 Nov 2023 15:11:10 +0700 Subject: [PATCH] lcd upload function --- src/espmega_iot_lcd.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/espmega_iot_lcd.hpp | 7 ++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/espmega_iot_lcd.cpp b/src/espmega_iot_lcd.cpp index 6006f45..d4c89b9 100644 --- a/src/espmega_iot_lcd.cpp +++ b/src/espmega_iot_lcd.cpp @@ -34,4 +34,40 @@ void lcd_init() lcd_reset(); delay(750); #endif +} + +bool lcd_upload_start(size_t size) +{ + Serial.begin(115200); + lcd_send_stop_bit(); + Serial.print("rest"); + lcd_send_stop_bit(); + Serial.print("connect"); + lcd_send_stop_bit(); + delay(1000); + Serial.print("whmi-wri 1024,115200,res0"); + lcd_send_stop_bit(); + lcd_wait_ack(); +} +bool lcd_upload_write(uint8_t *data, size_t size) +{ + for (int i = 0; i < size; i++) + { + Serial.write(data[i]); + } +} + +bool lcd_wait_ack() +{ + bool data_ok = false; + for (int i; i < 50; i++) + { + if (Serial.read() == 0x05) + { + data_ok = true; + break; + } + delay(100); + } + return data_ok; } \ No newline at end of file diff --git a/src/espmega_iot_lcd.hpp b/src/espmega_iot_lcd.hpp index 5960241..0e70e3c 100644 --- a/src/espmega_iot_lcd.hpp +++ b/src/espmega_iot_lcd.hpp @@ -2,8 +2,13 @@ #include + void lcd_send_stop_bit(); void lcd_send_command(String command); String lcd_wait_response(); void lcd_reset(); -void lcd_init(); \ No newline at end of file +void lcd_init(); + +bool lcd_upload_start(size_t size); +bool lcd_upload_write(uint8_t* data, size_t size); +bool lcd_wait_ack(); \ No newline at end of file