Skip to content

Commit 0cca9f6

Browse files
authored
feat: added Oscilloscope functionality (#2630)
1 parent 5d8d1e4 commit 0cca9f6

10 files changed

+721
-284
lines changed

lib/communication/analytics_class.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class AnalyticsClass {
3030

3131
complex = fft(yReal2.map((x) => Complex(x)).toList());
3232
yHat = fftToRfft(complex);
33+
yHatSquare = List<double>.filled(yHat.length, 0);
3334
for (int i = 0; i < yHat.length; i++) {
3435
yHatSquare[i] = pow(yHat[i], 2).toDouble();
3536
if (yHatSquare[i] > maximum) {
@@ -125,7 +126,7 @@ class AnalyticsClass {
125126
}
126127

127128
double amplitude = (sumGreaterThanOffset / n1) - (sumLesserThanOffset / n2);
128-
List<bool> bools = [];
129+
List<bool> bools = List.filled(yTmp.length - 1, false);
129130
double tmp;
130131
for (int i = 0; i < yTmp.length - 1; i++) {
131132
tmp = yTmp[i + 1] - yTmp[i];
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
class OscillscopeAxesScale {
2+
late double _yAxisScale;
3+
late double _yAxisScaleMin;
4+
late double _yAxisScaleMax;
5+
late double _xAxisScale;
6+
7+
OscillscopeAxesScale() {
8+
_yAxisScale = 16;
9+
_yAxisScaleMin = -16;
10+
_yAxisScaleMax = 16;
11+
_xAxisScale = 875;
12+
}
13+
14+
double get yAxisScale => _yAxisScale;
15+
double get yAxisScaleMin => _yAxisScaleMin;
16+
double get yAxisScaleMax => _yAxisScaleMax;
17+
double get xAxisScale => _xAxisScale;
18+
19+
void setYAxisScale(double value) {
20+
_yAxisScale = value;
21+
_yAxisScaleMax = value;
22+
_yAxisScaleMin = -value;
23+
}
24+
25+
void setYAxisScaleMin(double value) {
26+
_yAxisScaleMin = value;
27+
}
28+
29+
void setYAxisScaleMax(double value) {
30+
_yAxisScaleMax = value;
31+
}
32+
33+
void setXAxisScale(double value) {
34+
_xAxisScale = value;
35+
}
36+
37+
double getTimebaseInterval() {
38+
switch (_xAxisScale) {
39+
case 875.00:
40+
return 100;
41+
case 1000.00:
42+
return 0.2;
43+
case 2000.00:
44+
return 0.3;
45+
case 4000.00:
46+
return 0.7;
47+
case 8000.00:
48+
return 1;
49+
case 25600.00:
50+
return 4;
51+
case 38400.00:
52+
return 10;
53+
case 51200.00:
54+
return 10;
55+
case 102400.00:
56+
return 20;
57+
default:
58+
return _xAxisScale / 5000;
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)