Skip to content

Commit 7463f92

Browse files
authored
feat: added functionality for Multimeter (#2767)
1 parent 413451d commit 7463f92

File tree

8 files changed

+952
-247
lines changed

8 files changed

+952
-247
lines changed

lib/communication/analogChannel/analog_input_source.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ class AnalogInputSource {
3939
gainEnabled = true;
4040
gainPGA = 2;
4141
_gain = 0;
42+
} else {
43+
gainPGA = 1;
44+
_gain = 0;
4245
}
43-
_gain = 0;
4446
regenerateCalibration();
4547
}
4648

lib/communication/digitalChannel/digital_channel.dart

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class DigitalChannel {
77
static const int everyFourthRisingEdge = 4;
88
static const int everyRisingEdge = 3;
99
static const int everyFallingEdge = 2;
10+
static const int captureDelay = 2;
1011
static List<String> digitalChannelNames = [
1112
'LA1',
1213
'LA2',
@@ -58,25 +59,22 @@ class DigitalChannel {
5859
final int s = initialStates[channelName]!;
5960
initialState = s == 1;
6061
}
61-
this.timestamps.setRange(0, timestamps.length, timestamps);
62+
this.timestamps.setRange(0, timestamps.length - 1, timestamps);
6263
dLength = timestamps.length;
63-
double factor;
64-
switch (prescaler) {
65-
case 0:
66-
factor = 64;
67-
break;
68-
case 1:
69-
factor = 8;
70-
break;
71-
case 2:
72-
factor = 4;
73-
break;
74-
default:
75-
factor = 1;
76-
break;
64+
double factor = 64;
65+
List<double> diff = [];
66+
for (int i = 0; i < this.timestamps.length - 1; i++) {
67+
diff.add(this.timestamps[i + 1] - this.timestamps[i]);
68+
}
69+
for (int i = 0; i < diff.length; i++) {
70+
if (diff[i] < 0) {
71+
for (int j = i + 1; j < this.timestamps.length; j++) {
72+
this.timestamps[j] += (1 << 16) - 1;
73+
}
74+
}
7775
}
7876
for (int i = 0; i < this.timestamps.length; i++) {
79-
this.timestamps[i] /= factor;
77+
this.timestamps[i] = (this.timestamps[i] + (i * captureDelay)) / factor;
8078
}
8179
if (dLength > 0) {
8280
maxT = this.timestamps[this.timestamps.length - 1];
@@ -99,35 +97,35 @@ class DigitalChannel {
9997
plotLength = 1;
10098
} else if (mode == everyEdge) {
10199
xAxis[0] = 0;
102-
yAxis[0] = state as double;
100+
yAxis[0] = state.toDouble();
103101
int length = 0;
104102
for (int i = 1, j = 1; i < dLength; i++, j++) {
105103
xAxis[j] = timestamps[i];
106-
yAxis[j] = state as double;
104+
yAxis[j] = state.toDouble();
107105
if (state == high) {
108106
state = low;
109107
} else {
110108
state = high;
111109
}
112110
j++;
113111
xAxis[j] = timestamps[i];
114-
yAxis[j] = state as double;
112+
yAxis[j] = state.toDouble();
115113
length = j;
116114
}
117115
plotLength = length;
118116
} else if (mode == everyFallingEdge) {
119117
xAxis[0] = 0;
120-
yAxis[0] = high as double;
118+
yAxis[0] = high.toDouble();
121119
int length = 0;
122120
for (int i = 1, j = 1; i < dLength; i++, j++) {
123121
xAxis[j] = timestamps[i];
124-
yAxis[j] = high as double;
122+
yAxis[j] = high.toDouble();
125123
j++;
126124
xAxis[j] = timestamps[i];
127-
yAxis[j] = low as double;
125+
yAxis[j] = low.toDouble();
128126
j++;
129127
xAxis[j] = timestamps[i];
130-
yAxis[j] = high as double;
128+
yAxis[j] = high.toDouble();
131129
length = j;
132130
}
133131
state = high;
@@ -136,21 +134,29 @@ class DigitalChannel {
136134
mode == everyFourthRisingEdge ||
137135
mode == everySixteenthRisingEdge) {
138136
xAxis[0] = 0;
139-
yAxis[0] = low as double;
137+
yAxis[0] = low.toDouble();
140138
int length = 0;
141139
for (int i = 1, j = 1; i < dLength; i++, j++) {
142140
xAxis[j] = timestamps[i];
143-
yAxis[j] = low as double;
141+
yAxis[j] = low.toDouble();
144142
j++;
145143
xAxis[j] = timestamps[i];
146-
yAxis[j] = high as double;
144+
yAxis[j] = high.toDouble();
147145
j++;
148146
xAxis[j] = timestamps[i];
149-
yAxis[j] = low as double;
147+
yAxis[j] = low.toDouble();
150148
length = j;
151149
}
152150
state = low;
153151
plotLength = length;
154152
}
155153
}
154+
155+
List<double> getXAxis() {
156+
return xAxis.sublist(0, plotLength);
157+
}
158+
159+
List<double> getYAxis() {
160+
return yAxis.sublist(0, plotLength);
161+
}
156162
}

0 commit comments

Comments
 (0)