+ Added to get current mode of zone

+ Option to get/set cycle num
 + Option to read device settings
 + Option to set/get sync settings
 * Fix GUI max led count

Signed-off-by: Nagy Tam?s (T-bond) <tbondvagyok@gmail.com>
This commit is contained in:
Nagy Tam?s (T-bond)
2020-04-08 15:29:27 +02:00
committed by Adam Honse
parent 4b4d3bf790
commit f9a25c9612
3 changed files with 129 additions and 33 deletions

View File

@@ -37,7 +37,7 @@ MSIMysticLightController::~MSIMysticLightController()
unsigned int MSIMysticLightController::GetZoneMinLedCount(ZONE /*zone*/)
{
return 1;
return 1u;
}
unsigned int MSIMysticLightController::GetZoneMaxLedCount(ZONE zone)
@@ -47,9 +47,9 @@ unsigned int MSIMysticLightController::GetZoneMaxLedCount(ZONE zone)
case J_RAINBOW_1:
case J_RAINBOW_2:
case J_CORSAIR:
return 240;
return 4u; // TODO: It can be different by zone and by mobo
default:
return 1;
return 1u;
}
}
@@ -62,7 +62,7 @@ unsigned int MSIMysticLightController::GetZoneLedCount(ZONE zone)
return GetZoneMaxLedCount(zone);
}
return requestedZone->led_count;
return requestedZone->cycle_or_led_num;
}
void MSIMysticLightController::SetZoneLedCount(ZONE zone, unsigned int led_count)
@@ -74,7 +74,8 @@ void MSIMysticLightController::SetZoneLedCount(ZONE zone, unsigned int led_count
return;
}
requestedZone->led_count = std::min(GetZoneMaxLedCount(zone), std::max(GetZoneMinLedCount(zone), led_count));
led_count = std::min(GetZoneMaxLedCount(zone), std::max(GetZoneMinLedCount(zone), led_count));
requestedZone->cycle_or_led_num = led_count;
}
void MSIMysticLightController::SetMode(ZONE zone, EFFECT mode, SPEED speed, BRIGHTNESS brightness, bool rainbow_color)
@@ -86,8 +87,8 @@ void MSIMysticLightController::SetMode(ZONE zone, EFFECT mode, SPEED speed, BRIG
}
zoneData->effect = mode;
zoneData->speedAndBrightnessFlags = (zoneData->speedAndBrightnessFlags & 128) | brightness << 2 | speed;
zoneData->colorFlags = static_cast<unsigned char>(std::bitset<8>(zoneData->colorFlags).set(7, !rainbow_color).to_ulong());
zoneData->speedAndBrightnessFlags = (zoneData->speedAndBrightnessFlags & 128u) | brightness << 2u | speed;
zoneData->colorFlags = BitSet(zoneData->colorFlags, !rainbow_color, 7u);
}
std::string MSIMysticLightController::GetDeviceName()
@@ -202,6 +203,7 @@ ZoneData *MSIMysticLightController::GetZoneData(ZONE zone)
return nullptr;
}
RainbowZoneData *MSIMysticLightController::GetRainbowZoneData(ZONE zone)
{
switch (zone)
@@ -235,12 +237,12 @@ bool MSIMysticLightController::ReadFwVersion()
// Now read the LDROM
// Checksum also available at report ID 184, with highCheksum stored at index 8, and low at 9
request[1] = 182;
request[1] = 182u;
num &= hid_write(dev, request, 64);
num &= hid_read(dev, response, 64);
highValue = response[2] >> 4;
lowValue = response[2] & 15;
highValue = response[2] >> 4u;
lowValue = response[2] & 15u;
version_LDROM = std::to_string(static_cast<int>(highValue)).append(".").append(std::to_string(static_cast<int>(lowValue)));
@@ -269,37 +271,124 @@ void MSIMysticLightController::ReadName()
void MSIMysticLightController::SetDeviceSettings(bool is_fan, FAN_TYPE fan_type,
unsigned char corsair_device_quantity,
bool is_LL120Outer_individual) { // If is_fan false, it is a stripe
bool is_LL120Outer_individual)
{
// If is_fan false, it is a stripe
CorsairZoneData &settingsZone = data.j_corsair;
settingsZone.fan_flags = (settingsZone.fan_flags & 128) | fan_type << 1 | is_fan;
settingsZone.corsair_quantity = corsair_device_quantity << 2;
settingsZone.is_individual = static_cast<unsigned char>(std::bitset<8>(settingsZone.padding).set(0, is_LL120Outer_individual).to_ulong());
settingsZone.fan_flags = (settingsZone.fan_flags & 128u) | fan_type << 1u | is_fan;
settingsZone.corsair_quantity = corsair_device_quantity << 2u;
settingsZone.is_individual = BitSet(settingsZone.is_individual, is_LL120Outer_individual, 0u);
}
bool MSIMysticLightController::SetVolume(unsigned char main, unsigned char left, unsigned char right) {
bool MSIMysticLightController::SetVolume(unsigned char main, unsigned char left, unsigned char right)
{
unsigned char packet[64];
std::fill_n(packet, sizeof packet, 204);
std::fill_n(packet, sizeof packet, 204u);
if(main > 100)
if(main > 100u)
{
main = 100;
main = 100u;
}
if(left > 100)
if(left > 100u)
{
left = 100;
left = 100u;
}
if(right > 100)
if(right > 100u)
{
right = 100;
right = 100u;
}
packet[0] = 1;
packet[1] = 192;
packet[0] = 1u;
packet[1] = 192u;
packet[3] = main;
packet[4] = left;
packet[5] = right;
return hid_write(dev, packet, sizeof packet);
}
void MSIMysticLightController::SetBoardSyncSettings(bool onboard_sync, bool combine_JRGB, bool combine_JPIPE1,
bool combine_JPIPE2, bool combine_JRAINBOW1, bool combine_JRAINBOW2,
bool combine_crossair)
{
ZoneData &syncZone = data.on_board_led;
syncZone.colorFlags = BitSet(syncZone.colorFlags, onboard_sync, 0u);
syncZone.colorFlags = BitSet(syncZone.colorFlags, combine_JRAINBOW1, 1u);
syncZone.colorFlags = BitSet(syncZone.colorFlags, combine_JRAINBOW2, 2u);
syncZone.colorFlags = BitSet(syncZone.colorFlags, combine_crossair, 3u);
syncZone.colorFlags = BitSet(syncZone.colorFlags, combine_JPIPE1, 4u);
syncZone.colorFlags = BitSet(syncZone.colorFlags, combine_JPIPE2, 5u);
syncZone.speedAndBrightnessFlags = BitSet(syncZone.speedAndBrightnessFlags, combine_JRGB, 7u);
}
void MSIMysticLightController::GetMode(ZONE zone, EFFECT &mode, SPEED &speed, BRIGHTNESS &brightness, bool &rainbow_color)
{
ZoneData *zoneData = GetZoneData(zone);
if (!zoneData)
{
return;
}
mode = static_cast<EFFECT>(zoneData->effect);
speed = static_cast<SPEED>(zoneData->speedAndBrightnessFlags & 3u);
brightness = static_cast<BRIGHTNESS>((zoneData->speedAndBrightnessFlags >> 2u) & 31u);
rainbow_color = (zoneData->colorFlags & 128u) >> 7u;
}
unsigned char MSIMysticLightController::BitSet(unsigned char value, bool bit, unsigned int position)
{
return static_cast<unsigned char>(std::bitset<8>(value).set(position, bit).to_ulong());
}
void MSIMysticLightController::SetCycleCount(ZONE zone, unsigned char cycle_num)
{
RainbowZoneData *requestedZone = GetRainbowZoneData(zone);
if (!requestedZone)
{
return;
}
requestedZone->cycle_or_led_num = cycle_num;
}
unsigned char MSIMysticLightController::GetCycleCount(ZONE zone)
{
RainbowZoneData *requestedZone = GetRainbowZoneData(zone);
if (!requestedZone)
{
return 0;
}
return requestedZone->cycle_or_led_num;
}
void MSIMysticLightController::GetBoardSyncSettings(bool &onboard_sync, bool &combine_JRGB, bool &combine_JPIPE1,
bool &combine_JPIPE2, bool &combine_JRAINBOW1,
bool &combine_JRAINBOW2, bool &combine_crossair)
{
ZoneData &syncZone = data.on_board_led;
onboard_sync = syncZone.colorFlags & 1u;
combine_JRAINBOW1 = syncZone.colorFlags >> 1u & 1u;
combine_JRAINBOW2 = syncZone.colorFlags >> 1u & 1u;
combine_crossair = syncZone.colorFlags >> 3u & 1u;
combine_JPIPE1 = syncZone.colorFlags >> 4u & 1u;
combine_JPIPE2 = syncZone.colorFlags >> 5u & 1u;
combine_JRGB = (syncZone.speedAndBrightnessFlags & 128u) >> 7u;
}
void MSIMysticLightController::GetDeviceSettings(bool &stripe_or_fan, FAN_TYPE &fan_type,
unsigned char &corsair_device_quantity,
bool &is_LL120Outer_individual)
{
CorsairZoneData &settingsZone = data.j_corsair;
stripe_or_fan = settingsZone.fan_flags & 1u;
fan_type = static_cast<FAN_TYPE >((settingsZone.fan_flags & 14u) >> 1u);
corsair_device_quantity = (settingsZone.corsair_quantity & 252u) >> 2u;
is_LL120Outer_individual = settingsZone.is_individual & 1u;
}

View File

@@ -136,22 +136,22 @@ struct CorsairZoneData
struct ZoneData
{
unsigned char effect = EFFECT::STATIC;
Color color { std::numeric_limits<unsigned char>::max(), 0, 0 };
unsigned char speedAndBrightnessFlags = 40;
Color color2 { 0, std::numeric_limits<unsigned char>::max(), 0 };
unsigned char colorFlags = 128;
Color color { std::numeric_limits<unsigned char>::max(), 0u, 0u };
unsigned char speedAndBrightnessFlags = 40u;
Color color2 { 0, std::numeric_limits<unsigned char>::max(), 0u };
unsigned char colorFlags = 128u;
const unsigned char padding = 0;
const unsigned char padding = 0u;
};
struct RainbowZoneData : ZoneData
{
unsigned char led_count = 20;
unsigned char cycle_or_led_num = 20u;
};
struct FeaturePacket
{
const unsigned char report_id = 82; // Report ID
const unsigned char report_id = 82u; // Report ID
ZoneData j_rgb_1; // 1
ZoneData j_pipe_1; // 11
ZoneData j_pipe_2; // 21
@@ -171,7 +171,7 @@ struct FeaturePacket
ZoneData on_board_led_9; // 164
ZoneData j_rgb_2; // 174
unsigned char save_data = 0; // 184
unsigned char save_data = 0u; // 184
};
@@ -187,13 +187,19 @@ public:
void SetZoneLedCount(ZONE zone, unsigned int led_count);
void SetMode(ZONE zone, EFFECT mode, SPEED speed, BRIGHTNESS brightness, bool rainbow_color);
void GetMode(ZONE zone, EFFECT &mode, SPEED &speed, BRIGHTNESS &brightness, bool &rainbow_color);
void SetZoneColor(ZONE zone, unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2);
void SetCycleCount(ZONE zone, unsigned char cycle_num);
unsigned char GetCycleCount(ZONE zone);
std::pair<Color, Color>
GetZoneColor(ZONE zone);
bool Update();
void SetDeviceSettings(bool stripe_or_fan, FAN_TYPE fan_type, unsigned char corsair_device_quantity, bool is_LL120Outer_individual);
void GetDeviceSettings(bool &stripe_or_fan, FAN_TYPE &fan_type, unsigned char &corsair_device_quantity, bool &is_LL120Outer_individual);
bool SetVolume(unsigned char main, unsigned char left, unsigned char right);
void SetBoardSyncSettings(bool onboard_sync, bool combine_JRGB, bool combine_JPIPE1, bool combine_JPIPE2, bool combine_JRAINBOW1, bool combine_JRAINBOW2, bool combine_crossair);
void GetBoardSyncSettings(bool &onboard_sync, bool &combine_JRGB, bool &combine_JPIPE1, bool &combine_JPIPE2, bool &combine_JRAINBOW1, bool &combine_JRAINBOW2, bool &combine_crossair);
std::string GetDeviceName();
std::string GetDeviceLocation();
@@ -209,6 +215,7 @@ private:
ZoneData* GetZoneData(ZONE zone);
RainbowZoneData*
GetRainbowZoneData(ZONE zone);
static unsigned char BitSet(unsigned char value, bool bit, unsigned int position);
hid_device* dev;
std::string name;

View File

@@ -66,7 +66,7 @@ void RGBController_MSIMysticLight::SetupZones()
new_zone.type = ZONE_TYPE_LINEAR;
new_zone.leds_min = controller->GetZoneMinLedCount(zd.value);
new_zone.leds_min = controller->GetZoneMaxLedCount(zd.value);
new_zone.leds_max = controller->GetZoneMaxLedCount(zd.value);
new_zone.leds_count = controller->GetZoneLedCount(zd.value);
zones.push_back(new_zone);