Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ sudo udevadm control --reload-rules && sudo udevadm trigger
| Logitech G431/G432/G433 | All | x | | | | | | | | | | | | | | | | | | | | | | | | |
| Logitech G930 | All | x | x | | | | | | | | | | | | | | | | | | | | | | | |
| Logitech G PRO X 2 LIGHTSPEED | All | x | x | | | x | | | | x | x | | | | | | | | | | | | | | | |
| Logitech G PRO X 3 LIGHTSPEED | All | | x | | | x | | | | | | | | | | | | | | | | | | | | |
| Logitech G PRO Series | All | x | x | | | x | | | | | | | | | | | | | | | | | | | | |
| Logitech Zone Wired/Zone 750 | All | x | | | | | | x | x | | | | | | | | | | | | | | | | | |
| Corsair Headset Device | All | x | x | x | x | | | | | | | | | | | | | | | | | | | x | | |
Expand Down
2 changes: 2 additions & 0 deletions lib/device_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "devices/logitech_g930.hpp"
#include "devices/logitech_gpro.hpp"
#include "devices/logitech_gpro_x2_lightspeed.hpp"
#include "devices/logitech_gpro_x3_lightspeed.hpp"
#include "devices/logitech_zone_wired.hpp"

// SteelSeries devices with SteelSeries protocol templates
Expand Down Expand Up @@ -128,6 +129,7 @@ void DeviceRegistry::initialize()
registerDevice(std::make_unique<LogitechG432>());
registerDevice(std::make_unique<LogitechG930>());
registerDevice(std::make_unique<LogitechGProX2Lightspeed>());
registerDevice(std::make_unique<LogitechGProX3Lightspeed>());
registerDevice(std::make_unique<LogitechGPro>());
registerDevice(std::make_unique<LogitechZoneWired>());

Expand Down
45 changes: 0 additions & 45 deletions lib/devices/logitech_g522_lightspeed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,51 +304,6 @@ class LogitechG522Lightspeed : public protocols::LogitechCenturionProtocol {
return VoicePromptsResult { .enabled = enabled };
}

/**
* @brief Build the auto-sleep write parameters: <sleep minutes> <lights dim> <lights off>.
*
* The same command also carries the two lighting inactivity timers (minutes, 0 = never),
* and the headset rejects a write without them, so keep the values that were read back.
*/
static Result<std::array<uint8_t, 3>> buildAutoSleepParams(uint8_t minutes, std::span<const uint8_t> current)
{
if (current.size() < 3) {
return DeviceError::protocolError("Unexpected G522 auto-sleep reply");
}
return std::array<uint8_t, 3> { minutes, current[1], current[2] };
}

Result<InactiveTimeResult> setInactiveTime(hid_device* device_handle, uint8_t minutes) override
{
auto current = sendCenturionFeatureRequest(
device_handle,
static_cast<uint16_t>(protocols::CenturionFeature::CenturionAutoSleep),
0x00);
if (!current) {
return current.error();
}

auto params = buildAutoSleepParams(minutes, *current);
if (!params) {
return params.error();
}

if (auto write_result = sendCenturionFeatureRequest(
device_handle,
static_cast<uint16_t>(protocols::CenturionFeature::CenturionAutoSleep),
0x10,
*params);
!write_result) {
return write_result.error();
}

return InactiveTimeResult {
.minutes = minutes,
.min_minutes = 0,
.max_minutes = 90
};
}

