diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..4b76f7f --- /dev/null +++ b/.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 +... + diff --git a/Sensors.c b/Sensors.c index 1ebb354..0e2be2b 100644 --- a/Sensors.c +++ b/Sensors.c @@ -80,7 +80,7 @@ static const SensorType* sensorTypes[] = {&DHT11, &DHT12_SW, &DHT20, &DHT &Dallas, &AM2320_SW, &AM2320_I2C, &HTU21x, &AHT10, &SHT30, &GXHT30, &LM75, &HDC1080, &BMP180, &BMP280, &BME280, &BME680, &MAX31855, &MAX6675, - &SCD30}; + &SCD30}; const SensorType* unitemp_sensors_getTypeFromInt(uint8_t index) { if(index > SENSOR_TYPES_COUNT) return NULL; diff --git a/sensors/BMP180.c b/sensors/BMP180.c index e94f380..aa01982 100644 --- a/sensors/BMP180.c +++ b/sensors/BMP180.c @@ -101,8 +101,7 @@ bool unitemp_BMP180_init(Sensor* sensor) { bmp180_instance->bmp180_cal.MC = (buff[18] << 8) | buff[19]; bmp180_instance->bmp180_cal.MD = (buff[20] << 8) | buff[21]; - -UNITEMP_DEBUG( + UNITEMP_DEBUG( "Sensor BMP180 (0x%02X) calibration values: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d", i2c_sensor->currentI2CAdr, bmp180_instance->bmp180_cal.AC1, diff --git a/sensors/SCD30.c b/sensors/SCD30.c index dd045df..b5f15b5 100644 --- a/sensors/SCD30.c +++ b/sensors/SCD30.c @@ -23,46 +23,46 @@ #include "../interfaces/I2CSensor.h" //#include <3rdparty/everest/include/everest/kremlin/c_endianness.h> -inline static uint16_t load16(uint8_t *b) { +inline static uint16_t load16(uint8_t* b) { uint16_t x; memcpy(&x, b, 2); return x; } -inline static uint32_t load32(uint8_t *b) { +inline static uint32_t load32(uint8_t* b) { uint32_t x; memcpy(&x, b, 4); return x; } -inline static void store16(uint8_t *b, uint16_t i) { +inline static void store16(uint8_t* b, uint16_t i) { memcpy(b, &i, 2); } -inline static void store32(uint8_t *b, uint32_t i) { +inline static void store32(uint8_t* b, uint32_t i) { memcpy(b, &i, 4); } #if BYTE_ORDER == BIG_ENDIAN - #define htobe16(x) (x) - #define htobe32(x) (x) - #define htole16(x) __builtin_bswap16 (x) - #define htole32(x) __builtin_bswap32 (x) - #define be16toh(x) (x) - #define be32toh(x) (x) - #define le16toh(x) __builtin_bswap16 (x) - #define le32toh(x) __builtin_bswap32 (x) +#define htobe16(x) (x) +#define htobe32(x) (x) +#define htole16(x) __builtin_bswap16(x) +#define htole32(x) __builtin_bswap32(x) +#define be16toh(x) (x) +#define be32toh(x) (x) +#define le16toh(x) __builtin_bswap16(x) +#define le32toh(x) __builtin_bswap32(x) #elif BYTE_ORDER == LITTLE_ENDIAN - #define htobe16(x) __builtin_bswap16 (x) - #define htobe32(x) __builtin_bswap32 (x) - #define htole16(x) (x) - #define htole32(x) (x) - #define be16toh(x) __builtin_bswap16 (x) - #define be32toh(x) __builtin_bswap32 (x) - #define le16toh(x) (x) - #define le32toh(x) (x) +#define htobe16(x) __builtin_bswap16(x) +#define htobe32(x) __builtin_bswap32(x) +#define htole16(x) (x) +#define htole32(x) (x) +#define be16toh(x) __builtin_bswap16(x) +#define be32toh(x) __builtin_bswap32(x) +#define le16toh(x) (x) +#define le32toh(x) (x) #else - # error "What kind of system is this?" +#error "What kind of system is this?" #endif #define load16_le(b) (le16toh(load16(b))) @@ -81,7 +81,6 @@ typedef union { float value; } ByteToFl; - bool unitemp_SCD30_alloc(Sensor* sensor, char* args); bool unitemp_SCD30_init(Sensor* sensor); bool unitemp_SCD30_deinit(Sensor* sensor); @@ -122,7 +121,8 @@ static bool getAutoSelfCalibration(Sensor* sensor) __attribute__((unused)); static bool getFirmwareVersion(Sensor* sensor, uint16_t* val) __attribute__((unused)); -static bool setForcedRecalibrationFactor(Sensor* sensor, uint16_t concentration) __attribute__((unused)); +static bool setForcedRecalibrationFactor(Sensor* sensor, uint16_t concentration) + __attribute__((unused)); static uint16_t getAltitudeCompensation(Sensor* sensor) __attribute__((unused)); static bool setAltitudeCompensation(Sensor* sensor, uint16_t altitude) __attribute__((unused)); static bool setAmbientPressure(Sensor* sensor, uint16_t pressure_mbar) __attribute__((unused)); @@ -130,7 +130,8 @@ static bool setAmbientPressure(Sensor* sensor, uint16_t pressure_mbar) __attribu static float getTemperatureOffset(Sensor* sensor) __attribute__((unused)); static bool setTemperatureOffset(Sensor* sensor, float tempOffset) __attribute__((unused)); -static bool beginMeasuringWithSettings(Sensor* sensor, uint16_t pressureOffset) __attribute__((unused)); +static bool beginMeasuringWithSettings(Sensor* sensor, uint16_t pressureOffset) + __attribute__((unused)); static bool beginMeasuring(Sensor* sensor) __attribute__((unused)); static bool stopMeasurement(Sensor* sensor) __attribute__((unused)); @@ -154,11 +155,10 @@ bool unitemp_SCD30_free(Sensor* sensor) { bool unitemp_SCD30_init(Sensor* sensor) { if(beginMeasuring(sensor) == true) { // Start continuous measurements - setMeasurementInterval(sensor, SCD30.pollingInterval/1000); + setMeasurementInterval(sensor, SCD30.pollingInterval / 1000); setAutoSelfCalibration(sensor, true); setAmbientPressure(sensor, 0); - } - else + } else return false; return true; @@ -175,10 +175,10 @@ UnitempStatus unitemp_SCD30_update(Sensor* sensor) { static uint8_t computeCRC8(uint8_t* message, uint8_t len) { uint8_t crc = 0xFF; // Init with 0xFF - for (uint8_t x = 0; x < len; x++) { + for(uint8_t x = 0; x < len; x++) { crc ^= message[x]; // XOR-in the next input byte - for (uint8_t i = 0; i < 8; i++) { - if ((crc & 0x80) != 0) + for(uint8_t i = 0; i < 8; i++) { + if((crc & 0x80) != 0) crc = (uint8_t)((crc << 1) ^ 0x31); else crc <<= 1; @@ -192,10 +192,10 @@ static bool sendCommandWithCRC(Sensor* sensor, uint16_t command, uint16_t argume static const uint8_t cmdSize = 5; uint8_t bytes[cmdSize]; - uint8_t *pointer = bytes; + uint8_t* pointer = bytes; store16_be(pointer, command); pointer += 2; - uint8_t *argPos = pointer; + uint8_t* argPos = pointer; store16_be(pointer, arguments); pointer += 2; *pointer = computeCRC8(argPos, pointer - argPos); @@ -218,15 +218,13 @@ static bool sendCommand(Sensor* sensor, uint16_t command) { static uint16_t readRegister(Sensor* sensor, uint16_t registerAddress) { static const uint8_t regSize = 2; - if(!sendCommand(sensor, registerAddress)) - return 0; // Sensor did not ACK + if(!sendCommand(sensor, registerAddress)) return 0; // Sensor did not ACK furi_delay_ms(3); uint8_t bytes[regSize]; I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; - if(!unitemp_i2c_readArray(i2c_sensor, regSize, bytes)) - return 0; + if(!unitemp_i2c_readArray(i2c_sensor, regSize, bytes)) return 0; return load16_be(bytes); } @@ -234,8 +232,7 @@ static uint16_t readRegister(Sensor* sensor, uint16_t registerAddress) { static bool loadWord(uint8_t* buff, uint16_t* val) { uint16_t tmp = load16_be(buff); uint8_t expectedCRC = computeCRC8(buff, 2); - if(buff[2] != expectedCRC) - return false; + if(buff[2] != expectedCRC) return false; *val = tmp; return true; } @@ -243,21 +240,19 @@ static bool loadWord(uint8_t* buff, uint16_t* val) { static bool getSettingValue(Sensor* sensor, uint16_t registerAddress, uint16_t* val) { static const uint8_t respSize = 3; - if(!sendCommand(sensor, registerAddress)) - return false; // Sensor did not ACK + if(!sendCommand(sensor, registerAddress)) return false; // Sensor did not ACK furi_delay_ms(3); uint8_t bytes[respSize]; I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; - if(!unitemp_i2c_readArray(i2c_sensor, respSize, bytes)) - return false; + if(!unitemp_i2c_readArray(i2c_sensor, respSize, bytes)) return false; return loadWord(bytes, val); } static bool loadFloat(uint8_t* buff, float* val) { -// ByteToFl tmp; + // ByteToFl tmp; size_t cntr = 0; uint8_t floatBuff[4]; for(size_t i = 0; i < 2; i++) { @@ -304,26 +299,23 @@ static bool readMeasurement(Sensor* sensor) { bool error = false; if(loadFloat(bytes, &tempCO2)) { sensor->co2 = tempCO2; - } - else { + } else { FURI_LOG_E(APP_NAME, "Error while parsing CO2"); error = true; } bytes += 6; if(loadFloat(bytes, &tempTemperature)) { - sensor->temp = tempTemperature; - } - else { - FURI_LOG_E(APP_NAME, "Error while parsing temp"); - error = true; + sensor->temp = tempTemperature; + } else { + FURI_LOG_E(APP_NAME, "Error while parsing temp"); + error = true; } bytes += 6; if(loadFloat(bytes, &tempHumidity)) { sensor->hum = tempHumidity; - } - else { + } else { FURI_LOG_E(APP_NAME, "Error while parsing humidity"); error = true; } @@ -336,7 +328,8 @@ static void reset(Sensor* sensor) { } static bool setAutoSelfCalibration(Sensor* sensor, bool enable) { - return sendCommandWithCRC(sensor, COMMAND_AUTOMATIC_SELF_CALIBRATION, enable); // Activate continuous ASC + return sendCommandWithCRC( + sensor, COMMAND_AUTOMATIC_SELF_CALIBRATION, enable); // Activate continuous ASC } // Get the current ASC setting @@ -351,7 +344,7 @@ static bool getFirmwareVersion(Sensor* sensor, uint16_t* val) { // Set the forced recalibration factor. See 1.3.7. // The reference CO2 concentration has to be within the range 400 ppm ≤ cref(CO2) ≤ 2000 ppm. static bool setForcedRecalibrationFactor(Sensor* sensor, uint16_t concentration) { - if (concentration < 400 || concentration > 2000) { + if(concentration < 400 || concentration > 2000) { return false; // Error check. } return sendCommandWithCRC(sensor, COMMAND_SET_FORCED_RECALIBRATION_FACTOR, concentration); @@ -373,8 +366,7 @@ static bool setTemperatureOffset(Sensor* sensor, float tempOffset) { //"The SCD30 offset temperature is obtained by subtracting the reference temperature from the SCD30 output temperature" // https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/9.5_CO2/Sensirion_CO2_Sensors_SCD30_Low_Power_Mode.pdf - if (tempOffset < 0.0) - return false; + if(tempOffset < 0.0) return false; uint16_t value = tempOffset * 100; @@ -394,7 +386,7 @@ static bool setAltitudeCompensation(Sensor* sensor, uint16_t altitude) { // Set the pressure compenstation. This is passed during measurement startup. // mbar can be 700 to 1200 static bool setAmbientPressure(Sensor* sensor, uint16_t pressure_mbar) { - if (pressure_mbar != 0 || pressure_mbar < 700 || pressure_mbar > 1200) { + if(pressure_mbar != 0 || pressure_mbar < 700 || pressure_mbar > 1200) { return false; } return sendCommandWithCRC(sensor, COMMAND_CONTINUOUS_MEASUREMENT, pressure_mbar); @@ -422,10 +414,8 @@ static bool stopMeasurement(Sensor* sensor) { // Sets interval between measurements // 2 seconds to 1800 seconds (30 minutes) static bool setMeasurementInterval(Sensor* sensor, uint16_t interval) { - if(interval < 2 || interval > 1800) - return false; - if(!sendCommandWithCRC(sensor, COMMAND_SET_MEASUREMENT_INTERVAL, interval)) - return false; + if(interval < 2 || interval > 1800) return false; + if(!sendCommandWithCRC(sensor, COMMAND_SET_MEASUREMENT_INTERVAL, interval)) return false; uint16_t verInterval = readRegister(sensor, COMMAND_SET_MEASUREMENT_INTERVAL); if(verInterval != interval) { FURI_LOG_E(APP_NAME, "Measure interval wrong! Val: %02x", verInterval); diff --git a/views/General_view.c b/views/General_view.c index 581afcb..5d575ed 100644 --- a/views/General_view.c +++ b/views/General_view.c @@ -163,20 +163,18 @@ static void _draw_co2(Canvas* canvas, Sensor* sensor, Color color) { canvas_draw_icon(canvas, x + 3, y + 3, &I_co2_11x14); int16_t concentration_int = sensor->co2; -// int8_t concentration_dec = (int16_t)(sensor->co2 * 10) % 10; + // int8_t concentration_dec = (int16_t)(sensor->co2 * 10) % 10; //Целая часть if(concentration_int > 9999) { snprintf(app->buff, BUFF_SIZE, "MAX "); canvas_set_font(canvas, FontPrimary); - } - else { + } else { snprintf(app->buff, BUFF_SIZE, "%d", concentration_int); canvas_set_font(canvas, FontBigNumbers); } - canvas_draw_str_aligned( - canvas, x + 70, y + 10, AlignRight, AlignCenter, app->buff); + canvas_draw_str_aligned(canvas, x + 70, y + 10, AlignRight, AlignCenter, app->buff); } static void _draw_singleSensor(Canvas* canvas, Sensor* sensor, const uint8_t pos[2], Color color) { @@ -344,7 +342,8 @@ static void _draw_carousel_values(Canvas* canvas) { temp_positions[2][0], temp_positions[2][1], ColorWhite); - _draw_humidity(canvas, unitemp_sensor_getActive(generalview_sensor_index), hum_positions[1]); + _draw_humidity( + canvas, unitemp_sensor_getActive(generalview_sensor_index), hum_positions[1]); _draw_co2(canvas, unitemp_sensor_getActive(generalview_sensor_index), ColorWhite); break; }