Skip to content

Commit

Permalink
* add a light switch in app_camera
Browse files Browse the repository at this point in the history
  • Loading branch information
lxowalle committed Oct 17, 2024
1 parent 7c02fc5 commit ae6a527
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 5 deletions.
31 changes: 31 additions & 0 deletions projects/app_camera/main/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "maix_util.hpp"
#include "maix_image.hpp"
#include "maix_app.hpp"
#include "maix_pinmap.hpp"
#include "maix_gpio.hpp"
#include "maix_fs.hpp"
#include "maix_vision.hpp"
#include "sophgo_middleware.hpp"
Expand All @@ -16,6 +18,8 @@
#include <unistd.h>

using namespace maix;
using namespace maix::peripheral;

#define MMF_VENC_CHN (1)
static struct {
uint32_t cam_start_snap_flag : 1;
Expand Down Expand Up @@ -51,6 +55,7 @@ static struct {
display::Display *other_disp;
touchscreen::TouchScreen *touchscreen;
video::Encoder *encoder;
gpio::GPIO *light;
} priv;

static void _capture_image(maix::camera::Camera &camera, maix::image::Image *img);
Expand Down Expand Up @@ -255,6 +260,12 @@ int app_base_init(void)
priv.touchscreen = new touchscreen::TouchScreen();
err::check_bool_raise(priv.touchscreen->is_opened(), "touchscreen open failed");

// init light
pinmap::set_pin_function("B3", "GPIOB3");
priv.light = new gpio::GPIO("B3", gpio::Mode::OUT);
priv.light->low();
err::check_null_raise(priv.light, "light gpio open failed");

// init gui
maix::lvgl_init(priv.other_disp, priv.touchscreen);
app_init(*priv.camera);
Expand All @@ -267,6 +278,11 @@ int app_base_deinit(void)
{
maix::lvgl_destroy();

if (priv.light) {
delete priv.light;
priv.light = NULL;
}

if (priv.touchscreen) {
delete priv.touchscreen;
priv.touchscreen = NULL;
Expand Down Expand Up @@ -556,6 +572,21 @@ static int app_config_param(void)
app_base_init();
}

if (ui_get_light_btn_update_flag()) {
if (ui_get_light_btn_touched()) {
log::info("light on");
if (priv.light) {
priv.light->high();
}
} else {
log::info("light off");
if (priv.light) {
priv.light->low();
}
}
}


if (ui_get_ev_setting_flag()) {
if (ui_get_ev_auto_flag()) {
printf("EV setting: Auto\n");
Expand Down
46 changes: 41 additions & 5 deletions projects/app_camera/main/app/ui_event_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "ui_utils.h"
#include "ui_event_handler.h"

// #define DEBUG_ENABLE
#define DEBUG_ENABLE
#ifdef DEBUG_ENABLE
#define DEBUG_EN(x) \
bool g_debug_flag = x;
Expand All @@ -18,6 +18,9 @@
#define DEBUG_PRT(fmt, ...)
#endif

LV_IMG_DECLARE(img_light_on);
LV_IMG_DECLARE(img_light_off);

extern lv_obj_t *g_camera_video_button;
extern lv_obj_t *g_start_snap_button;
extern lv_obj_t *g_exit_button;
Expand All @@ -42,6 +45,7 @@ extern lv_obj_t *g_focus_button;
extern lv_obj_t *g_shutter_plus_minus_button;
extern lv_obj_t *g_iso_plus_minus_button;
extern lv_obj_t *g_raw_button;
extern lv_obj_t *g_light_button;

static struct {
unsigned int camera_snap_start_flag : 1;
Expand All @@ -66,6 +70,8 @@ static struct {
unsigned int focus_btn_update_flag : 1;
unsigned int raw_btn_touched : 1;
unsigned int raw_btn_update_flag : 1;
unsigned int light_btn_touched : 1;
unsigned int light_btn_update_flag : 1;

unsigned int resolution_setting_idx;
} priv = {
Expand Down Expand Up @@ -433,7 +439,7 @@ void event_touch_iso_plus_cb(lv_event_t *e)
if (code == LV_EVENT_CLICKED) {
int iso;
ui_get_iso_value(&iso);
DEBUG_PRT("get iso: %d\n", iso);
DEBUG_PRT("get iso: %f\n", iso);
int index_of_table = get_index_of_iso_table(iso);
DEBUG_PRT("caculated index_of_table: %d\n", index_of_table);
index_of_table += 1;
Expand All @@ -456,12 +462,12 @@ void event_touch_iso_minus_cb(lv_event_t *e)
if (code == LV_EVENT_CLICKED) {
int iso;
ui_get_iso_value(&iso);
DEBUG_PRT("get iso: %d\n", iso);
DEBUG_PRT("get iso: %f\n", iso);
int index_of_table = get_index_of_iso_table(iso);
DEBUG_PRT("caculated index_of_table: %d\n", index_of_table);
index_of_table -= 1;
iso = get_iso_from_iso_table(index_of_table);
DEBUG_PRT("caculated iso: %d\n", iso);
DEBUG_PRT("caculated iso: %f\n", iso);
ui_set_iso_value(iso);

priv.iso_setting_flag = 1;
Expand Down Expand Up @@ -534,6 +540,26 @@ void event_touch_raw_cb(lv_event_t * e)
}
}

void event_touch_light_cb(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_CLICKED) {
if (lv_obj_get_state(g_light_button) != LV_STATE_FOCUSED) {
priv.light_btn_touched = 1;
priv.light_btn_update_flag = 1;

lv_obj_t *img = lv_obj_get_child(g_light_button, -1);
lv_image_set_src(img, &img_light_on);
} else {
priv.light_btn_touched = 0;
priv.light_btn_update_flag = 1;

lv_obj_t *img = lv_obj_get_child(g_light_button, -1);
lv_image_set_src(img, &img_light_off);
}
}
}

static double bar_value_to_exp_us(lv_obj_t *obj, uint16_t shutter_bar_value)
{
DEBUG_EN(0);
Expand Down Expand Up @@ -586,7 +612,7 @@ static int bar_value_to_iso(lv_obj_t *obj, uint16_t bar_value)
int index_of_table = bar_value / (double)((bar->max_value - bar->min_value) / (number_of_table - 1));
DEBUG_PRT("caculated index_of_table:%d\n", index_of_table);
int iso = camera_config.iso_table[index_of_table];
DEBUG_PRT("found iso:%d\n", iso);
DEBUG_PRT("found iso:%f\n", iso);
return iso;
}

Expand Down Expand Up @@ -1458,4 +1484,14 @@ bool ui_get_raw_btn_update_flag() {

bool ui_get_raw_btn_touched() {
return priv.raw_btn_touched ? true : false;
}

bool ui_get_light_btn_update_flag() {
bool flag = priv.light_btn_update_flag ? true : false;
priv.light_btn_update_flag = false;
return flag;
}

bool ui_get_light_btn_touched() {
return priv.light_btn_touched ? true : false;
}
3 changes: 3 additions & 0 deletions projects/app_camera/main/app/ui_event_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void event_touch_shutter_minus_cb(lv_event_t *e);
void event_touch_iso_plus_cb(lv_event_t *e);
void event_touch_iso_minus_cb(lv_event_t *e);
void event_touch_raw_cb(lv_event_t * e);
void event_touch_light_cb(lv_event_t * e);

bool ui_get_cam_snap_flag(void);
bool ui_get_cam_video_start_flag(void);
Expand Down Expand Up @@ -80,6 +81,8 @@ bool ui_get_focus_btn_update_flag();
bool ui_get_focus_btn_touched();
bool ui_get_raw_btn_update_flag();
bool ui_get_raw_btn_touched();
bool ui_get_light_btn_update_flag();
bool ui_get_light_btn_touched();

typedef struct {
unsigned int exposure_time_max;
Expand Down
21 changes: 21 additions & 0 deletions projects/app_camera/main/app/ui_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ lv_obj_t *g_center_img;

lv_obj_t *g_video_running_screen;
lv_obj_t *g_focus_button;
lv_obj_t *g_light_button;
lv_obj_t *g_raw_button;
lv_obj_t *g_shutter_plus_minus_button;
lv_obj_t *g_iso_plus_minus_button;
Expand All @@ -65,6 +66,8 @@ LV_IMG_DECLARE(img_video_stop);
LV_IMG_DECLARE(img_small_recording);
LV_IMG_DECLARE(img_focus);
LV_IMG_DECLARE(img_raw);
LV_IMG_DECLARE(img_light_on);
LV_IMG_DECLARE(img_light_off);

extern void event_touch_exit_cb(lv_event_t * e);
extern void event_touch_delay_cb(lv_event_t * e);
Expand Down Expand Up @@ -270,6 +273,24 @@ static void left_screen_init(void)
lv_obj_set_style_text_font(label, &lv_font_montserrat_16, 0);
lv_obj_center(label);
}

{
lv_obj_t *obj = lv_obj_create(scr);
lv_obj_set_size(obj, lv_pct(100), lv_pct(25));
lv_obj_set_pos(obj, 0, lv_pct(150));
lv_obj_set_style_bg_color(obj, lv_color_hex(0), 0);
lv_obj_set_style_bg_color(obj, lv_color_hex(0x2e2e2e), LV_STATE_CHECKED);
lv_obj_set_style_border_side(obj, LV_BORDER_SIDE_NONE, 0);
lv_obj_set_style_radius(obj, 0, 0);
lv_obj_remove_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_add_flag(obj, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_CHECKABLE);
lv_obj_add_event_cb(obj, event_touch_light_cb, LV_EVENT_CLICKED, NULL);
g_light_button = obj;

img = lv_image_create(obj);
lv_image_set_src(img, &img_light_off);
lv_obj_center(img);
}
}

static void right_screen_init(void)
Expand Down
Loading

0 comments on commit ae6a527

Please sign in to comment.