led: Add flash LED type
Camera flashes are also exported via the LED subsystem. We use a separate LED type so they're not picked by default. We don't use them as fallbacks either.
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Phosh Developers
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0+
|
||||
* Author: Guido Günther <agx@sigxcpu.org>
|
||||
*
|
||||
* See Documentation/ABI/testing/sysfs-class-led-trigger-pattern
|
||||
*/
|
||||
|
||||
#define G_LOG_DOMAIN "fbd-dev-led-flash"
|
||||
|
||||
#include "fbd-dev-led-priv.h"
|
||||
#include "fbd-dev-led-flash.h"
|
||||
#include "fbd-enums.h"
|
||||
#include "fbd-udev.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
/**
|
||||
* fbd-dev-led-flash:
|
||||
*
|
||||
* The LED of a camera flash
|
||||
*/
|
||||
typedef struct _FbdDevLedFlash {
|
||||
FbdDevLed parent;
|
||||
} FbdDevLedFlash;
|
||||
|
||||
|
||||
G_DEFINE_TYPE (FbdDevLedFlash, fbd_dev_led_flash, FBD_TYPE_DEV_LED)
|
||||
|
||||
|
||||
static gboolean
|
||||
fbd_dev_led_flash_probe (FbdDevLed *led, GError **error)
|
||||
{
|
||||
GUdevDevice *dev = fbd_dev_led_get_device (led);
|
||||
const gchar *name, *path;
|
||||
guint max_brightness;
|
||||
|
||||
name = g_udev_device_get_name (dev);
|
||||
if (!g_udev_device_get_sysfs_attr (dev, "flash_strobe") ||
|
||||
!g_udev_device_get_sysfs_attr (dev, "flash_brightness")) {
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s is no flash LED", name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
max_brightness = g_udev_device_get_sysfs_attr_as_int (dev, LED_MAX_BRIGHTNESS_ATTR);
|
||||
if (!max_brightness) {
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s has no max_brightness", name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fbd_dev_led_set_max_brightness (led, max_brightness);
|
||||
fbd_dev_led_set_supported_color (led, FBD_FEEDBACK_LED_COLOR_FLASH);
|
||||
|
||||
path = g_udev_device_get_sysfs_path (dev);
|
||||
g_debug ("LED at '%s' usable as flash", path);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
fbd_dev_led_flash_class_init (FbdDevLedFlashClass *klass)
|
||||
{
|
||||
FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_CLASS (klass);
|
||||
|
||||
fbd_dev_led_class->probe = fbd_dev_led_flash_probe;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
fbd_dev_led_flash_init (FbdDevLedFlash *self)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FbdDevLed *
|
||||
fbd_dev_led_flash_new (GUdevDevice *dev, GError **err)
|
||||
{
|
||||
return g_initable_new (FBD_TYPE_DEV_LED_FLASH, NULL, err, "dev", dev, NULL);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Phosh Developers
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0+
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "fbd-dev-led.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define FBD_TYPE_DEV_LED_FLASH fbd_dev_led_flash_get_type()
|
||||
|
||||
G_DECLARE_FINAL_TYPE (FbdDevLedFlash, fbd_dev_led_flash, FBD, DEV_LED_FLASH, FbdDevLed)
|
||||
|
||||
FbdDevLed *fbd_dev_led_flash_new (GUdevDevice *dev, GError **err);
|
||||
|
||||
G_END_DECLS
|
||||
+9
-2
@@ -53,8 +53,15 @@ find_led_by_color (FbdDevLeds *self, FbdFeedbackLedColor color)
|
||||
return led;
|
||||
}
|
||||
|
||||
/* If we did not match a color pick the first */
|
||||
return self->leds->data;
|
||||
/* If we did not match a color pick the first non flash LED */
|
||||
for (GSList *l = self->leds; l != NULL; l = l->next) {
|
||||
FbdDevLed *led = FBD_DEV_LED (l->data);
|
||||
|
||||
if (!fbd_dev_led_supports_color (led, FBD_FEEDBACK_LED_COLOR_FLASH))
|
||||
return led;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ G_BEGIN_DECLS
|
||||
* @FBD_FEEDBACK_LED_COLOR_GREEN: A green LED
|
||||
* @FBD_FEEDBACK_LED_COLOR_BLUE: A blue LED
|
||||
* @FBD_FEEDBACK_LED_COLOR_RGB: A multicolor LED that can display arbitrary RGB values
|
||||
* @FBD_FEEDBACK_LED_COLOR_FLASH: A flash (usually white)
|
||||
*
|
||||
* The color of a hardware LED.
|
||||
*/
|
||||
@@ -25,6 +26,8 @@ typedef enum _FbdFeedbackLedColor {
|
||||
FBD_FEEDBACK_LED_COLOR_GREEN = 2,
|
||||
FBD_FEEDBACK_LED_COLOR_BLUE = 3,
|
||||
FBD_FEEDBACK_LED_COLOR_RGB = 4,
|
||||
/* Keep this last in the list */
|
||||
FBD_FEEDBACK_LED_COLOR_FLASH = 5,
|
||||
} FbdFeedbackLedColor;
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -16,6 +16,7 @@ sources = [
|
||||
'fbd-dev-vibra.c',
|
||||
'fbd-dev-sound.c',
|
||||
'fbd-dev-led.c',
|
||||
'fbd-dev-led-flash.c',
|
||||
'fbd-dev-led-multicolor.c',
|
||||
'fbd-dev-led-qcom.c',
|
||||
'fbd-dev-led-qcom-multicolor.c',
|
||||
|
||||
Reference in New Issue
Block a user