Asrock Polychrome USB Fix

This commit is contained in:
Shady Nawara 2023-01-18 04:45:40 +00:00 committed by Adam Honse
parent edf05dc121
commit 351515f025
4 changed files with 71 additions and 9 deletions

View file

@ -5,12 +5,14 @@
| lighting controller |
| |
| Ed Kambulow (dredvard) 12/20/2020 |
| Shady Nawara (ShadyNawara) 01/16/2023 |
\*-----------------------------------------*/
#include "RGBController.h"
#include "ASRockPolychromeUSBController.h"
#include <cstring>
#include <stdio.h>
#include "RGBController.h"
#include "ResourceManager.h"
#include "ASRockPolychromeUSBController.h"
#include "dependencies/dmiinfo.h"
#define POLYCHROME_USB_READ_ZONE_CONFIG 0x11
@ -91,6 +93,44 @@ void PolychromeUSBController::SetDeviceInfo()
WriteRGSwap(0,0,0,0,0,0,0,0);
ReadConfigTables();
/*--------------------------------------------------*\
| Read settings to check for configured RGSwap |
\*--------------------------------------------------*/
const std::string detector_name = "ASRock Polychrome USB";
const std::string json_rgswap = "RGSwap";
SettingsManager* settings_manager = ResourceManager::get()->GetSettingsManager();
json device_settings = settings_manager->GetSettings(detector_name);
/*---------------------------------------------------------*\
| Get RGSwap settings from the settings manager |
| If RGSwap settings are not found then write them out |
| RGSwap is disabled by default |
\*---------------------------------------------------------*/
if(!device_settings.contains(json_rgswap))
{
for(const char* z : polychrome_USB_zone_names)
{
device_settings[json_rgswap][z] = false;
}
settings_manager->SetSettings(detector_name, device_settings);
settings_manager->SaveSettings();
}
else
{
for(std::size_t idx = 0; idx < 8; idx++)
{
if(device_settings[json_rgswap].contains(polychrome_USB_zone_names[idx]))
{
rgswapconfig[idx] = device_settings[json_rgswap][polychrome_USB_zone_names[idx]];
}
}
}
/*--------------------------------------------------*\
| Disable RGSwap as it causes flashing on each update|
\*--------------------------------------------------*/
for (unsigned int zonecnt = 0; zonecnt < POLYCHROME_USB_ZONE_MAX_NUM; zonecnt++)
{
if(configtable[zonecnt] == 0x1E || !((configtable[9] >> zonecnt) & 1))
@ -103,7 +143,7 @@ void PolychromeUSBController::SetDeviceInfo()
}
newdev_info.num_leds = configtable[zonecnt];
newdev_info.rgswap = ((configtable[8] >> zonecnt) & 1);
newdev_info.rgswap = ((configtable[8] >> zonecnt) & 1) || rgswapconfig[zonecnt];
/*--------------------------------------------------------------------------------------------------*\
| We will need to know what zone type this is, so that we can look up the name and make calls later. |
@ -193,8 +233,18 @@ void PolychromeUSBController::WriteZone
usb_buf[0x01] = POLYCHROME_USB_SET_ZONE;
usb_buf[0x03] = device_info.zone_type;
usb_buf[0x04] = mode;
usb_buf[0x05] = RGBGetGValue(rgb);
usb_buf[0x06] = RGBGetRValue(rgb);
if(device_info.rgswap)
{
usb_buf[0x05] = RGBGetRValue(rgb);
usb_buf[0x06] = RGBGetGValue(rgb);
}
else
{
usb_buf[0x05] = RGBGetGValue(rgb);
usb_buf[0x06] = RGBGetRValue(rgb);
}
usb_buf[0x07] = RGBGetBValue(rgb);
usb_buf[0x08] = speed;
usb_buf[0x09] = 0xFF;
@ -397,9 +447,17 @@ PolychromeZoneInfo PolychromeUSBController::GetZoneConfig(unsigned char zone)
zoneinfo.mode = usb_buf[0x04] != 0xE2 && usb_buf[0x04] != 0xE3 && usb_buf[0x04] < 0x0F ? usb_buf[0x04] : 0x0F;
/*------------------------------------------------------*\
| G & R are swapped since RGSwap is disabled on init |
| G & R are swapped since RGSwap is disabled on init, |
| Unless overwritten in settings |
\*------------------------------------------------------*/
zoneinfo.color = ToRGBColor(g,r,b);
if(device_info.rgswap)
{
zoneinfo.color = ToRGBColor(r,g,b);
}
else
{
zoneinfo.color = ToRGBColor(g,r,b);
}
zoneinfo.speed = usb_buf[0x08];
zoneinfo.zone = usb_buf[0x03];

View file

@ -5,6 +5,7 @@
| lighting controller |
| |
| Ed Kambulow (dredvard) 12/20/2020 |
| Shady Nawara (ShadyNawara) 01/16/2023 |
\*-----------------------------------------*/
#include "RGBController.h"
@ -155,6 +156,7 @@ private:
unsigned int led_count;
std::string device_name;
unsigned char configtable[12];
bool rgswapconfig[8] = { 0 };
void SetDeviceInfo();
void ReadConfigTables();

View file

@ -5,13 +5,14 @@
| ASRock Polychrome USB Driver |
| |
| Ed Kambulow (Dredvard) 12/26/2020 |
| Shady Nawara (ShadyNawara) 01/16/2023 |
\*-----------------------------------------*/
#include "RGBController_ASRockPolychromeUSB.h"
#include <string.h>
#define ASROCK_USB_MAX_ZONES 8
#define ASROCK_ADDRESSABLE_MAX_LEDS 80
#define ASROCK_ADDRESSABLE_MAX_LEDS 100
/**------------------------------------------------------------------*\
@name ASrock Polychrome USB

View file

@ -5,6 +5,7 @@
| ASRock Polychrome USB Driver |
| |
| Ed Kambulow (Dredvard) 12/26/2020 |
| Shady Nawara (ShadyNawara) 01/16/2023 |
\*-----------------------------------------*/
#pragma once