Skip to content

Commit 221d683

Browse files
Add backlight mode (#32)
* Include .clang-format * Move .clang-format * Configure backlight mode * Bump version * Use extern array * Hide metering mode indicator
1 parent 8e9aec5 commit 221d683

8 files changed

+247
-44
lines changed

.clang-format

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
---
2+
Language: Cpp
3+
AccessModifierOffset: -4
4+
AlignAfterOpenBracket: AlwaysBreak
5+
AlignArrayOfStructures: None
6+
AlignConsecutiveMacros: None
7+
AlignConsecutiveAssignments: None
8+
AlignConsecutiveBitFields: None
9+
AlignConsecutiveDeclarations: None
10+
AlignEscapedNewlines: Left
11+
AlignOperands: Align
12+
AlignTrailingComments: false
13+
AllowAllArgumentsOnNextLine: true
14+
AllowAllParametersOfDeclarationOnNextLine: false
15+
AllowShortEnumsOnASingleLine: true
16+
AllowShortBlocksOnASingleLine: Never
17+
AllowShortCaseLabelsOnASingleLine: false
18+
AllowShortFunctionsOnASingleLine: None
19+
AllowShortLambdasOnASingleLine: All
20+
AllowShortIfStatementsOnASingleLine: WithoutElse
21+
AllowShortLoopsOnASingleLine: true
22+
AlwaysBreakAfterDefinitionReturnType: None
23+
AlwaysBreakAfterReturnType: None
24+
AlwaysBreakBeforeMultilineStrings: false
25+
AlwaysBreakTemplateDeclarations: Yes
26+
AttributeMacros:
27+
- __capability
28+
BinPackArguments: false
29+
BinPackParameters: false
30+
BraceWrapping:
31+
AfterCaseLabel: false
32+
AfterClass: false
33+
AfterControlStatement: Never
34+
AfterEnum: false
35+
AfterFunction: false
36+
AfterNamespace: false
37+
AfterObjCDeclaration: false
38+
AfterStruct: false
39+
AfterUnion: false
40+
AfterExternBlock: false
41+
BeforeCatch: false
42+
BeforeElse: false
43+
BeforeLambdaBody: false
44+
BeforeWhile: false
45+
IndentBraces: false
46+
SplitEmptyFunction: true
47+
SplitEmptyRecord: true
48+
SplitEmptyNamespace: true
49+
BreakBeforeBinaryOperators: None
50+
BreakBeforeConceptDeclarations: true
51+
BreakBeforeBraces: Attach
52+
BreakBeforeInheritanceComma: false
53+
BreakInheritanceList: BeforeColon
54+
BreakBeforeTernaryOperators: false
55+
BreakConstructorInitializersBeforeComma: false
56+
BreakConstructorInitializers: BeforeComma
57+
BreakAfterJavaFieldAnnotations: false
58+
BreakStringLiterals: false
59+
ColumnLimit: 99
60+
CommentPragmas: '^ IWYU pragma:'
61+
QualifierAlignment: Leave
62+
CompactNamespaces: false
63+
ConstructorInitializerIndentWidth: 4
64+
ContinuationIndentWidth: 4
65+
Cpp11BracedListStyle: true
66+
DeriveLineEnding: true
67+
DerivePointerAlignment: false
68+
DisableFormat: false
69+
EmptyLineAfterAccessModifier: Never
70+
EmptyLineBeforeAccessModifier: LogicalBlock
71+
ExperimentalAutoDetectBinPacking: false
72+
PackConstructorInitializers: BinPack
73+
BasedOnStyle: ''
74+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
75+
AllowAllConstructorInitializersOnNextLine: true
76+
FixNamespaceComments: false
77+
ForEachMacros:
78+
- foreach
79+
- Q_FOREACH
80+
- BOOST_FOREACH
81+
IfMacros:
82+
- KJ_IF_MAYBE
83+
IncludeBlocks: Preserve
84+
IncludeCategories:
85+
- Regex: '.*'
86+
Priority: 1
87+
SortPriority: 0
88+
CaseSensitive: false
89+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
90+
Priority: 3
91+
SortPriority: 0
92+
CaseSensitive: false
93+
- Regex: '.*'
94+
Priority: 1
95+
SortPriority: 0
96+
CaseSensitive: false
97+
IncludeIsMainRegex: '(Test)?$'
98+
IncludeIsMainSourceRegex: ''
99+
IndentAccessModifiers: false
100+
IndentCaseLabels: false
101+
IndentCaseBlocks: false
102+
IndentGotoLabels: true
103+
IndentPPDirectives: None
104+
IndentExternBlock: AfterExternBlock
105+
IndentRequires: false
106+
IndentWidth: 4
107+
IndentWrappedFunctionNames: true
108+
InsertTrailingCommas: None
109+
JavaScriptQuotes: Leave
110+
JavaScriptWrapImports: true
111+
KeepEmptyLinesAtTheStartOfBlocks: false
112+
LambdaBodyIndentation: Signature
113+
MacroBlockBegin: ''
114+
MacroBlockEnd: ''
115+
MaxEmptyLinesToKeep: 1
116+
NamespaceIndentation: None
117+
ObjCBinPackProtocolList: Auto
118+
ObjCBlockIndentWidth: 4
119+
ObjCBreakBeforeNestedBlockParam: true
120+
ObjCSpaceAfterProperty: true
121+
ObjCSpaceBeforeProtocolList: true
122+
PenaltyBreakAssignment: 10
123+
PenaltyBreakBeforeFirstCallParameter: 30
124+
PenaltyBreakComment: 10
125+
PenaltyBreakFirstLessLess: 0
126+
PenaltyBreakOpenParenthesis: 0
127+
PenaltyBreakString: 10
128+
PenaltyBreakTemplateDeclaration: 10
129+
PenaltyExcessCharacter: 100
130+
PenaltyReturnTypeOnItsOwnLine: 60
131+
PenaltyIndentedWhitespace: 0
132+
PointerAlignment: Left
133+
PPIndentWidth: -1
134+
ReferenceAlignment: Pointer
135+
ReflowComments: false
136+
RemoveBracesLLVM: false
137+
SeparateDefinitionBlocks: Leave
138+
ShortNamespaceLines: 1
139+
SortIncludes: Never
140+
SortJavaStaticImport: Before
141+
SortUsingDeclarations: false
142+
SpaceAfterCStyleCast: false
143+
SpaceAfterLogicalNot: false
144+
SpaceAfterTemplateKeyword: true
145+
SpaceBeforeAssignmentOperators: true
146+
SpaceBeforeCaseColon: false
147+
SpaceBeforeCpp11BracedList: false
148+
SpaceBeforeCtorInitializerColon: true
149+
SpaceBeforeInheritanceColon: true
150+
SpaceBeforeParens: Never
151+
SpaceBeforeParensOptions:
152+
AfterControlStatements: false
153+
AfterForeachMacros: false
154+
AfterFunctionDefinitionName: false
155+
AfterFunctionDeclarationName: false
156+
AfterIfMacros: false
157+
AfterOverloadedOperator: false
158+
BeforeNonEmptyParentheses: false
159+
SpaceAroundPointerQualifiers: Default
160+
SpaceBeforeRangeBasedForLoopColon: true
161+
SpaceInEmptyBlock: false
162+
SpaceInEmptyParentheses: false
163+
SpacesBeforeTrailingComments: 1
164+
SpacesInAngles: Never
165+
SpacesInConditionalStatement: false
166+
SpacesInContainerLiterals: false
167+
SpacesInCStyleCastParentheses: false
168+
SpacesInLineCommentPrefix:
169+
Minimum: 1
170+
Maximum: -1
171+
SpacesInParentheses: false
172+
SpacesInSquareBrackets: false
173+
SpaceBeforeSquareBrackets: false
174+
BitFieldColonSpacing: Both
175+
Standard: c++03
176+
StatementAttributeLikeMacros:
177+
- Q_EMIT
178+
StatementMacros:
179+
- Q_UNUSED
180+
- QT_REQUIRE_VERSION
181+
TabWidth: 4
182+
UseCRLF: false
183+
UseTab: Never
184+
WhitespaceSensitiveMacros:
185+
- STRINGIZE
186+
- PP_STRINGIZE
187+
- BOOST_PP_STRINGIZE
188+
- NS_SWIFT_NAME
189+
- CF_SWIFT_NAME
190+
...
191+

application.fam

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ App(
99
],
1010
stack_size=1 * 1024,
1111
order=90,
12-
fap_version=(0, 5),
12+
fap_version=(0, 6),
1313
fap_icon="lightmeter.png",
1414
fap_category="Tools",
1515
fap_private_libs=[

gui/scenes/lightmeter_scene_config.c

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "../../lightmeter.h"
22

3+
#define TAG "Scene Config"
4+
35
static const char* iso_numbers[] = {
46
[ISO_6] = "6",
57
[ISO_12] = "12",
@@ -39,6 +41,11 @@ static const char* diffusion_dome[] = {
3941
[WITH_DOME] = "Yes",
4042
};
4143

44+
static const char* backlight[] = {
45+
[BACKLIGHT_AUTO] = "Auto",
46+
[BACKLIGHT_ON] = "On",
47+
};
48+
4249
enum LightMeterSubmenuIndex {
4350
LightMeterSubmenuIndexISO,
4451
LightMeterSubmenuIndexND,
@@ -78,14 +85,36 @@ static void dome_presence_cb(VariableItem* item) {
7885
lightmeter_app_set_config(app, config);
7986
}
8087

88+
static void backlight_cb(VariableItem* item) {
89+
LightMeterApp* app = variable_item_get_context(item);
90+
uint8_t index = variable_item_get_current_value_index(item);
91+
92+
variable_item_set_current_value_text(item, backlight[index]);
93+
94+
LightMeterConfig* config = app->config;
95+
if(index != config->backlight) {
96+
if(index == BACKLIGHT_ON) {
97+
notification_message(
98+
app->notifications,
99+
&sequence_display_backlight_enforce_on); // force on backlight
100+
} else {
101+
notification_message(
102+
app->notifications,
103+
&sequence_display_backlight_enforce_auto); // force auto backlight
104+
}
105+
}
106+
config->backlight = index;
107+
lightmeter_app_set_config(app, config);
108+
}
109+
81110
static void ok_cb(void* context, uint32_t index) {
82111
LightMeterApp* app = context;
83112
UNUSED(app);
84113
switch(index) {
85-
case 3:
114+
case 4:
86115
view_dispatcher_send_custom_event(app->view_dispatcher, LightMeterAppCustomEventHelp);
87116
break;
88-
case 4:
117+
case 5:
89118
view_dispatcher_send_custom_event(app->view_dispatcher, LightMeterAppCustomEventAbout);
90119
break;
91120
default:
@@ -114,6 +143,11 @@ void lightmeter_scene_config_on_enter(void* context) {
114143
variable_item_set_current_value_index(item, config->dome);
115144
variable_item_set_current_value_text(item, diffusion_dome[config->dome]);
116145

146+
item =
147+
variable_item_list_add(var_item_list, "Backlight", COUNT_OF(backlight), backlight_cb, app);
148+
variable_item_set_current_value_index(item, config->backlight);
149+
variable_item_set_current_value_text(item, backlight[config->backlight]);
150+
117151
item = variable_item_list_add(var_item_list, "Help and Pinout", 0, NULL, NULL);
118152
item = variable_item_list_add(var_item_list, "About", 0, NULL, NULL);
119153

gui/views/main_view.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static const int nd_numbers[] = {
4141
[ND_4096] = 4096,
4242
};
4343

44-
static const float aperture_numbers[] = {
44+
const float aperture_numbers[] = {
4545
[AP_1] = 1.0,
4646
[AP_1_4] = 1.4,
4747
[AP_2] = 2.0,
@@ -59,7 +59,7 @@ static const float aperture_numbers[] = {
5959
[AP_128] = 128,
6060
};
6161

62-
static const float speed_numbers[] = {
62+
const float speed_numbers[] = {
6363
[SPEED_8000] = 1.0 / 8000, [SPEED_4000] = 1.0 / 4000, [SPEED_2000] = 1.0 / 2000,
6464
[SPEED_1000] = 1.0 / 1000, [SPEED_500] = 1.0 / 500, [SPEED_250] = 1.0 / 250,
6565
[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) {
307307

308308
canvas_set_font(canvas, FontPrimary);
309309
// metering mode A – ambient, F – flash
310-
canvas_draw_str_aligned(canvas, 1, 1, AlignLeft, AlignTop, "A");
310+
// canvas_draw_str_aligned(canvas, 1, 1, AlignLeft, AlignTop, "A");
311311

312312
snprintf(str, sizeof(str), "ISO: %d", iso_numbers[model->iso]);
313313
canvas_draw_str_aligned(canvas, 19, 1, AlignLeft, AlignTop, str);

lightmeter.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "lightmeter.h"
22
#include "lightmeter_helper.h"
33

4-
#define WORKER_TAG "MAIN APP"
4+
#define TAG "MAIN APP"
55

66
static bool lightmeter_custom_event_callback(void* context, uint32_t event) {
77
furi_assert(context);
@@ -31,20 +31,18 @@ LightMeterApp* lightmeter_app_alloc(uint32_t first_scene) {
3131
bh1750_set_power_state(1);
3232
bh1750_init();
3333
bh1750_set_mode(ONETIME_HIGH_RES_MODE);
34-
bh1750_set_mt_reg(100);
3534

3635
// Set default values to config
3736
app->config = malloc(sizeof(LightMeterConfig));
3837
app->config->iso = DEFAULT_ISO;
3938
app->config->nd = DEFAULT_ND;
4039
app->config->aperture = DEFAULT_APERTURE;
4140
app->config->dome = DEFAULT_DOME;
41+
app->config->backlight = DEFAULT_BACKLIGHT;
4242

4343
// Records
4444
app->gui = furi_record_open(RECORD_GUI);
4545
app->notifications = furi_record_open(RECORD_NOTIFICATION);
46-
notification_message(
47-
app->notifications, &sequence_display_backlight_enforce_on); // force on backlight
4846

4947
// View dispatcher
5048
app->view_dispatcher = view_dispatcher_alloc();
@@ -112,9 +110,11 @@ void lightmeter_app_free(LightMeterApp* app) {
112110

113111
// Records
114112
furi_record_close(RECORD_GUI);
115-
notification_message(
116-
app->notifications,
117-
&sequence_display_backlight_enforce_auto); // set backlight back to auto
113+
if(app->config->backlight != BACKLIGHT_AUTO) {
114+
notification_message(
115+
app->notifications,
116+
&sequence_display_backlight_enforce_auto); // set backlight back to auto
117+
}
118118
furi_record_close(RECORD_NOTIFICATION);
119119

120120
bh1750_set_power_state(0);

lightmeter.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ typedef struct {
2424
int nd;
2525
int aperture;
2626
int dome;
27+
int backlight;
2728
} LightMeterConfig;
2829

2930
typedef struct {

lightmeter_config.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#define LM_VERSION_APP "0.5"
3+
#define LM_VERSION_APP "0.6"
44
#define LM_DEVELOPED "Oleksii Kutuzov"
55
#define LM_GITHUB "https://github.com/oleksiikutuzov/flipperzero-lightmeter"
66

@@ -10,6 +10,7 @@
1010
#define DEFAULT_APERTURE AP_2_8
1111
#define DEFAULT_SPEED SPEED_125
1212
#define DEFAULT_DOME WITHOUT_DOME
13+
#define DEFAULT_BACKLIGHT BACKLIGHT_AUTO
1314

1415
typedef enum {
1516
ISO_6,
@@ -97,3 +98,5 @@ typedef enum {
9798
WITHOUT_DOME,
9899
WITH_DOME,
99100
} LightMeterDomePresence;
101+
102+
typedef enum { BACKLIGHT_AUTO, BACKLIGHT_ON } LightMeterBacklight;

0 commit comments

Comments
 (0)