Automatically create matrix

This commit is contained in:
Werner Sembach
2025-06-03 17:36:01 +02:00
committed by Adam Honse
parent 0bbec4dde9
commit 39055f205c
3 changed files with 36 additions and 3 deletions

View File

@@ -9,6 +9,8 @@
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#include <cstring>
#include <set>
#include "RGBController_HIDLampArray.h"
/**------------------------------------------------------------------*\
@@ -47,12 +49,36 @@ 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<unsigned int> columns;
std::set<unsigned int> 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());
memset(new_zone.matrix_map.map.data(), 0xFF, (new_zone.matrix_map.map.size() * sizeof(unsigned int)));
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++)