From 941951a3bc09d3c7f48f7f6127a53eae940fb1a0 Mon Sep 17 00:00:00 2001 From: r3n33 Date: Wed, 24 Jul 2024 14:48:41 -0500 Subject: [PATCH] Register Esp32Flash for use with QML --- esp32/esp32flash.cpp | 4 ++-- esp32/esp32flash.h | 16 ++++++++-------- main.cpp | 1 + utility.cpp | 11 +++++++++++ utility.h | 2 ++ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/esp32/esp32flash.cpp b/esp32/esp32flash.cpp index 27b4c9e8e..783d14f75 100644 --- a/esp32/esp32flash.cpp +++ b/esp32/esp32flash.cpp @@ -114,7 +114,7 @@ bool Esp32Flash::disconnectEsp() return true; } -bool Esp32Flash::flashFirmware(QByteArray data, size_t address) +bool Esp32Flash::flashFirmware(QByteArray data, quint64 address) { #ifdef HAS_SERIALPORT if (!sPort->isOpen()) { @@ -187,7 +187,7 @@ bool Esp32Flash::flashFirmware(QByteArray data, size_t address) #endif } -bool Esp32Flash::eraseFlash(size_t size, size_t address) +bool Esp32Flash::eraseFlash(quint64 size, quint64 address) { #ifdef HAS_SERIALPORT esp_loader_error_t err = esp_loader_flash_start(address, size, 1024); diff --git a/esp32/esp32flash.h b/esp32/esp32flash.h index 8354045ab..4f0242e28 100644 --- a/esp32/esp32flash.h +++ b/esp32/esp32flash.h @@ -35,14 +35,14 @@ class Esp32Flash : public QObject explicit Esp32Flash(QObject *parent = nullptr); ~Esp32Flash(); - bool connectEsp(QString port); - bool disconnectEsp(); - bool flashFirmware(QByteArray data, size_t address); - bool eraseFlash(size_t size, size_t address); - QString espPort(); - bool isBuiltinUsb(); - bool isEspConnected(); - target_chip_t getTarget(); + Q_INVOKABLE bool connectEsp(QString port); + Q_INVOKABLE bool disconnectEsp(); + Q_INVOKABLE bool flashFirmware(QByteArray data, quint64 address); + Q_INVOKABLE bool eraseFlash(quint64 size, quint64 address); + Q_INVOKABLE QString espPort(); + Q_INVOKABLE bool isBuiltinUsb(); + Q_INVOKABLE bool isEspConnected(); + Q_INVOKABLE target_chip_t getTarget(); signals: void flashProgress(double prog); diff --git a/main.cpp b/main.cpp index 4373a957a..cfa7a0b43 100755 --- a/main.cpp +++ b/main.cpp @@ -235,6 +235,7 @@ int main(int argc, char *argv[]) qmlRegisterType("Vedder.vesc.commands", 1, 0, "Commands"); qmlRegisterType("Vedder.vesc.configparams", 1, 0, "ConfigParams"); qmlRegisterType("Vedder.vesc.fwhelper", 1, 0, "FwHelper"); + qmlRegisterType("Vedder.vesc.esp32flash", 1, 0, "Esp32Flash"); qmlRegisterType("Vedder.vesc.tcpserversimple", 1, 0, "TcpServerSimple"); qmlRegisterType("Vedder.vesc.udpserversimple", 1, 0, "UdpServerSimple"); qmlRegisterType("Vedder.vesc.vesc3ditem", 1, 0, "Vesc3dItem"); diff --git a/utility.cpp b/utility.cpp index a5bb0647a..f9dd6fce0 100755 --- a/utility.cpp +++ b/utility.cpp @@ -2349,6 +2349,17 @@ QString Utility::md2html(QString md) return result; } +QByteArray Utility::readAllFromFile(const QString &filePath) +{ + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + return QByteArray(); + } + QByteArray data = file.readAll(); + file.close(); + return data; +} + void Utility::setDarkMode(bool isDarkSetting) { isDark = isDarkSetting; diff --git a/utility.h b/utility.h index 7bc8e7268..2740310cd 100644 --- a/utility.h +++ b/utility.h @@ -146,6 +146,8 @@ class Utility : public QObject Q_INVOKABLE static QString md2html(QString md); + Q_INVOKABLE QByteArray readAllFromFile(const QString &filePath); + signals: public slots: