Skip to content

Commit

Permalink
Unconfuse mouse_matrix and extended_matrix
Browse files Browse the repository at this point in the history
Seems during earlier development I confused extended_matrix and
mouse_matrix functions, where in the razerreport.cpp definition both
were equal. Make sure mouse_matrix matches the packet in openrazer.

This is apparently just used by Naga Pro (Wired/Wireless), Naga Chroma
and Naga Hex V2.
  • Loading branch information
z3ntu committed Jun 4, 2023
1 parent 31c3262 commit 4fe6756
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 36 deletions.
4 changes: 2 additions & 2 deletions data/devices/mouse.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"leds": [1, 4, 16, 17],
"fx": ["off", "breathing", "breathing_dual", "breathing_random", "reactive", "spectrum", "static", "wave", "brightness"],
"features": ["dpi", "poll_rate"],
"quirks": ["mouse_matrix", "matrix_brightness"],
"quirks": ["extended_matrix", "matrix_brightness"],
"max_dpi": 16000
},
{
Expand All @@ -42,7 +42,7 @@
"leds": [1, 4, 16, 17],
"fx": ["off", "breathing", "breathing_dual", "breathing_random", "reactive", "spectrum", "static", "wave", "brightness"],
"features": ["dpi", "poll_rate"],
"quirks": ["mouse_matrix", "matrix_brightness"],
"quirks": ["extended_matrix", "matrix_brightness"],
"max_dpi": 16000
}
]
6 changes: 3 additions & 3 deletions src/device/razermatrixdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ bool RazerMatrixDevice::displayCustomFrame()
return false;

