Begin implementing the HID LampArray protocol for Arduino test device

This commit is contained in:
Adam Honse
2024-05-06 19:00:41 -05:00
parent 4f59845e65
commit 0be978eae1
5 changed files with 203 additions and 25 deletions

View File

@@ -1,8 +1,22 @@
/*---------------------------------------------------------*\
| HIDLampArrayController.cpp |
| |
| Driver for HID LampArray Devices |
| |
| Adam Honse (calcprogrammer1@gmail.com) 26 Mar 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#include <cstring>
#include "HIDLampArrayController.h"
HIDLampArrayController::HIDLampArrayController(hid_device *dev_handle, const char *path)
HIDLampArrayController::HIDLampArrayController(lamparray_hid_devs *devs_handle)
{
devs = devs_handle;
GetLampArrayAttributesReport();
}
HIDLampArrayController::~HIDLampArrayController()
@@ -12,10 +26,34 @@ HIDLampArrayController::~HIDLampArrayController()
std::string HIDLampArrayController::GetDeviceLocation()
{
return("");
}
std::string HIDLampArrayController::GetSerialString()
{
return("");
}
unsigned int HIDLampArrayController::GetLampCount()
{
return(lamp_count);
}
void HIDLampArrayController::GetLampArrayAttributesReport()
{
unsigned char usb_buf[65];
int report_size;
memset(usb_buf, 0, sizeof(usb_buf));
usb_buf[0] = 0x01;
report_size = hid_get_feature_report(devs->hid_dev_LampArrayAttributesReport, usb_buf, sizeof(usb_buf));
lamp_count = (unsigned short)((usb_buf[2] << 8) | usb_buf[1]);
bounding_width = (unsigned int)((usb_buf[6] << 24) | (usb_buf[5] << 16) | (usb_buf[4] << 8) | usb_buf[3]);
bounding_height = (unsigned int)((usb_buf[10] << 24) | (usb_buf[9] << 16) | (usb_buf[8] << 8) | usb_buf[7]);
bounding_depth = (unsigned int)((usb_buf[14] << 24) | (usb_buf[13] << 16) | (usb_buf[12] << 8) | usb_buf[11]);
kind = (unsigned int)((usb_buf[18] << 24) | (usb_buf[17] << 16) | (usb_buf[16] << 8) | usb_buf[15]);
min_interval = (unsigned int)((usb_buf[22] << 24) | (usb_buf[21] << 16) | (usb_buf[20] << 8) | usb_buf[19]);
}

View File

@@ -1,3 +1,14 @@
/*---------------------------------------------------------*\
| HIDLampArrayController.h |
| |
| Driver for HID LampArray Devices |
| |
| Adam Honse (calcprogrammer1@gmail.com) 26 Mar 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#pragma once
#include <string>
@@ -5,16 +16,57 @@
#include "RGBController.h"
typedef struct
{
hid_device * hid_dev_LampArray;
hid_device * hid_dev_LampArrayAttributesReport;
hid_device * hid_dev_LampAttributesRequestReport;
hid_device * hid_dev_LampAttributesResponseReport;
hid_device * hid_dev_LampMultiUpdateReport;
hid_device * hid_dev_LampRangeUpdateReport;
hid_device * hid_dev_LampArrayControlReport;
} lamparray_hid_devs;
enum
{
HID_LAMPARRAY_KIND_UNDEFINED = 0x00, /* Undefined */
HID_LAMPARRAY_KIND_KEYBOARD = 0x01, /* LampArrayKindKeyboard */
HID_LAMPARRAY_KIND_MOUSE = 0x02, /* LampArrayKindMouse */
HID_LAMPARRAY_KIND_GAME_CONTROLLER = 0x03, /* LampArrayKindGameController */
HID_LAMPARRAY_KIND_PERIPHERAL = 0x04, /* LampArrayKindPeripheral */
HID_LAMPARRAY_KIND_SCENE = 0x05, /* LampArrayKindScene */
HID_LAMPARRAY_KIND_NOTIFICATIOn = 0x06, /* LampArrayKindNotification */
HID_LAMPARRAY_KIND_CHASSIS = 0x07, /* LampArrayKindChassis */
HID_LAMPARRAY_KIND_WEARABLE = 0x08, /* LampArrayKindWearable */
HID_LAMPARRAY_KIND_FURNITURE = 0x09, /* LampArrayKindFurniture */
HID_LAMPARRAY_KIND_ART = 0x0A, /* LampArrayKindArt */
};
class HIDLampArrayController
{
public:
HIDLampArrayController(hid_device *dev_handle, const char *path);
HIDLampArrayController(lamparray_hid_devs *devs_handle);
~HIDLampArrayController();
std::string GetDeviceLocation();
std::string GetSerialString();
unsigned int GetLampCount();
private:
hid_device *dev;
void GetLampArrayAttributesReport();
lamparray_hid_devs * devs;
std::string location;
/*-----------------------------------------------------*\
| Parameters from LampArrayAttributesReport |
\*-----------------------------------------------------*/
unsigned short lamp_count;
unsigned int bounding_width;
unsigned int bounding_height;
unsigned int bounding_depth;
unsigned int kind;
unsigned int min_interval;
};

