diff --git a/Controllers/HIDLampArrayController/HIDLampArrayController.cpp b/Controllers/HIDLampArrayController/HIDLampArrayController.cpp index ee1adb07f..d852e64db 100644 --- a/Controllers/HIDLampArrayController/HIDLampArrayController.cpp +++ b/Controllers/HIDLampArrayController/HIDLampArrayController.cpp @@ -12,9 +12,11 @@ #include #include "HIDLampArrayController.h" -HIDLampArrayController::HIDLampArrayController(lamparray_hid_devs *devs_handle) +HIDLampArrayController::HIDLampArrayController(hid_device *dev_handle, const char *path, std::string dev_name) { - devs = devs_handle; + dev = dev_handle; + location = path; + name = dev_name; /*-----------------------------------------------------*\ | Get LampArrayAttributesReport | @@ -39,12 +41,17 @@ HIDLampArrayController::HIDLampArrayController(lamparray_hid_devs *devs_handle) HIDLampArrayController::~HIDLampArrayController() { - + hid_close(dev); } std::string HIDLampArrayController::GetDeviceLocation() { - return(""); + return("HID: " + location); +} + +std::string HIDLampArrayController::GetDeviceName() +{ + return(name); } std::string HIDLampArrayController::GetSerialString() @@ -72,7 +79,7 @@ void HIDLampArrayController::GetLampArrayAttributesReport() /*-----------------------------------------------------*\ | Get the report | \*-----------------------------------------------------*/ - report_size = hid_get_feature_report(devs->hid_dev_LampArrayAttributesReport, usb_buf, sizeof(usb_buf)); + report_size = hid_get_feature_report(dev, usb_buf, sizeof(usb_buf)); memcpy(&LampArray, &usb_buf[1], sizeof(LampArray)); } @@ -93,7 +100,7 @@ void HIDLampArrayController::GetLampAttributesResponseReport() /*-----------------------------------------------------*\ | Get the report | \*-----------------------------------------------------*/ - report_size = hid_get_feature_report(devs->hid_dev_LampAttributesResponseReport, usb_buf, sizeof(usb_buf)); + report_size = hid_get_feature_report(dev, usb_buf, sizeof(usb_buf)); memcpy(&attributes, &usb_buf[1], sizeof(attributes)); @@ -122,7 +129,7 @@ void HIDLampArrayController::SetLampArrayControlReport(unsigned char AutonomousM /*-----------------------------------------------------*\ | Send the report | \*-----------------------------------------------------*/ - hid_send_feature_report(devs->hid_dev_LampArrayControlReport, usb_buf, sizeof(usb_buf)); + hid_send_feature_report(dev, usb_buf, sizeof(usb_buf)); } void HIDLampArrayController::SetLampAttributesRequestReport(unsigned short LampId) @@ -144,7 +151,7 @@ void HIDLampArrayController::SetLampAttributesRequestReport(unsigned short LampI /*-----------------------------------------------------*\ | Send the report | \*-----------------------------------------------------*/ - hid_send_feature_report(devs->hid_dev_LampAttributesRequestReport, usb_buf, sizeof(usb_buf)); + hid_send_feature_report(dev, usb_buf, sizeof(usb_buf)); } void HIDLampArrayController::SetLampMultiUpdateReport(unsigned char LampCount, unsigned char LampUpdateFlags, unsigned short * LampIds, LampArrayColor * UpdateColors) @@ -173,5 +180,5 @@ void HIDLampArrayController::SetLampMultiUpdateReport(unsigned char LampCount, u /*-----------------------------------------------------*\ | Send the report | \*-----------------------------------------------------*/ - hid_send_feature_report(devs->hid_dev_LampMultiUpdateReport, usb_buf, sizeof(usb_buf)); + hid_send_feature_report(dev, usb_buf, sizeof(usb_buf)); } diff --git a/Controllers/HIDLampArrayController/HIDLampArrayController.h b/Controllers/HIDLampArrayController/HIDLampArrayController.h index d828cea18..0c8168c63 100644 --- a/Controllers/HIDLampArrayController/HIDLampArrayController.h +++ b/Controllers/HIDLampArrayController/HIDLampArrayController.h @@ -12,7 +12,7 @@ #pragma once #include -#include +#include #include "RGBController.h" @@ -27,17 +27,6 @@ #define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop)) #endif -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; - PACK(struct LampArrayAttributes { unsigned short LampCount; @@ -119,24 +108,20 @@ enum class HIDLampArrayController { public: - HIDLampArrayController(lamparray_hid_devs *devs_handle); + HIDLampArrayController(hid_device *dev_handle, const char *path, std::string dev_name); ~HIDLampArrayController(); std::string GetDeviceLocation(); + std::string GetDeviceName(); std::string GetSerialString(); unsigned int GetLampCount(); -void SetLampMultiUpdateReport(unsigned char LampCount, unsigned char LampUpdateFlags, unsigned short * LampIds, LampArrayColor * UpdateColors); + void SetLampMultiUpdateReport(unsigned char LampCount, unsigned char LampUpdateFlags, unsigned short * LampIds, LampArrayColor * UpdateColors); + private: - - void GetLampArrayAttributesReport(); - void GetLampAttributesResponseReport(); - void SetLampArrayControlReport(unsigned char AutonomousMode); - void SetLampAttributesRequestReport(unsigned short LampId); - - - lamparray_hid_devs * devs; - std::string location; + hid_device * dev; + std::string location; + std::string name; /*-----------------------------------------------------*\ | Vector to store lamp attributes for each lamp | @@ -147,4 +132,9 @@ private: | Parameters from LampArrayAttributesReport | \*-----------------------------------------------------*/ LampArrayAttributes LampArray; + + void GetLampArrayAttributesReport(); + void GetLampAttributesResponseReport(); + void SetLampArrayControlReport(unsigned char AutonomousMode); + void SetLampAttributesRequestReport(unsigned short LampId); }; diff --git a/Controllers/HIDLampArrayController/HIDLampArrayControllerDetect.cpp b/Controllers/HIDLampArrayController/HIDLampArrayControllerDetect.cpp index d48e9f344..1f25ef0d7 100644 --- a/Controllers/HIDLampArrayController/HIDLampArrayControllerDetect.cpp +++ b/Controllers/HIDLampArrayController/HIDLampArrayControllerDetect.cpp @@ -9,71 +9,29 @@ | SPDX-License-Identifier: GPL-2.0-only | \*---------------------------------------------------------*/ -#include "Detector.h" +#include "DetectionManager.h" #include "HIDLampArrayController.h" #include "RGBController.h" #include "RGBController_HIDLampArray.h" #include -#include +#include -static lamparray_hid_devs devs; - -void DetectHIDLampArrayControllers(hid_device_info* info, const std::string& name) +DetectedControllers DetectHIDLampArrayControllers(hid_device_info* info, const std::string& name) { - hid_device* dev = hid_open_path(info->path); + DetectedControllers detected_controllers; + hid_device* dev; + + dev = hid_open_path(info->path); if(dev) { - 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); + HIDLampArrayController* controller = new HIDLampArrayController(dev, info->path, name); RGBController_HIDLampArray* rgb_controller = new RGBController_HIDLampArray(controller); - rgb_controller->name = name; - ResourceManager::get()->RegisterRGBController(rgb_controller); + detected_controllers.push_back(rgb_controller); } -} /* DetectHIDLampArrayControllers() */ -REGISTER_HID_DETECTOR("Arduino Zero HID Lamp Array Demo", DetectHIDLampArrayControllers, 0x2341, 0x804D); + return(detected_controllers); +} + +REGISTER_HID_DETECTOR_PU("Arduino Zero HID Lamp Array Demo", DetectHIDLampArrayControllers, 0x2341, 0x804D, 0x59, 0x01); diff --git a/Controllers/HIDLampArrayController/RGBController_HIDLampArray.cpp b/Controllers/HIDLampArrayController/RGBController_HIDLampArray.cpp index 0242f039c..8543fbbc9 100644 --- a/Controllers/HIDLampArrayController/RGBController_HIDLampArray.cpp +++ b/Controllers/HIDLampArrayController/RGBController_HIDLampArray.cpp @@ -15,7 +15,7 @@ RGBController_HIDLampArray::RGBController_HIDLampArray(HIDLampArrayController* c { controller = controller_ptr; - name = "HID LampArray Device"; + name = controller->GetDeviceName(); vendor = "Generic"; type = DEVICE_TYPE_MOUSEMAT; description = "HID LampArray Device"; @@ -34,7 +34,7 @@ RGBController_HIDLampArray::RGBController_HIDLampArray(HIDLampArrayController* c RGBController_HIDLampArray::~RGBController_HIDLampArray() { - + delete controller; } void RGBController_HIDLampArray::SetupZones() @@ -58,11 +58,6 @@ void RGBController_HIDLampArray::SetupZones() SetupColors(); } -void RGBController_HIDLampArray::ResizeZone(int /*zone*/, int /*new_size*/) -{ - -} - void RGBController_HIDLampArray::DeviceUpdateLEDs() { unsigned int leds_to_go = leds.size(); @@ -100,12 +95,12 @@ void RGBController_HIDLampArray::DeviceUpdateLEDs() } } -void RGBController_HIDLampArray::UpdateZoneLEDs(int /*zone*/) +void RGBController_HIDLampArray::DeviceUpdateZoneLEDs(int /*zone*/) { } -void RGBController_HIDLampArray::UpdateSingleLED(int /*led*/) +void RGBController_HIDLampArray::DeviceUpdateSingleLED(int /*led*/) { } diff --git a/Controllers/HIDLampArrayController/RGBController_HIDLampArray.h b/Controllers/HIDLampArrayController/RGBController_HIDLampArray.h index fb8ae6f5e..a8fe0daa2 100644 --- a/Controllers/HIDLampArrayController/RGBController_HIDLampArray.h +++ b/Controllers/HIDLampArrayController/RGBController_HIDLampArray.h @@ -21,11 +21,10 @@ public: ~RGBController_HIDLampArray(); void SetupZones(); - void ResizeZone(int zone, int new_size); void DeviceUpdateLEDs(); - void UpdateZoneLEDs(int zone); - void UpdateSingleLED(int led); + void DeviceUpdateZoneLEDs(int zone); + void DeviceUpdateSingleLED(int led); void DeviceUpdateMode();