mirror of
https://github.com/PixlOne/logiops.git
synced 2025-07-14 13:22:33 +08:00
Add Logi Bolt support
This commit is contained in:
parent
f2fd967865
commit
e50e566f20
@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <backend/hidpp10/Receiver.h>
|
#include <backend/hidpp10/Receiver.h>
|
||||||
#include <backend/hidpp10/Error.h>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
using namespace logid::backend::hidpp10;
|
using namespace logid::backend::hidpp10;
|
||||||
@ -36,6 +35,9 @@ Receiver::Receiver(const std::string& path, const std::shared_ptr<raw::DeviceMon
|
|||||||
if (e.code() == Error::InvalidAddress)
|
if (e.code() == Error::InvalidAddress)
|
||||||
throw InvalidReceiver();
|
throw InvalidReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: is there a better way of checking if this is a bolt receiver?
|
||||||
|
_is_bolt = pid() == 0xc548;
|
||||||
}
|
}
|
||||||
|
|
||||||
Receiver::NotificationFlags Receiver::getNotificationFlags() {
|
Receiver::NotificationFlags Receiver::getNotificationFlags() {
|
||||||
@ -118,6 +120,7 @@ struct Receiver::PairingInfo
|
|||||||
Receiver::getPairingInfo(hidpp::DeviceIndex index) {
|
Receiver::getPairingInfo(hidpp::DeviceIndex index) {
|
||||||
std::vector<uint8_t> request(1);
|
std::vector<uint8_t> request(1);
|
||||||
request[0] = index;
|
request[0] = index;
|
||||||
|
if (!_is_bolt)
|
||||||
request[0] += 0x1f;
|
request[0] += 0x1f;
|
||||||
|
|
||||||
auto response = getRegister(PairingInfo, request, hidpp::ReportType::Long);
|
auto response = getRegister(PairingInfo, request, hidpp::ReportType::Long);
|
||||||
@ -136,6 +139,9 @@ struct Receiver::ExtendedPairingInfo
|
|||||||
Receiver::getExtendedPairingInfo(hidpp::DeviceIndex index) {
|
Receiver::getExtendedPairingInfo(hidpp::DeviceIndex index) {
|
||||||
std::vector<uint8_t> request(1);
|
std::vector<uint8_t> request(1);
|
||||||
request[0] = index;
|
request[0] = index;
|
||||||
|
if (_is_bolt)
|
||||||
|
request[0] += 0x50;
|
||||||
|
else
|
||||||
request[0] += 0x2f;
|
request[0] += 0x2f;
|
||||||
|
|
||||||
auto response = getRegister(PairingInfo, request, hidpp::ReportType::Long);
|
auto response = getRegister(PairingInfo, request, hidpp::ReportType::Long);
|
||||||
@ -159,19 +165,48 @@ Receiver::getExtendedPairingInfo(hidpp::DeviceIndex index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string Receiver::getDeviceName(hidpp::DeviceIndex index) {
|
std::string Receiver::getDeviceName(hidpp::DeviceIndex index) {
|
||||||
std::vector<uint8_t> request(1);
|
std::vector<uint8_t> request(2);
|
||||||
|
std::string name;
|
||||||
request[0] = index;
|
request[0] = index;
|
||||||
|
if (_is_bolt) {
|
||||||
|
/* Undocumented, deduced the following
|
||||||
|
* param 1 refers to part of string, 1-indexed
|
||||||
|
*
|
||||||
|
* response at 0x01 is [reg] [param 1] [size] [str...]
|
||||||
|
* response at 0x02-... is [next part of str...]
|
||||||
|
*/
|
||||||
|
request[1] = 0x01;
|
||||||
|
|
||||||
|
auto resp = getRegister(PairingInfo, request, hidpp::ReportType::Long);
|
||||||
|
const uint8_t size = resp[2];
|
||||||
|
const uint8_t chunk_size = resp.size() - 3;
|
||||||
|
const uint8_t chunks = size/chunk_size + (size % chunk_size ? 1 : 0);
|
||||||
|
|
||||||
|
name.resize(size, ' ');
|
||||||
|
for (int i = 0; i < chunks; ++i) {
|
||||||
|
for (int j = 0; j < chunk_size; ++j) {
|
||||||
|
name[i*chunk_size + j] = (char)resp[j + 3];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i < chunks - 1) {
|
||||||
|
request[1] = i+1;
|
||||||
|
resp = getRegister(PairingInfo, request, hidpp::ReportType::Long);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
request[0] += 0x3f;
|
request[0] += 0x3f;
|
||||||
|
|
||||||
auto response = getRegister(PairingInfo, request, hidpp::ReportType::Long);
|
auto response = getRegister(PairingInfo, request, hidpp::ReportType::Long);
|
||||||
|
|
||||||
uint8_t size = response[1];
|
const uint8_t size = response[1];
|
||||||
assert(size <= 14);
|
|
||||||
|
|
||||||
std::string name(size, ' ');
|
name.resize(size, ' ');
|
||||||
for (std::size_t i = 0; i < size; i++)
|
for (std::size_t i = 0; i < size && i + 2 < response.size(); i++)
|
||||||
name[i] = (char) (response[i + 2]);
|
name[i] = (char) (response[i + 2]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +140,9 @@ namespace logid::backend::hidpp10 {
|
|||||||
static hidpp::DeviceIndex deviceDisconnectionEvent(const hidpp::Report& report);
|
static hidpp::DeviceIndex deviceDisconnectionEvent(const hidpp::Report& report);
|
||||||
|
|
||||||
static hidpp::DeviceConnectionEvent deviceConnectionEvent(const hidpp::Report& report);
|
static hidpp::DeviceConnectionEvent deviceConnectionEvent(const hidpp::Report& report);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool _is_bolt = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user