From 221d683061f92b1adedaa70fec82fd9a6eaac1e5 Mon Sep 17 00:00:00 2001 From: Oleksii Kutuzov <8535871+oleksiikutuzov@users.noreply.github.com> Date: Sun, 27 Nov 2022 20:20:23 +0100 Subject: [PATCH] Add backlight mode (#32) * Include .clang-format * Move .clang-format * Configure backlight mode * Bump version * Use extern array * Hide metering mode indicator --- .clang-format | 191 +++++++++++++++++++++++++++ application.fam | 2 +- gui/scenes/lightmeter_scene_config.c | 38 +++++- gui/views/main_view.c | 6 +- lightmeter.c | 14 +- lightmeter.h | 1 + lightmeter_config.h | 5 +- lightmeter_helper.c | 34 +---- 8 files changed, 247 insertions(+), 44 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000000..4b76f7fa43b --- /dev/null +++ b/.clang-format @@ -0,0 +1,191 @@ +--- +Language: Cpp +AccessModifierOffset: -4 +AlignAfterOpenBracket: AlwaysBreak +AlignArrayOfStructures: None +AlignConsecutiveMacros: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: false +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: WithoutElse +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +AttributeMacros: + - __capability +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: true +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: false +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: false +ColumnLimit: 99 +CommentPragmas: '^ IWYU pragma:' +QualifierAlignment: Leave +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +PackConstructorInitializers: BinPack +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentRequires: false +IndentWidth: 4 +IndentWrappedFunctionNames: true +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 10 +PenaltyBreakBeforeFirstCallParameter: 30 +PenaltyBreakComment: 10 +PenaltyBreakFirstLessLess: 0 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 10 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 100 +PenaltyReturnTypeOnItsOwnLine: 60 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Left +PPIndentWidth: -1 +ReferenceAlignment: Pointer +ReflowComments: false +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: Never +SortJavaStaticImport: Before +SortUsingDeclarations: false +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: Never +SpaceBeforeParensOptions: + AfterControlStatements: false + AfterForeachMacros: false + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: false + AfterOverloadedOperator: false + BeforeNonEmptyParentheses: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: c++03 +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME +... + diff --git a/application.fam b/application.fam index 49a4f9832d8..b1fd4f8bc99 100644 --- a/application.fam +++ b/application.fam @@ -9,7 +9,7 @@ App( ], stack_size=1 * 1024, order=90, - fap_version=(0, 5), + fap_version=(0, 6), fap_icon="lightmeter.png", fap_category="Tools", fap_private_libs=[ diff --git a/gui/scenes/lightmeter_scene_config.c b/gui/scenes/lightmeter_scene_config.c index 42952562b0d..05f0b0f88ad 100644 --- a/gui/scenes/lightmeter_scene_config.c +++ b/gui/scenes/lightmeter_scene_config.c @@ -1,5 +1,7 @@ #include "../../lightmeter.h" +#define TAG "Scene Config" + static const char* iso_numbers[] = { [ISO_6] = "6", [ISO_12] = "12", @@ -39,6 +41,11 @@ static const char* diffusion_dome[] = { [WITH_DOME] = "Yes", }; +static const char* backlight[] = { + [BACKLIGHT_AUTO] = "Auto", + [BACKLIGHT_ON] = "On", +}; + enum LightMeterSubmenuIndex { LightMeterSubmenuIndexISO, LightMeterSubmenuIndexND, @@ -78,14 +85,36 @@ static void dome_presence_cb(VariableItem* item) { lightmeter_app_set_config(app, config); } +static void backlight_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, backlight[index]); + + LightMeterConfig* config = app->config; + if(index != config->backlight) { + if(index == BACKLIGHT_ON) { + notification_message( + app->notifications, + &sequence_display_backlight_enforce_on); // force on backlight + } else { + notification_message( + app->notifications, + &sequence_display_backlight_enforce_auto); // force auto backlight + } + } + config->backlight = index; + lightmeter_app_set_config(app, config); +} + static void ok_cb(void* context, uint32_t index) { LightMeterApp* app = context; UNUSED(app); switch(index) { - case 3: + case 4: view_dispatcher_send_custom_event(app->view_dispatcher, LightMeterAppCustomEventHelp); break; - case 4: + case 5: view_dispatcher_send_custom_event(app->view_dispatcher, LightMeterAppCustomEventAbout); break; default: @@ -114,6 +143,11 @@ void lightmeter_scene_config_on_enter(void* context) { variable_item_set_current_value_index(item, config->dome); variable_item_set_current_value_text(item, diffusion_dome[config->dome]); + item = + variable_item_list_add(var_item_list, "Backlight", COUNT_OF(backlight), backlight_cb, app); + 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, "Help and Pinout", 0, NULL, NULL); item = variable_item_list_add(var_item_list, "About", 0, NULL, NULL); diff --git a/gui/views/main_view.c b/gui/views/main_view.c index 756346fa438..99f42a8980f 100644 --- a/gui/views/main_view.c +++ b/gui/views/main_view.c @@ -41,7 +41,7 @@ static const int nd_numbers[] = { [ND_4096] = 4096, }; -static const float aperture_numbers[] = { +const float aperture_numbers[] = { [AP_1] = 1.0, [AP_1_4] = 1.4, [AP_2] = 2.0, @@ -59,7 +59,7 @@ static const float aperture_numbers[] = { [AP_128] = 128, }; -static const float speed_numbers[] = { +const float speed_numbers[] = { [SPEED_8000] = 1.0 / 8000, [SPEED_4000] = 1.0 / 4000, [SPEED_2000] = 1.0 / 2000, [SPEED_1000] = 1.0 / 1000, [SPEED_500] = 1.0 / 500, [SPEED_250] = 1.0 / 250, [SPEED_125] = 1.0 / 125, [SPEED_60] = 1.0 / 60, [SPEED_30] = 1.0 / 30, @@ -307,7 +307,7 @@ void draw_top_row(Canvas* canvas, MainViewModel* context) { canvas_set_font(canvas, FontPrimary); // metering mode A – ambient, F – flash - canvas_draw_str_aligned(canvas, 1, 1, AlignLeft, AlignTop, "A"); + // canvas_draw_str_aligned(canvas, 1, 1, AlignLeft, AlignTop, "A"); snprintf(str, sizeof(str), "ISO: %d", iso_numbers[model->iso]); canvas_draw_str_aligned(canvas, 19, 1, AlignLeft, AlignTop, str); diff --git a/lightmeter.c b/lightmeter.c index 6034a9ee946..07661d2d4c6 100644 --- a/lightmeter.c +++ b/lightmeter.c @@ -1,7 +1,7 @@ #include "lightmeter.h" #include "lightmeter_helper.h" -#define WORKER_TAG "MAIN APP" +#define TAG "MAIN APP" static bool lightmeter_custom_event_callback(void* context, uint32_t event) { furi_assert(context); @@ -31,7 +31,6 @@ LightMeterApp* lightmeter_app_alloc(uint32_t first_scene) { bh1750_set_power_state(1); bh1750_init(); bh1750_set_mode(ONETIME_HIGH_RES_MODE); - bh1750_set_mt_reg(100); // Set default values to config app->config = malloc(sizeof(LightMeterConfig)); @@ -39,12 +38,11 @@ LightMeterApp* lightmeter_app_alloc(uint32_t first_scene) { app->config->nd = DEFAULT_ND; app->config->aperture = DEFAULT_APERTURE; app->config->dome = DEFAULT_DOME; + app->config->backlight = DEFAULT_BACKLIGHT; // Records app->gui = furi_record_open(RECORD_GUI); app->notifications = furi_record_open(RECORD_NOTIFICATION); - notification_message( - app->notifications, &sequence_display_backlight_enforce_on); // force on backlight // View dispatcher app->view_dispatcher = view_dispatcher_alloc(); @@ -112,9 +110,11 @@ void lightmeter_app_free(LightMeterApp* app) { // Records furi_record_close(RECORD_GUI); - notification_message( - app->notifications, - &sequence_display_backlight_enforce_auto); // set backlight back to auto + if(app->config->backlight != BACKLIGHT_AUTO) { + notification_message( + app->notifications, + &sequence_display_backlight_enforce_auto); // set backlight back to auto + } furi_record_close(RECORD_NOTIFICATION); bh1750_set_power_state(0); diff --git a/lightmeter.h b/lightmeter.h index 679b32d1561..ccb3afb96c3 100644 --- a/lightmeter.h +++ b/lightmeter.h @@ -24,6 +24,7 @@ typedef struct { int nd; int aperture; int dome; + int backlight; } LightMeterConfig; typedef struct { diff --git a/lightmeter_config.h b/lightmeter_config.h index 023235cff37..f05b4a98b80 100644 --- a/lightmeter_config.h +++ b/lightmeter_config.h @@ -1,6 +1,6 @@ #pragma once -#define LM_VERSION_APP "0.5" +#define LM_VERSION_APP "0.6" #define LM_DEVELOPED "Oleksii Kutuzov" #define LM_GITHUB "https://github.com/oleksiikutuzov/flipperzero-lightmeter" @@ -10,6 +10,7 @@ #define DEFAULT_APERTURE AP_2_8 #define DEFAULT_SPEED SPEED_125 #define DEFAULT_DOME WITHOUT_DOME +#define DEFAULT_BACKLIGHT BACKLIGHT_AUTO typedef enum { ISO_6, @@ -97,3 +98,5 @@ typedef enum { WITHOUT_DOME, WITH_DOME, } LightMeterDomePresence; + +typedef enum { BACKLIGHT_AUTO, BACKLIGHT_ON } LightMeterBacklight; diff --git a/lightmeter_helper.c b/lightmeter_helper.c index 1cdddfca91e..465ccbce100 100644 --- a/lightmeter_helper.c +++ b/lightmeter_helper.c @@ -1,33 +1,8 @@ #include "lightmeter_helper.h" #include "lightmeter_config.h" -static const float aperture_numbers[] = { - [AP_1] = 1.0, - [AP_1_4] = 1.4, - [AP_2] = 2.0, - [AP_2_8] = 2.8, - [AP_4] = 4.0, - [AP_5_6] = 5.6, - [AP_8] = 8, - [AP_11] = 11, - [AP_16] = 16, - [AP_22] = 22, - [AP_32] = 32, - [AP_45] = 45, - [AP_64] = 64, - [AP_90] = 90, - [AP_128] = 128, -}; - -static const float time_numbers[] = { - [SPEED_8000] = 1.0 / 8000, [SPEED_4000] = 1.0 / 4000, [SPEED_2000] = 1.0 / 2000, - [SPEED_1000] = 1.0 / 1000, [SPEED_500] = 1.0 / 500, [SPEED_250] = 1.0 / 250, - [SPEED_125] = 1.0 / 125, [SPEED_60] = 1.0 / 60, [SPEED_30] = 1.0 / 30, - [SPEED_15] = 1.0 / 15, [SPEED_8] = 1.0 / 8, [SPEED_4] = 1.0 / 4, - [SPEED_2] = 1.0 / 2, [SPEED_1S] = 1.0, [SPEED_2S] = 2.0, - [SPEED_4S] = 4.0, [SPEED_8S] = 8.0, [SPEED_15S] = 15.0, - [SPEED_30S] = 30.0, -}; +extern const float aperture_numbers[]; +extern const float speed_numbers[]; float lux2ev(float lux) { return log2(lux / 2.5); @@ -41,7 +16,6 @@ float getMinDistance(float x, float v1, float v2) { return v1; } -// Convert calculated aperture value to photography style aperture value. float normalizeAperture(float a) { for(int i = 0; i < AP_NUM; i++) { float a1 = aperture_numbers[i]; @@ -57,8 +31,8 @@ float normalizeAperture(float a) { float normalizeTime(float a) { for(int i = 0; i < SPEED_NUM; i++) { - float a1 = time_numbers[i]; - float a2 = time_numbers[i + 1]; + float a1 = speed_numbers[i]; + float a2 = speed_numbers[i + 1]; if(a1 < a && a2 >= a) { return getMinDistance(a, a1, a2);