use a shell command to set leds
This commit is contained in:
parent
4ab34c4547
commit
8a97652d05
1 changed files with 5 additions and 157 deletions
162
rog_ally.c
162
rog_ally.c
|
|
@ -1218,84 +1218,6 @@ static input_dev_t in_xbox_dev = {
|
|||
}
|
||||
};
|
||||
|
||||
static int rc71l_hidraw_map(const dev_in_settings_t *const conf, int hidraw_fd, in_message_t *const messages, size_t messages_len, void* user_data) {
|
||||
uint8_t data[256];
|
||||
const int read_res = read(hidraw_fd, data, sizeof(data));
|
||||
|
||||
if (read_res < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
//printf("Got %d bytes from Asus MCU\n", read_res); // either 6 or 32
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rc71l_hidraw_rumble(const dev_in_settings_t *const conf, int hidraw_fd, uint8_t left_motor, uint8_t right_motor, void* user_data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rc71l_hidraw_set_leds(const dev_in_settings_t *const conf, int hidraw_fd, uint8_t r, uint8_t g, uint8_t b, void* user_data) {
|
||||
const uint8_t brightness_buf[] = {
|
||||
0x5A, 0xBA, 0xC5, 0xC4, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
const uint8_t colors_buf[] = {
|
||||
0x5A, 0xB3, 0x00, ROG_ALLY_MODE_STATIC, r, g, b, 0x00, ROG_ALLY_DIRECTION_RIGHT, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
if (write(hidraw_fd, brightness_buf, sizeof(brightness_buf)) != 64) {
|
||||
fprintf(stderr, "Unable to send LEDs brightness (1) command change: %d\n", errno);
|
||||
goto rc71l_hidraw_set_leds_err;
|
||||
}
|
||||
|
||||
if (write(hidraw_fd, colors_buf, sizeof(colors_buf)) != 64) {
|
||||
fprintf(stderr, "Unable to send LEDs color command change (1)\n");
|
||||
goto rc71l_hidraw_set_leds_err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
rc71l_hidraw_set_leds_err:
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static void rc71l_hidraw_timer(
|
||||
const dev_in_settings_t *const conf,
|
||||
int fd,
|
||||
const char* const timer_name,
|
||||
uint64_t expired,
|
||||
void* user_data
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
static input_dev_t nkey_dev = {
|
||||
.dev_type = input_dev_type_hidraw,
|
||||
.filters = {
|
||||
.hidraw = {
|
||||
.pid = 0x1abe,
|
||||
.vid = 0x0b05,
|
||||
.rdesc_size = 167, // 48 83 167
|
||||
}
|
||||
},
|
||||
.user_data = NULL,
|
||||
.map = {
|
||||
.hidraw_callbacks = {
|
||||
.leds_callback = rc71l_hidraw_set_leds,
|
||||
.rumble_callback = rc71l_hidraw_rumble,
|
||||
.map_callback = rc71l_hidraw_map,
|
||||
.timeout_callback = rc71l_hidraw_timer,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static int rc71l_platform_init(const dev_in_settings_t *const conf, void** platform_data) {
|
||||
int res = -EINVAL;
|
||||
|
||||
|
|
@ -1336,87 +1258,17 @@ static void rc71l_platform_deinit(const dev_in_settings_t *const conf, void** pl
|
|||
*platform_data = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function should use the following:
|
||||
* pub static DBUS_NAME: &str = "org.asuslinux.Daemon";
|
||||
* pub static DBUS_PATH: &str = "/org/asuslinux/Daemon";
|
||||
* pub static DBUS_IFACE: &str = "org.asuslinux.Daemon";
|
||||
*/
|
||||
static int rc71l_platform_leds(const dev_in_settings_t *const conf, uint8_t r, uint8_t g, uint8_t b, void* platform_data) {
|
||||
rc71l_platform_t *const platform = (rc71l_platform_t*)platform_data;
|
||||
|
||||
// TODO: before removing this make sure to disable the hidraw backend
|
||||
return 0;
|
||||
|
||||
dbus_uint32_t new_brightness = (r << 24) | (g << 16) | (b << 8) | (3);
|
||||
|
||||
if (platform_data == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Replace "org.asuslinux.Daemon" and "/org/asuslinux/Aura" with the actual service and object paths
|
||||
const char *service_name = "org.asuslinux.Daemon";
|
||||
const char *object_path = "/org/asuslinux/Aura";
|
||||
const char *interface_name = "org.freedesktop.DBus.Properties";
|
||||
const char *target_interface_name = "org.asuslinux.Daemon";
|
||||
|
||||
// Replace "Brightness" with the actual property name
|
||||
const char *property_name = "Brightness";
|
||||
|
||||
// try to connect
|
||||
if (platform->dbus_conn == NULL) {
|
||||
platform->dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &platform->dbus_error);
|
||||
if (dbus_error_is_set(&platform->dbus_error)) {
|
||||
fprintf(stderr, "DBus error connection : %s -- %s \n", platform->dbus_error.name, platform->dbus_error.message);
|
||||
dbus_error_free(&platform->dbus_error);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Build the D-Bus message to set the property
|
||||
DBusMessage *const message = dbus_message_new_method_call(service_name, object_path, interface_name, "Set");
|
||||
if (!message) {
|
||||
fprintf(stderr, "Error creating D-Bus message\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
// Append the property name and the new value to the message
|
||||
//dbus_message_append_args(message, DBUS_TYPE_STRING, &target_interface_name, DBUS_TYPE_STRING, &property_name, DBUS_TYPE_INVALID);
|
||||
|
||||
// Initialize an iterator for the message arguments
|
||||
DBusMessageIter iter;
|
||||
dbus_message_iter_init_append(message, &iter);
|
||||
|
||||
dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &target_interface_name);
|
||||
|
||||
dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &property_name);
|
||||
|
||||
// Open the variant container
|
||||
DBusMessageIter variantIter;
|
||||
dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, "u", &variantIter);
|
||||
|
||||
// Append the uint32 value to the variant container
|
||||
dbus_message_iter_append_basic(&variantIter, DBUS_TYPE_UINT32, &new_brightness);
|
||||
|
||||
// Close the variant container
|
||||
dbus_message_iter_close_container(&iter, &variantIter);
|
||||
|
||||
// Send the message
|
||||
DBusMessage *reply = dbus_connection_send_with_reply_and_block(platform->dbus_conn, message, -1, &platform->dbus_error);
|
||||
dbus_message_unref(message);
|
||||
|
||||
if (!reply || dbus_error_is_set(&platform->dbus_error)) {
|
||||
fprintf(stderr, "D-Bus method call error: %s\n", platform->dbus_error.message);
|
||||
dbus_error_free(&platform->dbus_error);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
// Handle the reply if needed
|
||||
|
||||
// Free the D-Bus message
|
||||
//dbus_message_unref(message);
|
||||
|
||||
return 0;
|
||||
char command_str[64] = "\0";
|
||||
sprintf(command_str, "asusctl led-mode static -c %02X%02X%02X",r ,g ,b);
|
||||
|
||||
return system(command_str);
|
||||
}
|
||||
|
||||
int rc71l_timer_map(const dev_in_settings_t *const conf, int timer_fd, uint64_t expirations, in_message_t *const messages, size_t messages_len, void* user_data) {
|
||||
|
|
@ -1427,9 +1279,6 @@ int rc71l_timer_map(const dev_in_settings_t *const conf, int timer_fd, uint64_t
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1456,11 +1305,10 @@ input_dev_composite_t rc71l_composite = {
|
|||
&in_asus_kb_1_dev,
|
||||
&in_asus_kb_2_dev,
|
||||
&in_asus_kb_3_dev,
|
||||
&nkey_dev,
|
||||
&timer_dev,
|
||||
&in_touchscreen_dev,
|
||||
},
|
||||
.dev_count = 8,
|
||||
.dev_count = 7,
|
||||
.init_fn = rc71l_platform_init,
|
||||
.deinit_fn = rc71l_platform_deinit,
|
||||
.leds_fn = rc71l_platform_leds,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue