Skip to content

Commit 6d3fe6e

Browse files
committed
Trim files
1 parent 519a0d3 commit 6d3fe6e

File tree

3 files changed

+223
-224
lines changed

3 files changed

+223
-224
lines changed

CONTRIBUTING.md

100755100644
File mode changed.

avdweb_SWscope.cpp

+167-167
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,167 @@
1-
/*
2-
The library <Streaming.h> has to be installed too, download here:
3-
http://arduiniana.org/libraries/streaming/ The library <avdweb.h> has to be
4-
installed too, download here: nog doen
5-
6-
Copyright (C) 2016 Albert van Dalen http://www.avdweb.nl
7-
This program is free software: you can redistribute it and/or modify it under
8-
the terms of the GNU General Public License as published by the Free Software
9-
Foundation, either version 3 of the License, or (at your option) any later
10-
version. This program is distributed in the hope that it will be useful, but
11-
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12-
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at
13-
http://www.gnu.org/licenses .
14-
15-
HISTORY:
16-
1.0.0 1-1-2016
17-
1.0.1 14-1-2016 sample0_us
18-
1.0.2 10-2-2017 1, 2, 3, 4 channels
19-
1.0.3 10-2-2017 probeA sampleB probeABC probeABCD to avoid mistakes, all
20-
unsigned int -> int, added stop(), sizeof(int) SerialUSB -> Serial (incl.
21-
<Albert.h>), short 1.0.4 10-3-2017 for ISR measurements do show() in loop()
22-
1.0.5 28-1-2018 renamed sample to probe, Scope to SWscope
23-
24-
start ___|____________________________________|________
25-
26-
probe |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_
27-
28-
trigger ____________|________________________________________
29-
___________________________
30-
triggered ____________| |___________
31-
32-
samples 0 0 1 2 3 . . .
33-
________
34-
show ________________________| |______________
35-
____________________ ___________
36-
samplingOn ___| |_______________|
37-
38-
canShow ________________________|___________________________
39-
40-
*/
41-
42-
#include "avdweb_SWscope.h"
43-
#include "Albert.h"
44-
#include <Streaming.h>
45-
46-
void SWscope::start(byte _channels, int _preSamples,
47-
unsigned int _recordLenght) {
48-
ptr = samples = triggerPtr = preSamples = triggered = 0;
49-
stopPtr = 32767;
50-
samplingOn = 1;
51-
channels = _channels;
52-
recordLenght = maxScopeBytes / (sizeof(short) * channels);
53-
if (_recordLenght <= recordLenght)
54-
recordLenght = _recordLenght;
55-
if (abs(_preSamples) <= recordLenght)
56-
preSamples = _preSamples;
57-
}
58-
59-
void SWscope::stop() { stopPtr = calcPtr(ptr + 1); }
60-
61-
void SWscope::showIfReady() {
62-
if (!canShow)
63-
return;
64-
canShow = 0;
65-
while (!Serial)
66-
; // wait on Serial Monitor
67-
Serial << "\nusPerDiv: " << usPerDiv << "\nptr, values ";
68-
ptr = stopPtr;
69-
do {
70-
if (channels == 1)
71-
Serial << endl << ptr, ringBuffer.chA[ptr];
72-
if (channels == 2)
73-
Serial << endl << ptr, ringBuffer.chAB[ptr][0], ringBuffer.chAB[ptr][1];
74-
if (channels == 3)
75-
Serial << endl
76-
<< ptr,
77-
ringBuffer.chABC[ptr][0], ringBuffer.chABC[ptr][1],
78-
ringBuffer.chABC[ptr][2];
79-
if (channels == 4)
80-
Serial << endl
81-
<< ptr,
82-
ringBuffer.chABCD[ptr][0], ringBuffer.chABCD[ptr][1],
83-
ringBuffer.chABCD[ptr][2], ringBuffer.chABCD[ptr][3];
84-
if (ptr == triggerPtr)
85-
Serial << " trigger";
86-
ptr = calcPtr(ptr + 1);
87-
} while (ptr != stopPtr);
88-
stopPtr = 32767;
89-
}
90-
91-
void SWscope::probeA(short valueA) // 1 channel
92-
{
93-
if (samplingOn) {
94-
ringBuffer.chA[ptr] = valueA;
95-
sampleControl();
96-
}
97-
}
98-
99-
void SWscope::probeAB(short valueA, short valueB) // 2 channels
100-
{
101-
if (samplingOn) {
102-
ringBuffer.chAB[ptr][0] = valueA;
103-
ringBuffer.chAB[ptr][1] = valueB;
104-
sampleControl();
105-
}
106-
}
107-
108-
void SWscope::probeABC(short valueA, short valueB, short valueC) // 3 channels
109-
{
110-
if (samplingOn) {
111-
ringBuffer.chABC[ptr][0] = valueA;
112-
ringBuffer.chABC[ptr][1] = valueB;
113-
ringBuffer.chABC[ptr][2] = valueC;
114-
sampleControl();
115-
}
116-
}
117-
118-
void SWscope::probeABCD(short valueA, short valueB, short valueC,
119-
short valueD) // 4 channels
120-
{
121-
if (samplingOn) {
122-
ringBuffer.chABCD[ptr][0] = valueA;
123-
ringBuffer.chABCD[ptr][1] = valueB;
124-
ringBuffer.chABCD[ptr][2] = valueC;
125-
ringBuffer.chABCD[ptr][3] = valueD;
126-
sampleControl();
127-
}
128-
}
129-
130-
void SWscope::sampleControl() {
131-
if (samples == 0)
132-
sample0_us = micros();
133-
samples++;
134-
ptr = calcPtr(ptr + 1);
135-
if (ptr == stopPtr) {
136-
samplingOn = 0;
137-
canShow = 1;
138-
unsigned long stop_us = micros(); // to avoid delay, start with this
139-
usPerDiv = samples > 1 ? (stop_us - sample0_us) / (samples - 1)
140-
: 0; // is not exact?
141-
}
142-
}
143-
144-
unsigned int SWscope::calcPtr(int _ptr) {
145-
if (_ptr >= recordLenght)
146-
return (_ptr - recordLenght); // happens most frequent
147-
if (_ptr < 0)
148-
return (_ptr + recordLenght);
149-
return _ptr;
150-
}
151-
152-
void SWscope::trigger() {
153-
if (!triggered) {
154-
triggerPtr = ptr;
155-
stopPtr = calcPtr(triggerPtr - preSamples);
156-
triggered = 1;
157-
}
158-
}
159-
160-
void SWscope::testBuffer() {
161-
start(1);
162-
for (int i = 0; i < 25000; i++) {
163-
if (i == 0)
164-
trigger();
165-
probeA(i);
166-
}
167-
}
1+
/*
2+
The library <Streaming.h> has to be installed too, download here:
3+
http://arduiniana.org/libraries/streaming/ The library <avdweb.h> has to be
4+
installed too, download here: nog doen
5+
6+
Copyright (C) 2016 Albert van Dalen http://www.avdweb.nl
7+
This program is free software: you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License as published by the Free Software
9+
Foundation, either version 3 of the License, or (at your option) any later
10+
version. This program is distributed in the hope that it will be useful, but
11+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at
13+
http://www.gnu.org/licenses .
14+
15+
HISTORY:
16+
1.0.0 1-1-2016
17+
1.0.1 14-1-2016 sample0_us
18+
1.0.2 10-2-2017 1, 2, 3, 4 channels
19+
1.0.3 10-2-2017 probeA sampleB probeABC probeABCD to avoid mistakes, all
20+
unsigned int -> int, added stop(), sizeof(int) SerialUSB -> Serial (incl.
21+
<Albert.h>), short 1.0.4 10-3-2017 for ISR measurements do show() in loop()
22+
1.0.5 28-1-2018 renamed sample to probe, Scope to SWscope
23+
24+
start ___|____________________________________|________
25+
26+
probe |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_
27+
28+
trigger ____________|________________________________________
29+
___________________________
30+
triggered ____________| |___________
31+
32+
samples 0 0 1 2 3 . . .
33+
________
34+
show ________________________| |______________
35+
____________________ ___________
36+
samplingOn ___| |_______________|
37+
38+
canShow ________________________|___________________________
39+
40+
*/
41+
42+
#include "avdweb_SWscope.h"
43+
#include "Albert.h"
44+
#include <Streaming.h>
45+
46+
void SWscope::start(byte _channels, int _preSamples,
47+
unsigned int _recordLenght) {
48+
ptr = samples = triggerPtr = preSamples = triggered = 0;
49+
stopPtr = 32767;
50+
samplingOn = 1;
51+
channels = _channels;
52+
recordLenght = maxScopeBytes / (sizeof(short) * channels);
53+
if (_recordLenght <= recordLenght)
54+
recordLenght = _recordLenght;
55+
if (abs(_preSamples) <= recordLenght)
56+
preSamples = _preSamples;
57+
}
58+
59+
void SWscope::stop() { stopPtr = calcPtr(ptr + 1); }
60+
61+
void SWscope::showIfReady() {
62+
if (!canShow)
63+
return;
64+
canShow = 0;
65+
while (!Serial)
66+
; // wait on Serial Monitor
67+
Serial << "\nusPerDiv: " << usPerDiv << "\nptr, values ";
68+
ptr = stopPtr;
69+
do {
70+
if (channels == 1)
71+
Serial << endl << ptr, ringBuffer.chA[ptr];
72+
if (channels == 2)
73+
Serial << endl << ptr, ringBuffer.chAB[ptr][0], ringBuffer.chAB[ptr][1];
74+
if (channels == 3)
75+
Serial << endl
76+
<< ptr,
77+
ringBuffer.chABC[ptr][0], ringBuffer.chABC[ptr][1],
78+
ringBuffer.chABC[ptr][2];
79+
if (channels == 4)
80+
Serial << endl
81+
<< ptr,
82+
ringBuffer.chABCD[ptr][0], ringBuffer.chABCD[ptr][1],
83+
ringBuffer.chABCD[ptr][2], ringBuffer.chABCD[ptr][3];
84+
if (ptr == triggerPtr)
85+
Serial << " trigger";
86+
ptr = calcPtr(ptr + 1);
87+
} while (ptr != stopPtr);
88+
stopPtr = 32767;
89+
}
90+
91+
void SWscope::probeA(short valueA) // 1 channel
92+
{
93+
if (samplingOn) {
94+
ringBuffer.chA[ptr] = valueA;
95+
sampleControl();
96+
}
97+
}
98+
99+
void SWscope::probeAB(short valueA, short valueB) // 2 channels
100+
{
101+
if (samplingOn) {
102+
ringBuffer.chAB[ptr][0] = valueA;
103+
ringBuffer.chAB[ptr][1] = valueB;
104+
sampleControl();
105+
}
106+
}
107+
108+
void SWscope::probeABC(short valueA, short valueB, short valueC) // 3 channels
109+
{
110+
if (samplingOn) {
111+
ringBuffer.chABC[ptr][0] = valueA;
112+
ringBuffer.chABC[ptr][1] = valueB;
113+
ringBuffer.chABC[ptr][2] = valueC;
114+
sampleControl();
115+
}
116+
}
117+
118+
void SWscope::probeABCD(short valueA, short valueB, short valueC,
119+
short valueD) // 4 channels
120+
{
121+
if (samplingOn) {
122+
ringBuffer.chABCD[ptr][0] = valueA;
123+
ringBuffer.chABCD[ptr][1] = valueB;
124+
ringBuffer.chABCD[ptr][2] = valueC;
125+
ringBuffer.chABCD[ptr][3] = valueD;
126+
sampleControl();
127+
}
128+
}
129+
130+
void SWscope::sampleControl() {
131+
if (samples == 0)
132+
sample0_us = micros();
133+
samples++;
134+
ptr = calcPtr(ptr + 1);
135+
if (ptr == stopPtr) {
136+
samplingOn = 0;
137+
canShow = 1;
138+
unsigned long stop_us = micros(); // to avoid delay, start with this
139+
usPerDiv = samples > 1 ? (stop_us - sample0_us) / (samples - 1)
140+
: 0; // is not exact?
141+
}
142+
}
143+
144+
unsigned int SWscope::calcPtr(int _ptr) {
145+
if (_ptr >= recordLenght)
146+
return (_ptr - recordLenght); // happens most frequent
147+
if (_ptr < 0)
148+
return (_ptr + recordLenght);
149+
return _ptr;
150+
}
151+
152+
void SWscope::trigger() {
153+
if (!triggered) {
154+
triggerPtr = ptr;
155+
stopPtr = calcPtr(triggerPtr - preSamples);
156+
triggered = 1;
157+
}
158+
}
159+
160+
void SWscope::testBuffer() {
161+
start(1);
162+
for (int i = 0; i < 25000; i++) {
163+
if (i == 0)
164+
trigger();
165+
probeA(i);
166+
}
167+
}

0 commit comments

Comments
 (0)