Skip to content

Commit

Permalink
feat: added Oscilloscope functionality (#2630)
Browse files Browse the repository at this point in the history
  • Loading branch information
AsCress authored Feb 15, 2025
1 parent 5d8d1e4 commit 0cca9f6
Show file tree
Hide file tree
Showing 10 changed files with 721 additions and 284 deletions.
3 changes: 2 additions & 1 deletion lib/communication/analytics_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class AnalyticsClass {

complex = fft(yReal2.map((x) => Complex(x)).toList());
yHat = fftToRfft(complex);
yHatSquare = List<double>.filled(yHat.length, 0);
for (int i = 0; i < yHat.length; i++) {
yHatSquare[i] = pow(yHat[i], 2).toDouble();
if (yHatSquare[i] > maximum) {
Expand Down Expand Up @@ -125,7 +126,7 @@ class AnalyticsClass {
}

double amplitude = (sumGreaterThanOffset / n1) - (sumLesserThanOffset / n2);
List<bool> bools = [];
List<bool> bools = List.filled(yTmp.length - 1, false);
double tmp;
for (int i = 0; i < yTmp.length - 1; i++) {
tmp = yTmp[i + 1] - yTmp[i];
Expand Down
61 changes: 61 additions & 0 deletions lib/others/oscilloscope_axes_scale.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
class OscillscopeAxesScale {
late double _yAxisScale;
late double _yAxisScaleMin;
late double _yAxisScaleMax;
late double _xAxisScale;

OscillscopeAxesScale() {
_yAxisScale = 16;
_yAxisScaleMin = -16;
_yAxisScaleMax = 16;
_xAxisScale = 875;
}

double get yAxisScale => _yAxisScale;
double get yAxisScaleMin => _yAxisScaleMin;
double get yAxisScaleMax => _yAxisScaleMax;
double get xAxisScale => _xAxisScale;

void setYAxisScale(double value) {
_yAxisScale = value;
_yAxisScaleMax = value;
_yAxisScaleMin = -value;
}

void setYAxisScaleMin(double value) {
_yAxisScaleMin = value;
}

void setYAxisScaleMax(double value) {
_yAxisScaleMax = value;
}

void setXAxisScale(double value) {
_xAxisScale = value;
}

double getTimebaseInterval() {
switch (_xAxisScale) {
case 875.00:
return 100;
case 1000.00:
return 0.2;
case 2000.00:
return 0.3;
case 4000.00:
return 0.7;
case 8000.00:
return 1;
case 25600.00:
return 4;
case 38400.00:
return 10;
case 51200.00:
return 10;
case 102400.00:
return 20;
default:
return _xAxisScale / 5000;
}
}
}
Loading

0 comments on commit 0cca9f6

Please sign in to comment.