mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
ratbagd: make the LED properties writable
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
committed by
Benjamin Tissoires
parent
40bd189cc0
commit
f53bf7d4ad
@@ -258,7 +258,7 @@ org.freedesktop.ratbag1.Led
|
||||
Index of the LED
|
||||
|
||||
#### `Mode`
|
||||
- type: `u`, read-only, mutable
|
||||
- type: `u`, read-write, mutable
|
||||
|
||||
uint mapping to the mode enum from libratbag
|
||||
|
||||
@@ -268,29 +268,19 @@ uint mapping to the mode enum from libratbag
|
||||
String describing the LED type
|
||||
|
||||
#### `Color`
|
||||
- type: `(uuu)`, read-only, mutable
|
||||
- type: `(uuu)`, read-write, mutable
|
||||
uint triplet (RGB) of the LED's color
|
||||
|
||||
#### `EffectRate`
|
||||
- type: `u`, read-only, mutable
|
||||
- type: `u`, read-write, mutable
|
||||
|
||||
The effect rate in Hz, possible values are in the range 100 - 20000
|
||||
|
||||
#### `Brightness`
|
||||
- type: `u`, read-only, mutable
|
||||
- type: `u`, read-write, mutable
|
||||
|
||||
The brightness of the LED, possible values are in the range 0 - 255
|
||||
|
||||
### Methods:
|
||||
#### `SetMode(u) → ()`
|
||||
Set the mode to the given mode enum value from libratbag
|
||||
#### `SetColor((uuu)) → ()`
|
||||
Set the color to the given uint triplet (RGB)
|
||||
#### `SetEffectRate(u) → ()`
|
||||
Set the effect rate in Hz, possible values are in the range 100 - 20000
|
||||
#### `SetBrightness(i) → ()`
|
||||
Set the brightness, possible values are in the range 0 - 255
|
||||
|
||||
For easier debugging, objects paths are constructed from the device. e.g.
|
||||
`/org/freedesktop/ratbag/button/event5/p0/b10` is the button interface for
|
||||
button 10 on profile 0 on event5. The naming is subject to change. Do not
|
||||
|
||||
@@ -54,7 +54,11 @@ static int ratbagd_led_get_mode(sd_bus *bus,
|
||||
return sd_bus_message_append(reply, "u", mode);
|
||||
}
|
||||
|
||||
static int ratbagd_led_set_mode(sd_bus_message *m,
|
||||
static int ratbagd_led_set_mode(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
@@ -77,7 +81,7 @@ static int ratbagd_led_set_mode(sd_bus_message *m,
|
||||
NULL);
|
||||
}
|
||||
|
||||
return sd_bus_reply_method_return(m, "u", r);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int ratbagd_led_get_type(sd_bus *bus,
|
||||
@@ -127,7 +131,11 @@ static int ratbagd_led_get_color(sd_bus *bus,
|
||||
return sd_bus_message_append(reply, "(uuu)", c.red, c.green, c.blue);
|
||||
}
|
||||
|
||||
static int ratbagd_led_set_color(sd_bus_message *m,
|
||||
static int ratbagd_led_set_color(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
@@ -153,7 +161,7 @@ static int ratbagd_led_set_color(sd_bus_message *m,
|
||||
NULL);
|
||||
}
|
||||
|
||||
return sd_bus_reply_method_return(m, "u", r);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int ratbagd_led_get_effect_rate(sd_bus *bus,
|
||||
@@ -168,10 +176,14 @@ static int ratbagd_led_get_effect_rate(sd_bus *bus,
|
||||
int rate;
|
||||
|
||||
rate = ratbag_led_get_effect_rate(led->lib_led);
|
||||
return sd_bus_message_append(reply, "i", rate);
|
||||
return sd_bus_message_append(reply, "u", rate);
|
||||
}
|
||||
|
||||
static int ratbagd_led_set_effect_rate(sd_bus_message *m,
|
||||
static int ratbagd_led_set_effect_rate(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
@@ -197,7 +209,7 @@ static int ratbagd_led_set_effect_rate(sd_bus_message *m,
|
||||
NULL);
|
||||
}
|
||||
|
||||
return sd_bus_reply_method_return(m, "u", r);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int ratbagd_led_get_brightness(sd_bus *bus,
|
||||
@@ -215,7 +227,11 @@ static int ratbagd_led_get_brightness(sd_bus *bus,
|
||||
return sd_bus_message_append(reply, "u", brightness);
|
||||
}
|
||||
|
||||
static int ratbagd_led_set_brightness(sd_bus_message *m,
|
||||
static int ratbagd_led_set_brightness(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
@@ -241,22 +257,26 @@ static int ratbagd_led_set_brightness(sd_bus_message *m,
|
||||
NULL);
|
||||
}
|
||||
|
||||
return sd_bus_reply_method_return(m, "u", r);
|
||||
return r;
|
||||
}
|
||||
|
||||
const sd_bus_vtable ratbagd_led_vtable[] = {
|
||||
SD_BUS_VTABLE_START(0),
|
||||
SD_BUS_PROPERTY("Index", "u", NULL, offsetof(struct ratbagd_led, index), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Mode", "u", ratbagd_led_get_mode, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_WRITABLE_PROPERTY("Mode", "u",
|
||||
ratbagd_led_get_mode,
|
||||
ratbagd_led_set_mode, 0,
|
||||
SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("Type", "s", ratbagd_led_get_type, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Color", "(uuu)", ratbagd_led_get_color, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("EffectRate", "i", ratbagd_led_get_effect_rate, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("Brightness", "u", ratbagd_led_get_brightness, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
|
||||
SD_BUS_METHOD("SetMode", "u", "u", ratbagd_led_set_mode, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("SetColor", "(uuu)", "u", ratbagd_led_set_color, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("SetEffectRate", "u", "u", ratbagd_led_set_effect_rate, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("SetBrightness", "u", "u", ratbagd_led_set_brightness, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_WRITABLE_PROPERTY("Color", "(uuu)",
|
||||
ratbagd_led_get_color, ratbagd_led_set_color, 0,
|
||||
SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_WRITABLE_PROPERTY("EffectRate", "u",
|
||||
ratbagd_led_get_effect_rate, ratbagd_led_set_effect_rate, 0,
|
||||
SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_WRITABLE_PROPERTY("Brightness", "u",
|
||||
ratbagd_led_get_brightness, ratbagd_led_set_brightness, 0,
|
||||
SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_VTABLE_END,
|
||||
};
|
||||
|
||||
|
||||
@@ -536,9 +536,7 @@ class RatbagdLed(_RatbagdDBus):
|
||||
@param mode The new mode, as one of MODE_OFF, MODE_ON, MODE_CYCLE and
|
||||
MODE_BREATHING.
|
||||
"""
|
||||
ret = self._dbus_call("SetMode", "u", mode)
|
||||
self._set_dbus_property("Mode", "u", mode)
|
||||
return ret
|
||||
return self._set_dbus_property("Mode", "u", mode)
|
||||
|
||||
@GObject.Property
|
||||
def type(self):
|
||||
@@ -556,9 +554,7 @@ class RatbagdLed(_RatbagdDBus):
|
||||
|
||||
@param color An RGB color, as an integer triplet with values 0-255.
|
||||
"""
|
||||
ret = self._dbus_call("SetColor", "(uuu)", color)
|
||||
self._set_dbus_property("Color", "(uuu)", color)
|
||||
return ret
|
||||
return self._set_dbus_property("Color", "(uuu)", color)
|
||||
|
||||
@GObject.Property
|
||||
def effect_rate(self):
|
||||
@@ -571,9 +567,7 @@ class RatbagdLed(_RatbagdDBus):
|
||||
|
||||
@param effect_rate The new effect rate, as int
|
||||
"""
|
||||
ret = self._dbus_call("SetEffectRate", "u", effect_rate)
|
||||
self._set_dbus_property("EffectRate", "u", effect_rate)
|
||||
return ret
|
||||
return self._set_dbus_property("EffectRate", "u", effect_rate)
|
||||
|
||||
@GObject.Property
|
||||
def brightness(self):
|
||||
@@ -586,6 +580,4 @@ class RatbagdLed(_RatbagdDBus):
|
||||
|
||||
@param brightness The new brightness, as int
|
||||
"""
|
||||
ret = self._dbus_call("SetBrightness", "u", brightness)
|
||||
self._set_dbus_property("Brightness", "u", brightness)
|
||||
return ret
|
||||
return self._set_dbus_property("Brightness", "u", brightness)
|
||||
|
||||
Reference in New Issue
Block a user