Re-enable flash, refactor to use libmegapixels
This commit is contained in:
105
src/flash.c
105
src/flash.c
@@ -5,48 +5,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <libmegapixels.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GtkWidget *flash_window = NULL;
|
static GtkWidget *flash_window = NULL;
|
||||||
static GDBusProxy *dbus_brightness_proxy = NULL;
|
static GDBusProxy *dbus_brightness_proxy = NULL;
|
||||||
@@ -95,29 +54,6 @@ mp_flash_gtk_clean()
|
|||||||
g_object_unref(dbus_brightness_proxy);
|
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
|
static void
|
||||||
set_display_brightness(int brightness)
|
set_display_brightness(int brightness)
|
||||||
{
|
{
|
||||||
@@ -155,7 +91,7 @@ brightness_received(GDBusProxy *proxy, GAsyncResult *res, gpointer user_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
show_display_flash(MPFlash *flash)
|
show_display_flash(libmegapixels_camera *camera)
|
||||||
{
|
{
|
||||||
if (!flash_window)
|
if (!flash_window)
|
||||||
return false;
|
return false;
|
||||||
@@ -183,21 +119,21 @@ show_display_flash(MPFlash *flash)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mp_flash_enable(MPFlash *flash)
|
mp_flash_enable(libmegapixels_camera *camera)
|
||||||
{
|
{
|
||||||
switch (flash->type) {
|
switch (camera->flash_type) {
|
||||||
case FLASH_TYPE_LED:
|
case LIBMEGAPIXELS_FLASH_V4L:
|
||||||
lseek(flash->led.fd, 0, SEEK_SET);
|
case LIBMEGAPIXELS_FLASH_LED:
|
||||||
dprintf(flash->led.fd, "1\n");
|
libmegapixels_flash_on(camera);
|
||||||
break;
|
break;
|
||||||
case FLASH_TYPE_DISPLAY:
|
case LIBMEGAPIXELS_FLASH_SCREEN:
|
||||||
g_main_context_invoke(NULL, (GSourceFunc)show_display_flash, flash);
|
g_main_context_invoke(NULL, (GSourceFunc)show_display_flash, camera);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
hide_display_flash(MPFlash *flash)
|
hide_display_flash(libmegapixels_camera *camera)
|
||||||
{
|
{
|
||||||
if (!flash_window)
|
if (!flash_window)
|
||||||
return false;
|
return false;
|
||||||
@@ -209,14 +145,15 @@ hide_display_flash(MPFlash *flash)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mp_flash_disable(MPFlash *flash)
|
mp_flash_disable(libmegapixels_camera *camera)
|
||||||
{
|
{
|
||||||
switch (flash->type) {
|
switch (camera->flash_type) {
|
||||||
case FLASH_TYPE_LED:
|
case LIBMEGAPIXELS_FLASH_V4L:
|
||||||
// Flash gets reset automatically
|
case LIBMEGAPIXELS_FLASH_LED:
|
||||||
break;
|
libmegapixels_flash_off(camera);
|
||||||
case FLASH_TYPE_DISPLAY:
|
break;
|
||||||
g_main_context_invoke(NULL, (GSourceFunc)hide_display_flash, flash);
|
case LIBMEGAPIXELS_FLASH_SCREEN:
|
||||||
break;
|
g_main_context_invoke(NULL, (GSourceFunc)hide_display_flash, camera);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
src/flash.h
11
src/flash.h
@@ -1,13 +1,8 @@
|
|||||||
#include "gio/gio.h"
|
#include "gio/gio.h"
|
||||||
|
#include <libmegapixels.h>
|
||||||
typedef struct _MPFlash MPFlash;
|
|
||||||
|
|
||||||
void mp_flash_gtk_init(GDBusConnection *conn);
|
void mp_flash_gtk_init(GDBusConnection *conn);
|
||||||
void mp_flash_gtk_clean();
|
void mp_flash_gtk_clean();
|
||||||
|
|
||||||
MPFlash *mp_led_flash_from_path(const char *path);
|
void mp_flash_enable(libmegapixels_camera *camera);
|
||||||
MPFlash *mp_create_display_flash();
|
void mp_flash_disable(libmegapixels_camera *camera);
|
||||||
void mp_flash_free(MPFlash *flash);
|
|
||||||
|
|
||||||
void mp_flash_enable(MPFlash *flash);
|
|
||||||
void mp_flash_disable(MPFlash *flash);
|
|
||||||
|
@@ -113,6 +113,8 @@ update_process_pipeline()
|
|||||||
.focus.manual = state_io.focus.manual,
|
.focus.manual = state_io.focus.manual,
|
||||||
|
|
||||||
.balance = { balance_red, 1.0f, balance_blue },
|
.balance = { balance_red, 1.0f, balance_blue },
|
||||||
|
|
||||||
|
.flash_enabled = state_io.flash_enabled,
|
||||||
};
|
};
|
||||||
|
|
||||||
mp_process_pipeline_update_state(&new_state);
|
mp_process_pipeline_update_state(&new_state);
|
||||||
@@ -179,11 +181,9 @@ capture(MPPipeline *pipeline, const void *data)
|
|||||||
mp_camera_start_capture(mpcamera);
|
mp_camera_start_capture(mpcamera);
|
||||||
|
|
||||||
// Enable flash
|
// Enable flash
|
||||||
/* TODO: implement
|
if (state_io.flash_enabled) {
|
||||||
if (info->flash && flash_enabled) {
|
mp_flash_enable(state_io.camera);
|
||||||
mp_flash_enable(info->flash);
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
update_process_pipeline();
|
update_process_pipeline();
|
||||||
|
|
||||||
@@ -335,8 +335,9 @@ do_aaa()
|
|||||||
static void
|
static void
|
||||||
on_frame(MPBuffer buffer, void *_data)
|
on_frame(MPBuffer buffer, void *_data)
|
||||||
{
|
{
|
||||||
// Don't process frame when the window is not active
|
// Don't process frame when the window is not active, unless we're capturing an image,
|
||||||
if (!check_window_active()) {
|
// in which case the flash window may be active instead of this window
|
||||||
|
if (!check_window_active() && state_io.captures_remaining == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,11 +406,9 @@ on_frame(MPBuffer buffer, void *_data)
|
|||||||
mp_camera_start_capture(mpcamera);
|
mp_camera_start_capture(mpcamera);
|
||||||
|
|
||||||
// Disable flash
|
// Disable flash
|
||||||
/* TODO: implement
|
if (state_io.flash_enabled) {
|
||||||
if (info->flash && flash_enabled) {
|
mp_flash_disable(state_io.camera);
|
||||||
mp_flash_disable(info->flash);
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
update_process_pipeline();
|
update_process_pipeline();
|
||||||
}
|
}
|
||||||
|
@@ -147,6 +147,8 @@ update_io_pipeline()
|
|||||||
.stats.temp = state.stats.temp,
|
.stats.temp = state.stats.temp,
|
||||||
.stats.tint = state.stats.tint,
|
.stats.tint = state.stats.tint,
|
||||||
.stats.focus = state.stats.focus,
|
.stats.focus = state.stats.focus,
|
||||||
|
|
||||||
|
.flash_enabled = state.flash_enabled,
|
||||||
};
|
};
|
||||||
mp_io_pipeline_update_state(&new_state);
|
mp_io_pipeline_update_state(&new_state);
|
||||||
}
|
}
|
||||||
@@ -197,7 +199,8 @@ update_state(const mp_state_main *new_state)
|
|||||||
state.stats.focus = new_state->stats.focus;
|
state.stats.focus = new_state->stats.focus;
|
||||||
|
|
||||||
// Make the right settings available for the camera
|
// Make the right settings available for the camera
|
||||||
gtk_widget_set_visible(flash_button, state.control_flash);
|
// Even if there's no flash led/v4l, it'll just default to using the screen as flash, so always enable this button
|
||||||
|
gtk_widget_set_visible(flash_button, true);
|
||||||
gtk_widget_set_visible(iso_button, state.gain.control != 0);
|
gtk_widget_set_visible(iso_button, state.gain.control != 0);
|
||||||
gtk_widget_set_visible(shutter_button, state.exposure.control != 0);
|
gtk_widget_set_visible(shutter_button, state.exposure.control != 0);
|
||||||
|
|
||||||
|
@@ -1315,6 +1315,8 @@ update_state(MPPipeline *pipeline, const mp_state_proc *new_state)
|
|||||||
state_proc.balance[1] = new_state->balance[1];
|
state_proc.balance[1] = new_state->balance[1];
|
||||||
state_proc.balance[2] = new_state->balance[2];
|
state_proc.balance[2] = new_state->balance[2];
|
||||||
|
|
||||||
|
state_proc.flash_enabled = new_state->flash_enabled;
|
||||||
|
|
||||||
if (output_changed) {
|
if (output_changed) {
|
||||||
state_proc.camera_rotation = mod(
|
state_proc.camera_rotation = mod(
|
||||||
state_proc.mode->rotation - state_proc.device_rotation, 360);
|
state_proc.mode->rotation - state_proc.device_rotation, 360);
|
||||||
@@ -1337,7 +1339,6 @@ update_state(MPPipeline *pipeline, const mp_state_proc *new_state)
|
|||||||
.has_auto_focus_start = false,
|
.has_auto_focus_start = false,
|
||||||
.preview_buffer_width = output_buffer_width,
|
.preview_buffer_width = output_buffer_width,
|
||||||
.preview_buffer_height = output_buffer_height,
|
.preview_buffer_height = output_buffer_height,
|
||||||
.control_flash = false,
|
|
||||||
|
|
||||||
.gain.control = state_proc.gain.control,
|
.gain.control = state_proc.gain.control,
|
||||||
.gain.auto_control = state_proc.gain.auto_control,
|
.gain.auto_control = state_proc.gain.auto_control,
|
||||||
@@ -1363,6 +1364,8 @@ update_state(MPPipeline *pipeline, const mp_state_proc *new_state)
|
|||||||
.stats.temp = state_proc.stats.temp,
|
.stats.temp = state_proc.stats.temp,
|
||||||
.stats.tint = state_proc.stats.tint,
|
.stats.tint = state_proc.stats.tint,
|
||||||
.stats.focus = state_proc.stats.focus,
|
.stats.focus = state_proc.stats.focus,
|
||||||
|
|
||||||
|
.flash_enabled = state_proc.flash_enabled,
|
||||||
};
|
};
|
||||||
mp_main_update_state(&new_main);
|
mp_main_update_state(&new_main);
|
||||||
}
|
}
|
||||||
|
@@ -34,7 +34,6 @@ struct mp_process_pipeline_state {
|
|||||||
|
|
||||||
bool control_gain;
|
bool control_gain;
|
||||||
bool control_exposure;
|
bool control_exposure;
|
||||||
bool control_flash;
|
|
||||||
bool control_focus;
|
bool control_focus;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -31,7 +31,6 @@ typedef struct state_main {
|
|||||||
int burst_length;
|
int burst_length;
|
||||||
|
|
||||||
// Control state
|
// Control state
|
||||||
bool control_flash;
|
|
||||||
bool flash_enabled;
|
bool flash_enabled;
|
||||||
controlstate gain;
|
controlstate gain;
|
||||||
controlstate exposure;
|
controlstate exposure;
|
||||||
@@ -109,4 +108,6 @@ typedef struct state_proc {
|
|||||||
int mode_balance;
|
int mode_balance;
|
||||||
int mode_exposure;
|
int mode_exposure;
|
||||||
int mode_focus;
|
int mode_focus;
|
||||||
|
|
||||||
|
bool flash_enabled;
|
||||||
} mp_state_proc;
|
} mp_state_proc;
|
Reference in New Issue
Block a user