Not so good

This commit is contained in:
Denis Manherz 2024-08-27 23:06:59 +02:00
parent af96dbf8de
commit 8a1f2d40a0
12 changed files with 325 additions and 169 deletions

17
.vscode/c_cpp_properties.json vendored Normal file
View file

@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/nix/store/lbk30k56awz9vz9qpid93fkjns0xwlhd-gcc-wrapper-13.3.0/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}

View file

@ -26,12 +26,12 @@
kdePackages.qtbase.dev
kdePackages.qtdeclarative
kdePackages.qttools.dev
kdePakcages.qtserialport.dev
makeWrapper
pkg-config
qt6.wrapQtAppsHook
qtcreator
qt6.full
qt6.qtbase
libusb1
hidapi
];

View file

@ -58,9 +58,9 @@ First Part
0x4c 0-4 Brightness und 0-4 Speed bei breathing 0x(br)(sp)
0x4d ???
0x4e-0x62 Bei Breathing RGB * 7
0x63-0x66 ??
0x67-0x7a Bei Steady RGB * 7
0x7b-end ????
0x63-0x65 ??
0x66-0x7a Bei Steady RGB * 7
0x7a-end ????
bei einem modus wechsel ändert sich brightness und speed nicht auser man ändert sie nochmal explizit

View file

