fix warnings, setButton, getButton

This commit is contained in:
Denis Manherz 2024-09-02 20:59:03 +02:00
parent c1fc9140a7
commit 6b154d7f7b
5 changed files with 88 additions and 136 deletions

View file

@ -23,3 +23,5 @@ setButton could be accepting multiple keybardkeys max 2
test le _keyboardKeys
multimedia keys working on windows but not on linux for some reason
if u bind media keys from _keyboardKeys in le_buttons.cpp its working dont know what the other keycodes are about maybe only specific for windows??

View file

@ -141,7 +141,6 @@ ssize_t A811::setDPI(DPI_MODE mode, unsigned char color[3], int dpi, int active)
uint8_t lsb = dpi_value & 0xFF; // Extract the least significant byte
uint8_t msb = (dpi_value >> 8) & 0xFF; // Extract the most significant byte
_conf12->c1.dpi_modes = // number of active modes
(1 & 0x0f) << 4 | ((active & 0x0F));
@ -167,7 +166,7 @@ int A811::getDPI(DPI_MODE mode)
uint8_t msb = _conf12->c1.hdpi[((uint8_t)mode - 1) * 2 + 1];
// Reconstruct the dpi_value
uint16_t dpi_value = msb << 8 | lsb & 0xFF;
uint16_t dpi_value = msb << 8 | (lsb & 0xFF);
std::cout << std::hex << dpi_value << " : " << (int)lsb << " : " << (int)msb << std::endl;
@ -214,25 +213,24 @@ ssize_t A811::setMultimediaButton(int id, std::string keyname)
for (int i = 0; i < (int)sizeof(_conf12->c2.mouse_buttons[id]); ++i)
{
std::cout << std::hex << (int)mahbytes[i] << "|";
mahbytes[i] = ((unsigned char *)&arr)[i];
std::cout << std::hex << (int)mahbytes[i] << std::endl;
}
}
else if (id >= 7 && id < 15)
{
// Assuming keyname is a valid key in the _keycodes map
auto it = _keycodes.find(keyname);
if (it != _keycodes.end())
{
const std::array<uint8_t, 4> &keycode_array = it->second; // Get the array from the map
// std::copy(keycode_array.begin(), keycode_array.end(), _conf12->c2.side[id - 7].keycode);
}
else
if (_keycodes.find(keyname) == _keycodes.end())
{
logError("ERROR: Keyname not found in keycodes.", __FILE__, __LINE__, __func__);
return ssize_t(1); // or handle the error appropriately
}
auto arr = _keycodes[keyname];
unsigned char *mahbytes = (unsigned char *)&_conf12->c2.side[id - 7];
for (int i = 0; i < (int)sizeof(_conf12->c2.mouse_buttons[id]); ++i)
{
mahbytes[i] = ((unsigned char *)&arr)[i];
}
}
else
{
@ -243,7 +241,7 @@ ssize_t A811::setMultimediaButton(int id, std::string keyname)
return ssize_t(0);
}
ssize_t A811::setMacroButton(int id, int macro_id, int cycle_type, int cycle_cnt)
ssize_t A811::setMacroButton(int id, uint8_t macro_id, uint8_t cycle_type, uint8_t cycle_cnt)
{
unsigned char keyConf[4] = {0x70, macro_id, cycle_type, cycle_cnt};
@ -298,7 +296,7 @@ ssize_t A811::setButton(int id, std::string keyboardKey, int mod)
{
key[2] = it->second;
key[3] = 0x00; // optional button
memcpy(&_conf12->c2.side[id], key, sizeof(_conf12->c2.side[id]));
memcpy(&_conf12->c2.side[id - 7], key, sizeof(_conf12->c2.side[id]));
}
else
{
@ -319,14 +317,18 @@ _r_button A811::getButton(int id)
{
_r_button b;
/*
if (id >= 0 && id < 7){
if (id >= 0 && id < 7)
{
// Assuming keyname is a valid key in the _keycodes map
auto it = _buttonNames.find(id);
if (it != _buttonNames.end()) {
if (it != _buttonNames.end())
{
b.name = it->second;
} else {
}
else
{
logError("ERROR: Button name not found in _buttonNames.", __FILE__, __LINE__, __func__);
// Handle the error appropriately, e.g., returning an empty _r_button
return _r_button(); // Return empty or error _r_button
@ -335,10 +337,13 @@ _r_button A811::getButton(int id)
else if (id >= 7 && id < 15)
{
// Assuming keyname is a valid key in the _keycodes map
auto it = _buttonNames.find(id-7);
if (it != _buttonNames.end()) {
auto it = _buttonNames.find(id);
if (it != _buttonNames.end())
{
b.name = it->second;
} else {
}
else
{
logError("ERROR: Button name not found in _buttonNames.", __FILE__, __LINE__, __func__);
// Handle the error appropriately, e.g., returning an empty _r_button
return _r_button(); // Return empty or error _r_button
@ -348,7 +353,7 @@ _r_button A811::getButton(int id)
{
logError("ERROR: Invalid button id.", __FILE__, __LINE__, __func__);
}
*/
return _r_button();
}

View file

@ -229,7 +229,7 @@ public:
* @return ssize_t Returns the status of the operation, where 0 indicates
* success and a negative value indicates failure.
*/
ssize_t setMacroButton(int, int, int, int);
ssize_t setMacroButton(int, uint8_t, uint8_t, uint8_t);
/**
* @brief Assign a simple keyboard key w/o modifier to a button.
*

View file

@ -17,6 +17,8 @@ Conf::Conf(QObject *parent) : QObject(parent)
memset(m_conf1, 0, sizeof(conf_1));
memset(m_conf2, 0, sizeof(conf_2));
m_mouse = new A811();
connection = &(Connection::getInstance());
if (connection->findDevice())
{
@ -124,8 +126,6 @@ void Conf::testFunc()
asd->writeConfigToDevice(CONF_TYPE::LIGHT);
asd->setUSBPollingRate(POLLING_RATE::P_1000);
std::cout << "UBS Polling rate: " << (int)asd->getUSBPollingRate() << std::endl;
std::cout << "BATTERYSTATUS: " << (int)asd->getBatteryStatus() << std::endl;
std::cout << "LIGHTMODE: " << (int)asd->getLightMode() << std::endl;
@ -135,36 +135,52 @@ void Conf::testFunc()
sleep(2);
asd->setMultimediaButton(2, "media_volume_up");
// does not work for some reason
asd->setMultimediaButton(6, "dpi-cycle");
asd->setButton(7, "Volume_Up", 0);
asd->setButton(8, "b", 2);
asd->setButton(9, "c", 4);
asd->setButton(10, "d", 8);
asd->setButton(11, "e", 3);
asd->setButton(12, "f", 5);
asd->setButton(13, "g", 7);
asd->setButton(14, "h", 9);
// dont know if every keycode is working
int bid = 0;
std::cout << "Button " << bid << asd->getButton(bid).name << std::endl;
asd->writeConfigToDevice(CONF_TYPE::KEY);
std::cout << asd->getButton(3).name << std::endl;
asd->setLightMode(LIGHT_MODE::BREATHING, 4, 4);
unsigned char *cols;
cols = asd->getLightModeColors(LIGHT_MODE::BREATHING);
for (int i = 0; i < 21; i++)
{
std::cout << cols[i];
}
std::cout << std::endl;
asd->getLightModeColors(LIGHT_MODE::COLORFUL_STREAMING);
unsigned char cols2[21] = {0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00};
asd->setLightModeColors(LIGHT_MODE::BREATHING, cols2);
unsigned char cols3[3] = {0xff, 0x00, 0x00};
asd->setDPI(DPI_MODE::DPI_1, cols3, 26000, 5);
asd->setDPI(DPI_MODE::DPI_1, cols3, 800, 5);
cols3[0] = 0x0;
cols3[1] = 0xff;
asd->setDPI(DPI_MODE::DPI_2, cols3, 800, 5);
asd->setDPI(DPI_MODE::DPI_2, cols3, 1000, 5);
cols3[1] = 0x0;
cols3[2] = 0xff;
asd->setDPI(DPI_MODE::DPI_3, cols3, 1600, 5);
asd->setDPI(DPI_MODE::DPI_3, cols3, 1200, 5);
cols3[0] = 0xff;
cols3[2] = 0xff;
asd->setDPI(DPI_MODE::DPI_4, cols3, 3200, 5);
asd->setDPI(DPI_MODE::DPI_4, cols3, 1400, 5);
cols3[0] = 0xff;
cols3[1] = 0xff;
cols3[2] = 0xff;
asd->setDPI(DPI_MODE::DPI_5, cols3, 26000, 5);
asd->setDPI(DPI_MODE::DPI_5, cols3, 1500, 5);
// asd->writeConfigToDevice(CONF_TYPE::KEY);
std::cout << "DPI at this: " << asd->getDPI(DPI_MODE::DPI_1) << std::endl;
@ -193,29 +209,6 @@ ssize_t Conf::restoreConfigs()
return 0;
}
ssize_t Conf::deviceConfig()
{
unsigned char _data[8] = {0x05, 0x22, 0, 0, 0, 0, 0, 0};
/*if(!connection->isWireless())
_data[1] = 0x12;*/
ssize_t r;
CHK(connection->open());
CHK(connection->setReport(0x0305, (unsigned char *)_data, 8));
CHK(connection->getReport(0x0308, (unsigned char *)0x0, 520));
CHK(connection->close());
return 0;
}
void Conf::setDeviceConfig(ssize_t stat)
{
std::cout << "Setting new conf" << std::endl;
writeConfigToDevice(m_conf1);
writeConfigToDevice(m_conf2);
Q_EMIT deviceConfigChanged();
}
ssize_t Conf::writeConfigToFile(const char *filePath)
{
FILE *outfile;
@ -273,12 +266,6 @@ ssize_t Conf::writeConfigToDevice(conf_1 *conf)
CHK(connection->setReport(0x0308, (unsigned char *)conf, 520));
CHK(connection->close());
for (int i = 0; i < (0x44 - 0x16); i++)
{
std::cout << std::hex << (int)conf->__u5[i] << "\t";
}
std::cout << std::endl;
return 0;
}
@ -297,40 +284,9 @@ ssize_t Conf::readConfigFromDevice(conf_2 *conf)
return 0;
}
ssize_t Conf::batteryStatus()
{
unsigned char dat[8];
memset(dat, 0, 8 * sizeof(unsigned char));
unsigned char _data[8] = {0x05, 0x90, 0, 0, 0, 0, 0, 0};
ssize_t r;
CHK(connection->open());
CHK(connection->setReport(0x0305, (unsigned char *)_data, 8));
CHK(connection->getReport(0x0305, (unsigned char *)dat, 8));
CHK(connection->close());
for (int i = 0; i < 16; i++)
{
std::cout << std::hex << (int)dat[i] << "\t";
}
std::cout << std::endl;
if (dat[2] == 0x10 && dat[3] == 0x01)
return -1;
return (int)dat[3];
}
void Conf::setBatteryStatus(ssize_t bat)
{
m_bat = batteryStatus();
Q_EMIT batteryStatusChanged();
}
ssize_t Conf::readMacroFromDevice(macro *_macro, int id)
{
if (id > 255)
if (id > (uint8_t)255)
{
std::cout << "No more than 255 macros on device" << std::endl;
return -1;
@ -338,7 +294,7 @@ ssize_t Conf::readMacroFromDevice(macro *_macro, int id)
memset(_macro, 0, 520 * sizeof(unsigned char));
unsigned char _data[8] = {0x05, 0x31, id, 0, 0, 0, 0, 0};
unsigned char _data[8] = {0x05, 0x31, (uint8_t)id, 0, 0, 0, 0, 0};
ssize_t r;
CHK(connection->open());
@ -436,12 +392,6 @@ ssize_t Conf::readConfigFromDevice(conf_1 *conf)
CHK(connection->getReport(0x0308, (unsigned char *)conf, 520));
CHK(connection->close());
for (int i = 0; i < (0x44 - 0x16); i++)
{
std::cout << std::hex << (int)conf->__u5[i] << "\t";
}
std::cout << std::endl;
return ssize_t(0);
}
@ -488,16 +438,17 @@ ssize_t Conf::readConfigFromFile(const char *filePath, conf_1 *conf)
if (infile == NULL)
{
fprintf(stderr, "\nError opening file\n");
exit(1);
return ssize_t(1);
}
// reading to read_struct
fread(conf, sizeof(struct conf_1), 1, infile);
if (sizeof(struct conf_1) > fread(conf, sizeof(struct conf_1), 1, infile))
fprintf(stderr, "\nError file\n");
// close file
fclose(infile);
return 0;
return ssize_t(0);
}
ssize_t Conf::readConfigFromFile(const char *filePath, conf_2 *conf)
@ -509,16 +460,17 @@ ssize_t Conf::readConfigFromFile(const char *filePath, conf_2 *conf)
if (infile == NULL)
{
fprintf(stderr, "\nError opening file\n");
exit(1);
return ssize_t(1);
}
// reading to read_struct
fread(conf, sizeof(struct conf_2), 1, infile);
if (sizeof(struct conf_2) > fread(conf, sizeof(struct conf_2), 1, infile))
fprintf(stderr, "\nError file\n");
// close file
fclose(infile);
return 0;
return ssize_t(0);
}
ssize_t Conf::readConfigFromFile(const char *filePath)
@ -529,11 +481,12 @@ ssize_t Conf::readConfigFromFile(const char *filePath)
if (infile == NULL)
{
fprintf(stderr, "\nError opening file\n");
exit(1);
return ssize_t(1);
}
fread(m_conf1, sizeof(struct conf_1), 1, infile);
fread(m_conf2, sizeof(struct conf_2), 1, infile);
if (sizeof(struct conf_1) > fread(m_conf1, sizeof(struct conf_1), 1, infile) ||
sizeof(struct conf_2) > fread(m_conf2, sizeof(struct conf_2), 1, infile))
fprintf(stderr, "\nError file\n");
fclose(infile);
return 0;

