Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignAfterOpenBracket: BlockIndent
BracedInitializerIndentWidth: 4
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
Expand Down Expand Up @@ -65,29 +66,28 @@ AlignConsecutiveTableGenDefinitionColons:
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignEscapedNewlines: Right
AlignOperands: Align
AlignEscapedNewlines: Left
AlignOperands: DontAlign
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
Kind: Always
OverEmptyLines: 2
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowBreakBeforeNoexceptSpecifier: Never
AllowShortBlocksOnASingleLine: Never
AllowBreakBeforeNoexceptSpecifier: Always
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseExpressionOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AllowShortLoopsOnASingleLine: true
AllowShortNamespacesOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AttributeMacros:
- __capability
BinPackArguments: true
BinPackArguments: false
BinPackParameters: BinPack
BitFieldColonSpacing: Both
BraceWrapping:
Expand All @@ -99,7 +99,7 @@ BraceWrapping:
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterStruct: true
AfterUnion: false
BeforeCatch: false
BeforeElse: false
Expand All @@ -109,23 +109,23 @@ BraceWrapping:
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakAdjacentStringLiterals: true
BreakAdjacentStringLiterals: false
BreakAfterAttributes: Leave
BreakAfterJavaFieldAnnotations: false
BreakAfterReturnType: None
BreakArrays: true
BreakAfterReturnType: Automatic
BreakArrays: false
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Attach
BreakBeforeBraces: Custom
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakBinaryOperations: Never
BreakConstructorInitializers: BeforeColon
BreakFunctionDefinitionParameters: false
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
BreakStringLiterals: false
BreakTemplateDeclarations: MultiLine
ColumnLimit: 80
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
Expand All @@ -143,7 +143,7 @@ ForEachMacros:
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
Expand All @@ -161,16 +161,16 @@ IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentCaseLabels: true
IndentExportBlock: true
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 2
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: false
InsertNewlineAtEOF: true
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
Expand All @@ -183,10 +183,10 @@ JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLines:
AtEndOfFile: false
AtStartOfBlock: true
AtStartOfFile: true
AtStartOfBlock: false
AtStartOfFile: false
KeepFormFeed: false
LambdaBodyIndentation: Signature
LambdaBodyIndentation: OuterScope
LineEnding: DeriveLF
MacroBlockBegin: ''
MacroBlockEnd: ''
Expand Down Expand Up @@ -217,7 +217,7 @@ QualifierAlignment: Leave
ReferenceAlignment: Pointer
ReflowComments: Always
RemoveBracesLLVM: false
RemoveEmptyLinesInUnwrappedLines: false
RemoveEmptyLinesInUnwrappedLines: true
RemoveParentheses: Leave
RemoveSemicolon: false
RequiresClausePosition: OwnLine
Expand All @@ -228,8 +228,8 @@ SkipMacroDefinitionBody: false
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: true
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
Expand All @@ -255,7 +255,7 @@ SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInContainerLiterals: true
SpacesInContainerLiterals: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
Expand All @@ -274,7 +274,7 @@ StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TableGenBreakInsideDAGArg: DontBreak
TabWidth: 8
TabWidth: 4
UseTab: Never
VerilogBreakBetweenInstancePorts: true
WhitespaceSensitiveMacros:
Expand All @@ -285,4 +285,3 @@ WhitespaceSensitiveMacros:
- STRINGIZE
WrapNamespaceBodyWithEmptyLines: Leave
...

31 changes: 31 additions & 0 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Format Check

on:
push:
branches:
- main
pull_request:

jobs:
format-check:
name: Check Code Formatting
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v4

- name: Install Dependencies
run: npm ci

- name: Install Clang Format
uses: jidicula/[email protected]
with:
clang-format-version: '20'
check-path: 'src'

