|
@@ -5,48 +5,7 @@
|
|
|
#include <inttypes.h>
|
|
|
#include <stdio.h>
|
|
|
#include <unistd.h>
|
|
|
-
|
|
|
-typedef enum {
|
|
|
- FLASH_TYPE_LED,
|
|
|
- FLASH_TYPE_DISPLAY,
|
|
|
-} FlashType;
|
|
|
-
|
|
|
-typedef struct {
|
|
|
- char path[260];
|
|
|
- int fd;
|
|
|
-} MPLEDFlash;
|
|
|
-
|
|
|
-typedef struct {
|
|
|
-} MPDisplayFlash;
|
|
|
-
|
|
|
-struct _MPFlash {
|
|
|
- FlashType type;
|
|
|
-
|
|
|
- union {
|
|
|
- MPLEDFlash led;
|
|
|
- MPDisplayFlash display;
|
|
|
- };
|
|
|
-};
|
|
|
-
|
|
|
-MPFlash *
|
|
|
-mp_led_flash_from_path(const char *path)
|
|
|
-{
|
|
|
- MPFlash *flash = malloc(sizeof(MPFlash));
|
|
|
- flash->type = FLASH_TYPE_LED;
|
|
|
-
|
|
|
- strncpy(flash->led.path, path, 259);
|
|
|
-
|
|
|
- char mpath[275];
|
|
|
- snprintf(mpath, 275, "%s/flash_strobe", path);
|
|
|
- flash->led.fd = open(mpath, O_WRONLY);
|
|
|
- if (flash->led.fd == -1) {
|
|
|
- g_printerr("Failed to open %s\n", mpath);
|
|
|
- free(flash);
|
|
|
- return NULL;
|
|
|
- }
|
|
|
-
|
|
|
- return flash;
|
|
|
-}
|
|
|
+#include <libmegapixels.h>
|
|
|
|
|
|
static GtkWidget *flash_window = NULL;
|
|
|
static GDBusProxy *dbus_brightness_proxy = NULL;
|
|
@@ -95,29 +54,6 @@ mp_flash_gtk_clean()
|
|
|
g_object_unref(dbus_brightness_proxy);
|
|
|
}
|
|
|
|
|
|
-MPFlash *
|
|
|
-mp_create_display_flash()
|
|
|
-{
|
|
|
- MPFlash *flash = malloc(sizeof(MPFlash));
|
|
|
- flash->type = FLASH_TYPE_DISPLAY;
|
|
|
-
|
|
|
- return flash;
|
|
|
-}
|
|
|
-
|
|
|
-void
|
|
|
-mp_flash_free(MPFlash *flash)
|
|
|
-{
|
|
|
- switch (flash->type) {
|
|
|
- case FLASH_TYPE_LED:
|
|
|
- close(flash->led.fd);
|
|
|
- break;
|
|
|
- case FLASH_TYPE_DISPLAY:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- free(flash);
|
|
|
-}
|
|
|
-
|
|
|
static void
|
|
|
set_display_brightness(int brightness)
|
|
|
{
|
|
@@ -155,7 +91,7 @@ brightness_received(GDBusProxy *proxy, GAsyncResult *res, gpointer user_data)
|
|
|
}
|
|
|
|
|
|
static bool
|
|
|
-show_display_flash(MPFlash *flash)
|
|
|
+show_display_flash(libmegapixels_camera *camera)
|
|
|
{
|
|
|
if (!flash_window)
|
|
|
return false;
|
|
@@ -183,21 +119,21 @@ show_display_flash(MPFlash *flash)
|
|
|
}
|
|
|
|
|
|
void
|
|
|
-mp_flash_enable(MPFlash *flash)
|
|
|
+mp_flash_enable(libmegapixels_camera *camera)
|
|
|
{
|
|
|
- switch (flash->type) {
|
|
|
- case FLASH_TYPE_LED:
|
|
|
- lseek(flash->led.fd, 0, SEEK_SET);
|
|
|
- dprintf(flash->led.fd, "1\n");
|
|
|
- break;
|
|
|
- case FLASH_TYPE_DISPLAY:
|
|
|
- g_main_context_invoke(NULL, (GSourceFunc)show_display_flash, flash);
|
|
|
- break;
|
|
|
+ switch (camera->flash_type) {
|
|
|
+ case LIBMEGAPIXELS_FLASH_V4L:
|
|
|
+ case LIBMEGAPIXELS_FLASH_LED:
|
|
|
+ libmegapixels_flash_on(camera);
|
|
|
+ break;
|
|
|
+ case LIBMEGAPIXELS_FLASH_SCREEN:
|
|
|
+ g_main_context_invoke(NULL, (GSourceFunc)show_display_flash, camera);
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static bool
|
|
|
-hide_display_flash(MPFlash *flash)
|
|
|
+hide_display_flash(libmegapixels_camera *camera)
|
|
|
{
|
|
|
if (!flash_window)
|
|
|
return false;
|
|
@@ -209,14 +145,15 @@ hide_display_flash(MPFlash *flash)
|
|
|
}
|
|
|
|
|
|
void
|
|
|
-mp_flash_disable(MPFlash *flash)
|
|
|
+mp_flash_disable(libmegapixels_camera *camera)
|
|
|
{
|
|
|
- switch (flash->type) {
|
|
|
- case FLASH_TYPE_LED:
|
|
|
- // Flash gets reset automatically
|
|
|
- break;
|
|
|
- case FLASH_TYPE_DISPLAY:
|
|
|
- g_main_context_invoke(NULL, (GSourceFunc)hide_display_flash, flash);
|
|
|
- break;
|
|
|
+ switch (camera->flash_type) {
|
|
|
+ case LIBMEGAPIXELS_FLASH_V4L:
|
|
|
+ case LIBMEGAPIXELS_FLASH_LED:
|
|
|
+ libmegapixels_flash_off(camera);
|
|
|
+ break;
|
|
|
+ case LIBMEGAPIXELS_FLASH_SCREEN:
|
|
|
+ g_main_context_invoke(NULL, (GSourceFunc)hide_display_flash, camera);
|
|
|
+ break;
|
|
|
}
|
|
|
}
|