View file

@ -21,15 +21,10 @@
class Conf : public QObject
{
Q_OBJECT
Q_PROPERTY(ssize_t deviceConfig READ deviceConfig WRITE setDeviceConfig NOTIFY deviceConfigChanged)
Q_PROPERTY(int lightMode READ lightMode WRITE setLightMode NOTIFY lightModeChanged)
Q_PROPERTY(ssize_t batteryStatus READ batteryStatus WRITE setBatteryStatus NOTIFY batteryStatusChanged)
public:
explicit Conf(QObject *parent = nullptr);
ssize_t deviceConfig();
Q_INVOKABLE void setDeviceConfig(ssize_t stat);
Q_SIGNAL void deviceConfigChanged();
int lightMode();
Q_INVOKABLE void setLightMode(int mode);
@ -63,16 +58,13 @@ public:
Q_INVOKABLE ssize_t appendMacroToFile(macro *_macro, const char *filePath);
Q_INVOKABLE ssize_t deleteMacroFromFile(macro *_macro, const char *filePath);
ssize_t batteryStatus();
Q_INVOKABLE void setBatteryStatus(ssize_t bat);
Q_SIGNAL void batteryStatusChanged();
Q_INVOKABLE void testFunc();
Q_SIGNALS:
private:
macro **m_macros;
A811 *m_mouse;
ssize_t m_stat;
ssize_t m_bat;
int m_lightMode;