RazerMatrixLED *led = static_cast<RazerMatrixLED *>(leds.values().first());
if (quirks.contains(RazerDeviceQuirks::MouseMatrix)) {
return led->setMouseMatrixEffect(RazerMouseMatrixEffectId::CustomFrame);
if (hasQuirk(RazerDeviceQuirks::ExtendedMatrix) || hasQuirk(RazerDeviceQuirks::MouseMatrix)) {
return led->setExtendedMatrixEffect(RazerMatrixEffectId::CustomFrame);
} else {
return led->setMatrixEffect(RazerMatrixEffectId::CustomFrame);
}
Expand All @@ -71,7 +71,7 @@ bool RazerMatrixDevice::defineCustomFrame(uchar row, uchar startColumn, uchar en

razer_report report, response_report;

if (quirks.contains(RazerDeviceQuirks::FireflyCustomFrame)) {
if (hasQuirk(RazerDeviceQuirks::FireflyCustomFrame)) {
report = razer_chroma_misc_one_row_set_custom_frame(startColumn, endColumn, reinterpret_cast<const uchar *>(rgbData2.constData()));
} else {
report = razer_chroma_standard_matrix_set_custom_frame(row, startColumn, endColumn, reinterpret_cast<const uchar *>(rgbData2.constData()));
Expand Down
33 changes: 17 additions & 16 deletions src/led/razermatrixled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool RazerMatrixLED::setOff()
return false;
saveFxAndColors(RazerEffect::Off, 0);
if (device->hasQuirk(RazerDeviceQuirks::ExtendedMatrix)) {
return setExtendedMatrixEffect(RazerMouseMatrixEffectId::Off);
return setExtendedMatrixEffect(RazerMatrixEffectId::Off);
} else if (device->hasQuirk(RazerDeviceQuirks::MouseMatrix)) {
return setMouseMatrixEffect(RazerMouseMatrixEffectId::Off);
} else {
Expand All @@ -66,7 +66,7 @@ bool RazerMatrixLED::setStatic(RGB color)
return false;
saveFxAndColors(RazerEffect::Static, 1, color);
if (device->hasQuirk(RazerDeviceQuirks::ExtendedMatrix)) {
return setExtendedMatrixEffect(RazerMouseMatrixEffectId::Static, 0x00, 0x00, 0x01, color.r, color.g, color.b);
return setExtendedMatrixEffect(RazerMatrixEffectId::Static, 0x00, 0x00, 0x01, color.r, color.g, color.b);
} else if (device->hasQuirk(RazerDeviceQuirks::MouseMatrix)) {
return setMouseMatrixEffect(RazerMouseMatrixEffectId::Static, 0x00, 0x00, 0x01, color.r, color.g, color.b);
} else {
Expand All @@ -81,7 +81,7 @@ bool RazerMatrixLED::setBreathing(RGB color)
return false;
saveFxAndColors(RazerEffect::Breathing, 1, color);
if (device->hasQuirk(RazerDeviceQuirks::ExtendedMatrix)) {
return setExtendedMatrixEffect(RazerMouseMatrixEffectId::Breathing, 0x01, 0x00, 0x01, color.r, color.g, color.b);
return setExtendedMatrixEffect(RazerMatrixEffectId::Breathing, 0x01, 0x00, 0x01, color.r, color.g, color.b);
} else if (device->hasQuirk(RazerDeviceQuirks::MouseMatrix)) {
return setMouseMatrixEffect(RazerMouseMatrixEffectId::Breathing, 0x01, 0x00, 0x01, color.r, color.g, color.b);
} else {
Expand All @@ -96,7 +96,7 @@ bool RazerMatrixLED::setBreathingDual(RGB color, RGB color2)
return false;
saveFxAndColors(RazerEffect::BreathingDual, 2, color, color2);
if (device->hasQuirk(RazerDeviceQuirks::ExtendedMatrix)) {
return setExtendedMatrixEffect(RazerMouseMatrixEffectId::Breathing, 0x02, 0x00, 0x02, color.r, color.g, color.b, color2.r, color2.g, color2.b);
return setExtendedMatrixEffect(RazerMatrixEffectId::Breathing, 0x02, 0x00, 0x02, color.r, color.g, color.b, color2.r, color2.g, color2.b);
} else if (device->hasQuirk(RazerDeviceQuirks::MouseMatrix)) {
return setMouseMatrixEffect(RazerMouseMatrixEffectId::Breathing, 0x02, 0x00, 0x02, color.r, color.g, color.b, color2.r, color2.g, color2.b);
} else {
Expand All @@ -111,7 +111,7 @@ bool RazerMatrixLED::setBreathingRandom()
return false;
saveFxAndColors(RazerEffect::BreathingRandom, 0);
if (device->hasQuirk(RazerDeviceQuirks::ExtendedMatrix)) {
return setExtendedMatrixEffect(RazerMouseMatrixEffectId::Breathing);
return setExtendedMatrixEffect(RazerMatrixEffectId::Breathing);
} else if (device->hasQuirk(RazerDeviceQuirks::MouseMatrix)) {
return setMouseMatrixEffect(RazerMouseMatrixEffectId::Breathing);
} else {
Expand All @@ -136,7 +136,7 @@ bool RazerMatrixLED::setSpectrum()
return false;
saveFxAndColors(RazerEffect::Spectrum, 0);
if (device->hasQuirk(RazerDeviceQuirks::ExtendedMatrix)) {
return setExtendedMatrixEffect(RazerMouseMatrixEffectId::Spectrum);
return setExtendedMatrixEffect(RazerMatrixEffectId::Spectrum);
} else if (device->hasQuirk(RazerDeviceQuirks::MouseMatrix)) {
return setMouseMatrixEffect(RazerMouseMatrixEffectId::Spectrum);
} else {
Expand All @@ -152,10 +152,11 @@ bool RazerMatrixLED::setWave(WaveDirection direction)
saveFxAndColors(RazerEffect::Wave, 0);
if (device->hasQuirk(RazerDeviceQuirks::ExtendedMatrix)) {
// Wave direction is 0x00 / 0x01 instead of 0x01 / 0x02 for extended_matrix, so subtract one
return setExtendedMatrixEffect(RazerMouseMatrixEffectId::Wave, static_cast<uchar>(direction) - 0x01, 0x28);
return setExtendedMatrixEffect(RazerMatrixEffectId::Wave, static_cast<uchar>(direction) - 0x01, 0x28);
} else if (device->hasQuirk(RazerDeviceQuirks::MouseMatrix)) {
// Wave direction is 0x00 / 0x01 instead of 0x01 / 0x02 for mouse_matrix, so subtract one
return setMouseMatrixEffect(RazerMouseMatrixEffectId::Wave, static_cast<uchar>(direction) - 0x01, 0x28);
// TODO
qWarning("Unknown to set wave with mouse matrix");
return false;
} else {
return setMatrixEffect(RazerMatrixEffectId::Wave, static_cast<uchar>(direction));
}
Expand All @@ -168,7 +169,7 @@ bool RazerMatrixLED::setReactive(ReactiveSpeed speed, RGB color)
return false;
saveFxAndColors(RazerEffect::Reactive, 1, color);
if (device->hasQuirk(RazerDeviceQuirks::ExtendedMatrix)) {
return setExtendedMatrixEffect(RazerMouseMatrixEffectId::Reactive, 0x00, static_cast<uchar>(speed), 0x01, color.r, color.g, color.b);
return setExtendedMatrixEffect(RazerMatrixEffectId::Reactive, 0x00, static_cast<uchar>(speed), 0x01, color.r, color.g, color.b);
} else if (device->hasQuirk(RazerDeviceQuirks::MouseMatrix)) {
return setMouseMatrixEffect(RazerMouseMatrixEffectId::Reactive, 0x00, static_cast<uchar>(speed), 0x01, color.r, color.g, color.b);
} else {
Expand Down Expand Up @@ -239,11 +240,14 @@ bool RazerMatrixLED::setMatrixEffect(RazerMatrixEffectId effect, uchar arg1, uch
return true;
}

bool RazerMatrixLED::setExtendedMatrixEffect(RazerMouseMatrixEffectId effect, uchar arg3, uchar arg4, uchar arg5, uchar arg6, uchar arg7, uchar arg8, uchar arg9, uchar arg10, uchar arg11)
bool RazerMatrixLED::setExtendedMatrixEffect(RazerMatrixEffectId effect, uchar arg3, uchar arg4, uchar arg5, uchar arg6, uchar arg7, uchar arg8, uchar arg9, uchar arg10, uchar arg11)
{
razer_report report, response_report;

report = razer_chroma_extended_matrix_effect(RazerVarstore::STORE, this->ledId, effect);
// Custom Frame uses 0x00 LED ID
RazerLedId ledId = effect == RazerMatrixEffectId::CustomFrame ? RazerLedId::Unspecified : this->ledId;

report = razer_chroma_extended_matrix_effect(RazerVarstore::STORE, ledId, effect);
report.arguments[3] = arg3;
report.arguments[4] = arg4;
report.arguments[5] = arg5;
Expand All @@ -264,10 +268,7 @@ bool RazerMatrixLED::setMouseMatrixEffect(RazerMouseMatrixEffectId effect, uchar
{
razer_report report, response_report;

// Custom Frame uses 0x00 LED ID
RazerLedId ledId = effect == RazerMouseMatrixEffectId::CustomFrame ? RazerLedId::Unspecified : this->ledId;

report = razer_chroma_extended_mouse_matrix_effect(RazerVarstore::STORE, ledId, effect);
report = razer_chroma_extended_mouse_matrix_effect(RazerVarstore::STORE, this->ledId, effect);
report.arguments[3] = arg3;
report.arguments[4] = arg4;
report.arguments[5] = arg5;
Expand Down
2 changes: 1 addition & 1 deletion src/led/razermatrixled.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class RazerMatrixLED : public RazerLED

bool setMatrixEffect(RazerMatrixEffectId effect,
uchar arg1 = 0x00, uchar arg2 = 0x00, uchar arg3 = 0x00, uchar arg4 = 0x00, uchar arg5 = 0x00, uchar arg6 = 0x00, uchar arg7 = 0x00, uchar arg8 = 0x00);
bool setExtendedMatrixEffect(RazerMouseMatrixEffectId effect,
bool setExtendedMatrixEffect(RazerMatrixEffectId effect,
uchar arg3 = 0x00, uchar arg4 = 0x00, uchar arg5 = 0x00, uchar arg6 = 0x00, uchar arg7 = 0x00, uchar arg8 = 0x00, uchar arg9 = 0x00, uchar arg10 = 0x00, uchar arg11 = 0x00);
bool setMouseMatrixEffect(RazerMouseMatrixEffectId effect,
uchar arg3 = 0x00, uchar arg4 = 0x00, uchar arg5 = 0x00, uchar arg6 = 0x00, uchar arg7 = 0x00, uchar arg8 = 0x00, uchar arg9 = 0x00, uchar arg10 = 0x00, uchar arg11 = 0x00);
Expand Down
13 changes: 4 additions & 9 deletions src/razer_test_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,12 @@ enum class RazerMatrixEffectId : uchar {
Starlight = 0x19
};

// Also used by "extended matrix"
// TODO Rename enum
enum class RazerMouseMatrixEffectId : uchar {
Off = 0x00,
Static = 0x01,
Breathing = 0x02,
Spectrum = 0x03,
Wave = 0x04,
Reactive = 0x05,
Starlight = 0x07,
CustomFrame = 0x08
Reactive = 0x02,
Breathing = 0x03,
Spectrum = 0x04,
Static = 0x06,
};

enum class RazerDeviceQuirks {
Expand Down
8 changes: 4 additions & 4 deletions src/razerreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ razer_report razer_chroma_standard_matrix_set_custom_frame(uchar row_index, ucha
return report;
}

razer_report razer_chroma_extended_mouse_matrix_effect(RazerVarstore variable_storage, RazerLedId led_id, RazerMouseMatrixEffectId effect)
razer_report razer_chroma_extended_mouse_matrix_effect(RazerVarstore variable_storage, RazerLedId led_id, RazerMouseMatrixEffectId effect_id)
{
razer_report report = get_razer_report(0x0F, 0x02, 80);
razer_report report = get_razer_report(0x03, 0x0D, 80);
report.arguments[0] = static_cast<uchar>(variable_storage);
report.arguments[1] = static_cast<uchar>(led_id);
report.arguments[2] = static_cast<uchar>(effect);
report.arguments[2] = static_cast<uchar>(effect_id);

return report;
}
Expand All @@ -206,7 +206,7 @@ razer_report razer_chroma_extended_matrix_get_brightness(RazerVarstore variable_
return report;
}

razer_report razer_chroma_extended_matrix_effect(RazerVarstore variable_storage, RazerLedId led_id, RazerMouseMatrixEffectId effect_id)
razer_report razer_chroma_extended_matrix_effect(RazerVarstore variable_storage, RazerLedId led_id, RazerMatrixEffectId effect_id)
{
razer_report report = get_razer_report(0x0F, 0x02, 80);
report.arguments[0] = static_cast<uchar>(variable_storage);
Expand Down
2 changes: 1 addition & 1 deletion src/razerreport.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ razer_report razer_chroma_standard_matrix_set_custom_frame(uchar row_index, ucha

razer_report razer_chroma_extended_matrix_set_brightness(RazerVarstore variable_storage, RazerLedId led_id, uchar brightness);
razer_report razer_chroma_extended_matrix_get_brightness(RazerVarstore variable_storage, RazerLedId led_id);
razer_report razer_chroma_extended_matrix_effect(RazerVarstore variable_storage, RazerLedId led_id, RazerMouseMatrixEffectId effect_id);
razer_report razer_chroma_extended_matrix_effect(RazerVarstore variable_storage, RazerLedId led_id, RazerMatrixEffectId effect_id);

razer_report razer_chroma_extended_mouse_matrix_effect(RazerVarstore variable_storage, RazerLedId led_id, RazerMouseMatrixEffectId effect);

Expand Down

0 comments on commit 4fe6756

Please sign in to comment.