Skip to content

Commit df970fa

Browse files
committed
clang-format run incl. workflow for feature branch format check
1 parent c48f828 commit df970fa

File tree

91 files changed

+1210
-1173
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1210
-1173
lines changed

.github/workflows/featureBranches.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,43 @@ jobs:
146146
- name: Run tests on native environment
147147
run: platformio test --environment test -vvv
148148

149+
# Perform clang-format check
150+
check_format:
151+
# The type of runner that the job will run on.
152+
runs-on: ubuntu-latest
153+
needs: intro
154+
155+
steps:
156+
- name: Checkout repository
157+
uses: actions/checkout@v6
158+
159+
- name: Cache pip
160+
uses: actions/cache@v5
161+
with:
162+
path: ~/.cache/pip
163+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
164+
restore-keys: |
165+
${{ runner.os }}-pip-
166+
167+
- name: Cache PlatformIO
168+
uses: actions/cache@v5
169+
with:
170+
path: ~/.platformio
171+
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
172+
173+
- name: Set up Python
174+
uses: actions/setup-python@v6
175+
with:
176+
python-version: '3.9'
177+
178+
- name: Install PlatformIO
179+
run: |
180+
python -m pip install --upgrade pip
181+
pip install --upgrade platformio
182+
183+
- name: Run clang-format check
184+
run: find lib -iname '*.h' -iname '*.hpp' -o -iname '*.cpp' | xargs clang-format -i --dry-run -Werror
185+
149186
# Build documentation
150187
doc:
151188
# The type of runner that the job will run on.

lib/ArduinoNative/src/FS.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ FS NativeFS;
6363