Result<MicMuteLedBrightnessResult> setMicMuteLedBrightness(hid_device* device_handle, uint8_t brightness) override
{
uint8_t mute_led = static_cast<uint8_t>(static_cast<bool>(brightness)); // 0 or 1
Expand Down
97 changes: 97 additions & 0 deletions lib/devices/logitech_gpro_x3_lightspeed.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#pragma once

#include "protocols/logitech_centurion_protocol.hpp"
#include <array>
#include <chrono>
#include <span>
#include <string_view>
#include <vector>

using namespace std::string_view_literals;

namespace headsetcontrol {

/**
* @brief Logitech G PRO X 3 LIGHTSPEED (receiver PID 0x0b45).
*
* Verified on USB device revision 1.02: Centurion frames use prefix 50 23 on
* interface 3. Feature indexes are discovered through the receiver bridge.
* EQ is intentionally omitted until its version-2 payload is verified.
*/
class LogitechGProX3Lightspeed : public protocols::LogitechCenturionProtocol {
public:
static constexpr std::array<uint16_t, 1> SUPPORTED_PRODUCT_IDS { 0x0b45 };
static constexpr std::array<uint8_t, 2> FRAME_PREFIX { 0x50, 0x23 };

constexpr uint16_t getVendorId() const override
{
return VENDOR_LOGITECH;
}

std::vector<uint16_t> getProductIds() const override
{
return { SUPPORTED_PRODUCT_IDS.begin(), SUPPORTED_PRODUCT_IDS.end() };
}

std::string_view getDeviceName() const override
{
return "Logitech G PRO X 3 LIGHTSPEED"sv;
}

constexpr int getCapabilities() const override
{
return B(CAP_BATTERY_STATUS) | B(CAP_INACTIVE_TIME);
}

constexpr capability_detail getCapabilityDetail(enum capabilities cap) const override
{
switch (cap) {
case CAP_BATTERY_STATUS:
case CAP_INACTIVE_TIME:
return { .usagepage = 0xffa0, .usageid = 0x0001, .interface_id = 3 };
default:
return HIDDevice::getCapabilityDetail(cap);
}
}

Result<BatteryResult> getBattery(hid_device* device_handle) override
{
auto start_time = std::chrono::steady_clock::now();

auto battery = sendCenturionFeatureRequest(
device_handle,
static_cast<uint16_t>(protocols::CenturionFeature::CenturionBatterySoc),
0x00);
if (!battery) {
return battery.error();
}

auto battery_result = parseCenturionBatteryResponse(*battery);
if (!battery_result) {
return battery_result.error();
}

battery_result->raw_data = *battery;
auto end_time = std::chrono::steady_clock::now();
battery_result->query_duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time);
return *battery_result;
}

protected:
std::span<const uint8_t> centurionFramePrefix() const override
{
return FRAME_PREFIX;
}

protocols::CenturionOptions centurionOptions() const override
{
return {
.exact_direct_length = true,
.detect_connection_events = true,
.probe_offline_on_timeout = true,
.lookup_features_by_id = true,
};
}
};

} // namespace headsetcontrol
45 changes: 45 additions & 0 deletions lib/devices/protocols/logitech_centurion_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,51 @@ class LogitechCenturionProtocol : public HIDDevice {
}

public:
/**
* @brief Build the auto-sleep write parameters: <sleep minutes> <lights dim> <lights off>.
*
* The same command also carries the two lighting inactivity timers (minutes, 0 = never),
* and the headset rejects a write without them, so keep the values that were read back.
*/
static Result<std::array<uint8_t, 3>> buildAutoSleepParams(uint8_t minutes, std::span<const uint8_t> current)
{
if (current.size() < 3) {
return DeviceError::protocolError("Unexpected Centurion auto-sleep reply");
}
return std::array<uint8_t, 3> { minutes, current[1], current[2] };
}

Result<InactiveTimeResult> setInactiveTime(hid_device* device_handle, uint8_t minutes) override
{
auto current = sendCenturionFeatureRequest(
device_handle,
static_cast<uint16_t>(CenturionFeature::CenturionAutoSleep),
0x00);
if (!current) {
return current.error();
}

auto params = buildAutoSleepParams(minutes, *current);
if (!params) {
return params.error();
}

if (auto write_result = sendCenturionFeatureRequest(
device_handle,
static_cast<uint16_t>(CenturionFeature::CenturionAutoSleep),
0x10,
*params);
!write_result) {
return write_result.error();
}

return InactiveTimeResult {
.minutes = minutes,
.min_minutes = 0,
.max_minutes = 90
};
}