- name: Run Prettier
run: ./node_modules/.bin/prettier --check 'src/**/*.{js,json,css,html}' platformio.ini package.json README.md vite.config.mjs tailwind.config.js
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"scripts": {
"build": "npm run format && npm run assets && npm run pio",
"format": "npm run format:cpp && npm run format:web",
"format:web": "prettier --write 'src/**/*.{js,json,css,html}' platformio.ini package.json readme.md vite.config.mjs tailwind.config.js",
"format:cpp": "command -v dlang-format >/dev/null 2>&1 && find src -iname '*.h' -o -iname '*.cpp' | xargs clang-format -i || echo 'clang-format not found, skipping format:cpp'",
"format:web": "prettier --write 'src/**/*.{js,json,css,html}' platformio.ini package.json README.md vite.config.mjs tailwind.config.js",
"format:cpp": "command -v clang-format >/dev/null 2>&1 && find src -iname '*.h' -o -iname '*.cpp' -o -iname '*.ino' | xargs clang-format -i || echo 'clang-format not found, skipping format:cpp'",
"assets": "vite build --emptyOutDir",
"pio": "npm run pio:firmware && sleep 2 && npm run pio:filesystem",
"pio:firmware": "pio run -t upload",
Expand Down
42 changes: 20 additions & 22 deletions src/JsonSetting.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
#include "JsonSetting.h"

String JsonSetting::intVectorToString(const std::vector<int> &vec) {
String result;
for (size_t i = 0; i < vec.size(); ++i) {
result += String(vec[i]);
if (i < vec.size() - 1) {
result += ",";
String result;
for (size_t i = 0; i < vec.size(); ++i) {
result += String(vec[i]);
if (i < vec.size() - 1) {
result += ",";
}
}
}
return result;
return result;
}

bool JsonSetting::validate(String str) {
switch (type) {
case JsonSettingType::JST_INT_VECTOR:
return validateIntVector(str);
default:
return true;
}
switch (type) {
case JsonSettingType::JST_INT_VECTOR: return validateIntVector(str);
default: return true;
}
}

bool JsonSetting::validateIntVector(String str) {
for (size_t i = 0; i < str.length(); ++i) {
if (str[i] == ',' || str[i] == '-') {
continue;
for (size_t i = 0; i < str.length(); ++i) {
if (str[i] == ',' || str[i] == '-') {
continue;
}
if (str[i] < '0' || str[i] > '9') {
lastValidationError = "Non-integer value found";
return false;
}
}
if (str[i] < '0' || str[i] > '9') {
lastValidationError = "Non-integer value found";
return false;
}
}
return true;
return true;
}
73 changes: 35 additions & 38 deletions src/JsonSetting.h
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
#ifndef JsonSetting_h
#define JsonSetting_h
#pragma once

#include "JsonSetting.h"
#include <Preferences.h>
#include <vector>

typedef enum { JST_STR, JST_INT, JST_FLOAT, JST_INT_VECTOR } JsonSettingType;
typedef enum {
JST_STR,
JST_INT,
JST_FLOAT,
JST_INT_VECTOR
} JsonSettingType;

class JsonSetting {
public:
JsonSetting(String strDefault)
: type(JsonSettingType::JST_STR), strDefault(strDefault) {}
JsonSetting(int intDefault)
: type(JsonSettingType::JST_INT), intDefault(intDefault) {}
JsonSetting(float floatDefault)
: type(JsonSettingType::JST_FLOAT), floatDefault(floatDefault) {
strDefault = String(floatDefault);
}
JsonSetting(std::vector<int> intVectorDefault)
: type(JsonSettingType::JST_INT_VECTOR),
intVectorDefault(intVectorDefault) {
strDefault = intVectorToString(intVectorDefault);
}

bool validate(String str);
String getLastValidationError() { return lastValidationError; }

private:
JsonSettingType type;

String strDefault;
int intDefault;
float floatDefault;
std::vector<int> intVectorDefault;

String intVectorToString(const std::vector<int> &vec);

String lastValidationError;
bool validateIntVector(String str);

friend class JsonSettings;
public:
JsonSetting(String strDefault) : type(JsonSettingType::JST_STR), strDefault(strDefault) {}
JsonSetting(int intDefault) : type(JsonSettingType::JST_INT), intDefault(intDefault) {}
JsonSetting(float floatDefault) : type(JsonSettingType::JST_FLOAT), floatDefault(floatDefault) {
strDefault = String(floatDefault);
}
JsonSetting(std::vector<int> intVectorDefault)
: type(JsonSettingType::JST_INT_VECTOR), intVectorDefault(intVectorDefault) {
strDefault = intVectorToString(intVectorDefault);
}

bool validate(String str);
String getLastValidationError() { return lastValidationError; }

private:
JsonSettingType type;

String strDefault;
int intDefault;
float floatDefault;
std::vector<int> intVectorDefault;

String intVectorToString(const std::vector<int> &vec);

String lastValidationError;
bool validateIntVector(String str);

friend class JsonSettings;
};

#endif
Loading