Allow disabling thermal profiles switching and leds management

This commit is contained in:
Denis 2024-01-07 15:44:47 +01:00
parent e0d36026e7
commit f75351fa36
No known key found for this signature in database
GPG key ID: DD9B63F805CF5C03
6 changed files with 102 additions and 63 deletions

View file

@ -22,6 +22,8 @@ int main(int argc, char ** argv) {
.rumble_on_mode_switch = true, .rumble_on_mode_switch = true,
.m1m2_mode = 0, .m1m2_mode = 0,
.touchbar = true, .touchbar = true,
.enable_thermal_profiles_switching = false,
.enable_leds_commands = false,
}; };
load_in_config(&in_settings, configuration_file); load_in_config(&in_settings, configuration_file);

View file

@ -11,4 +11,6 @@ gyro_to_analog_activation_treshold = 1;
touchbar = true; touchbar = true;
controller_bluetooth = true; controller_bluetooth = true;
dualsense_edge = false; dualsense_edge = false;
swap_y_z = true; swap_y_z = true;
enable_thermal_profiles_switching = true;
enable_leds_commands = true;

2
main.c
View file

@ -21,6 +21,8 @@ int main(int argc, char ** argv) {
.rumble_on_mode_switch = true, .rumble_on_mode_switch = true,
.m1m2_mode = 1, .m1m2_mode = 1,
.touchbar = true, .touchbar = true,
.enable_thermal_profiles_switching = false,
.enable_leds_commands = false,
}; };
load_in_config(&in_settings, configuration_file); load_in_config(&in_settings, configuration_file);

View file