6464
size_t File::size() const
6565
{
66-
size_t fileSize = 0U;
67-
size_t currPos = ftell(m_fd);
68-
66+
size_t fileSize = 0U;
67+
size_t currPos = ftell(m_fd);
68+
6969
if (0 == fseek(m_fd, 0, SEEK_END))
7070
{
7171
long pos = ftell(m_fd);

lib/ArduinoNative/src/Print.cpp

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,32 @@
6161
* Public Methods
6262
*****************************************************************************/
6363

64-
size_t Print::write(const uint8_t *buffer, size_t size)
64+
size_t Print::write(const uint8_t* buffer, size_t size)
6565
{
6666
size_t n = 0;
67-
while(size--) {
67+
while (size--)
68+
{
6869
n += write(*buffer++);
6970
}
7071
return n;
7172
}
7273

73-
size_t Print::write(const char *str)
74+
size_t Print::write(const char* str)
7475
{
75-
if(str == nullptr) {
76+
if (str == nullptr)
77+
{
7678
return 0;
7779
}
7880

79-
return write(reinterpret_cast<const uint8_t *>(str), strlen(str));
81+
return write(reinterpret_cast<const uint8_t*>(str), strlen(str));
8082
}
8183

82-
size_t Print::write(const char *buffer, size_t size)
84+
size_t Print::write(const char* buffer, size_t size)
8385
{
84-
return write(reinterpret_cast<const uint8_t *>(buffer), size);
86+
return write(reinterpret_cast<const uint8_t*>(buffer), size);
8587
}
8688

87-
size_t Print::print(const String &s)
89+
size_t Print::print(const String& s)
8890
{
8991
return write(s.c_str(), s.length());
9092
}
@@ -101,16 +103,22 @@ size_t Print::print(char c)
101103

102104
size_t Print::print(long n, int base)
103105
{
104-
if(base == 0) {
106+
if (base == 0)
107+
{
105108
return write(n);
106-
} else if(base == 10) {
107-
if(n < 0) {
109+
}
110+
else if (base == 10)
111+
{
112+
if (n < 0)
113+
{
108114
int t = print('-');
109-
n = -n;
115+
n = -n;
110116
return printNumber(n, 10) + t;
111117
}
112118
return printNumber(n, 10);
113-
} else {
119+
}
120+
else
121+
{
114122
return printNumber(n, base);
115123
}
116124
}
@@ -120,10 +128,10 @@ size_t Print::println()
120128
return print("\r\n");
121129
}
122130

123-
size_t Print::println(const String &s)
131+
size_t Print::println(const String& s)
124132
{
125-
size_t n = print(s);
126-
n += println();
133+
size_t n = print(s);
134+
n += println();
127135
return n;
128136
}
129137

@@ -137,22 +145,25 @@ size_t Print::println(const String &s)
137145

138146
size_t Print::printNumber(unsigned long n, uint8_t base)
139147
{
140-
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
141-
char *str = &buf[sizeof(buf) - 1];
148+
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
149+
char* str = &buf[sizeof(buf) - 1];
142150

143-
*str = '\0';
151+
*str = '\0';
144152

145153
// prevent crash if called with base == 1
146-
if(base < 2) {
154+
if (base < 2)
155+
{
147156
base = 10;
148157
}
149158

150-
do {
151-
unsigned long m = n;
152-
n /= base;
153-
char c = m - base * n;
154-
*--str = c < 10 ? c + '0' : c + 'A' - 10;
155-
} while(n);
159+
do
160+
{
161+
unsigned long m = n;
162+
n /= base;
163+
char c = m - base * n;
164+
*--str = c < 10 ? c + '0' : c + 'A' - 10;
165+
}
166+
while (n);
156167

157168
return write(str);
158169
}

lib/AsyncHttpClient/src/AsyncHttpClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ bool AsyncHttpClient::parseChunkedResponseChunkData(const uint8_t* data, size_t
13141314

13151315
/* Abort by set EOF. */
13161316
m_chunkIndex = 0U;
1317-
isDataEOF = true;
1317+
isDataEOF = true;
13181318
}
13191319
else
13201320
{

lib/AsyncHttpClient/src/HttpHeader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ HttpHeader& HttpHeader::operator=(const HttpHeader& hdr)
6363
{
6464
if (this != &hdr)
6565
{
66-
m_name = hdr.m_name;
66+
m_name = hdr.m_name;
6767
m_value = hdr.m_value;
6868
}
6969

@@ -76,11 +76,11 @@ void HttpHeader::parse(const String& line)
7676

7777
if (0 <= idx)
7878
{
79-
m_name = line.substring(0, idx);
79+
m_name = line.substring(0, idx);
8080
m_value = line.substring(idx + 2);
8181

8282
/* There may be CRLF at the end, which must be removed. */
83-
idx = m_value.indexOf("\r\n");
83+
idx = m_value.indexOf("\r\n");
8484

8585
if (0 <= idx)
8686
{

lib/AudioService/src/AudioService.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565

6666
bool AudioService::start()
6767
{
68-
bool isSuccessful = true;
69-
AudioDrv& audioDrv = AudioDrv::getInstance();
68+
bool isSuccessful = true;
69+
AudioDrv& audioDrv = AudioDrv::getInstance();
7070

7171
if ((IoPin::NC == CONFIG_PIN_I2S_WS) ||
7272
(IoPin::NC == CONFIG_PIN_I2S_SC) ||
@@ -92,8 +92,8 @@ bool AudioService::start()
9292
else
9393
{
9494
uint8_t idx = 0U;
95-
96-
while(MAX_TONE_DETECTORS > idx)
95+
96+
while (MAX_TONE_DETECTORS > idx)
9797
{
9898
if (false == audioDrv.registerObserver(m_audioToneDetector[idx]))
9999
{
@@ -120,12 +120,12 @@ bool AudioService::start()
120120

121121
void AudioService::stop()
122122
{
123-
AudioDrv& audioDrv = AudioDrv::getInstance();
124-
uint8_t idx = 0U;
123+
AudioDrv& audioDrv = AudioDrv::getInstance();
124+
uint8_t idx = 0U;
125125

126126
audioDrv.unregisterObserver(m_spectrumAnalyzer);
127127

128-
while(MAX_TONE_DETECTORS > idx)
128+
while (MAX_TONE_DETECTORS > idx)
129129
{
130130
audioDrv.unregisterObserver(m_audioToneDetector[idx]);
131131

lib/AudioService/src/AudioToneDetector.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,34 +67,34 @@ void AudioToneDetector::notify(int32_t* data, size_t size)
6767
if (((EPSILON < m_targetFreq) || (-EPSILON > m_targetFreq)) &&
6868
(nullptr != data))
6969
{
70-
size_t index = 0U;
71-
float q0 = 0.0F;
72-
float q1 = 0.0F;
73-
float q2 = 0.0F;
74-
float realValue = 0.0F;
75-
float imagValue = 0.0F;
76-
float magnitude = 0.0F;
77-
float scalingFactor = static_cast<float>(size) / 2.0F;
78-
79-
while(size > index)
70+
size_t index = 0U;
71+
float q0 = 0.0F;
72+
float q1 = 0.0F;
73+
float q2 = 0.0F;
74+
float realValue = 0.0F;
75+
float imagValue = 0.0F;
76+
float magnitude = 0.0F;
77+
float scalingFactor = static_cast<float>(size) / 2.0F;
78+
79+
while (size > index)
8080
{
8181
float fData = static_cast<float>(data[index]);
8282

83-
q0 = m_coeff * q1 - q2 + applyHanningWindow(fData, index, AudioDrv::SAMPLES);
84-
q2 = q1;
85-
q1 = q0;
83+
q0 = m_coeff * q1 - q2 + applyHanningWindow(fData, index, AudioDrv::SAMPLES);
84+
q2 = q1;
85+
q1 = q0;
8686

8787
++index;
8888
}
8989

90-
realValue = q1 - q2 * m_cosValue;
90+
realValue = q1 - q2 * m_cosValue;
9191
realValue /= scalingFactor;
9292

93-
imagValue = q2 * m_sinValue;
93+
imagValue = q2 * m_sinValue;
9494
imagValue /= scalingFactor;
9595

96-
magnitude = sqrtf(realValue * realValue + imagValue * imagValue);
97-
magnitude = applyHanningMagnitudeCorrection(magnitude);
96+
magnitude = sqrtf(realValue * realValue + imagValue * imagValue);
97+
magnitude = applyHanningMagnitudeCorrection(magnitude);
9898

9999
if (m_threshold < magnitude)
100100
{
@@ -137,23 +137,23 @@ void AudioToneDetector::notify(int32_t* data, size_t size)
137137

138138
void AudioToneDetector::preCompute()
139139
{
140-
float fIndex = 0.5F + ((AudioDrv::SAMPLES * m_targetFreq) / AudioDrv::SAMPLE_RATE);
141-
uint32_t index = static_cast<uint32_t>(fIndex);
140+
float fIndex = 0.5F + ((AudioDrv::SAMPLES * m_targetFreq) / AudioDrv::SAMPLE_RATE);
141+
uint32_t index = static_cast<uint32_t>(fIndex);
142142

143-
m_omega = (2.0F * M_PI) / AudioDrv::SAMPLES;
144-
m_omega *= index;
143+
m_omega = (2.0F * M_PI) / AudioDrv::SAMPLES;
144+
m_omega *= index;
145145

146-
m_cosValue = cos(m_omega);
147-
m_sinValue = sin(m_omega);
146+
m_cosValue = cos(m_omega);
147+
m_sinValue = sin(m_omega);
148148

149-
m_coeff = 2.0F * m_cosValue;
149+
m_coeff = 2.0F * m_cosValue;
150150
}
151151

152152
float AudioToneDetector::applyHanningWindow(float data, uint32_t sampleIndex, uint32_t samples)
153153
{
154154
float fSamples = static_cast<float>(samples);
155155

156-
return data * (0.54F - 0.46F * cos( 2.0F * M_PI * sampleIndex / fSamples));
156+
return data * (0.54F - 0.46F * cos(2.0F * M_PI * sampleIndex / fSamples));
157157
}
158158

159159
float AudioToneDetector::applyHanningMagnitudeCorrection(float data)

0 commit comments

Comments
 (0)