Implement getting lamp attributes for each lamp and disabling autonomous mode, work on multi update

This commit is contained in:
Adam Honse
2024-05-07 00:13:49 -05:00
parent 82f54ba227
commit bce77303c2
2 changed files with 212 additions and 17 deletions

View File

@@ -16,7 +16,25 @@ HIDLampArrayController::HIDLampArrayController(lamparray_hid_devs *devs_handle)
{
devs = devs_handle;
/*-----------------------------------------------------*\
| Get LampArrayAttributesReport |
\*-----------------------------------------------------*/
GetLampArrayAttributesReport();
/*-----------------------------------------------------*\
| Set LampAttributesRequestReport for LampId 0 |
\*-----------------------------------------------------*/
SetLampAttributesRequestReport(0);
/*-----------------------------------------------------*\
| Get LampAttributesResponseReport for each LampId |
\*-----------------------------------------------------*/
for(unsigned int LampId = 0; LampId < LampArray.LampCount; LampId++)
{
GetLampAttributesResponseReport();
}
SetLampArrayControlReport(false);
}
HIDLampArrayController::~HIDLampArrayController()
@@ -36,24 +54,124 @@ std::string HIDLampArrayController::GetSerialString()
unsigned int HIDLampArrayController::GetLampCount()
{
return(lamp_count);
return(LampArray.LampCount);
}
void HIDLampArrayController::GetLampArrayAttributesReport()
{
unsigned char usb_buf[65];
unsigned char usb_buf[sizeof(LampArrayAttributes) + 1];
int report_size;
memset(usb_buf, 0, sizeof(usb_buf));
usb_buf[0] = 0x01;
/*-----------------------------------------------------*\
| First byte is the report ID |
\*-----------------------------------------------------*/
usb_buf[0] = HID_LAMPARRAY_LAMP_ARRAY_ATTRIBUTES_REPORT_ID;
report_size = hid_get_feature_report(devs->hid_dev_LampArrayAttributesReport, usb_buf, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Get the report |
\*-----------------------------------------------------*/
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]);
memcpy(&LampArray, &usb_buf[1], sizeof(LampArray));
}
void HIDLampArrayController::GetLampAttributesResponseReport()
{
unsigned char usb_buf[65];
int report_size;
LampAttributes attributes;
memset(usb_buf, 0, sizeof(usb_buf));
/*-----------------------------------------------------*\
| First byte is the report ID |
\*-----------------------------------------------------*/
usb_buf[0] = HID_LAMPARRAY_LAMP_ATTRIBUTES_RESPONSE_REPORT_ID;
/*-----------------------------------------------------*\
| Get the report |
\*-----------------------------------------------------*/
report_size = hid_get_feature_report(devs->hid_dev_LampAttributesResponseReport, usb_buf, sizeof(usb_buf));
memcpy(&attributes, &usb_buf[1], sizeof(attributes));
/*-----------------------------------------------------*\
| Store the attributes |
\*-----------------------------------------------------*/
Lamps.push_back(attributes);
}
void HIDLampArrayController::SetLampArrayControlReport(unsigned char AutonomousMode)
{
unsigned char usb_buf[sizeof(LampArrayControl) + 1];
memset(usb_buf, 0, sizeof(usb_buf));
/*-----------------------------------------------------*\
| First byte is the report ID |
\*-----------------------------------------------------*/
usb_buf[0] = HID_LAMPARRAY_LAMP_ARRAY_CONTROL_REPORT_ID;
/*-----------------------------------------------------*\
| Fill in control data |
\*-----------------------------------------------------*/
((LampArrayControl *)&usb_buf[1])->AutonomousMode = AutonomousMode;
/*-----------------------------------------------------*\
| Send the report |
\*-----------------------------------------------------*/
hid_send_feature_report(devs->hid_dev_LampArrayControlReport, usb_buf, sizeof(usb_buf));
}
void HIDLampArrayController::SetLampAttributesRequestReport(unsigned short LampId)
{
unsigned char usb_buf[sizeof(LampAttributesRequest) + 1];
memset(usb_buf, 0, sizeof(usb_buf));
/*-----------------------------------------------------*\
| First byte is the report ID |
\*-----------------------------------------------------*/
usb_buf[0] = HID_LAMPARRAY_LAMP_ATTRIBUTES_REQUEST_REPORT_ID;
/*-----------------------------------------------------*\
| Fill in request data |
\*-----------------------------------------------------*/
((LampAttributesRequest *)&usb_buf[1])->LampId = LampId;
/*-----------------------------------------------------*\
| Send the report |
\*-----------------------------------------------------*/
hid_send_feature_report(devs->hid_dev_LampAttributesRequestReport, usb_buf, sizeof(usb_buf));
}
void HIDLampArrayController::SetLampMultiUpdateReport(unsigned char LampCount, unsigned char LampUpdateFlags, unsigned char * LampIds, LampArrayColor * UpdateColors)
{
unsigned char usb_buf[sizeof(LampMultiUpdate) + 1];
memset(usb_buf, 0, sizeof(usb_buf));
/*-----------------------------------------------------*\
| First byte is the report ID |
\*-----------------------------------------------------*/
usb_buf[0] = HID_LAMPARRAY_LAMP_MULTI_UPDATE_REPORT_ID;
/*-----------------------------------------------------*\
| Fill in multi update data |
\*-----------------------------------------------------*/
((LampMultiUpdate *)&usb_buf[1])->LampCount = LampCount;
((LampMultiUpdate *)&usb_buf[1])->LampUpdateFlags = LampUpdateFlags;
for(unsigned char LampId = 0; LampId < LampCount; LampId++)
{
((LampMultiUpdate *)&usb_buf[1])->LampIds[LampId] = LampIds[LampId];
((LampMultiUpdate *)&usb_buf[1])->UpdateColors[LampId] = UpdateColors[LampId];
}
/*-----------------------------------------------------*\
| Send the report |
\*-----------------------------------------------------*/
hid_send_feature_report(devs->hid_dev_LampMultiUpdateReport, usb_buf, sizeof(usb_buf));
}