View File

@@ -1,3 +1,14 @@
/*---------------------------------------------------------*\
| HIDLampArrayControllerDetect.cpp |
| |
| Detector for HID LampArray Devices |
| |
| Adam Honse (calcprogrammer1@gmail.com) 26 Mar 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#include "Detector.h"
#include "HIDLampArrayController.h"
#include "RGBController.h"
@@ -5,15 +16,61 @@
#include <vector>
#include <hidapi/hidapi.h>
static lamparray_hid_devs devs;
void DetectHIDLampArrayControllers(hid_device_info* info, const std::string& name)
{
hid_device* dev = hid_open_path(info->path);
if(dev)
{
HIDLampArrayController* controller = new HIDLampArrayController(dev, info->path);
if(info->usage_page == 0x59 && info->usage == 0x01)
{
devs.hid_dev_LampArray = dev;
}
if(info->usage_page == 0x59 && info->usage == 0x02)
{
devs.hid_dev_LampArrayAttributesReport = dev;
}
if(info->usage_page == 0x59 && info->usage == 0x20)
{
devs.hid_dev_LampAttributesRequestReport = dev;
}
if(info->usage_page == 0x59 && info->usage == 0x22)
{
devs.hid_dev_LampAttributesResponseReport = dev;
}
if(info->usage_page == 0x59 && info->usage == 0x50)
{
devs.hid_dev_LampMultiUpdateReport = dev;
}
if(info->usage_page == 0x59 && info->usage == 0x60)
{
devs.hid_dev_LampRangeUpdateReport = dev;
}
if(info->usage_page == 0x59 && info->usage == 0x70)
{
devs.hid_dev_LampArrayControlReport = dev;
}
}
if(devs.hid_dev_LampArray
&& devs.hid_dev_LampArrayAttributesReport
&& devs.hid_dev_LampAttributesRequestReport
&& devs.hid_dev_LampAttributesResponseReport
&& devs.hid_dev_LampMultiUpdateReport
&& devs.hid_dev_LampRangeUpdateReport
&& devs.hid_dev_LampArrayControlReport)
{
HIDLampArrayController* controller = new HIDLampArrayController(&devs);
RGBController_HIDLampArray* rgb_controller = new RGBController_HIDLampArray(controller);
rgb_controller->name = name;
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}

View File

@@ -1,21 +1,32 @@
/*---------------------------------------------------------*\
| RGBController_HIDLampArray.cpp |
| |
| RGBController for HID LampArray Devices |
| |
| Adam Honse (calcprogrammer1@gmail.com) 26 Mar 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#include "RGBController_HIDLampArray.h"
RGBController_HIDLampArray::RGBController_HIDLampArray(HIDLampArrayController* controller_ptr)
{
controller = controller_ptr;
controller = controller_ptr;
name = "HID LampArray Device";
vendor = "Generic";
type = DEVICE_TYPE_MOUSEMAT;
description = "HID LampArray Device";
location = controller->GetDeviceLocation();
serial = controller->GetSerialString();
name = "HID LampArray Device";
vendor = "Generic";
type = DEVICE_TYPE_MOUSEMAT;
description = "HID LampArray Device";
location = controller->GetDeviceLocation();
serial = controller->GetSerialString();
mode Direct;
Direct.name = "Direct";
Direct.value = 0;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
Direct.name = "Direct";
Direct.value = 0;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
SetupZones();
@@ -28,7 +39,23 @@ RGBController_HIDLampArray::~RGBController_HIDLampArray()
void RGBController_HIDLampArray::SetupZones()
{
zone new_zone;
new_zone.name = "Test Zone";
new_zone.type = ZONE_TYPE_SINGLE;
new_zone.leds_count = controller->GetLampCount();
new_zone.leds_min = new_zone.leds_count;
new_zone.leds_max = new_zone.leds_count;
new_zone.matrix_map = NULL;
zones.push_back(new_zone);
for(unsigned int led_idx = 0; led_idx < new_zone.leds_count; led_idx++)
{
led new_led;
new_led.name = "Test LED";
leds.push_back(new_led);
}
SetupColors();
}
void RGBController_HIDLampArray::ResizeZone(int /*zone*/, int /*new_size*/)

View File

@@ -1,12 +1,16 @@
/*-----------------------------------------------------*\
| RGBController_HIDLampArray.h |
| |
| Generic RGB Interface HID LampArray Devices |
| |
| Adam Honse <calcprogrammer1@gmail.com> 3/26/2024 |
\*-----------------------------------------------------*/
/*---------------------------------------------------------*\
| RGBController_HIDLampArray.h |
| |
| RGBController for HID LampArray Devices |
| |
| Adam Honse (calcprogrammer1@gmail.com) 26 Mar 2024 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "HIDLampArrayController.h"