@ -343,9 +343,11 @@ static int asus_kbd_ev_map(
} else if ((e->ev[i].code == KEY_DELETE) && (e->ev[i].value != 0)) { } else if ((e->ev[i].code == KEY_DELETE) && (e->ev[i].value != 0)) {
// this is left screen button, on long release both 0 and 1 events are emitted so just discard the 0 // this is left screen button, on long release both 0 and 1 events are emitted so just discard the 0
asus_kbd_user_data->parent->next_thermal_profile = asus_kbd_user_data->parent->current_thermal_profile + 1; if (conf->enable_thermal_profiles_switching) {
asus_kbd_user_data->parent->next_thermal_profile = asus_kbd_user_data->parent->current_thermal_profile + 1;
printf("Requested switch to thermal profile %d\n", (int)asus_kbd_user_data->parent->next_thermal_profile); printf("Requested switch to thermal profile %d\n", (int)asus_kbd_user_data->parent->next_thermal_profile);
}
} else if ((e->ev[i].code == KEY_F17) && (e->ev[i].value != 0)) { } else if ((e->ev[i].code == KEY_F17) && (e->ev[i].value != 0)) {
// this is right screen button, on long press, after passing short threshold both 0 and 1 events are emitted so just discard the 0 // this is right screen button, on long press, after passing short threshold both 0 and 1 events are emitted so just discard the 0
@ -1302,12 +1304,18 @@ static int rc71l_hidraw_set_leds(const dev_in_settings_t *const conf, int hidraw
hidraw_data->parent->static_led_color.g = g; hidraw_data->parent->static_led_color.g = g;
hidraw_data->parent->static_led_color.b = b; hidraw_data->parent->static_led_color.b = b;
return rc71l_hidraw_set_leds_inner( const int res = conf->enable_leds_commands ? rc71l_hidraw_set_leds_inner(
hidraw_fd, hidraw_fd,
hidraw_data->parent->static_led_color.r, hidraw_data->parent->static_led_color.r,
hidraw_data->parent->static_led_color.g, hidraw_data->parent->static_led_color.g,
hidraw_data->parent->static_led_color.b hidraw_data->parent->static_led_color.b
); ) : 0;
if (res != 0) {
sprintf(stderr, "Error setting leds: %d\n", res);
}
return res;
} }
#define PROFILES_COUNT 3 #define PROFILES_COUNT 3
@ -1332,44 +1340,46 @@ static void rc71l_hidraw_timer(
return; return;
} }
if (hidraw_data->parent->current_thermal_profile != hidraw_data->parent->next_thermal_profile) { if (conf->enable_thermal_profiles_switching) {
if (hidraw_data->parent->thermal_profile_expired == 0) { if (hidraw_data->parent->current_thermal_profile != hidraw_data->parent->next_thermal_profile) {
++hidraw_data->parent->thermal_profile_expired; if (hidraw_data->parent->thermal_profile_expired == 0) {
uint64_t thermal_profile_index = hidraw_data->parent->next_thermal_profile % PROFILES_COUNT; ++hidraw_data->parent->thermal_profile_expired;
uint64_t thermal_profile_index = hidraw_data->parent->next_thermal_profile % PROFILES_COUNT;
int change_thermal_result = system(profiles[thermal_profile_index]); int change_thermal_result = system(profiles[thermal_profile_index]);
if (change_thermal_result == 0) { if (change_thermal_result == 0) {
const int leds_set = rc71l_hidraw_set_leds_inner( const int leds_set = rc71l_hidraw_set_leds_inner(
hidraw_fd, hidraw_fd,
thermal_profile_index == 2 ? 0xFF : 0x00, thermal_profile_index == 2 ? 0xFF : 0x00,
thermal_profile_index == 1 ? 0xFF : 0x00, thermal_profile_index == 1 ? 0xFF : 0x00,
thermal_profile_index == 0 ? 0xFF : 0x00 thermal_profile_index == 0 ? 0xFF : 0x00
); );
if (leds_set != 0) { if (leds_set != 0) {
sprintf(stderr, "Error setting leds to tell the user about the new profile: %d\n", leds_set); sprintf(stderr, "Error setting leds to tell the user about the new profile: %d\n", leds_set);
}
} else {
fprintf(
stderr,
"Error setting the new thermal profile with '%s': %d\n",
profiles[thermal_profile_index],
change_thermal_result
);
} }
} else { } else {
fprintf( ++hidraw_data->parent->thermal_profile_expired;
stderr,
"Error setting the new thermal profile with '%s': %d\n",
profiles[thermal_profile_index],
change_thermal_result
);
}
} else {
++hidraw_data->parent->thermal_profile_expired;
if (hidraw_data->parent->thermal_profile_expired > 18) { if (hidraw_data->parent->thermal_profile_expired > 18) {
hidraw_data->parent->current_thermal_profile = hidraw_data->parent->next_thermal_profile; hidraw_data->parent->current_thermal_profile = hidraw_data->parent->next_thermal_profile;
hidraw_data->parent->thermal_profile_expired = 0; hidraw_data->parent->thermal_profile_expired = 0;
rc71l_hidraw_set_leds_inner( rc71l_hidraw_set_leds_inner(
hidraw_fd, hidraw_fd,
hidraw_data->parent->static_led_color.r, hidraw_data->parent->static_led_color.r,
hidraw_data->parent->static_led_color.g, hidraw_data->parent->static_led_color.g,
hidraw_data->parent->static_led_color.b hidraw_data->parent->static_led_color.b
); );
}
} }
} }
} }
@ -1415,34 +1425,42 @@ static int rc71l_platform_init(const dev_in_settings_t *const conf, void** platf
res = 0; res = 0;
char command_str[64] = "\0"; if (conf->enable_leds_commands) {
sprintf( char command_str[64] = "\0";
command_str, sprintf(
"asusctl led-mode static -c %02X%02X%02X", command_str,
platform->static_led_color.r, "asusctl led-mode static -c %02X%02X%02X",
platform->static_led_color.g, platform->static_led_color.r,
platform->static_led_color.b platform->static_led_color.g,
); platform->static_led_color.b
const int led_mode_cmd_result = system(command_str);
if (led_mode_cmd_result != 0) {
fprintf(
stderr,
"Error setting led mode to static over asusctl: %d\n",
led_mode_cmd_result
); );
}
memset(command_str, 0, sizeof(command_str)); const int led_mode_cmd_result = system(command_str);
sprintf(command_str, "asusctl -k high"); if (led_mode_cmd_result != 0) {
fprintf(
stderr,
"Error setting led mode to static over asusctl: %d\n",
led_mode_cmd_result
);
const int led_brightness_cmd_result = system(command_str); res = led_mode_cmd_result;
if (led_brightness_cmd_result != 0) { goto rc71l_platform_init_err;
fprintf( }
stderr,
"Error setting led brightness over asusctl: %d\n", memset(command_str, 0, sizeof(command_str));
led_brightness_cmd_result sprintf(command_str, "asusctl -k high");
);
const int led_brightness_cmd_result = system(command_str);
if (led_brightness_cmd_result != 0) {
fprintf(
stderr,
"Error setting led brightness over asusctl: %d\n",
led_brightness_cmd_result
);
res = led_brightness_cmd_result;
goto rc71l_platform_init_err;
}
} }
rc71l_platform_init_err: rc71l_platform_init_err:

View file

@ -55,6 +55,20 @@ void load_in_config(dev_in_settings_t *const out_conf, const char* const filepat
fprintf(stderr, "touchbar (bool) configuration not found. Default value will be used.\n"); fprintf(stderr, "touchbar (bool) configuration not found. Default value will be used.\n");
} }
int enable_thermal_profiles_switching;
if (config_lookup_bool(&cfg, "enable_thermal_profiles_switching", &enable_thermal_profiles_switching) != CONFIG_FALSE) {
out_conf->enable_thermal_profiles_switching = enable_thermal_profiles_switching;
} else {
fprintf(stderr, "enable_thermal_profiles_switching (bool) configuration not found. Default value will be used.\n");
}
int enable_leds_commands;
if (config_lookup_bool(&cfg, "enable_leds_commands", &enable_leds_commands) != CONFIG_FALSE) {
out_conf->enable_leds_commands = enable_leds_commands;
} else {
fprintf(stderr, "enable_leds_commands (bool) configuration not found. Default value will be used.\n");
}
config_destroy(&cfg); config_destroy(&cfg);
load_in_config_err: load_in_config_err:
@ -134,7 +148,6 @@ void load_out_config(dev_out_settings_t *const out_conf, const char* const filep
fprintf(stderr, "gyro_to_analog_mapping (int) configuration not found. Default value will be used.\n"); fprintf(stderr, "gyro_to_analog_mapping (int) configuration not found. Default value will be used.\n");
} }
config_destroy(&cfg); config_destroy(&cfg);
load_out_config_err: load_out_config_err:

View file

@ -8,6 +8,8 @@ typedef struct dev_in_settings {
uint16_t ff_gain; uint16_t ff_gain;
uint8_t m1m2_mode; uint8_t m1m2_mode;
bool touchbar; bool touchbar;
bool enable_thermal_profiles_switching;
bool enable_leds_commands;
} dev_in_settings_t; } dev_in_settings_t;
void load_in_config(dev_in_settings_t *const out_conf, const char* const filepath); void load_in_config(dev_in_settings_t *const out_conf, const char* const filepath);