View File

@@ -16,6 +16,17 @@
#include "RGBController.h"
/*---------------------------------------------------------*\
| Struct packing macro for GCC and MSVC |
\*---------------------------------------------------------*/
#ifdef __GNUC__
#define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__))
#endif
#ifdef _MSC_VER
#define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop))
#endif
typedef struct
{
hid_device * hid_dev_LampArray;
@@ -27,6 +38,68 @@ typedef struct
hid_device * hid_dev_LampArrayControlReport;
} lamparray_hid_devs;
PACK(struct LampArrayAttributes
{
unsigned short LampCount;
unsigned int BoundingBoxWidthInMillimeters;
unsigned int BoundingBoxHeightInMillimeters;
unsigned int BoundingBoxDepthInMillimeters;
unsigned int LampArrayKind;
unsigned int MinUpdateIntervalInMilliseconds;
});
PACK(struct LampArrayColor
{
unsigned char RedChannel;
unsigned char GreenChannel;
unsigned char BlueChannel;
unsigned char IntensityChannel;
});
PACK(struct LampArrayControl
{
unsigned char AutonomousMode;
});
PACK(struct LampAttributes
{
unsigned short LampId;
unsigned int PositionXInMillimeters;
unsigned int PositionYInMillimeters;
unsigned int PositionZInMillimeters;
unsigned int UpdateLatencyInMilliseconds;
unsigned int LampPurposes;
unsigned char RedLevelCount;
unsigned char GreenLevelCount;
unsigned char BlueLevelCount;
unsigned char IntensityLevelCount;
unsigned char IsProgrammable;
unsigned char LampKey;
});
PACK(struct LampAttributesRequest
{
unsigned short LampId;
});
#define LAMP_MULTI_UPDATE_LAMP_COUNT 8
PACK(struct LampMultiUpdate
{
unsigned char LampCount;
unsigned char LampUpdateFlags;
unsigned char LampIds[LAMP_MULTI_UPDATE_LAMP_COUNT];
LampArrayColor UpdateColors[LAMP_MULTI_UPDATE_LAMP_COUNT];
});
enum
{
HID_LAMPARRAY_LAMP_ARRAY_ATTRIBUTES_REPORT_ID = 0x01, /* LampArrayAttributesReport ID */
HID_LAMPARRAY_LAMP_ATTRIBUTES_REQUEST_REPORT_ID = 0x02, /* LampAttributesRequestReport ID */
HID_LAMPARRAY_LAMP_ATTRIBUTES_RESPONSE_REPORT_ID = 0x03, /* LampAttributesResponseReport ID */
HID_LAMPARRAY_LAMP_MULTI_UPDATE_REPORT_ID = 0x04, /* LampMultiUpdateReport ID */
HID_LAMPARRAY_LAMP_ARRAY_CONTROL_REPORT_ID = 0x06, /* LampArrayControlReport ID */
};
enum
{
HID_LAMPARRAY_KIND_UNDEFINED = 0x00, /* Undefined */
@@ -35,7 +108,7 @@ enum
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_NOTIFICATION = 0x06, /* LampArrayKindNotification */
HID_LAMPARRAY_KIND_CHASSIS = 0x07, /* LampArrayKindChassis */
HID_LAMPARRAY_KIND_WEARABLE = 0x08, /* LampArrayKindWearable */
HID_LAMPARRAY_KIND_FURNITURE = 0x09, /* LampArrayKindFurniture */
@@ -56,17 +129,21 @@ public:
private:
void GetLampArrayAttributesReport();
void GetLampAttributesResponseReport();
void SetLampArrayControlReport(unsigned char AutonomousMode);
void SetLampAttributesRequestReport(unsigned short LampId);
void SetLampMultiUpdateReport(unsigned char LampCount, unsigned char LampUpdateFlags, unsigned char * LampIds, LampArrayColor * UpdateColors);
lamparray_hid_devs * devs;
std::string location;
/*-----------------------------------------------------*\
| Vector to store lamp attributes for each lamp |
\*-----------------------------------------------------*/
std::vector<LampAttributes> Lamps;
/*-----------------------------------------------------*\
| 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;
LampArrayAttributes LampArray;
};