Browse Source

Add backlight mode (#32)

* Include .clang-format

* Move .clang-format

* Configure backlight mode

* Bump version

* Use extern array

* Hide metering mode indicator
Oleksii Kutuzov 3 years ago
parent
commit
221d683061
8 changed files with 247 additions and 44 deletions
  1. 191 0
      .clang-format
  2. 1 1
      application.fam
  3. 36 2
      gui/scenes/lightmeter_scene_config.c
  4. 3 3
      gui/views/main_view.c
  5. 7 7
      lightmeter.c
  6. 1 0
      lightmeter.h
  7. 4 1
      lightmeter_config.h
  8. 4 30
      lightmeter_helper.c

+ 191 - 0
.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
+...
+

+ 1 - 1
application.fam

@@ -9,7 +9,7 @@ App(
     ],
     ],
     stack_size=1 * 1024,
     stack_size=1 * 1024,
     order=90,
     order=90,
-    fap_version=(0, 5),
+    fap_version=(0, 6),
     fap_icon="lightmeter.png",
     fap_icon="lightmeter.png",
     fap_category="Tools",
     fap_category="Tools",
     fap_private_libs=[
     fap_private_libs=[

+ 36 - 2
gui/scenes/lightmeter_scene_config.c

@@ -1,5 +1,7 @@
 #include "../../lightmeter.h"
 #include "../../lightmeter.h"
 
 
+#define TAG "Scene Config"
+
 static const char* iso_numbers[] = {
 static const char* iso_numbers[] = {
     [ISO_6] = "6",
     [ISO_6] = "6",
     [ISO_12] = "12",
     [ISO_12] = "12",
@@ -39,6 +41,11 @@ static const char* diffusion_dome[] = {
     [WITH_DOME] = "Yes",
     [WITH_DOME] = "Yes",
 };
 };
 
 
+static const char* backlight[] = {
+    [BACKLIGHT_AUTO] = "Auto",
+    [BACKLIGHT_ON] = "On",
+};
+
 enum LightMeterSubmenuIndex {
 enum LightMeterSubmenuIndex {
     LightMeterSubmenuIndexISO,
     LightMeterSubmenuIndexISO,
     LightMeterSubmenuIndexND,
     LightMeterSubmenuIndexND,
@@ -78,14 +85,36 @@ static void dome_presence_cb(VariableItem* item) {
     lightmeter_app_set_config(app, config);
     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) {
 static void ok_cb(void* context, uint32_t index) {
     LightMeterApp* app = context;
     LightMeterApp* app = context;
     UNUSED(app);
     UNUSED(app);
     switch(index) {
     switch(index) {
-    case 3:
+    case 4:
         view_dispatcher_send_custom_event(app->view_dispatcher, LightMeterAppCustomEventHelp);
         view_dispatcher_send_custom_event(app->view_dispatcher, LightMeterAppCustomEventHelp);
         break;
         break;
-    case 4:
+    case 5:
         view_dispatcher_send_custom_event(app->view_dispatcher, LightMeterAppCustomEventAbout);
         view_dispatcher_send_custom_event(app->view_dispatcher, LightMeterAppCustomEventAbout);
         break;
         break;
     default:
     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_index(item, config->dome);
     variable_item_set_current_value_text(item, diffusion_dome[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, "Help and Pinout", 0, NULL, NULL);
     item = variable_item_list_add(var_item_list, "About", 0, NULL, NULL);
     item = variable_item_list_add(var_item_list, "About", 0, NULL, NULL);
 
 

+ 3 - 3
gui/views/main_view.c

@@ -41,7 +41,7 @@ static const int nd_numbers[] = {
     [ND_4096] = 4096,
     [ND_4096] = 4096,
 };
 };
 
 
-static const float aperture_numbers[] = {
+const float aperture_numbers[] = {
     [AP_1] = 1.0,
     [AP_1] = 1.0,
     [AP_1_4] = 1.4,
     [AP_1_4] = 1.4,
     [AP_2] = 2.0,
     [AP_2] = 2.0,
@@ -59,7 +59,7 @@ static const float aperture_numbers[] = {
     [AP_128] = 128,
     [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_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_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_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);
         canvas_set_font(canvas, FontPrimary);
         // metering mode A – ambient, F – flash
         // 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]);
         snprintf(str, sizeof(str), "ISO: %d", iso_numbers[model->iso]);
         canvas_draw_str_aligned(canvas, 19, 1, AlignLeft, AlignTop, str);
         canvas_draw_str_aligned(canvas, 19, 1, AlignLeft, AlignTop, str);

+ 7 - 7
lightmeter.c

@@ -1,7 +1,7 @@
 #include "lightmeter.h"
 #include "lightmeter.h"
 #include "lightmeter_helper.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) {
 static bool lightmeter_custom_event_callback(void* context, uint32_t event) {
     furi_assert(context);
     furi_assert(context);
@@ -31,7 +31,6 @@ LightMeterApp* lightmeter_app_alloc(uint32_t first_scene) {
     bh1750_set_power_state(1);
     bh1750_set_power_state(1);
     bh1750_init();
     bh1750_init();
     bh1750_set_mode(ONETIME_HIGH_RES_MODE);
     bh1750_set_mode(ONETIME_HIGH_RES_MODE);
-    bh1750_set_mt_reg(100);
 
 
     // Set default values to config
     // Set default values to config
     app->config = malloc(sizeof(LightMeterConfig));
     app->config = malloc(sizeof(LightMeterConfig));
@@ -39,12 +38,11 @@ LightMeterApp* lightmeter_app_alloc(uint32_t first_scene) {
     app->config->nd = DEFAULT_ND;
     app->config->nd = DEFAULT_ND;
     app->config->aperture = DEFAULT_APERTURE;
     app->config->aperture = DEFAULT_APERTURE;
     app->config->dome = DEFAULT_DOME;
     app->config->dome = DEFAULT_DOME;
+    app->config->backlight = DEFAULT_BACKLIGHT;
 
 
     // Records
     // Records
     app->gui = furi_record_open(RECORD_GUI);
     app->gui = furi_record_open(RECORD_GUI);
     app->notifications = furi_record_open(RECORD_NOTIFICATION);
     app->notifications = furi_record_open(RECORD_NOTIFICATION);
-    notification_message(
-        app->notifications, &sequence_display_backlight_enforce_on); // force on backlight
 
 
     // View dispatcher
     // View dispatcher
     app->view_dispatcher = view_dispatcher_alloc();
     app->view_dispatcher = view_dispatcher_alloc();
@@ -112,9 +110,11 @@ void lightmeter_app_free(LightMeterApp* app) {
 
 
     // Records
     // Records
     furi_record_close(RECORD_GUI);
     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);
     furi_record_close(RECORD_NOTIFICATION);
 
 
     bh1750_set_power_state(0);
     bh1750_set_power_state(0);

+ 1 - 0
lightmeter.h

@@ -24,6 +24,7 @@ typedef struct {
     int nd;
     int nd;
     int aperture;
     int aperture;
     int dome;
     int dome;
+    int backlight;
 } LightMeterConfig;
 } LightMeterConfig;
 
 
 typedef struct {
 typedef struct {

+ 4 - 1
lightmeter_config.h

@@ -1,6 +1,6 @@
 #pragma once
 #pragma once
 
 
-#define LM_VERSION_APP "0.5"
+#define LM_VERSION_APP "0.6"
 #define LM_DEVELOPED "Oleksii Kutuzov"
 #define LM_DEVELOPED "Oleksii Kutuzov"
 #define LM_GITHUB "https://github.com/oleksiikutuzov/flipperzero-lightmeter"
 #define LM_GITHUB "https://github.com/oleksiikutuzov/flipperzero-lightmeter"
 
 
@@ -10,6 +10,7 @@
 #define DEFAULT_APERTURE AP_2_8
 #define DEFAULT_APERTURE AP_2_8
 #define DEFAULT_SPEED SPEED_125
 #define DEFAULT_SPEED SPEED_125
 #define DEFAULT_DOME WITHOUT_DOME
 #define DEFAULT_DOME WITHOUT_DOME
+#define DEFAULT_BACKLIGHT BACKLIGHT_AUTO
 
 
 typedef enum {
 typedef enum {
     ISO_6,
     ISO_6,
@@ -97,3 +98,5 @@ typedef enum {
     WITHOUT_DOME,
     WITHOUT_DOME,
     WITH_DOME,
     WITH_DOME,
 } LightMeterDomePresence;
 } LightMeterDomePresence;
+
+typedef enum { BACKLIGHT_AUTO, BACKLIGHT_ON } LightMeterBacklight;

+ 4 - 30
lightmeter_helper.c

@@ -1,33 +1,8 @@
 #include "lightmeter_helper.h"
 #include "lightmeter_helper.h"
 #include "lightmeter_config.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) {
 float lux2ev(float lux) {
     return log2(lux / 2.5);
     return log2(lux / 2.5);
@@ -41,7 +16,6 @@ float getMinDistance(float x, float v1, float v2) {
     return v1;
     return v1;
 }
 }
 
 
-// Convert calculated aperture value to photography style aperture value.
 float normalizeAperture(float a) {
 float normalizeAperture(float a) {
     for(int i = 0; i < AP_NUM; i++) {
     for(int i = 0; i < AP_NUM; i++) {
         float a1 = aperture_numbers[i];
         float a1 = aperture_numbers[i];
@@ -57,8 +31,8 @@ float normalizeAperture(float a) {
 
 
 float normalizeTime(float a) {
 float normalizeTime(float a) {
     for(int i = 0; i < SPEED_NUM; i++) {
     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) {
         if(a1 < a && a2 >= a) {
             return getMinDistance(a, a1, a2);
             return getMinDistance(a, a1, a2);