Skip to content

Commit

Permalink
Register Esp32Flash for use with QML
Browse files Browse the repository at this point in the history
  • Loading branch information
r3n33 committed Jul 24, 2024
1 parent 85fc61f commit 941951a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions esp32/esp32flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions esp32/esp32flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ int main(int argc, char *argv[])
qmlRegisterType<Commands>("Vedder.vesc.commands", 1, 0, "Commands");
qmlRegisterType<ConfigParams>("Vedder.vesc.configparams", 1, 0, "ConfigParams");
qmlRegisterType<FwHelper>("Vedder.vesc.fwhelper", 1, 0, "FwHelper");
qmlRegisterType<Esp32Flash>("Vedder.vesc.esp32flash", 1, 0, "Esp32Flash");
qmlRegisterType<TcpServerSimple>("Vedder.vesc.tcpserversimple", 1, 0, "TcpServerSimple");
qmlRegisterType<UdpServerSimple>("Vedder.vesc.udpserversimple", 1, 0, "UdpServerSimple");
qmlRegisterType<Vesc3dItem>("Vedder.vesc.vesc3ditem", 1, 0, "Vesc3dItem");
Expand Down
11 changes: 11 additions & 0 deletions utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 941951a

Please sign in to comment.