Skip to content

Commit b3037e2

Browse files
authored
Merge pull request #5 from ardlib/master
Update to Code Format
2 parents cd9e3ae + dc6bca6 commit b3037e2

File tree

7 files changed

+158
-135
lines changed

7 files changed

+158
-135
lines changed

.clang-format

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# We'll use defaults from the LLVM style, but with 4 columns indentation.
2+
# Webkit is preference of Albert van Dalen
3+
BasedOnStyle: WebKit
4+
IndentWidth: 4

.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/checkout@v4
1414
- uses: arduino/arduino-lint-action@v1
1515
with:
16-
library-manager: submit
16+
library-manager: update
1717
compliance: strict
1818

1919
format:

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ It is not always possible to debug Arduino programs by the serial monitor, as th
1212
See the website:
1313
http://www.avdweb.nl/arduino/libraries/oscilloscope.html
1414

15+
## Developer Note
16+
17+
Please run code formatting before committing the code.
18+
19+
```sh
20+
clang-format -i src/*.* examples/**/*.ino
21+
```
22+
1523
## License
1624

1725
`SPDX: GPL-3.0-or-later`

examples/example_scope_avdweb_2channels/example_scope_avdweb_2channels.ino

+15-13
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55

66
SWscope scope;
77

8-
void setup(void) {
9-
Serial.begin(115200);
10-
scope.start(2, 10); // 2 integer channels , preSamples = 10, buffer is
11-
// 100/4=25 integer values
12-
// scope.testBuffer(); // print 100/2 = 50 integer values with only channel A
8+
void setup(void)
9+
{
10+
Serial.begin(115200);
11+
scope.start(2, 10); // 2 integer channels , preSamples = 10, buffer is
12+
// 100/4=25 integer values
13+
// scope.testBuffer(); // print 100/2 = 50 integer values with only channel A
1314
}
1415

15-
void loop(void) {
16-
static int internalValue;
17-
internalValue += 2;
18-
scope.probeAB(internalValue,
19-
analogRead(A0)); // channel A = internalValue, channel B = ADC
20-
if (internalValue > 10)
21-
scope.trigger();
22-
scope.showIfReady();
16+
void loop(void)
17+
{
18+
static int internalValue;
19+
internalValue += 2;
20+
scope.probeAB(internalValue,
21+
analogRead(A0)); // channel A = internalValue, channel B = ADC
22+
if (internalValue > 10)
23+
scope.trigger();
24+
scope.showIfReady();
2325
}

library.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
name=CodeDebugScope
2-
version=0.0.0
2+
version=0.0.1
33
author=Albert van Dalen <http://www.avdweb.nl>
44
license=GPL-3.0-or-later
55
maintainer=Abhijit Bose (aka. Boseji) <boseji.com>
66
sentence=CodeDebugScope Library
77
paragraph=Easy to use Debug Library that works by capturing data in background and relaying it when needed over serial connection.
88
category=Data Processing
9-
url=https://github.com/avandalen/avdweb_scope
9+
url=https://github.com/avdwebLibraries/avdweb_CodeDebugScope
1010
architectures=*
1111
includes=CodeDebugScope.h
1212
depends=Streaming

src/CodeDebugScope.cpp

+104-94
Original file line numberDiff line numberDiff line change
@@ -77,126 +77,136 @@ template <class T> // easy printing multiple variables with separator ','
7777
}
7878
*/
7979
void SWscope::start(byte _channels, int _preSamples,
80-
unsigned int _recordLenght) {
81-
ptr = samples = triggerPtr = preSamples = triggered = 0;
82-
stopPtr = 32767;
83-
samplingOn = 1;
84-
channels = _channels;
85-
recordLenght = maxScopeBytes / (sizeof(short) * channels);
86-
if (_recordLenght <= recordLenght)
87-
recordLenght = _recordLenght;
88-
if (abs(_preSamples) <= recordLenght)
89-
preSamples = _preSamples;
80+
unsigned int _recordLenght)
81+
{
82+
ptr = samples = triggerPtr = preSamples = triggered = 0;
83+
stopPtr = 32767;
84+
samplingOn = 1;
85+
channels = _channels;
86+
recordLenght = maxScopeBytes / (sizeof(short) * channels);
87+
if (_recordLenght <= recordLenght)
88+
recordLenght = _recordLenght;
89+
if (abs(_preSamples) <= recordLenght)
90+
preSamples = _preSamples;
9091
}
9192

92-
void SWscope::showIfReady() {
93-
if (!canShow)
94-
return;
95-
canShow = 0;
96-
Serial.begin(115200); // HIER doen Serial part moet buiten de bibliotheek
97-
// interrupts(); // hoeft niet
98-
while (!Serial)
99-
; // wait on Serial Monitor
100-
Serial << "\nusPerDiv: " << usPerDiv << "\nptr, values ";
101-
ptr = stopPtr;
102-
do {
103-
if (channels == 1)
104-
Serial << endl << ptr, ringBuffer.chA[ptr];
105-
if (channels == 2)
106-
Serial << endl << ptr, ringBuffer.chAB[ptr][0], ringBuffer.chAB[ptr][1];
107-
if (channels == 3)
108-
Serial << endl
109-
<< ptr,
110-
ringBuffer.chABC[ptr][0], ringBuffer.chABC[ptr][1],
111-
ringBuffer.chABC[ptr][2];
112-
if (channels == 4)
113-
Serial << endl
114-
<< ptr,
115-
ringBuffer.chABCD[ptr][0], ringBuffer.chABCD[ptr][1],
116-
ringBuffer.chABCD[ptr][2], ringBuffer.chABCD[ptr][3];
117-
if (ptr == triggerPtr)
118-
Serial << " trigger";
119-
ptr = calcPtr(ptr + 1);
120-
} while (ptr != stopPtr);
121-
stopPtr = 32767;
93+
void SWscope::showIfReady()
94+
{
95+
if (!canShow)
96+
return;
97+
canShow = 0;
98+
Serial.begin(115200); // HIER doen Serial part moet buiten de bibliotheek
99+
// interrupts(); // hoeft niet
100+
while (!Serial)
101+
; // wait on Serial Monitor
102+
Serial << "\nusPerDiv: " << usPerDiv << "\nptr, values ";
103+
ptr = stopPtr;
104+
do {
105+
if (channels == 1)
106+
Serial << endl
107+
<< ptr,
108+
ringBuffer.chA[ptr];
109+
if (channels == 2)
110+
Serial << endl
111+
<< ptr,
112+
ringBuffer.chAB[ptr][0], ringBuffer.chAB[ptr][1];
113+
if (channels == 3)
114+
Serial << endl
115+
<< ptr,
116+
ringBuffer.chABC[ptr][0], ringBuffer.chABC[ptr][1],
117+
ringBuffer.chABC[ptr][2];
118+
if (channels == 4)
119+
Serial << endl
120+
<< ptr,
121+
ringBuffer.chABCD[ptr][0], ringBuffer.chABCD[ptr][1],
122+
ringBuffer.chABCD[ptr][2], ringBuffer.chABCD[ptr][3];
123+
if (ptr == triggerPtr)
124+
Serial << " trigger";
125+
ptr = calcPtr(ptr + 1);
126+
} while (ptr != stopPtr);
127+
stopPtr = 32767;
122128
}
123129

124130
void SWscope::stop() { stopPtr = calcPtr(ptr + 1); }
125131

126132
void SWscope::probeA(short valueA) // 1 channel
127133
{
128-
if (samplingOn) {
129-
ringBuffer.chA[ptr] = valueA;
130-
sampleControl();
131-
}
134+
if (samplingOn) {
135+
ringBuffer.chA[ptr] = valueA;
136+
sampleControl();
137+
}
132138
}
133139

134140
void SWscope::probeAB(short valueA, short valueB) // 2 channels
135141
{
136-
if (samplingOn) {
137-
ringBuffer.chAB[ptr][0] = valueA;
138-
ringBuffer.chAB[ptr][1] = valueB;
139-
sampleControl();
140-
}
142+
if (samplingOn) {
143+
ringBuffer.chAB[ptr][0] = valueA;
144+
ringBuffer.chAB[ptr][1] = valueB;
145+
sampleControl();
146+
}
141147
}
142148

143149
void SWscope::probeABC(short valueA, short valueB, short valueC) // 3 channels
144150
{
145-
if (samplingOn) {
146-
ringBuffer.chABC[ptr][0] = valueA;
147-
ringBuffer.chABC[ptr][1] = valueB;
148-
ringBuffer.chABC[ptr][2] = valueC;
149-
sampleControl();
150-
}
151+
if (samplingOn) {
152+
ringBuffer.chABC[ptr][0] = valueA;
153+
ringBuffer.chABC[ptr][1] = valueB;
154+
ringBuffer.chABC[ptr][2] = valueC;
155+
sampleControl();
156+
}
151157
}
152158

153159
void SWscope::probeABCD(short valueA, short valueB, short valueC,
154-
short valueD) // 4 channels
160+
short valueD) // 4 channels
155161
{
156-
if (samplingOn) {
157-
ringBuffer.chABCD[ptr][0] = valueA;
158-
ringBuffer.chABCD[ptr][1] = valueB;
159-
ringBuffer.chABCD[ptr][2] = valueC;
160-
ringBuffer.chABCD[ptr][3] = valueD;
161-
sampleControl();
162-
}
162+
if (samplingOn) {
163+
ringBuffer.chABCD[ptr][0] = valueA;
164+
ringBuffer.chABCD[ptr][1] = valueB;
165+
ringBuffer.chABCD[ptr][2] = valueC;
166+
ringBuffer.chABCD[ptr][3] = valueD;
167+
sampleControl();
168+
}
163169
}
164170

165-
void SWscope::sampleControl() { // doen micros weggelaten if(samples == 0)
166-
// sample0_us = micros();
167-
samples++;
168-
ptr = calcPtr(ptr + 1);
169-
if (ptr == stopPtr) {
170-
samplingOn = 0;
171-
canShow = 1;
172-
unsigned long stop_us; // doen = micros(); // to avoid delay, start with
173-
// this
174-
usPerDiv = samples > 1 ? (stop_us - sample0_us) / (samples - 1)
175-
: 0; // is not exact?
176-
}
171+
void SWscope::sampleControl()
172+
{ // doen micros weggelaten if(samples == 0)
173+
// sample0_us = micros();
174+
samples++;
175+
ptr = calcPtr(ptr + 1);
176+
if (ptr == stopPtr) {
177+
samplingOn = 0;
178+
canShow = 1;
179+
unsigned long stop_us; // doen = micros(); // to avoid delay, start with
180+
// this
181+
usPerDiv = samples > 1 ? (stop_us - sample0_us) / (samples - 1)
182+
: 0; // is not exact?
183+
}
177184
}
178185

179-
unsigned int SWscope::calcPtr(int _ptr) {
180-
if (_ptr >= recordLenght)
181-
return (_ptr - recordLenght); // happens most frequent
182-
if (_ptr < 0)
183-
return (_ptr + recordLenght);
184-
return _ptr;
186+
unsigned int SWscope::calcPtr(int _ptr)
187+
{
188+
if (_ptr >= recordLenght)
189+
return (_ptr - recordLenght); // happens most frequent
190+
if (_ptr < 0)
191+
return (_ptr + recordLenght);
192+
return _ptr;
185193
}
186194

187-
void SWscope::trigger() {
188-
if (!triggered) {
189-
triggerPtr = ptr;
190-
stopPtr = calcPtr(triggerPtr - preSamples);
191-
triggered = 1;
192-
}
195+
void SWscope::trigger()
196+
{
197+
if (!triggered) {
198+
triggerPtr = ptr;
199+
stopPtr = calcPtr(triggerPtr - preSamples);
200+
triggered = 1;
201+
}
193202
}
194203

195-
void SWscope::testBuffer() {
196-
start(1);
197-
for (int i = 0; i < 25000; i++) {
198-
if (i == 0)
199-
trigger();
200-
probeA(i);
201-
}
204+
void SWscope::testBuffer()
205+
{
206+
start(1);
207+
for (int i = 0; i < 25000; i++) {
208+
if (i == 0)
209+
trigger();
210+
probeA(i);
211+
}
202212
}

src/CodeDebugScope.h

+24-25
Original file line numberDiff line numberDiff line change
@@ -38,42 +38,41 @@
3838
#if defined(__arm__)
3939
const unsigned int maxScopeBytes = 7000; // SAMD21: max ~ 7000
4040
#else
41-
const int maxScopeBytes =
42-
500; // ATTENTION SET HERE, AVR ATmega328: max ~ 780 ATmega168: max ~ 320
41+
const int maxScopeBytes = 500; // ATTENTION SET HERE, AVR ATmega328: max ~ 780 ATmega168: max ~ 320
4342
// const int maxScopeBytes = 100; // ATTENTION SET HERE, AVR ATmega328: max ~
4443
// 780 ATmega168: max ~ 320
4544
#endif
4645

4746
class SWscope {
4847
public:
49-
void start(byte _channels, int _preSamples = 0,
50-
unsigned int _recordLenght = 65535);
51-
void probeA(short valueA);
52-
void probeAB(short valueA, short valueB);
53-
void probeABC(short valueA, short valueB, short valueC);
54-
void probeABCD(short valueA, short valueB, short valueC, short valueD);
55-
void trigger();
56-
void stop();
57-
void showIfReady();
58-
void testBuffer();
48+
void start(byte _channels, int _preSamples = 0,
49+
unsigned int _recordLenght = 65535);
50+
void probeA(short valueA);
51+
void probeAB(short valueA, short valueB);
52+
void probeABC(short valueA, short valueB, short valueC);
53+
void probeABCD(short valueA, short valueB, short valueC, short valueD);
54+
void trigger();
55+
void stop();
56+
void showIfReady();
57+
void testBuffer();
5958

60-
volatile bool canShow;
59+
volatile bool canShow;
6160

6261
protected:
63-
void sampleControl();
64-
unsigned int calcPtr(int ptr);
62+
void sampleControl();
63+
unsigned int calcPtr(int ptr);
6564

66-
volatile union {
67-
short chA[maxScopeBytes / 2];
68-
short chAB[maxScopeBytes / 4][2];
69-
short chABC[maxScopeBytes / 3][3];
70-
short chABCD[maxScopeBytes / 8][4];
71-
} ringBuffer;
65+
volatile union {
66+
short chA[maxScopeBytes / 2];
67+
short chAB[maxScopeBytes / 4][2];
68+
short chABC[maxScopeBytes / 3][3];
69+
short chABCD[maxScopeBytes / 8][4];
70+
} ringBuffer;
7271

73-
volatile unsigned long sample0_us, usPerDiv;
74-
volatile bool triggered, samplingOn;
75-
volatile byte channels; // 1, 2, 3, 4 channels
76-
volatile int recordLenght, preSamples, ptr, samples, triggerPtr, stopPtr;
72+
volatile unsigned long sample0_us, usPerDiv;
73+
volatile bool triggered, samplingOn;
74+
volatile byte channels; // 1, 2, 3, 4 channels
75+
volatile int recordLenght, preSamples, ptr, samples, triggerPtr, stopPtr;
7776
};
7877

7978
#endif

0 commit comments

Comments
 (0)