From 8b84cedeaa0e7fbc009765c7662746baf9298729 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Tue, 3 Jun 2025 17:36:01 +0200 Subject: [PATCH] Automatically create matrix --- .../HIDLampArrayController.cpp | 5 ++++ .../HIDLampArrayController.h | 2 ++ .../RGBController_HIDLampArray.cpp | 30 +++++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Controllers/HIDLampArrayController/HIDLampArrayController.cpp b/Controllers/HIDLampArrayController/HIDLampArrayController.cpp index d852e64db..a2dff0f43 100644 --- a/Controllers/HIDLampArrayController/HIDLampArrayController.cpp +++ b/Controllers/HIDLampArrayController/HIDLampArrayController.cpp @@ -64,6 +64,11 @@ unsigned int HIDLampArrayController::GetLampCount() return(LampArray.LampCount); } +std::vector HIDLampArrayController::GetLamps() +{ + return(Lamps); +} + void HIDLampArrayController::GetLampArrayAttributesReport() { unsigned char usb_buf[sizeof(LampArrayAttributes) + 1]; diff --git a/Controllers/HIDLampArrayController/HIDLampArrayController.h b/Controllers/HIDLampArrayController/HIDLampArrayController.h index 0c8168c63..382e62334 100644 --- a/Controllers/HIDLampArrayController/HIDLampArrayController.h +++ b/Controllers/HIDLampArrayController/HIDLampArrayController.h @@ -116,6 +116,8 @@ public: std::string GetSerialString(); unsigned int GetLampCount(); + std::vector GetLamps(); + void SetLampMultiUpdateReport(unsigned char LampCount, unsigned char LampUpdateFlags, unsigned short * LampIds, LampArrayColor * UpdateColors); private: diff --git a/Controllers/HIDLampArrayController/RGBController_HIDLampArray.cpp b/Controllers/HIDLampArrayController/RGBController_HIDLampArray.cpp index 798723103..65343ca8f 100644 --- a/Controllers/HIDLampArrayController/RGBController_HIDLampArray.cpp +++ b/Controllers/HIDLampArrayController/RGBController_HIDLampArray.cpp @@ -11,6 +11,8 @@ #include "RGBController_HIDLampArray.h" +#include + /**------------------------------------------------------------------*\ @name HID LampArray Controllers @category Keyboard @@ -47,12 +49,34 @@ RGBController_HIDLampArray::~RGBController_HIDLampArray() void RGBController_HIDLampArray::SetupZones() { zone new_zone; - new_zone.name = "Test Zone"; - new_zone.type = ZONE_TYPE_SINGLE; + new_zone.name = "LampArray"; + new_zone.type = ZONE_TYPE_MATRIX; 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; + + std::set columns; + std::set rows; + + for(std::size_t lamp_idx = 0; lamp_idx < controller->GetLamps().size(); lamp_idx++) + { + rows.insert(controller->GetLamps()[lamp_idx].PositionYInMillimeters); + columns.insert(controller->GetLamps()[lamp_idx].PositionXInMillimeters); + } + + new_zone.matrix_map.height = rows.size(); + new_zone.matrix_map.width = columns.size(); + new_zone.matrix_map.map.resize(rows.size() * columns.size()); + + for(std::size_t lamp_idx = 0; lamp_idx < controller->GetLamps().size(); lamp_idx++) + { + //FIXME this assumes that matrix_size is big enough which is only guaranteed when no key possition is doubled + size_t idx = std::distance(columns.begin(), columns.find(controller->GetLamps()[lamp_idx].PositionXInMillimeters)); + size_t idy = std::distance(rows.begin(), rows.find(controller->GetLamps()[lamp_idx].PositionYInMillimeters)); + + new_zone.matrix_map.map[idx + idy * new_zone.matrix_map.width] = lamp_idx; + } + zones.push_back(new_zone); for(unsigned int led_idx = 0; led_idx < new_zone.leds_count; led_idx++)