@@ -7,6 +7,7 @@ class DigitalChannel {
7
7
static const int everyFourthRisingEdge = 4 ;
8
8
static const int everyRisingEdge = 3 ;
9
9
static const int everyFallingEdge = 2 ;
10
+ static const int captureDelay = 2 ;
10
11
static List <String > digitalChannelNames = [
11
12
'LA1' ,
12
13
'LA2' ,
@@ -58,25 +59,22 @@ class DigitalChannel {
58
59
final int s = initialStates[channelName]! ;
59
60
initialState = s == 1 ;
60
61
}
61
- this .timestamps.setRange (0 , timestamps.length, timestamps);
62
+ this .timestamps.setRange (0 , timestamps.length - 1 , timestamps);
62
63
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
+ }
77
75
}
78
76
for (int i = 0 ; i < this .timestamps.length; i++ ) {
79
- this .timestamps[i] /= factor;
77
+ this .timestamps[i] = ( this .timestamps[i] + (i * captureDelay)) / factor;
80
78
}
81
79
if (dLength > 0 ) {
82
80
maxT = this .timestamps[this .timestamps.length - 1 ];
@@ -99,35 +97,35 @@ class DigitalChannel {
99
97
plotLength = 1 ;
100
98
} else if (mode == everyEdge) {
101
99
xAxis[0 ] = 0 ;
102
- yAxis[0 ] = state as double ;
100
+ yAxis[0 ] = state. toDouble () ;
103
101
int length = 0 ;
104
102
for (int i = 1 , j = 1 ; i < dLength; i++ , j++ ) {
105
103
xAxis[j] = timestamps[i];
106
- yAxis[j] = state as double ;
104
+ yAxis[j] = state. toDouble () ;
107
105
if (state == high) {
108
106
state = low;
109
107
} else {
110
108
state = high;
111
109
}
112
110
j++ ;
113
111
xAxis[j] = timestamps[i];
114
- yAxis[j] = state as double ;
112
+ yAxis[j] = state. toDouble () ;
115
113
length = j;
116
114
}
117
115
plotLength = length;
118
116
} else if (mode == everyFallingEdge) {
119
117
xAxis[0 ] = 0 ;
120
- yAxis[0 ] = high as double ;
118
+ yAxis[0 ] = high. toDouble () ;
121
119
int length = 0 ;
122
120
for (int i = 1 , j = 1 ; i < dLength; i++ , j++ ) {
123
121
xAxis[j] = timestamps[i];
124
- yAxis[j] = high as double ;
122
+ yAxis[j] = high. toDouble () ;
125
123
j++ ;
126
124
xAxis[j] = timestamps[i];
127
- yAxis[j] = low as double ;
125
+ yAxis[j] = low. toDouble () ;
128
126
j++ ;
129
127
xAxis[j] = timestamps[i];
130
- yAxis[j] = high as double ;
128
+ yAxis[j] = high. toDouble () ;
131
129
length = j;
132
130
}
133
131
state = high;
@@ -136,21 +134,29 @@ class DigitalChannel {
136
134
mode == everyFourthRisingEdge ||
137
135
mode == everySixteenthRisingEdge) {
138
136
xAxis[0 ] = 0 ;
139
- yAxis[0 ] = low as double ;
137
+ yAxis[0 ] = low. toDouble () ;
140
138
int length = 0 ;
141
139
for (int i = 1 , j = 1 ; i < dLength; i++ , j++ ) {
142
140
xAxis[j] = timestamps[i];
143
- yAxis[j] = low as double ;
141
+ yAxis[j] = low. toDouble () ;
144
142
j++ ;
145
143
xAxis[j] = timestamps[i];
146
- yAxis[j] = high as double ;
144
+ yAxis[j] = high. toDouble () ;
147
145
j++ ;
148
146
xAxis[j] = timestamps[i];
149
- yAxis[j] = low as double ;
147
+ yAxis[j] = low. toDouble () ;
150
148
length = j;
151
149
}
152
150
state = low;
153
151
plotLength = length;
154
152
}
155
153
}
154
+
155
+ List <double > getXAxis () {
156
+ return xAxis.sublist (0 , plotLength);
157
+ }
158
+
159
+ List <double > getYAxis () {
160
+ return yAxis.sublist (0 , plotLength);
161
+ }
156
162
}
0 commit comments