Skip to content

Commit

Permalink
Merge pull request #148 from corrados/use_clang_format
Browse files Browse the repository at this point in the history
Use clang format
  • Loading branch information
corrados authored Jun 15, 2024
2 parents b307264 + d9247d4 commit 594ce4a
Show file tree
Hide file tree
Showing 13 changed files with 1,884 additions and 1,801 deletions.
26 changes: 26 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
BasedOnStyle: Google
IndentWidth: 2
TabWidth: 2
UseTab: Never
BreakBeforeBraces: Allman
ColumnLimit: 0
SpaceBeforeParens: ControlStatements
SpaceAfterCStyleCast: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpacesInContainerLiterals: false
AlignAfterOpenBracket: DontAlign
AlignTrailingComments: true
BinPackArguments: false
BinPackParameters: false
PenaltyBreakBeforeFirstCallParameter: 0

AllowShortCaseLabelsOnASingleLine: true
AlignConsecutiveAssignments: true
SpacesBeforeTrailingComments: 1
AlignOperands: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: All
IndentPPDirectives: AfterHash
#AllowShortLiteralsOnASingleLine: true
#BracketAlignmentStyle: BAS_Align
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,13 @@ jobs:
python -m pip install --upgrade pip
pip install --upgrade platformio setuptools wheel
- name: Install clang-format
run: sudo apt-get install clang-format

- name: Check clang-format
run: |
# Only check the format of the files in the root directory
clang-format --dry-run --Werror *.c *.cpp *.h *.ino
- name: Build
run: pio ci -c platformio.ini .
49 changes: 24 additions & 25 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,67 +19,66 @@

//#define USE_SERIAL_DEBUG_PLOTTING

#define VERSION_MAJOR 0
#define VERSION_MINOR 9
#define VERSION_MAJOR 0
#define VERSION_MINOR 9

#define MAX_NUM_PADS 12 // a maximum of 12 pads are supported
#define MAX_NUM_PAD_INPUTS 5 // a maximum of 5 sensors per pad is supported (where one is rim and one is the sum of three)
#define MAX_NUM_PADS 12 // a maximum of 12 pads are supported
#define MAX_NUM_PAD_INPUTS 5 // a maximum of 5 sensors per pad is supported (where one is rim and one is the sum of three)


inline void update_fifo ( const float input,
const int fifo_length,
float* fifo_memory )
inline void update_fifo(const float input,
const int fifo_length,
float* fifo_memory)
{
// move all values in the history one step back and put new value on the top
for ( int i = 0; i < fifo_length - 1; i++ )
for (int i = 0; i < fifo_length - 1; i++)
{
fifo_memory[i] = fifo_memory[i + 1];
}
fifo_memory[fifo_length - 1] = input;
}

inline void allocate_initialize ( float** array_memory,
const int array_length )
inline void allocate_initialize(float** array_memory,
const int array_length)
{
// (delete and) allocate memory
if ( *array_memory != nullptr )
if (*array_memory != nullptr)
{
delete[] *array_memory;
delete[] * array_memory;
}

*array_memory = new float[array_length];

// initialization values
for ( int i = 0; i < array_length; i++ )
for (int i = 0; i < array_length; i++)
{
( *array_memory )[i] = 0.0f;
(*array_memory)[i] = 0.0f;
}
}

class FastWriteFIFO
{
public:
void initialize ( const int len )
public:
void initialize(const int len)
{
pointer = 0;
fifo_length = len;
allocate_initialize ( &fifo_memory, len );
allocate_initialize(&fifo_memory, len);
}

void add ( const float input )
void add(const float input)
{
// write new value and increment data pointer with wrap around
fifo_memory[pointer] = input;
pointer = ( pointer + 1 ) % fifo_length;
pointer = (pointer + 1) % fifo_length;
}

const float operator[] ( const int index )
const float operator[](const int index)
{
return fifo_memory[( pointer + index ) % fifo_length];
return fifo_memory[(pointer + index) % fifo_length];
}

protected:
protected:
float* fifo_memory = nullptr;
int pointer;
int fifo_length;
int pointer;
int fifo_length;
};
Loading

0 comments on commit 594ce4a

Please sign in to comment.