Skip to content

Commit

Permalink
Add lux only mode (#35)
Browse files Browse the repository at this point in the history
* Add lux meter only mode

* Update images and readme

* Update images
  • Loading branch information
oleksiikutuzov authored Dec 12, 2022
1 parent 221d683 commit 78c2005
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 26 deletions.
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ App(
],
stack_size=1 * 1024,
order=90,
fap_version=(0, 6),
fap_version=(0, 7),
fap_icon="lightmeter.png",
fap_category="Tools",
fap_private_libs=[
Expand Down
30 changes: 28 additions & 2 deletions gui/scenes/lightmeter_scene_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ static const char* backlight[] = {
[BACKLIGHT_ON] = "On",
};

static const char* lux_only[] = {
[LUX_ONLY_OFF] = "Off",
[LUX_ONLY_ON] = "On",
};

enum LightMeterSubmenuIndex {
LightMeterSubmenuIndexISO,
LightMeterSubmenuIndexND,
LightMeterSubmenuIndexDome,
LightMeterSubmenuIndexBacklight,
LightMeterSubmenuIndexLuxMeter,
LightMeterSubmenuIndexHelp,
LightMeterSubmenuIndexAbout,
};

static void iso_numbers_cb(VariableItem* item) {
Expand Down Expand Up @@ -107,14 +116,25 @@ static void backlight_cb(VariableItem* item) {
lightmeter_app_set_config(app, config);
}

static void lux_only_cb(VariableItem* item) {
LightMeterApp* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);

variable_item_set_current_value_text(item, lux_only[index]);

LightMeterConfig* config = app->config;
config->lux_only = index;
lightmeter_app_set_config(app, config);
}

static void ok_cb(void* context, uint32_t index) {
LightMeterApp* app = context;
UNUSED(app);
switch(index) {
case 4:
case LightMeterSubmenuIndexHelp:
view_dispatcher_send_custom_event(app->view_dispatcher, LightMeterAppCustomEventHelp);
break;
case 5:
case LightMeterSubmenuIndexAbout:
view_dispatcher_send_custom_event(app->view_dispatcher, LightMeterAppCustomEventAbout);
break;
default:
Expand Down Expand Up @@ -148,6 +168,11 @@ void lightmeter_scene_config_on_enter(void* context) {
variable_item_set_current_value_index(item, config->backlight);
variable_item_set_current_value_text(item, backlight[config->backlight]);

item = variable_item_list_add(
var_item_list, "Lux meter only", COUNT_OF(lux_only), lux_only_cb, app);
variable_item_set_current_value_index(item, config->lux_only);
variable_item_set_current_value_text(item, lux_only[config->lux_only]);

item = variable_item_list_add(var_item_list, "Help and Pinout", 0, NULL, NULL);
item = variable_item_list_add(var_item_list, "About", 0, NULL, NULL);

Expand Down Expand Up @@ -187,4 +212,5 @@ void lightmeter_scene_config_on_exit(void* context) {
main_view_set_iso(app->main_view, app->config->iso);
main_view_set_nd(app->main_view, app->config->nd);
main_view_set_dome(app->main_view, app->config->dome);
main_view_set_lux_only(app->main_view, app->config->lux_only);
}
2 changes: 2 additions & 0 deletions gui/scenes/lightmeter_scene_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ void lightmeter_scene_help_on_enter(void* context) {
furi_string_cat(temp_str, "\e#Pinout:\r\n");
furi_string_cat(
temp_str,
" VCC: 3.3V\r\n"
" GND: GND\r\n"
" SDA: 15 [C1]\r\n"
" SCL: 16 [C0]\r\n");

Expand Down
80 changes: 58 additions & 22 deletions gui/views/main_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,37 +94,39 @@ static void main_view_draw_callback(Canvas* canvas, void* context) {
furi_assert(context);
MainViewModel* model = context;

// FURI_LOG_D("MAIN VIEW", "Drawing");

canvas_clear(canvas);

// top row
draw_top_row(canvas, model);
// draw button
canvas_set_font(canvas, FontSecondary);
elements_button_left(canvas, "Config");

// add f, T values
canvas_set_font(canvas, FontBigNumbers);
if(!model->lux_only) {
// top row
draw_top_row(canvas, model);

// draw f icon and number
canvas_draw_icon(canvas, 15, 17, &I_f_10x14);
draw_aperture(canvas, model);
// add f, T values
canvas_set_font(canvas, FontBigNumbers);

// draw T icon and number
canvas_draw_icon(canvas, 15, 34, &I_T_10x14);
draw_speed(canvas, model);
// draw f icon and number
canvas_draw_icon(canvas, 15, 17, &I_f_10x14);
draw_aperture(canvas, model);

// draw button
canvas_set_font(canvas, FontSecondary);
elements_button_left(canvas, "Config");
// draw T icon and number
canvas_draw_icon(canvas, 15, 34, &I_T_10x14);
draw_speed(canvas, model);

// draw ND number
draw_nd_number(canvas, model);
// draw ND number
draw_nd_number(canvas, model);

// draw EV number
canvas_set_font(canvas, FontSecondary);
draw_EV_number(canvas, model);
// draw EV number
canvas_set_font(canvas, FontSecondary);
draw_EV_number(canvas, model);

// draw mode indicator
draw_mode_indicator(canvas, model);
// draw mode indicator
draw_mode_indicator(canvas, model);
} else {
draw_lux_only_mode(canvas, model);
}
}

static void main_view_process(MainView* main_view, InputEvent* event) {
Expand Down Expand Up @@ -267,6 +269,12 @@ void main_view_set_dome(MainView* main_view, bool dome) {
main_view->view, MainViewModel * model, { model->dome = dome; }, true);
}

void main_view_set_lux_only(MainView* main_view, bool lux_only) {
furi_assert(main_view);
with_view_model(
main_view->view, MainViewModel * model, { model->lux_only = lux_only; }, true);
}

bool main_view_get_dome(MainView* main_view) {
furi_assert(main_view);
bool val = false;
Expand Down Expand Up @@ -412,6 +420,8 @@ void draw_nd_number(Canvas* canvas, MainViewModel* context) {

char str[9];

canvas_set_font(canvas, FontSecondary);

if(model->response) {
snprintf(str, sizeof(str), "ND: %d", nd_numbers[model->nd]);
} else {
Expand All @@ -432,3 +442,29 @@ void draw_EV_number(Canvas* canvas, MainViewModel* context) {
canvas_draw_str_aligned(canvas, 87, 29, AlignLeft, AlignBottom, "EV: --");
}
}

void draw_lux_only_mode(Canvas* canvas, MainViewModel* context) {
MainViewModel* model = context;

if(!model->response) {
canvas_draw_box(canvas, 0, 0, 128, 12);
canvas_set_color(canvas, ColorWhite);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 24, 10, "No sensor found");
canvas_set_color(canvas, ColorBlack);
} else {
char str[12];

canvas_set_font(canvas, FontPrimary);

canvas_draw_line(canvas, 0, 10, 128, 10);
canvas_draw_str_aligned(canvas, 64, 1, AlignCenter, AlignTop, "Lux meter mode");

canvas_set_font(canvas, FontBigNumbers);
snprintf(str, sizeof(str), "%.0f", (double)model->lux);
canvas_draw_str_aligned(canvas, 80, 32, AlignRight, AlignCenter, str);

canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 85, 39, AlignLeft, AlignBottom, "Lux");
}
}
5 changes: 5 additions & 0 deletions gui/views/main_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef struct {
int aperture;
int speed;
bool dome;
bool lux_only;
} MainViewModel;

typedef void (*LightMeterMainViewButtonCallback)(void* context);
Expand Down Expand Up @@ -58,6 +59,8 @@ void main_view_set_speed(MainView* main_view, int val);

void main_view_set_dome(MainView* main_view, bool val);

void main_view_set_lux_only(MainView* main_view, bool val);

bool main_view_get_dome(MainView* main_view);

void draw_top_row(Canvas* canvas, MainViewModel* context);
Expand All @@ -71,3 +74,5 @@ void draw_mode_indicator(Canvas* canvas, MainViewModel* context);
void draw_nd_number(Canvas* canvas, MainViewModel* context);

void draw_EV_number(Canvas* canvas, MainViewModel* context);

void draw_lux_only_mode(Canvas* canvas, MainViewModel* context);
1 change: 1 addition & 0 deletions lightmeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef struct {
int aperture;
int dome;
int backlight;
int lux_only;
} LightMeterConfig;

typedef struct {
Expand Down
7 changes: 6 additions & 1 deletion lightmeter_config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#define LM_VERSION_APP "0.6"
#define LM_VERSION_APP "0.7"
#define LM_DEVELOPED "Oleksii Kutuzov"
#define LM_GITHUB "https://github.com/oleksiikutuzov/flipperzero-lightmeter"

Expand Down Expand Up @@ -99,4 +99,9 @@ typedef enum {
WITH_DOME,
} LightMeterDomePresence;

typedef enum {
LUX_ONLY_OFF,
LUX_ONLY_ON,
} LightMeterLuxOnlyMode;

typedef enum { BACKLIGHT_AUTO, BACKLIGHT_ON } LightMeterBacklight;

0 comments on commit 78c2005

Please sign in to comment.