Skip to content

Commit 8a1ccc4

Browse files
config on SD card - read/save, change meter resolution, add stats in lux_only mode (#39)
* add Measurement Resolution setting * load settings on main_view enter, add peak lux stat * very simple histogram * add todo for later * save/read settings to SD card * fix config path and button rendering * increase stack size convert `flipper_format_*_hex` to `flipper_format_*_int32` * proper `bh1750_set_mode` on app init - move `bh1750_set_mode` after config is loaded - replace hardcoded value with `app->config->measurement_resolution` * add I2C addr selection, fix sensor init single callback function that handles sensor mode and address setting this requires oleksiikutuzov/flipperzero-BH1750#1 to be merged * bump lib to origin * inscreasing stack size to be safe * Revert "Merge branch 'main' into advanced-mode" This reverts commit 0c0d0b9655310dabb100512ad7bdf23073e9b9e7, reversing changes made to 7998c32a6941aa1ead4f71d020575979cd139d36. * Fix conflicts * More files to the state of the main branch * Fix formatting * Update changelog * Write sensor type to config, set address for MAX sensor * Switching address for both sensors * Use shortcut for appdata folder, update changelog * Update license to current state * Update docs * Update screenshots --------- Co-authored-by: Oleksii Kutuzov <[email protected]> Co-authored-by: Oleksii Kutuzov <[email protected]>
1 parent a476434 commit 8a1ccc4

File tree

16 files changed

+569
-24
lines changed

16 files changed

+569
-24
lines changed

.clang-format

Lines changed: 191 additions & 0 deletions
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+

.flipcorg/gallery/gui_config_2.png

1.93 KB
Loading
333 Bytes
Loading

application.fam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ App(
77
requires=[
88
"gui",
99
],
10-
stack_size=1 * 1024,
10+
stack_size= 4 * 1024,
1111
order=90,
12-
fap_version=(1, 1),
12+
fap_version=(1, 2),
1313
fap_icon="lightmeter.png",
1414
fap_category="GPIO",
1515
fap_private_libs=[
File renamed without changes.

docs/changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## v1.2
2+
3+
* Lux only screen now has statistics
4+
* Settings are now stored on SD card
5+
* You can choose the resolution (BH1750 only) and address for sensor
6+
7+
(thanks to @danielskowronski for contributing to this update)
8+
19
## v1.1
210

311
Added support for MAX44009 sensor (thanks to @wosk)

gui/scenes/lightmeter_scene_config.c

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,31 @@ static const char* sensor_type[] = {
5656
[SENSOR_MAX44009] = "MAX44009",
5757
};
5858

59+
static const char* measurement_resolution[] = {
60+
[LOW_RES] = "Low",
61+
[HIGH_RES] = "High",
62+
[HIGH_RES2] = "High2",
63+
};
64+
65+
static const char* device_addr_bh1750[] = {
66+
[ADDR_LOW] = "0x23",
67+
[ADDR_HIGH] = "0x5C",
68+
};
69+
70+
static const char* device_addr_max44009[] = {
71+
[ADDR_LOW] = "0x4A",
72+
[ADDR_HIGH] = "0x4B",
73+
};
74+
5975
enum LightMeterSubmenuIndex {
6076
LightMeterSubmenuIndexISO,
6177
LightMeterSubmenuIndexND,
6278
LightMeterSubmenuIndexDome,
6379
LightMeterSubmenuIndexBacklight,
6480
LightMeterSubmenuIndexLuxMeter,
6581
LightMeterSubmenuIndexSensorType,
82+
LightMeterSubmenuIndexMeasurementResolution,
83+
LightMeterSubmenuIndexI2CAddress,
6684
LightMeterSubmenuIndexHelp,
6785
LightMeterSubmenuIndexAbout,
6886
};
@@ -133,6 +151,60 @@ static void lux_only_cb(VariableItem* item) {
133151
lightmeter_app_set_config(app, config);
134152
}
135153

154+
static void measurement_resolution_cb(VariableItem* item) {
155+
LightMeterApp* app = variable_item_get_context(item);
156+
uint8_t index = variable_item_get_current_value_index(item);
157+
158+
variable_item_set_current_value_text(item, measurement_resolution[index]);
159+
160+
LightMeterConfig* config = app->config;
161+
config->measurement_resolution = index;
162+
lightmeter_app_set_config(app, config);
163+
164+
lightmeter_app_i2c_init_sensor(app);
165+
}
166+
167+
static void update_item_addr(LightMeterApp* app) {
168+
VariableItem* item = app->var_item_addr;
169+
switch(app->config->sensor_type) {
170+
case SENSOR_BH1750:
171+
variable_item_set_current_value_index(item, app->config->device_addr);
172+
variable_item_set_current_value_text(item, device_addr_bh1750[app->config->device_addr]);
173+
break;
174+
case SENSOR_MAX44009:
175+
variable_item_set_current_value_index(item, app->config->device_addr);
176+
variable_item_set_current_value_text(item, device_addr_max44009[app->config->device_addr]);
177+
break;
178+
default:
179+
FURI_LOG_E(TAG, "Invalid sensor type %ld", app->config->sensor_type);
180+
return;
181+
}
182+
}
183+
184+
static void device_addr_cb(VariableItem* item) {
185+
LightMeterApp* app = variable_item_get_context(item);
186+
uint8_t index = variable_item_get_current_value_index(item);
187+
188+
switch(app->config->sensor_type) {
189+
case SENSOR_BH1750:
190+
variable_item_set_current_value_text(item, device_addr_bh1750[index]);
191+
break;
192+
case SENSOR_MAX44009:
193+
variable_item_set_current_value_text(item, device_addr_max44009[index]);
194+
break;
195+
default:
196+
FURI_LOG_E(TAG, "Invalid sensor type %ld", app->config->sensor_type);
197+
return;
198+
}
199+
// variable_item_set_current_value_text(item, device_addr[index]);
200+
201+
LightMeterConfig* config = app->config;
202+
config->device_addr = index;
203+
lightmeter_app_set_config(app, config);
204+
205+
lightmeter_app_i2c_init_sensor(app);
206+
}
207+
136208
static void sensor_type_cb(VariableItem* item) {
137209
LightMeterApp* app = variable_item_get_context(item);
138210
uint8_t index = variable_item_get_current_value_index(item);
@@ -141,6 +213,9 @@ static void sensor_type_cb(VariableItem* item) {
141213

142214
LightMeterConfig* config = app->config;
143215
config->sensor_type = index;
216+
217+
update_item_addr(app);
218+
144219
lightmeter_app_set_config(app, config);
145220
}
146221

@@ -195,6 +270,36 @@ void lightmeter_scene_config_on_enter(void* context) {
195270
variable_item_set_current_value_index(item, config->sensor_type);
196271
variable_item_set_current_value_text(item, sensor_type[config->sensor_type]);
197272

273+
item = variable_item_list_add(
274+
var_item_list,
275+
"Resolution",
276+
COUNT_OF(measurement_resolution),
277+
measurement_resolution_cb,
278+
app);
279+
variable_item_set_current_value_index(item, config->measurement_resolution);
280+
variable_item_set_current_value_text(
281+
item, measurement_resolution[config->measurement_resolution]);
282+
283+
switch(config->sensor_type) {
284+
case SENSOR_BH1750:
285+
item = variable_item_list_add(
286+
var_item_list, "I2C address", COUNT_OF(device_addr_bh1750), device_addr_cb, app);
287+
variable_item_set_current_value_index(item, config->device_addr);
288+
variable_item_set_current_value_text(item, device_addr_bh1750[config->device_addr]);
289+
break;
290+
case SENSOR_MAX44009:
291+
item = variable_item_list_add(
292+
var_item_list, "I2C address", COUNT_OF(device_addr_max44009), device_addr_cb, app);
293+
variable_item_set_current_value_index(item, config->device_addr);
294+
variable_item_set_current_value_text(item, device_addr_max44009[config->device_addr]);
295+
break;
296+
default:
297+
FURI_LOG_E(TAG, "Invalid sensor type %ld", config->sensor_type);
298+
return;
299+
}
300+
app->var_item_addr = item;
301+
update_item_addr(app);
302+
198303
item = variable_item_list_add(var_item_list, "Help and Pinout", 0, NULL, NULL);
199304
item = variable_item_list_add(var_item_list, "About", 0, NULL, NULL);
200305

@@ -235,4 +340,5 @@ void lightmeter_scene_config_on_exit(void* context) {
235340
main_view_set_nd(app->main_view, app->config->nd);
236341
main_view_set_dome(app->main_view, app->config->dome);
237342
main_view_set_lux_only(app->main_view, app->config->lux_only);
343+
main_view_set_measurement_resolution(app->main_view, app->config->measurement_resolution);
238344
}

gui/scenes/lightmeter_scene_help.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ void lightmeter_scene_help_on_enter(void* context) {
77
temp_str = furi_string_alloc();
88
furi_string_printf(
99
temp_str,
10-
"App works with BH1750 and MAX44409 ambient light sensor connected via I2C interface\n\n");
10+
"App works with BH1750/MAX44009\nambient light sensor\nconnected via I2C interface\n\n");
1111
furi_string_cat(temp_str, "\e#Pinout:\r\n");
1212
furi_string_cat(
1313
temp_str,
1414
" VCC: 3.3V\r\n"
1515
" GND: GND\r\n"
1616
" SDA: 15 [C1]\r\n"
1717
" SCL: 16 [C0]\r\n");
18+
furi_string_cat(temp_str, "\r\n\e#Resolutions:\r\n");
19+
furi_string_cat(
20+
temp_str,
21+
"Low: 4.0lx (16ms, 0-54k)\r\n"
22+
"High: 1.0lx (120ms, 0-54k)\r\n"
23+
"High2: 0.5lx (120ms, 0-27k)\r\n");
1824

1925
widget_add_text_scroll_element(app->widget, 0, 0, 128, 64, furi_string_get_cstr(temp_str));
2026
furi_string_free(temp_str);

0 commit comments

Comments
 (0)