Skip to content

Commit

Permalink
add game_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
vvvrrooomm committed Dec 18, 2020
1 parent b4c19cb commit 6bdae45
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 14 deletions.
11 changes: 8 additions & 3 deletions daemon/openrazer_daemon/dbus_services/dbus_methods/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,18 @@ def set_fan_speed(self, fan_id, fan_speed):
driver_file.write(payload)


@endpoint('razer.device.misc', 'setFanMode', in_sig='yy')
def set_fan_mode(self, fan_id, fan_mode):
@endpoint('razer.device.misc', 'setFanMode', in_sig='yyy')
def set_fan_mode(self, fan_id, fan_mode, game_mode):
"""
set fan mode
:param fan_id: might change fans separately if more than one available (ususally 0x00)
:param fan_mode: 0x00: automatic 0x01: manual
:param game_mode: This argument is for power mode of the CPU,
0 - balanced
1 - gaming
2 - creator
4 - custom
with 4 goes CPU boost and GPU boost power
"""

self.logger.debug("DBus call set_fan_mode")
Expand Down
4 changes: 2 additions & 2 deletions driver/razerchromacommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ struct razer_report razer_chroma_get_fan_speeed(unsigned char fan_id)
/*
* sets fan mode - manual or automatic
*/
struct razer_report razer_chroma_set_fan_mode(unsigned char fan_id, unsigned char fan_mode)
struct razer_report razer_chroma_set_fan_mode(unsigned char fan_id, unsigned char fan_mode, unsigned char game_mode )
{
struct razer_report report = get_razer_report(0x0d, 0x02, 0x04);
report.arguments[0] = 0x00; //frame_id: fixed value
report.arguments[1] = fan_id; //maybe fans can be set separately by id?
report.arguments[2] = 0x00; // unknown observed: 0x00
report.arguments[2] = game_mode; // thx phush0! 0x0:balanced, 0x1:gaming, 0x2:creator, 0x4:custom
report.arguments[3] = fan_mode;

return report;
Expand Down
2 changes: 1 addition & 1 deletion driver/razerchromacommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct razer_report razer_chroma_mouse_extended_matrix_effect_breathing_dual(uns
* class 0x0d as well
*/
struct razer_report razer_chroma_set_fan_speed(unsigned char fan_id, unsigned char fan_speed);
struct razer_report razer_chroma_set_fan_mode(unsigned char fan_id, unsigned char fan_mode);
struct razer_report razer_chroma_set_fan_mode(unsigned char fan_id, unsigned char fan_mode, unsigned char game_mode);

/*
* Misc Functions
Expand Down
4 changes: 2 additions & 2 deletions driver/razerkbd_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ static ssize_t razer_attr_write_fan_mode(struct device *dev, struct device_attri
switch(usb_dev->descriptor.idProduct) {
case USB_DEVICE_ID_RAZER_BLADE_EARLY_2020_BASE:
default:
if (count < 2) printk(KERN_WARNING "razerkbd: fan speed expects 2 bytes: fan_id, fan_mode");
report = razer_chroma_set_fan_mode(buf[0], buf[1]);
if (count < 3) printk(KERN_WARNING "razerkbd: fan speed expects 3 bytes: fan_id, fan_mode, game_mode");
report = razer_chroma_set_fan_mode(buf[0], buf[1], buf[2]);
break;
}
response = razer_send_payload(usb_dev, &report);
Expand Down
9 changes: 7 additions & 2 deletions examples/fan_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@

mode_manual = 0x01
mode_automatic = 0x01

game_mode_balanced = 0x00
game_mode_gaming = 0x01
game_mode_creator = 0x02
game_mode_custom = 0x04 # CPU boost and GPU boost power
high_speed = 0x36
low_speed = 0x2b

Expand All @@ -40,8 +45,8 @@

# Ad an example for each effect
if effect == 'fan_mode':
device.fx.fan_mode(mode_automatic)
device.fx.fan_mode(mode_automatic, game_mode_balanced)

elif effect == 'fan_speed':
device.fx.fan_speed(high_speed)
device.fx.fan_mode(mode_manual)
device.fx.fan_mode(mode_manual, game_mode_custom)
13 changes: 9 additions & 4 deletions pylib/openrazer/client/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,20 +384,25 @@ def set_fan_speed(self, fan_id: int, fan_speed: int) -> bool:

return True

def set_fan_mode(self, fan_id: int, fan_mode: int) -> bool:
def set_fan_mode(self, fan_id: int, fan_mode: int, game_mode: int) -> bool:
"""
Fan Mode
:param fan_id: usually 0x00
:param fan_speed: 0x00: automatic 0x01: manual
:param fan_mode: 0x00: automatic 0x01: manual
:param game_mode: This argument is for power mode of the CPU,
0 - balanced
1 - gaming
2 - creator
4 - custom
with 4 goes CPU boost and GPU boost power
:return: True if success, False otherwise
:rtype: bool
:raises ValueError: If parameters are invalid
"""

self._dbus_interfaces['device'].setFanMode(fan_id, fan_mode)
self._dbus_interfaces['device'].setFanMode(fan_id, fan_mode, game_mode)

return True

Expand Down
1 change: 1 addition & 0 deletions scripts/generate_fake_driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ declare -A files_metadata=(
["device_type"]="r;%(name)s"
["dpi"]="rw;800:800"
["dpi_stages"]="rw;0x010320032005dc05dc"
["fan_mode"]="rw;"
["firmware_version"]="r;v1.0"
["game_led_state"]="rw;0"
["is_mug_present"]="r;0"
Expand Down

0 comments on commit 6bdae45

Please sign in to comment.