Просмотр исходного кода

Revert "Merge lightmeter from https://github.com/xMasterX/all-the-plugins"

This reverts commit da344e03b0fd729baba346ac20c87c2deddad55a, reversing
changes made to 0947380fdcb39b3c9926b42d30b5f6382221e1e7.
Willy-JL 2 лет назад
Родитель
Сommit
2cde37fa90

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

BIN
lightmeter/.flipcorg/gallery/gui_config.png


BIN
lightmeter/.flipcorg/gallery/gui_config_2.png


BIN
lightmeter/.flipcorg/gallery/gui_lux_meter.png


BIN
lightmeter/.flipcorg/gallery/gui_main.png


+ 4 - 0
lightmeter/.gitignore

@@ -0,0 +1,4 @@
+dist/*
+.vscode
+.clang-format
+.editorconfig

+ 1 - 0
lightmeter/lib/BH1750

@@ -0,0 +1 @@
+Subproject commit cf05c49076a54dc0559d193e5aec29ff7455aa65

+ 0 - 150
lightmeter/lib/BH1750/BH1750.c

@@ -1,150 +0,0 @@
-/**
- * @file BH1750.h
- * @author Oleksii Kutuzov (oleksii.kutuzov@icloud.com)
- * @brief 
- * @version 0.1
- * @date 2022-11-06
- * 
- * @copyright Copyright (c) 2022
- * 
- * Ported from:
- * https://github.com/lamik/Light_Sensors_STM32
- */
-
-#include "BH1750.h"
-
-BH1750_mode bh1750_mode = BH1750_DEFAULT_MODE; // Current sensor mode
-uint8_t bh1750_mt_reg = BH1750_DEFAULT_MTREG; // Current MT register value
-uint8_t bh1750_addr = BH1750_ADDRESS;
-
-BH1750_STATUS bh1750_init() {
-    if(BH1750_OK == bh1750_reset()) {
-        if(BH1750_OK == bh1750_set_mt_reg(BH1750_DEFAULT_MTREG)) {
-            return BH1750_OK;
-        }
-    }
-    return BH1750_ERROR;
-}
-
-BH1750_STATUS bh1750_init_with_addr(uint8_t addr) {
-    bh1750_addr = (addr << 1);
-    return bh1750_init();
-}
-
-BH1750_STATUS bh1750_reset() {
-    uint8_t command = 0x07;
-    bool status;
-
-    furi_hal_i2c_acquire(I2C_BUS);
-    status = furi_hal_i2c_tx(I2C_BUS, bh1750_addr, &command, 1, I2C_TIMEOUT);
-    furi_hal_i2c_release(I2C_BUS);
-
-    if(status) {
-        return BH1750_OK;
-    }
-
-    return BH1750_ERROR;
-}
-
-BH1750_STATUS bh1750_set_power_state(uint8_t PowerOn) {
-    PowerOn = (PowerOn ? 1 : 0);
-    bool status;
-
-    furi_hal_i2c_acquire(I2C_BUS);
-    status = furi_hal_i2c_tx(I2C_BUS, bh1750_addr, &PowerOn, 1, I2C_TIMEOUT);
-    furi_hal_i2c_release(I2C_BUS);
-
-    if(status) {
-        return BH1750_OK;
-    }
-
-    return BH1750_ERROR;
-}
-
-BH1750_STATUS bh1750_set_mode(BH1750_mode mode) {
-    if(!((mode >> 4) || (mode >> 5))) {
-        return BH1750_ERROR;
-    }
-
-    if((mode & 0x0F) > 3) {
-        return BH1750_ERROR;
-    }
-
-    bool status;
-
-    bh1750_mode = mode;
-
-    furi_hal_i2c_acquire(I2C_BUS);
-    status = furi_hal_i2c_tx(I2C_BUS, bh1750_addr, &mode, 1, I2C_TIMEOUT);
-    furi_hal_i2c_release(I2C_BUS);
-
-    if(status) {
-        return BH1750_OK;
-    }
-
-    return BH1750_ERROR;
-}
-
-BH1750_STATUS bh1750_set_mt_reg(uint8_t mt_reg) {
-    if(mt_reg < 31 || mt_reg > 254) {
-        return BH1750_ERROR;
-    }
-
-    bh1750_mt_reg = mt_reg;
-
-    uint8_t tmp[2];
-    bool status;
-
-    tmp[0] = (0x40 | (mt_reg >> 5));
-    tmp[1] = (0x60 | (mt_reg & 0x1F));
-
-    furi_hal_i2c_acquire(I2C_BUS);
-    status = furi_hal_i2c_tx(I2C_BUS, bh1750_addr, &tmp[0], 1, I2C_TIMEOUT);
-    furi_hal_i2c_release(I2C_BUS);
-    if(!status) {
-        return BH1750_ERROR;
-    }
-
-    furi_hal_i2c_acquire(I2C_BUS);
-    status = furi_hal_i2c_tx(I2C_BUS, bh1750_addr, &tmp[1], 1, I2C_TIMEOUT);
-    furi_hal_i2c_release(I2C_BUS);
-    if(status) {
-        return BH1750_OK;
-    }
-
-    return BH1750_ERROR;
-}
-
-BH1750_STATUS bh1750_trigger_manual_conversion() {
-    if(BH1750_OK == bh1750_set_mode(bh1750_mode)) {
-        return BH1750_OK;
-    }
-    return BH1750_ERROR;
-}
-
-BH1750_STATUS bh1750_read_light(float* result) {
-    float result_tmp;
-    uint8_t rcv[2];
-    bool status;
-
-    furi_hal_i2c_acquire(I2C_BUS);
-    status = furi_hal_i2c_rx(I2C_BUS, bh1750_addr, rcv, 2, I2C_TIMEOUT);
-    furi_hal_i2c_release(I2C_BUS);
-
-    if(status) {
-        result_tmp = (rcv[0] << 8) | (rcv[1]);
-
-        if(bh1750_mt_reg != BH1750_DEFAULT_MTREG) {
-            result_tmp *= (float)((uint8_t)BH1750_DEFAULT_MTREG / (float)bh1750_mt_reg);
-        }
-
-        if(bh1750_mode == ONETIME_HIGH_RES_MODE_2 || bh1750_mode == CONTINUOUS_HIGH_RES_MODE_2) {
-            result_tmp /= 2.0;
-        }
-
-        *result = result_tmp / BH1750_CONVERSION_FACTOR;
-
-        return BH1750_OK;
-    }
-    return BH1750_ERROR;
-}

