Skip to content

Commit

Permalink
Add backlight mode (#32)
Browse files Browse the repository at this point in the history
* Include .clang-format

* Move .clang-format

* Configure backlight mode

* Bump version

* Use extern array

* Hide metering mode indicator
  • Loading branch information
oleksiikutuzov authored Nov 27, 2022
1 parent 8e9aec5 commit 221d683
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 44 deletions.
191 changes: 191 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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
...

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, 5),
fap_version=(0, 6),
fap_icon="lightmeter.png",
fap_category="Tools",
fap_private_libs=[
Expand Down
38 changes: 36 additions & 2 deletions gui/scenes/lightmeter_scene_config.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "../../lightmeter.h"

#define TAG "Scene Config"

static const char* iso_numbers[] = {
[ISO_6] = "6",
[ISO_12] = "12",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions gui/views/main_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions lightmeter.c
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -31,20 +31,18 @@ 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));
app->config->iso = DEFAULT_ISO;
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();
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lightmeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef struct {
int nd;
int aperture;
int dome;
int backlight;
} LightMeterConfig;

typedef struct {
Expand Down
5 changes: 4 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.5"
#define LM_VERSION_APP "0.6"
#define LM_DEVELOPED "Oleksii Kutuzov"
#define LM_GITHUB "https://github.com/oleksiikutuzov/flipperzero-lightmeter"

Expand All @@ -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,
Expand Down Expand Up @@ -97,3 +98,5 @@ typedef enum {
WITHOUT_DOME,
WITH_DOME,
} LightMeterDomePresence;

typedef enum { BACKLIGHT_AUTO, BACKLIGHT_ON } LightMeterBacklight;
Loading

0 comments on commit 221d683

Please sign in to comment.