@@ -85,6 +85,34 @@ static bool g_wasExecuting;
85
85
86
86
// //////////////////////////////////////////////////////////////////////////////
87
87
88
+ bool Parameters::isDlogItemAvailable (int slotIndex, int subchannelIndex, int resourceIndex) {
89
+ if (numDlogItems >= dlog_file::MAX_NUM_OF_Y_AXES) {
90
+ return false ;
91
+ }
92
+
93
+ if (getResourceMinPeriod (slotIndex, subchannelIndex, resourceIndex) > period) {
94
+ return false ;
95
+ }
96
+
97
+ if (period < PERIOD_MIN) {
98
+ if (numDlogItems > 0 && dlogItems[0 ].slotIndex != slotIndex) {
99
+ return false ;
100
+ }
101
+ }
102
+
103
+ return true ;
104
+ }
105
+
106
+ bool Parameters::isDlogItemAvailable (int slotIndex, int subchannelIndex, DlogResourceType resourceType) {
107
+ int numResources = g_slots[slotIndex]->getNumDlogResources (subchannelIndex);
108
+ for (int resourceIndex = 0 ; resourceIndex < numResources; resourceIndex++) {
109
+ if (g_slots[slotIndex]->getDlogResourceType (subchannelIndex, resourceIndex) == resourceType) {
110
+ return isDlogItemAvailable (slotIndex, subchannelIndex, resourceIndex);
111
+ }
112
+ }
113
+ return false ;
114
+ }
115
+
88
116
eez_err_t Parameters::enableDlogItem (int slotIndex, int subchannelIndex, int resourceIndex, bool enable) {
89
117
int dlogItemIndex;
90
118
bool enabled = findDlogItemIndex (slotIndex, subchannelIndex, resourceIndex, dlogItemIndex);
@@ -99,6 +127,10 @@ eez_err_t Parameters::enableDlogItem(int slotIndex, int subchannelIndex, int res
99
127
return SCPI_ERROR_HARDWARE_MISSING;
100
128
}
101
129
130
+ if (!isDlogItemAvailable (slotIndex, subchannelIndex, resourceIndex)) {
131
+ return SCPI_ERROR_HARDWARE_MISSING;
132
+ }
133
+
102
134
if (dlogItemIndex < numDlogItems) {
103
135
for (int i = numDlogItems - 1 ; i >= dlogItemIndex; i--) {
104
136
memcpy (dlogItems + i + 1 , dlogItems + i, sizeof (DlogItem));
@@ -208,6 +240,37 @@ bool Parameters::findDlogItemIndex(int slotIndex, int subchannelIndex, DlogResou
208
240
return false ;
209
241
}
210
242
243
+ float Parameters::getResourceMinPeriod (int slotIndex, int subchannelIndex, int resourceIndex) {
244
+ float minPeriod = g_slots[slotIndex]->getDlogResourceMinPeriod (subchannelIndex, resourceIndex);
245
+ if (isNaN (minPeriod)) {
246
+ return PERIOD_MIN;
247
+ }
248
+ return minPeriod;
249
+ }
250
+
251
+ unsigned Parameters::setPeriod (float value) {
252
+ period = value;
253
+
254
+ int numDisabled = 0 ;
255
+
256
+ for (int slotIndex = 0 ; slotIndex < NUM_SLOTS; slotIndex++) {
257
+ int numSubchannels = g_slots[slotIndex]->getNumSubchannels ();
258
+ for (int subchannelIndex = 0 ; subchannelIndex < numSubchannels; subchannelIndex++) {
259
+ int numResources = g_slots[slotIndex]->getNumDlogResources (subchannelIndex);
260
+ for (int resourceIndex = 0 ; resourceIndex < numResources; resourceIndex++) {
261
+ if (isDlogItemEnabled (slotIndex, subchannelIndex, resourceIndex)) {
262
+ if (!isDlogItemAvailable (slotIndex, subchannelIndex, resourceIndex)) {
263
+ enableDlogItem (slotIndex, subchannelIndex, resourceIndex, false );
264
+ numDisabled++;
265
+ }
266
+ }
267
+ }
268
+ }
269
+ }
270
+
271
+ return numDisabled;
272
+ }
273
+
211
274
// //////////////////////////////////////////////////////////////////////////////
212
275
213
276
State getState () {
@@ -602,7 +665,7 @@ void initDlogValues(Recording &recording) {
602
665
603
666
float div = (rangeMax - rangeMin) / NUM_VERT_DIVISIONS;
604
667
recording.dlogValues [yAxisIndex].div = div ;
605
- recording.dlogValues [yAxisIndex].offset = -div * NUM_VERT_DIVISIONS / 2 ;
668
+ recording.dlogValues [yAxisIndex].offset = -rangeMin - div * NUM_VERT_DIVISIONS / 2 ;
606
669
}
607
670
}
608
671
@@ -620,15 +683,15 @@ void calcColumnIndexes(Recording &recording) {
620
683
for (int yAxisIndex = 0 ; yAxisIndex < recording.parameters .numYAxes ; yAxisIndex++) {
621
684
auto &yAxis = recording.parameters .yAxes [yAxisIndex];
622
685
623
- recording.columnFloatIndexes [yAxisIndex] = columnIndex;
624
-
625
686
if (yAxis.unit == UNIT_BIT) {
626
687
if (bitMask == 0 ) {
627
688
bitMask = 0x4000 ;
628
689
} else {
629
690
bitMask >>= 1 ;
630
691
}
631
692
693
+ recording.columnFloatIndexes [yAxisIndex] = columnIndex;
694
+
632
695
if (bitMask == 1 ) {
633
696
columnIndex++;
634
697
bitMask = 0 ;
@@ -639,6 +702,8 @@ void calcColumnIndexes(Recording &recording) {
639
702
bitMask = 0 ;
640
703
}
641
704
705
+ recording.columnFloatIndexes [yAxisIndex] = columnIndex;
706
+
642
707
columnIndex++;
643
708
}
644
709
}
@@ -733,7 +798,7 @@ void autoScale(Recording &recording) {
733
798
dlogValueParams.offset = dlogValueParams.div * (NUM_VERT_DIVISIONS / 2 - (visibleDlogValueIndex + 1 ) * numDivisions);
734
799
} else {
735
800
dlogValueParams.div = (rangeMax - rangeMin) / numDivisions;
736
- dlogValueParams.offset = dlogValueParams.div * (NUM_VERT_DIVISIONS / 2 - (visibleDlogValueIndex + 1 ) * numDivisions);
801
+ dlogValueParams.offset = -rangeMin + dlogValueParams.div * (NUM_VERT_DIVISIONS / 2 - (visibleDlogValueIndex + 1 ) * numDivisions);
737
802
}
738
803
}
739
804
}
@@ -765,7 +830,7 @@ void scaleToFit(Recording &recording) {
765
830
DlogValueParams &dlogValueParams = recording.dlogValues [dlogValueIndex];
766
831
float numDivisions = 1 .0f * NUM_VERT_DIVISIONS;
767
832
dlogValueParams.div = (totalMax - totalMin) / numDivisions;
768
- dlogValueParams.offset = - dlogValueParams.div * NUM_VERT_DIVISIONS / 2 ;
833
+ dlogValueParams.offset = -totalMin - dlogValueParams.div * NUM_VERT_DIVISIONS / 2 ;
769
834
}
770
835
}
771
836
@@ -1099,33 +1164,12 @@ class DlogParamsPage : public SetPage {
1099
1164
}
1100
1165
1101
1166
static float getResourceMinPeriod (int slotIndex, int subchannelIndex, int resourceIndex) {
1102
- float minPeriod = g_slots[slotIndex]->getDlogResourceMinPeriod (subchannelIndex, resourceIndex);
1103
- if (isNaN (minPeriod)) {
1104
- return PERIOD_MIN;
1105
- }
1106
- return minPeriod;
1167
+ return Parameters::getResourceMinPeriod (slotIndex, subchannelIndex, resourceIndex);
1107
1168
}
1108
1169
1109
1170
static void setPeriod (float value) {
1110
1171
g_parameters.period = value;
1111
-
1112
- int numUnchecked = 0 ;
1113
-
1114
- for (int slotIndex = 0 ; slotIndex < NUM_SLOTS; slotIndex++) {
1115
- int numSubchannels = g_slots[slotIndex]->getNumSubchannels ();
1116
- for (int subchannelIndex = 0 ; subchannelIndex < numSubchannels; subchannelIndex++) {
1117
- int numResources = g_slots[slotIndex]->getNumDlogResources (subchannelIndex);
1118
- for (int resourceIndex = 0 ; resourceIndex < numResources; resourceIndex++) {
1119
- if (g_parameters.isDlogItemEnabled (slotIndex, subchannelIndex, resourceIndex)) {
1120
- if (getResourceMinPeriod (slotIndex, subchannelIndex, resourceIndex) - g_parameters.period >= 1E-6 ) {
1121
- g_parameters.enableDlogItem (slotIndex, subchannelIndex, resourceIndex, false );
1122
- numUnchecked++;
1123
- }
1124
- }
1125
- }
1126
- }
1127
- }
1128
-
1172
+ int numUnchecked = g_parameters.setPeriod (value);
1129
1173
if (numUnchecked > 0 ) {
1130
1174
psu::gui::infoMessage (" Some resources unchecked." );
1131
1175
}
@@ -1293,8 +1337,8 @@ void data_dlog_period_has_predefined_values(DataOperationEnum operation, Cursor
1293
1337
1294
1338
void action_dlog_period_select_predefined_value () {
1295
1339
pushSelectFromEnumPage (g_predefinedDlogPeriodsEnumDefinition, 0 , nullptr , [] (uint16_t value) {
1296
- DlogParamsPage::setPeriod (g_predefinedDlogPeriods[value] );
1297
- popPage ( );
1340
+ popPage ( );
1341
+ DlogParamsPage::setPeriod (g_predefinedDlogPeriods[value] );
1298
1342
}, true , false );
1299
1343
}
1300
1344
@@ -1399,16 +1443,7 @@ void data_dlog_item_is_available(DataOperationEnum operation, Cursor cursor, Val
1399
1443
int subchannelIndex;
1400
1444
int resourceIndex;
1401
1445
if (DlogParamsPage::findResource (cursor, slotIndex, subchannelIndex, resourceIndex)) {
1402
- bool enabled = DlogParamsPage::g_parameters.isDlogItemEnabled (slotIndex, subchannelIndex, resourceIndex);
1403
- if (!enabled && (
1404
- DlogParamsPage::g_parameters.numDlogItems >= dlog_file::MAX_NUM_OF_Y_AXES ||
1405
- DlogParamsPage::getResourceMinPeriod (slotIndex, subchannelIndex, resourceIndex)
1406
- > DlogParamsPage::g_parameters.period
1407
- )) {
1408
- value = 0 ;
1409
- } else {
1410
- value = 1 ;
1411
- }
1446
+ value = DlogParamsPage::g_parameters.isDlogItemAvailable (slotIndex, subchannelIndex, resourceIndex);
1412
1447
} else {
1413
1448
value = 0 ;
1414
1449
}
0 commit comments