@ -8,15 +8,22 @@ ecm_add_qml_module(kirigami-hello
target_sources(kirigami-hello
PRIVATE
main.cpp
conf.cpp
conf.h
test.h
test.cpp
conf.cpp conf.h
)
ecm_target_qml_sources(kirigami-hello
SOURCES
Main.qml
action.qml
)
target_link_libraries(kirigami-hello
PRIVATE
Qt6::Core
Qt6::Quick
Qt6::Qml
Qt6::Gui

View file

@ -3,6 +3,7 @@ import QtQuick
import QtQuick.Layouts
import QtQuick.Controls as Controls
import org.kde.kirigami as Kirigami
import CustomComponents 1.0
// Provides basic features needed for all kirigami applications
Kirigami.ApplicationWindow {
@ -12,89 +13,53 @@ Kirigami.ApplicationWindow {
width: 400
height: 300
property var devices: Conf.deviceList
function updateDevices() {
for (var i = 0; i < devices.length; i++) {
var component = Qt.createComponent("action.qml");
var sprite = component.createObject(null, {
text: devices[i],
shortcut: StandardKey.Quit
});
drawer.actions.push(sprite);
if (sprite == null) {
// Error Handling
console.log("Error creating object");
}
}
}
// Window title
// i18nc() makes a string translatable
// and provides additional context for the translators
title: i18nc("@title:window", "Hello World")
globalDrawer: Kirigami.GlobalDrawer {
id: drawer
isMenu: true
actions: []
Component.onCompleted: updateDevices()
}
// Set the first page that will be loaded when the app opens
// This can also be set to an id of a Kirigami.Page
pageStack.initialPage: Kirigami.Page {
id: main
Controls.Label {
// Center label horizontally and vertically within parent object
anchors.centerIn: parent
text: i18n("Hello World!")
}
}
Kirigami.CardsListView {
id: cardsView
model: kountdownModel
delegate: kountdownDelegate
}
ListModel {
id: kountdownModel
// Each ListElement is an element on the list, containing information
ListElement {
name: "Dog birthday!!"
description: "Big doggo birthday blowout."
date: 100
}
}
Component {
id: kountdownDelegate
Kirigami.AbstractCard {
contentItem: Item {
// implicitWidth/Height define the natural width/height
// of an item if no width or height is specified.
// The setting below defines a component's preferred size based on its content
implicitWidth: delegateLayout.implicitWidth
implicitHeight: delegateLayout.implicitHeight
GridLayout {
id: delegateLayout
anchors {
left: parent.left
top: parent.top
right: parent.right
}
rowSpacing: Kirigami.Units.largeSpacing
columnSpacing: Kirigami.Units.largeSpacing
columns: root.wideScreen ? 4 : 2
Kirigami.Heading {
Layout.fillHeight: true
level: 1
text: date
}
ColumnLayout {
Kirigami.Heading {
Layout.fillWidth: true
level: 2
text: name
}
Kirigami.Separator {
Layout.fillWidth: true
visible: description.length > 0
}
Controls.Label {
Layout.fillWidth: true
wrapMode: Text.WordWrap
text: description
visible: description.length > 0
}
}
Controls.Button {
Layout.alignment: Qt.AlignRight
Layout.columnSpan: 2
text: i18n("Edit")
// onClicked: to be done... soon!
}
}
}
id: nameDelegate
Text {
text: model.display
font.pixelSize: 32
}
}
}
}

14
src/action.qml Normal file
View file

@ -0,0 +1,14 @@
// Includes relevant modules used by the QML
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls as Controls
import org.kde.kirigami as Kirigami
Kirigami.Action {
text: "ff"
//icon.name: "gtk-quit"
shortcut: StandardKey.Quit
//onTriggered: Conf.setDeviceList(null)
}

67
src/conf.cpp Normal file
View file

@ -0,0 +1,67 @@
#include "conf.h"
#include <iostream>
#include <QDebug>
#include "test.h"
Conf::Conf(QObject *parent) : QObject(parent) {}
QStringList Conf::deviceList()
{
libusb_context *ctx;
int r = libusb_init(&ctx);
if (r < 0)
{
std::cout << libusb_error_name(r) << std::endl;
exit(1);
}
QStringList deviceLists;
libusb_device **list;
libusb_device *found = NULL;
ssize_t cnt = libusb_get_device_list(ctx, &list);
ssize_t i = 0;
//std::cout << cnt << "\n";
for (i = 0; i < cnt; i++)
{
libusb_device *device = list[i];
found = device;
uint8_t addr = libusb_get_device_address(found);
uint8_t bus = libusb_get_bus_number(found);
libusb_device_descriptor desc;
libusb_get_device_descriptor(found, &desc);
QString formattedString = QString::asprintf("%04X:%04X", desc.idVendor, desc.idProduct);
deviceLists.append(formattedString);
//std::cout << "Bus " << unsigned(bus) << " Device " << unsigned(addr) << ": ID " << std::hex << desc.idVendor << ":" << desc.idProduct << std::dec << std::endl;
}
return deviceLists;
}
void Conf::setDeviceList(QStringList deviceList)
{
QStringList deviceLists;
libusb_device **list;
libusb_device *found = NULL;
ssize_t cnt = libusb_get_device_list(NULL, &list);
ssize_t i = 0;
std::cout << cnt << "\n";
for (i = 0; i < cnt; i++)
{
libusb_device *device = list[i];
found = device;
uint8_t addr = libusb_get_device_address(found);
uint8_t bus = libusb_get_bus_number(found);
libusb_device_descriptor desc;
libusb_get_device_descriptor(found, &desc);
deviceLists << QString::number(desc.idVendor) << QString::fromUtf8(":") << QString::number(desc.idProduct);
std::cout << "Bus " << unsigned(bus) << " Device " << unsigned(addr) << ": ID " << std::hex << desc.idVendor << ":" << desc.idProduct << std::dec << std::endl;
if (desc.idProduct == 0x2f && desc.idVendor == 0x258a)
{
// std::cout << std::hex << (int)(desc.bNumConfigurations) << std::endl;
break;
}
}
m_deviceList = deviceLists;
Q_EMIT deviceListChanged();
}

28
src/conf.h Normal file
View file

@ -0,0 +1,28 @@
#ifndef CONFIG_H
#define CONFIG_H
#include <QObject>
#include <QtQml>
#include <libusb-1.0/libusb.h>
#include <QString>
#include <QStringList>
class Conf : public QObject
{
Q_OBJECT
Q_PROPERTY(QStringList deviceList READ deviceList WRITE setDeviceList NOTIFY deviceListChanged)
public:
explicit Conf(QObject *parent = nullptr);
QStringList deviceList();
Q_INVOKABLE void setDeviceList(QStringList deviceList);
Q_SIGNAL void deviceListChanged();
Q_SIGNALS:
private:
QStringList m_deviceList = {QString::fromStdString("nullptr"), QString::fromStdString("bsd")};
};
#endif

View file

@ -8,100 +8,16 @@
#include <QtQml>
#include <libusb-1.0/libusb.h>
#include <iostream>
#include <structs.h>
#include <QObject>
#include <QQmlContext>
#include <QString>
#include <string>
struct keystuff
{
char type; // 0x21 -> keycode
char _mods : 4;
char mods : 4; // 1111 -> all 4 mods
};
struct col_rgb
{
uint8_t r;
uint8_t g;
uint8_t b;
};
struct dpi
{
uint16_t a;
uint16_t b;
uint16_t c;
uint16_t d;
uint16_t e;
};
struct col_7
{
col_rgb a;
col_rgb b;
col_rgb c;
col_rgb d;
col_rgb e;
col_rgb f;
col_rgb g;
};
struct conf_1
{
uint8_t __u1; // 0x00 0x08
uint8_t con; // wireless 21 wired 11
uint8_t __u2; // 0x02 zero
uint8_t req_type; // 0x92, 0x50 maybe for if write or read 0x00
uint8_t __u3[0x8 - 0x4]; // 0x04-0x07 zeroes
uint8_t __64; // 0x08
uint8_t profile; // 0x17 profile 1, 0x01 profile 2
uint8_t polling_rate; // 0x0a, 0x01-0x04->[125,250,500,1000]
uint8_t dpi_modes; // 0x0b, 0x11-0x15 erste 4 welches ist aktiv? dann welhce für conf??
uint8_t __u4; // 0x0c zero
dpi hdpi; // 0x0 0x0d-0x16 jeweils 2 byte most significant byte last, * 50 -> annäherung an dpi -50
uint8_t __u5[0x44 - 0x17]; // 0x17 - 0x44 ????? zeros
uint8_t light_mode; // 0x45 Lighting Mode, 02 Steady, 01 Colorful Streaming, 03 Breathing
uint8_t col_brightness_speed; // 0x46 0-4 Brightness und 0-4 Speed bei colorful 0x(br)(sp)
uint8_t __u8; // 0x47 ???
uint8_t st_brightness_colnr; // 0x48 Brightness und colnr bei steady 0x(br)(colnr)
uint8_t __u9; // 0x49-0x4b ???
uint8_t __u10;
uint8_t __u11;
uint8_t br_brightness_speed; // 0x4c 0-4 Brightness und 0-4 Speed bei breathing 0x(br)(sp)
uint8_t __u12; // 0x4d ??
col_7 col_breathing; // 0x4e-0x62Bei Breathing RGB * 7
uint32_t __u13; // 0x63-066 ??
col_7 col_steady; // 0x67-0x7a Bei Steady RGB * 7
uint8_t __rest[397]; // ????
};
struct key_conf
{
uint8_t pref;
uint8_t mod;
uint8_t keycode;
uint8_t __u1;
};
struct conf_2
{
uint8_t __u1; // 0x00 0x08
uint8_t con; // wireless 22 wired 12
uint8_t __u2; // 0x02 zero
uint8_t req_type; // 0x92, 0x50 maybe for if write or read 0x00
uint8_t __u3[0x8 - 0x4]; // 0x04-0x07 zeroes
key_conf l_mouse; // 0x08-0x0b 4 Byte für linke Maustaste
key_conf r_mouse; // 0x0c-0x0f 4 Byte für rechte Maustaste
key_conf m_mouse; // 0x10-0x13 4 Byte für Mausrad taste
key_conf b_mouse; // 0x14-0x17 4 Byte für taste 13, Zurück Taste, über taste 5,6
key_conf f_mouse; // 0x18-0x1b 4 Byte für taste 12, Forward Taste, über taste 2,4
key_conf m_mouse_1; // 0x1c-0x1f 4 Byte für taste 14, 1. über mausrad
key_conf m_mouse_2; // 0x20-0x23 4 Byte für taste 15, 2. über mausrad
uint32_t __u4; // 0x24-0x27 zeros
key_conf side[8]; // Jeweils 4 Byte (3 Sicher) für die Belegung der Tasten 1-8 an der Seite
uint8_t __u5[0x207 - 0x47]; // 0x48-0x58 ?? 0x58-end zeros
};
#include "conf.h"
int main(int argc, char *argv[])
{
unsigned char data[520];
unsigned char data2[520];
unsigned char deviceData[520];
@ -116,6 +32,8 @@ int main(int argc, char *argv[])
QApplication::setApplicationName(QStringLiteral("Kirigami Tutorial"));
QApplication::setDesktopFileName(QStringLiteral("org.kde.tutorial"));
QApplication::setStyle(QStringLiteral("breeze"));
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE"))
{
@ -124,9 +42,15 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine;
Conf backend;
qmlRegisterSingletonInstance<Conf>("CustomComponents", 1, 0, "Conf", &backend);
qmlRegisterType<Conf>("CustomComponents", 1, 0, "Test");
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
engine.loadFromModule("org.kde.tutorial", "Main");
if (engine.rootObjects().isEmpty())
{
return -1;
@ -157,8 +81,7 @@ int main(int argc, char *argv[])
std::cout << "Bus " << unsigned(bus) << " Device " << unsigned(addr) << ": ID " << std::hex << desc.idVendor << ":" << desc.idProduct << std::dec << std::endl;
if (desc.idProduct == 0x2f && desc.idVendor == 0x258a)
{
std::cout << "test" << std::endl;
std::cout << std::hex << (int)(desc.bNumConfigurations) << std::endl;
// std::cout << std::hex << (int)(desc.bNumConfigurations) << std::endl;
break;
}
}
@ -190,8 +113,12 @@ int main(int argc, char *argv[])
_data->light_mode = 0x2;
_data->req_type = 0x92;
_data->st_brightness_colnr = {0x16};
std::cout << std::endl;
std::cout << std::endl;
_data->col_steady[18] = 0x00;
_data->col_steady[19] = 0xff;
_data->col_steady[20] = 0xff;
_data->col_breathing[0] = 0xff;
_data->col_breathing[1] = 0xff;
_data->col_breathing[2] = 0x00;
memset(send_data0, 0, 8 * sizeof(unsigned char));
send_data0[0] = 0x05;
@ -229,14 +156,16 @@ int main(int argc, char *argv[])
if ((r = libusb_control_transfer(handle, 0xa1, 0x01, 0x0308, 1, deviceData, 520, 5000)) < 0)
std::cout << "libusb_control_transfer2: " << libusb_error_name(r) << std::endl;
if ((r = libusb_release_interface(handle, 1)) < 0)
std::cout << "libusb_release_interface: " << libusb_error_name(r) << std::endl;
if ((r = libusb_attach_kernel_driver(handle, 1)) < 0)
std::cout << "libusb_attach_kernel_driver: " << libusb_error_name(r) << std::endl;
libusb_close(handle);
libusb_free_device_list(list, 1);
return app.exec();
}

64
src/structs.h Normal file
View file

@ -0,0 +1,64 @@
#ifndef STRUCTS_H
#define STRUCTS_H
#include <cstdint>
struct conf_1
{
uint8_t __u1; // 0x00 0x08
uint8_t con; // wireless 21 wired 11
uint8_t __u2; // 0x02 zero
uint8_t req_type; // 0x92, 0x50 maybe for if write or read 0x00
uint8_t __u3[0x8 - 0x4]; // 0x04-0x07 zeroes
uint8_t __64; // 0x08 0x64
uint8_t profile; // 0x17 profile 1, 0x01 profile 2
uint8_t polling_rate; // 0x0a, 0x01-0x04->[125,250,500,1000]
uint8_t dpi_modes; // 0x0b, 0x11-0x15 erste 4 welches ist aktiv? dann welhce für conf??
uint8_t __u4; // 0x0c zero
uint8_t hdpi[10]; // 0x0 0x0d-0x16 jeweils 2 byte most significant byte last, * 50 -> annäherung an dpi -50
uint8_t __u5[0x44 - 0x17]; // 0x17 - 0x44 ????? zeros
uint8_t light_mode; // 0x45 Lighting Mode, 02 Steady, 01 Colorful Streaming, 03 Breathing
uint8_t col_brightness_speed; // 0x46 0-4 Brightness und 0-4 Speed bei colorful 0x(br)(sp)
uint8_t __u8; // 0x47 ???
uint8_t st_brightness_colnr; // 0x48 Brightness und colnr bei steady 0x(br)(colnr)
uint8_t __u9[3]; // 0x49-0x4b ???
uint8_t br_brightness_speed; // 0x4c 0-4 Brightness und 0-4 Speed bei breathing 0x(br)(sp)
uint8_t __u12; // 0x4d ??
uint8_t col_breathing[21]; // 0x4e-0x62 Bei Breathing RGB * 7
uint8_t __u10[3]; // 0x63-065 ??
uint8_t col_steady[21]; // 0x66-0x7a Bei Steady RGB * 7
uint8_t __rest[0x207 - 0x7a]; // ????
};
struct key_conf
{
uint8_t pref;
uint8_t mod;
uint8_t keycode;
uint8_t __u1;
};
struct conf_2
{
uint8_t __u1; // 0x00 0x08
uint8_t con; // wireless 22 wired 12
uint8_t __u2; // 0x02 zero
uint8_t req_type; // 0x92, 0x50 maybe for if write or read 0x00
uint8_t __u3[0x8 - 0x4]; // 0x04-0x07 zeroes
key_conf l_mouse; // 0x08-0x0b 4 Byte für linke Maustaste
key_conf r_mouse; // 0x0c-0x0f 4 Byte für rechte Maustaste
key_conf m_mouse; // 0x10-0x13 4 Byte für Mausrad taste
key_conf b_mouse; // 0x14-0x17 4 Byte für taste 13, Zurück Taste, über taste 5,6
key_conf f_mouse; // 0x18-0x1b 4 Byte für taste 12, Forward Taste, über taste 2,4
key_conf m_mouse_1; // 0x1c-0x1f 4 Byte für taste 14, 1. über mausrad
key_conf m_mouse_2; // 0x20-0x23 4 Byte für taste 15, 2. über mausrad
uint8_t __u4[4]; // 0x24-0x27 zeros
key_conf side[8]; // Jeweils 4 Byte (3 Sicher) für die Belegung der Tasten 1-8 an der Seite
uint8_t __u5[0x207 - 0x47]; // 0x48-0x58 ?? 0x58-end zeros
};
struct macro {
};
#endif

44
src/test.cpp Normal file
View file

@ -0,0 +1,44 @@
#include "test.h"
DataEntryModel::DataEntryModel(QObject *parent)
: QAbstractListModel(parent)
{
// initialize our data (QList<QString>) with a list of color names
m_data = QColor::colorNames();
}
DataEntryModel::~DataEntryModel()
{
}
int DataEntryModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
// return our data count
return m_data.count();
}
QVariant DataEntryModel::data(const QModelIndex &index, int role) const
{
// the index returns the requested row and column information.
// we ignore the column and only use the row information
int row = index.row();
// boundary check for the row
if(row < 0 || row >= m_data.count()) {
return QVariant();
}
// A model can return data for different roles.
// The default role is the display role.
// it can be accesses in QML with "model.display"
switch(role) {
case Qt::DisplayRole:
// Return the color name for the particular row
// Qt automatically converts it to the QVariant type
return m_data.value(row);
}
// The view asked for other data, just return an empty QVariant
return QVariant();
}

21
src/test.h Normal file
View file

@ -0,0 +1,21 @@
#ifndef DATAENTRYMODEL_H
#define DATAENTRYMODEL_H
#include <QtCore>
#include <QtGui>
class DataEntryModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit DataEntryModel(QObject *parent = 0);
~DataEntryModel();
public: // QAbstractItemModel interface
virtual int rowCount(const QModelIndex &parent) const;
virtual QVariant data(const QModelIndex &index, int role) const;
private:
QList<QString> m_data;
};
#endif // DATAENTRYMODEL_H