static constexpr bool isBridgeSubMessageSizeSupported(size_t sub_message_size)
{
return sub_message_size <= MAX_BRIDGE_SUB_MESSAGE_SIZE;
Expand Down
42 changes: 42 additions & 0 deletions tests/test_protocols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "devices/logitech_astro_a50_gen4.hpp"
#include "devices/logitech_g522_lightspeed.hpp"
#include "devices/logitech_gpro_x2_lightspeed.hpp"
#include "devices/logitech_gpro_x3_lightspeed.hpp"
#include "devices/plantronics_bt600.hpp"
#include "devices/protocols/hidpp_protocol.hpp"
#include "devices/protocols/logitech_calibrations.hpp"
Expand All @@ -36,6 +37,7 @@
#include <sstream>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>

namespace headsetcontrol::testing {
Expand Down Expand Up @@ -1611,6 +1613,45 @@ static void assertFrame(const std::vector<uint8_t>& actual, std::initializer_lis
}
}

// Replies captured from a G PRO X 3 LIGHTSPEED receiver (046d:0b45, bcdDevice 1.02).
class TestableProX3 : public LogitechGProX3Lightspeed {
public:
mutable ScriptedHIDInterface hid;
auto getHIDInterface() const -> HIDInterface& override { return hid; }
};

void testLogitechProX3CapturedTraffic()
{
const auto prefix = LogitechGProX3Lightspeed::FRAME_PREFIX;
TestableProX3 dev;
dev.hid.replies.push_back(centurionFrame(prefix, { 0x00, 0x01, 0x03, 0x00, 0x01 }));
queueBridgeReply(dev.hid, prefix, 0, { 5, 0, 3 });
queueBridgeReply(dev.hid, prefix, 5, { 0x4e, 0x50, 0 });
auto battery = dev.getBattery(nullptr);
ASSERT_TRUE(battery.hasValue(), "Captured X3 battery reply should parse");
ASSERT_EQ(78, battery->level_percent, "X3 battery percentage");
ASSERT_EQ(BATTERY_AVAILABLE, battery->status, "X3 battery status");
assertFrame(dev.hid.writes.back(), { 0x50, 0x23, 8, 0, 3, 0x11, 0, 3, 0, 5, 1 }, "X3 battery query");

ASSERT_TRUE((dev.getAdvertisedCapabilities() & (B(CAP_SIDETONE) | B(CAP_SIDETONE_STATUS))) == 0, "X3 does not advertise sidetone");
ASSERT_TRUE(dev.getSidetone(nullptr).hasError(), "X3 sidetone read is unsupported");
ASSERT_TRUE(dev.setSidetone(nullptr, 64).hasError(), "X3 sidetone write is unsupported");
ASSERT_EQ(3u, dev.hid.writes.size(), "Unsupported sidetone must not send HID commands");

queueBridgeReply(dev.hid, prefix, 0, { 0x11, 0, 4 });
queueBridgeReply(dev.hid, prefix, 0x11, { 15, 0, 0 });
queueBridgeReply(dev.hid, prefix, 0x11, {});
ASSERT_TRUE(dev.setInactiveTime(nullptr, 15).hasValue(), "X3 sleep timer write");
assertFrame(dev.hid.writes.back(), { 0x50, 0x23, 0x0b, 0, 3, 0x11, 0, 6, 0, 0x11, 0x11, 15, 0, 0 }, "X3 sleep write");
ASSERT_TRUE(dev.hid.replies.empty(), "Captured replies consumed");
ASSERT_TRUE(protocols::LogitechCenturionProtocol::buildAutoSleepParams(15, std::array<uint8_t, 2> { 15, 0 }).hasError(), "Reject truncated sleep reply");
auto preserved = protocols::LogitechCenturionProtocol::buildAutoSleepParams(15, std::array<uint8_t, 3> { 5, 1, 2 });
ASSERT_TRUE(preserved.hasValue(), "Sleep params should build from a full reply");
ASSERT_EQ(15, (*preserved)[0], "Minutes replaced");
ASSERT_EQ(1, (*preserved)[1], "Second timer field preserved");
ASSERT_EQ(2, (*preserved)[2], "Third timer field preserved");
}

void testCenturionG522FramePrefix()
{
std::cout << " Testing Logitech Centurion G522 frame prefix..." << std::endl;
Expand Down Expand Up @@ -2832,6 +2873,7 @@ void runAllProtocolTests()
runTest("Logitech Centurion Bridge Size Limit", testCenturionBridgeMessageSizeLimit);
runTest("Logitech Centurion G522 Frame Prefix", testCenturionG522FramePrefix);
runTest("Logitech Centurion Connection Status", testCenturionConnectionStatusHelpers);
runTest("Logitech G PRO X 3 Captured Traffic", testLogitechProX3CapturedTraffic);
runTest("Logitech G522 Battery Wire", testCenturionG522BatteryWire);
runTest("Logitech G522 Offline Detection", testCenturionG522Offline);
runTest("Logitech G522 Sidetone And Auto-Sleep Parsing", testG522SidetoneAndAutoSleepParsing);
Expand Down
Loading