diff --git a/conf1.bin b/conf1.bin index ada0558..c1b2b13 100644 Binary files a/conf1.bin and b/conf1.bin differ diff --git a/conf2.bin b/conf2.bin index ae723bd..8861721 100644 Binary files a/conf2.bin and b/conf2.bin differ diff --git a/src/Main.qml b/src/Main.qml index 83b152f..e77ab37 100644 --- a/src/Main.qml +++ b/src/Main.qml @@ -13,7 +13,7 @@ Kirigami.ApplicationWindow { width: 400 height: 300 - property var devices: Conf.deviceList + property var devices: Conf.stat // Window title // i18nc() makes a string translatable @@ -23,7 +23,14 @@ Kirigami.ApplicationWindow { globalDrawer: Kirigami.GlobalDrawer { id: drawer isMenu: true - actions: devices + actions: [ + Kirigami.Action { + text: "fff" + icon.name: "gtk-quit" + shortcut: StandardKey.Quit + onTriggered: Conf.deviceConfig() + } + ] } // Set the first page that will be loaded when the app opens @@ -35,6 +42,9 @@ Kirigami.ApplicationWindow { anchors.centerIn: parent text: i18n("Hello World!") } + Controls.TextField { + placeholderText: qsTr("Enter name") + } Component { id: nameDelegate Text { @@ -42,6 +52,8 @@ Kirigami.ApplicationWindow { font.pixelSize: 32 } } - + actions: [ + + ] } } diff --git a/src/conf.cpp b/src/conf.cpp index c77563c..d072453 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -4,6 +4,9 @@ Conf::Conf(QObject *parent) : QObject(parent) { + m_conf1 = (conf_1 *)malloc(sizeof(conf_1)); + m_conf2 = (conf_2 *)malloc(sizeof(conf_2)); + int r = libusb_init(&m_ctx); if (r < 0) { @@ -17,8 +20,6 @@ Conf::Conf(QObject *parent) : QObject(parent) { libusb_device *device = list[i]; m_device = device; - uint8_t addr = libusb_get_device_address(m_device); - uint8_t bus = libusb_get_bus_number(m_device); libusb_device_descriptor desc; libusb_get_device_descriptor(m_device, &desc); if (desc.idProduct == 0x2f && desc.idVendor == 0x258a) @@ -26,19 +27,38 @@ Conf::Conf(QObject *parent) : QObject(parent) break; } } + + //read initial config from device + readConfigFromDevice(m_conf1); + readConfigFromDevice(m_conf2); + libusb_free_device_list(list, 1); } -QList Conf::deviceList() + +ssize_t Conf::lightMode(){ + return m_conf1->light_mode; +} + +void Conf::setLightMode(ssize_t mode){ + m_conf1->light_mode = mode; + + + Q_EMIT lightModeChanged(); +} + +ssize_t Conf::deviceConfig() { conf_1 *conf = (conf_1 *)malloc(sizeof(conf_1)); conf_2 *conf2 = (conf_2 *)malloc(sizeof(conf_2)); + writeConfigToDevice(m_conf1); + // readConfigFromDevice(conf); readConfigFromFile("conf1.bin", conf); readConfigFromDevice(conf2); // edit data - // conf->light_mode = 0x2; + conf->light_mode = 0x1; conf->req_type = 0x92; conf->st_brightness_colnr = {0x16}; conf->col_steady[18] = 0x00; @@ -54,20 +74,12 @@ QList Conf::deviceList() writeConfigToFile(conf, "conf1.bin"); writeConfigToFile(conf2, "conf2.bin"); - QQmlEngine engine; - - QList asd; - QQmlComponent component(&engine, - QUrl::fromLocalFile(QString::fromStdString("/home/denis/repos/a811/src/action.qml"))); - QObject *object = component.create(); - asd.append(object); - - return asd; + return 0; } -void Conf::setDeviceList(QList deviceList) +void Conf::setDeviceConfig(ssize_t stat) { - Q_EMIT deviceListChanged(); + Q_EMIT deviceConfigChanged(); } ssize_t Conf::writeConfigToDevice(conf_2 *conf) diff --git a/src/conf.h b/src/conf.h index 32aa645..0973fd9 100644 --- a/src/conf.h +++ b/src/conf.h @@ -19,13 +19,19 @@ class Conf : public QObject { Q_OBJECT - Q_PROPERTY(QList deviceList READ deviceList WRITE setDeviceList NOTIFY deviceListChanged) + Q_PROPERTY(ssize_t deviceConfig READ deviceConfig WRITE setDeviceConfig NOTIFY deviceConfigChanged) + Q_PROPERTY(ssize_t lightMode READ lightMode WRITE setLightMode NOTIFY lightModeChanged) public: explicit Conf(QObject *parent = nullptr); - QList deviceList(); - Q_INVOKABLE void setDeviceList(QList deviceList); - Q_SIGNAL void deviceListChanged(); + ssize_t deviceConfig(); + Q_INVOKABLE void setDeviceConfig(ssize_t stat); + Q_SIGNAL void deviceConfigChanged(); + + ssize_t lightMode(); + Q_INVOKABLE void setLightMode(ssize_t mode); + Q_SIGNAL void lightModeChanged(); + ssize_t writeConfigToFile(conf_1 *conf, const char *filePath); ssize_t writeConfigToFile(conf_2 *conf, const char *filePath); ssize_t readConfigFromFile(const char *filePath, conf_1 *conf); @@ -38,7 +44,10 @@ public: Q_SIGNALS: private: - QList m_deviceList; + ssize_t m_stat; + ssize_t m_lightMode; + conf_1* m_conf1; + conf_2* m_conf2; libusb_device* m_device = NULL; libusb_context* m_ctx = NULL; }; diff --git a/src/main.cpp b/src/main.cpp index 1ed89db..3072861 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) { KIconTheme::initTheme(); // this is not available in nixpkgs version of - // KiconTheme + // KiconTheme // how did i fix this?????? QApplication app(argc, argv); KLocalizedString::setApplicationDomain("tutorial"); QApplication::setOrganizationName(QStringLiteral("KDE"));