+ 0 - 110
lightmeter/lib/BH1750/BH1750.h

@@ -1,110 +0,0 @@
-/**
- * @file BH1750.h
- * @author Oleksii Kutuzov (oleksii.kutuzov@icloud.com)
- * @brief 
- * @version 0.1
- * @date 2022-11-06
- * 
- * @copyright Copyright (c) 2022
- * 
- * Ported from:
- * https://github.com/lamik/Light_Sensors_STM32
- */
-
-#include <furi.h>
-#include <furi_hal.h>
-
-#ifndef BH1750_H_
-#define BH1750_H_
-
-// I2C BUS
-#define I2C_BUS &furi_hal_i2c_handle_external
-#define I2C_TIMEOUT 10
-
-#define BH1750_ADDRESS (0x23 << 1)
-
-#define BH1750_POWER_DOWN 0x00
-#define BH1750_POWER_ON 0x01
-#define BH1750_RESET 0x07
-#define BH1750_DEFAULT_MTREG 69
-#define BH1750_DEFAULT_MODE ONETIME_HIGH_RES_MODE
-
-#define BH1750_CONVERSION_FACTOR 1.2
-
-typedef enum { BH1750_OK = 0, BH1750_ERROR = 1 } BH1750_STATUS;
-
-typedef enum {
-    CONTINUOUS_HIGH_RES_MODE = 0x10,
-    CONTINUOUS_HIGH_RES_MODE_2 = 0x11,
-    CONTINUOUS_LOW_RES_MODE = 0x13,
-    ONETIME_HIGH_RES_MODE = 0x20,
-    ONETIME_HIGH_RES_MODE_2 = 0x21,
-    ONETIME_LOW_RES_MODE = 0x23
-} BH1750_mode;
-
-/**
- * @brief Initialize the sensor. Sends the reset command and sets the measurement register to the default value.
- * 
- * @return BH1750_STATUS
- */
-BH1750_STATUS bh1750_init();
-
-/**
- * @brief Change the I2C device address and then initialize the sensor.
- * 
- * @return BH1750_STATUS
- */
-BH1750_STATUS bh1750_init_with_addr(uint8_t addr);
-
-/**
- * @brief Reset all registers to the default value.
- * 
- * @return BH1750_STATUS 
- */
-BH1750_STATUS bh1750_reset();
-
-/**
- * @brief Sets the power state. 1 - running; 0 - sleep, low power. 
- * 
- * @param PowerOn sensor state.
- * @return BH1750_STATUS 
- */
-BH1750_STATUS bh1750_set_power_state(uint8_t PowerOn);
-
-/**
- * @brief Set the Measurement Time register. It allows to increase or decrease the sensitivity.
- * 
- * @param MTreg value from 31 to 254, defaults to 69.
- * 
- * @return BH1750_STATUS 
- */
-BH1750_STATUS bh1750_set_mt_reg(uint8_t MTreg);
-
-/**
- * @brief Set the mode of converting. Look into the bh1750_mode enum.
- * 
- * @param Mode mode enumerator
- * @return BH1750_STATUS 
- */
-BH1750_STATUS bh1750_set_mode(BH1750_mode Mode);
-
-/**
- * @brief Trigger the conversion in manual modes. 
- * 
- * @details a low-resolution mode, the conversion time is typically 16 ms, and for a high-resolution 
- * mode is 120 ms. You need to wait until reading the measurement value. There is no need 
- * to exit low-power mode for manual conversion. It makes automatically.
- * 
- * @return BH1750_STATUS 
- */
-BH1750_STATUS bh1750_trigger_manual_conversion();
-
-/**
- * @brief Read the converted value and calculate the result.
- * 
- * @param Result stores received value to this variable.
- * @return BH1750_STATUS 
- */
-BH1750_STATUS bh1750_read_light(float* Result);
-
-#endif /* BH1750_H_ */

+ 0 - 21
lightmeter/lib/BH1750/LICENSE

@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2022 Oleksii Kutuzov
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.

+ 0 - 2
lightmeter/lib/BH1750/README.md

@@ -1,2 +0,0 @@
-# flipperzero-BH1750
-BH1750 light sensor library for Flipper Zero 

BIN
lightmeter/lib/BH1750/docs/BH1750.pdf