Compare commits

..

2 commits

Author SHA1 Message Date
Denis Manherz 42520f3399 some idea from the bro 2024-09-02 23:14:00 +02:00
Denis Manherz 6b154d7f7b fix warnings, setButton, getButton 2024-09-02 20:59:03 +02:00
6 changed files with 319 additions and 387 deletions

View file

@ -22,4 +22,6 @@ setButton could be accepting multiple keybardkeys max 2
test le _keyboardKeys
multimedia keys working on windows but not on linux for some reason
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

@ -0,0 +1,48 @@
conf_12 check:
class datacheck:
type : (type?, [0,...,3], {2, 7, 19}, <x, >x)
length
funcptr
datachekc(type, typedef, length, ptr):
funcpotr = ptr
check(*data):
actdata = funcpotr(data)
switch(type):
case a: return actdata > typedef[0]
case b: return (actdata > typedef[0]) && (actdata < typedef[1])
map [pos] -> datacheck(0, [0,7], 16, (data) => return (data << 4) | (data >> 4))
map [pos+16] -> datacheck(0, [0,7], 16, (data) => return (data << 4) | (data >> 4))
map [pos] -> datacheck(1, [0], 8*16, (data) => uint8_t x = 0; for (int i = 0; i < 16; ++i) x | data[i]; return !x;)
func a(pos):
return map[pos]
pos not per byte but bit
a(pos).check
confch3ck():
isok = True
extralen = 0
chk;
for(int i = 0; i < (int)sizeof(conf_12) * 8;):
chk = map[i]
res = chk.check(&(((unsigned char *)conf_12)[i]))
i+=chk.length;
if not res:
isok = False
break;
if chk.type == set;
print("is fucked at byte x / bit y with length chk.length it is not part of set [chk.typedef]")

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,39 +317,147 @@ _r_button A811::getButton(int id)
{
_r_button b;
/*
if (id >= 0 && id < 7){
// Assuming keyname is a valid key in the _keycodes map
auto it = _buttonNames.find(id);
if (it != _buttonNames.end()) {
b.name = it->second;
} 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
}
}
else if (id >= 7 && id < 15)
if (id >= 0 && id < 7)
{
// Assuming keyname is a valid key in the _keycodes map
auto it = _buttonNames.find(id);
if (it != _buttonNames.end())
{
// Assuming keyname is a valid key in the _keycodes map
auto it = _buttonNames.find(id-7);
if (it != _buttonNames.end()) {
b.name = it->second;
} 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
}
b.name = it->second;
}
else
{
logError("ERROR: Invalid button id.", __FILE__, __LINE__, __func__);
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
}
*/
}
else if (id >= 7 && id < 15)
{
// Assuming keyname is a valid key in the _keycodes map
auto it = _buttonNames.find(id);
if (it != _buttonNames.end())
{
b.name = it->second;
}
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
}
}
else
{
logError("ERROR: Invalid button id.", __FILE__, __LINE__, __func__);
}
return _r_button();
}
ssize_t A811::readMacrosFromDevice(int cnt)
{
if (cnt > 255)
{
std::cout << "No more than 255 macros on device" << std::endl;
return ssize_t(1);
}
_macros = (macro **)malloc(cnt * sizeof(macro *));
_connection->open();
_connection->keepConnection(true);
for (int i = 1; i <= cnt; i++)
{
// get macro
// ist das bissl kacke weil immer neuer handle und detach und attach hmm
_macros[i - 1] = (macro *)malloc(sizeof(macro));
readMacroFromDevice(_macros[i - 1], i);
}
_connection->keepConnection(false);
_connection->close();
// check if any macros are read or if any empty macros are read
// maybe just read all possible macros
// or this function is actually completely useless just keep track of the macros in the gui code
return ssize_t(0);
}
ssize_t A811::readMacroFromDevice(macro *_macro, int id)
{
if (id > (uint8_t)255)
{
std::cout << "No more than 255 macros on device" << std::endl;
return ssize_t(0);
}
memset(_macro, 0, 520 * sizeof(unsigned char));
unsigned char _data[8] = {0x05, 0x31, (uint8_t)id, 0, 0, 0, 0, 0};
ssize_t r;
CHK(_connection->open());
CHK(_connection->setReport(0x0305, (unsigned char *)_data, 8));
CHK(_connection->getReport(0x0308, (unsigned char *)_macro, 520));
CHK(_connection->close());
// check if empty macro, if valid macro
return ssize_t(0);
}
ssize_t A811::writeMacroToDevice(macro *p_macro)
{
// conf_1
p_macro->set_report_req[0] = 0x80;
p_macro->set_report_req[1] = 0x30;
p_macro->set_report_req[2] = 0x02;
ssize_t r;
CHK(_connection->open());
CHK(_connection->setReport(0x0308, (unsigned char *)p_macro, 520));
CHK(_connection->close());
// check if macro is valid
return ssize_t(0);
}
bool A811::isIdle()
{
unsigned char conf[8];
memset(conf, 0, 8);
unsigned char _data[8] = {0x05, 0x80, 0, 0, 0, 0, 0, 0};
ssize_t r;
CHK(_connection->open());
CHK(_connection->setReport(0x0305, _data, 8));
CHK(_connection->getReport(0x0305, (unsigned char *)conf, 8));
CHK(_connection->close());
if (conf[2] == 0x0 && conf[3] == 0x1)
return true;
else if (conf[2] == 0x1 && conf[3] == 0x1)
return false;
logError("ERROR: Reading idle status.", __FILE__, __LINE__, __func__);
return false;
}
ssize_t A811::restoreConfig()
{
unsigned char _data[8] = {0x05, 0x40, 0x01, 0, 0, 0, 0, 0};
ssize_t r;
CHK(_connection->open());
CHK(_connection->setReport(0x0305, (unsigned char *)_data, 8));
CHK(_connection->close());
return ssize_t(0);
}
ssize_t A811::readConfigFromDevice(CONF_TYPE t_conf)
{
unsigned char _data[8] = {0x05, 0x21, 0, 0, 0, 0, 0, 0};

View file

@ -173,7 +173,7 @@ public:
* @param mode The mode for which to set the DPI and color values.
* @param color RGB
* @param dpi DPI value 50-26000
* @param active 1-5 how many DPI_MODE should be active.
* @param active 1-5 how many DPI_MODE should be active.
*
* @return ssize_t Returns the status of the operation, where 0 indicates
* success and a negative value indicates failure.
@ -229,7 +229,8 @@ 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.
*
@ -255,6 +256,65 @@ public:
*/
_r_button getButton(int);
/**
* @brief Read macros from the mouse.
*
* Read a specific number of macros from the mouse.
*
* @param macros where the macros should be saved.
* @param cnt how many macros should be read.
*
* @return ssize_t Returns the status of the operation, where 0 indicates
* success and a negative value indicates failure.
*/
ssize_t readMacrosFromDevice(int);
/**
* @brief Read a single macro from the mouse.
*
* Read a specific macro from the mouse.
*
* @param macro where the macro should be saved.
* @param id id of the macro.
*
* @return ssize_t Returns the status of the operation, where 0 indicates
* success and a negative value indicates failure.
*/
ssize_t readMacroFromDevice(macro *, int);
/**
* @brief Write a single macro to the mouse.
*
* Read a specific macro from the mouse.
*
* @param macro the macro to be written.
*
* @return ssize_t Returns the status of the operation, where 0 indicates
* success and a negative value indicates failure.
*/
ssize_t writeMacroToDevice(macro *);
/**
* @brief Get the idle status of the mouse.
*
* Get the idle status of the mouse.
*
* @return bool returns true if idle, false else
*/
// the error logging here is kinda weird
bool isIdle();
// should be writing a custom thingy so i know what the restored config looks like
/**
* @brief Apply standard config.
*
* Write a standard configuration to the mouse if something went wrong.
*
* @return Returns the status of the operation, where 0 indicates
* success and a negative value indicates failure.
*/
ssize_t restoreConfig();
ssize_t readConfigFromDevice(CONF_TYPE);
ssize_t writeConfigToDevice(CONF_TYPE);

View file

@ -17,16 +17,15 @@ Conf::Conf(QObject *parent) : QObject(parent)
memset(m_conf1, 0, sizeof(conf_1));
memset(m_conf2, 0, sizeof(conf_2));
connection = &(Connection::getInstance());
if (connection->findDevice())
{
std::cerr << "ERROR: device not found" << std::endl;
exit(1);
}
// read initial config from device
readConfigFromDevice(m_conf1);
readConfigFromDevice(m_conf2);
m_mouse = new A811();
}
ssize_t Conf::appendMacroToFile(macro *macro, const char *filePath)
@ -109,111 +108,77 @@ ssize_t Conf::deleteMacroFromFile(macro *_macro, const char *filePath)
void Conf::testFunc()
{
/*macro **macros;
readMacrosFromDevice(macros, 4);
for (int i = 0; i < 4; i++)
{
appendMacroToFile(macros[i], "macrofileappend");
}*/
A811 *asd = new A811();
asd->readConfigFromDevice(CONF_TYPE::BATTERY);
asd->readConfigFromDevice(CONF_TYPE::LIGHT);
asd->readConfigFromDevice(CONF_TYPE::KEY);
asd->setLightMode(LIGHT_MODE::BREATHING, 1, 4);
asd->writeConfigToDevice(CONF_TYPE::LIGHT);
asd->setUSBPollingRate(POLLING_RATE::P_1000);
m_mouse->readConfigFromDevice(CONF_TYPE::BATTERY);
m_mouse->readConfigFromDevice(CONF_TYPE::LIGHT);
m_mouse->readConfigFromDevice(CONF_TYPE::KEY);
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;
m_mouse->setLightMode(LIGHT_MODE::BREATHING, 1, 4);
m_mouse->writeConfigToDevice(CONF_TYPE::LIGHT);
m_mouse->setUSBPollingRate(POLLING_RATE::P_1000);
asd->setLightMode(LIGHT_MODE::COLORFUL_STREAMING, 1, 2);
asd->writeConfigToDevice(CONF_TYPE::LIGHT);
std::cout << "UBS Polling rate: " << (int)m_mouse->getUSBPollingRate() << std::endl;
std::cout << "BATTERYSTATUS: " << (int)m_mouse->getBatteryStatus() << std::endl;
std::cout << "LIGHTMODE: " << (int)m_mouse->getLightMode() << std::endl;
m_mouse->setLightMode(LIGHT_MODE::COLORFUL_STREAMING, 1, 2);
m_mouse->writeConfigToDevice(CONF_TYPE::LIGHT);
sleep(2);
asd->setMultimediaButton(2, "media_volume_up");
asd->setMultimediaButton(6, "dpi-cycle");
m_mouse->setMultimediaButton(2, "media_volume_up");
// does not work for some reason
m_mouse->setMultimediaButton(6, "dpi-cycle");
m_mouse->setButton(7, "Volume_Up", 0);
m_mouse->setButton(8, "b", 2);
m_mouse->setButton(9, "c", 4);
m_mouse->setButton(10, "d", 8);
m_mouse->setButton(11, "e", 3);
m_mouse->setButton(12, "f", 5);
m_mouse->setButton(13, "g", 7);
m_mouse->setButton(14, "h", 9);
// dont know if every keycode is working
int bid = 0;
std::cout << "Button " << bid << m_mouse->getButton(bid).name << std::endl;
asd->writeConfigToDevice(CONF_TYPE::KEY);
std::cout << asd->getButton(3).name << std::endl;
m_mouse->writeConfigToDevice(CONF_TYPE::KEY);
std::cout << m_mouse->getButton(3).name << std::endl;
m_mouse->setLightMode(LIGHT_MODE::BREATHING, 4, 4);
asd->setLightMode(LIGHT_MODE::BREATHING, 4, 4);
unsigned char *cols;
cols = asd->getLightModeColors(LIGHT_MODE::BREATHING);
asd->getLightModeColors(LIGHT_MODE::COLORFUL_STREAMING);
cols = m_mouse->getLightModeColors(LIGHT_MODE::BREATHING);
for (int i = 0; i < 21; i++)
{
std::cout << cols[i];
}
std::cout << std::endl;
m_mouse->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);
m_mouse->setLightModeColors(LIGHT_MODE::BREATHING, cols2);
unsigned char cols3[3] = {0xff, 0x00, 0x00};
asd->setDPI(DPI_MODE::DPI_1, cols3, 26000, 5);
m_mouse->setDPI(DPI_MODE::DPI_1, cols3, 800, 5);
cols3[0] = 0x0;
cols3[1] = 0xff;
asd->setDPI(DPI_MODE::DPI_2, cols3, 800, 5);
m_mouse->setDPI(DPI_MODE::DPI_2, cols3, 1000, 5);
cols3[1] = 0x0;
cols3[2] = 0xff;
asd->setDPI(DPI_MODE::DPI_3, cols3, 1600, 5);
m_mouse->setDPI(DPI_MODE::DPI_3, cols3, 1200, 5);
cols3[0] = 0xff;
cols3[2] = 0xff;
asd->setDPI(DPI_MODE::DPI_4, cols3, 3200, 5);
m_mouse->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->writeConfigToDevice(CONF_TYPE::KEY);
std::cout << "DPI at this: "<< asd->getDPI(DPI_MODE::DPI_1) << std::endl;
m_mouse->setDPI(DPI_MODE::DPI_5, cols3, 1500, 5);
// m_mouse->writeConfigToDevice(CONF_TYPE::KEY);
std::cout << "DPI at this: " << m_mouse->getDPI(DPI_MODE::DPI_1) << std::endl;
std::cout << "Battery capacity:" << std::dec << asd->getBatteryCapacity() << std::endl;
asd->writeConfigToDevice(CONF_TYPE::LIGHT);
}
std::cout << "Battery capacity:" << std::dec << m_mouse->getBatteryCapacity() << std::endl;
m_mouse->writeConfigToDevice(CONF_TYPE::LIGHT);
int Conf::lightMode() { return m_conf1->light_mode; }
void Conf::setLightMode(int mode)
{
m_conf1->light_mode = (unsigned char)mode;
std::cout << (int)m_conf1->light_mode << std::endl;
Q_EMIT lightModeChanged();
}
ssize_t Conf::restoreConfigs()
{
unsigned char _data[8] = {0x05, 0x40, 0x01, 0, 0, 0, 0, 0};
ssize_t r;
CHK(connection->open());
CHK(connection->setReport(0x0305, (unsigned char *)_data, 8));
CHK(connection->close());
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();
m_mouse->readMacrosFromDevice(4);
}
ssize_t Conf::writeConfigToFile(const char *filePath)
@ -254,197 +219,6 @@ ssize_t Conf::writeConfigToFile(const char *filePath)
return 0;
}
ssize_t Conf::writeConfigToDevice(conf_2 *conf)
{
ssize_t r;
CHK(connection->open());
conf->req_type = 0x50;
CHK(connection->setReport(0x0308, (unsigned char *)conf, 520));
CHK(connection->close());
return 0;
}
ssize_t Conf::writeConfigToDevice(conf_1 *conf)
{
ssize_t r;
CHK(connection->open());
conf->req_type = 0x92;
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;
}
ssize_t Conf::readConfigFromDevice(conf_2 *conf)
{
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 *)conf, 520));
CHK(connection->close());
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)
{
std::cout << "No more than 255 macros on device" << std::endl;
return -1;
}
memset(_macro, 0, 520 * sizeof(unsigned char));
unsigned char _data[8] = {0x05, 0x31, id, 0, 0, 0, 0, 0};
ssize_t r;
CHK(connection->open());
CHK(connection->setReport(0x0305, (unsigned char *)_data, 8));
CHK(connection->getReport(0x0308, (unsigned char *)_macro, 520));
CHK(connection->close());
std::cout << std::hex << (int)_macro->macro_nr << "\t";
std::cout << std::endl;
return 0;
}
ssize_t Conf::writeMacroToDevice(macro *_macro)
{
// conf_1
_macro->set_report_req[0] = 0x80;
_macro->set_report_req[1] = 0x30;
_macro->set_report_req[2] = 0x02;
ssize_t r;
CHK(connection->open());
CHK(connection->setReport(0x0308, (unsigned char *)_macro, 520));
CHK(connection->close());
return 0;
}
ssize_t Conf::readMacrosFromDevice(macro **&macros, int cnt)
{
if (cnt > 255)
{
std::cout << "No more than 255 macros on device" << std::endl;
return -1;
}
macros = (macro **)malloc(cnt * sizeof(macro *));
connection->open();
connection->keepConnection(true);
for (int i = 1; i <= cnt; i++)
{
// get macro
// ist das bissl kacke weil immer neuer handle und detach und attach hmm
macros[i - 1] = (macro *)malloc(sizeof(macro));
readMacroFromDevice(macros[i - 1], i);
}
connection->keepConnection(false);
connection->close();
return 0;
}
ssize_t Conf::readAssignedMacrosFromDevice()
{
// check all the keys for macro mod
int macroCnt = 0;
for (int i = 0; i < 8; i++)
{
if (m_conf2->side[i].pref == 0x70 ||
(m_conf2->mouse_buttons[i].pref == 0x70 && i < 6))
macroCnt++;
}
std::cout << macroCnt << std::endl;
unsigned char conf[520];
memset(conf, 0, 520 * sizeof(unsigned char));
unsigned char _data[8] = {0x05, 0x31, 1, 0, 0, 0, 0, 0};
ssize_t r;
CHK(connection->open());
for (int i = 1; i <= macroCnt; i++)
{
_data[2] = i;
CHK(connection->setReport(0x0305, _data, 8));
CHK(connection->getReport(0x0308, (unsigned char *)conf, 520));
}
CHK(connection->close());
return 0;
}
ssize_t Conf::readConfigFromDevice(conf_1 *conf)
{
unsigned char _data[8] = {0x05, 0x21, 0, 0, 0, 0, 0, 0};
/*if(!connection->isWireless())
_data[1] = 0x11;*/
ssize_t r;
CHK(connection->open());
CHK(connection->setReport(0x0305, _data, 8));
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);
}
ssize_t Conf::writeConfigToFile()
{
QString path = QFileDialog::getSaveFileName(nullptr, i18n("Save File As"));
@ -488,16 +262,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 +284,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,50 +305,17 @@ 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;
}
ssize_t Conf::getIdleStatus()
{
unsigned char conf[8] = {
0,
0,
0,
0,
0,
0,
0,
0,
};
unsigned char _data[8] = {0x05, 0x80, 0, 0, 0, 0, 0, 0};
/*if(!connection->isWireless())
_data[1] = 0x11;*/
ssize_t r;
CHK(connection->open());
CHK(connection->setReport(0x0305, _data, 8));
CHK(connection->getReport(0x0305, (unsigned char *)conf, 8));
CHK(connection->close());
std::cout << "IDLE STATUS --------------------------" << std::endl;
for (int i = 0; i < 8; i++)
{
std::cout << std::hex << (int)conf[i] << "\t";
}
std::cout << "---------------" << std::endl;
return ssize_t(0);
return ssize_t();
}
ssize_t Conf::readConfigFromFile()
{
QFileDialog dialog(nullptr);

View file

@ -21,58 +21,31 @@
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);
Q_SIGNAL void lightModeChanged();
Q_INVOKABLE ssize_t restoreConfigs();
Q_INVOKABLE ssize_t writeConfigToFile();
ssize_t writeConfigToFile(const char *filePath);
Q_INVOKABLE ssize_t readConfigFromFile();
ssize_t readConfigFromFile(const char *filePath);
ssize_t getIdleStatus();
// all the config should be in a single file
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);
ssize_t readConfigFromFile(const char *filePath, conf_2 *conf);
ssize_t writeConfigToDevice(conf_1 *conf);
ssize_t writeConfigToDevice(conf_2 *conf);
ssize_t readConfigFromDevice(conf_1 *conf);
ssize_t readConfigFromDevice(conf_2 *conf);
Q_INVOKABLE ssize_t readAssignedMacrosFromDevice();
Q_INVOKABLE ssize_t readMacrosFromDevice(macro **&macros, int cnt);
Q_INVOKABLE ssize_t readMacroFromDevice(macro *_macro, int id);
Q_INVOKABLE ssize_t writeMacroToDevice(macro *_macro);
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;