@@ -439,6 +439,10 @@ class ScienceLab {
439
439
}
440
440
}
441
441
442
+ DigitalChannel getDigitalChannel (int i) {
443
+ return dChannels[i];
444
+ }
445
+
442
446
int ? calculateDigitalChannel (String name) {
443
447
if (DigitalChannel .digitalChannelNames.contains (name)) {
444
448
return DigitalChannel .digitalChannelNames.indexOf (name);
@@ -507,8 +511,44 @@ class ScienceLab {
507
511
return null ;
508
512
}
509
513
514
+ Future <bool > fetchLAChannel (int channelNumber,
515
+ LinkedHashMap <String , int > initialStates, int channels) async {
516
+ DigitalChannel dChan = dChannels[channelNumber];
517
+
518
+ LinkedHashMap <String , int > tempMap = LinkedHashMap <String , int >();
519
+ tempMap['LA1' ] = initialStates['LA1' ]! ;
520
+ tempMap['LA2' ] = initialStates['LA2' ]! ;
521
+ tempMap['LA3' ] = initialStates['LA3' ]! ;
522
+ tempMap['LA4' ] = initialStates['LA4' ]! ;
523
+ tempMap['RES' ] = initialStates['RES' ]! ;
524
+
525
+ int i = 0 ;
526
+ for (MapEntry <String , int > entry in initialStates.entries) {
527
+ if (dChan.channelNumber == i) {
528
+ i = entry.value;
529
+ break ;
530
+ }
531
+ i++ ;
532
+ }
533
+ List <int >? temp =
534
+ await fetchIntDataFromLA (i, dChan.channelNumber + 1 , channels);
535
+ List <double > data = List .filled (temp! .length - 1 , 0.0 );
536
+ if (temp[0 ] == 1 ) {
537
+ for (int j = 1 ; j < temp.length; j++ ) {
538
+ data[j - 1 ] = temp[j].toDouble ();
539
+ }
540
+ } else {
541
+ logger.e ("Error: Can't load data" );
542
+ return false ;
543
+ }
544
+ dChan.loadData (tempMap, data);
545
+
546
+ dChan.generateAxes ();
547
+ return true ;
548
+ }
549
+
510
550
Future <double > fetchLAChannelFrequency (
511
- int channelNumber, HashMap <String , int > initialStates) async {
551
+ int channelNumber, LinkedHashMap <String , int > initialStates) async {
512
552
double laChannelFrequency = 0 ;
513
553
DigitalChannel dChan = dChannels[channelNumber];
514
554
@@ -538,7 +578,7 @@ class ScienceLab {
538
578
if (count == maxSamples / 2 - 1 ) {
539
579
laChannelFrequency = 0 ;
540
580
} else if (yAxis.isNotEmpty &&
541
- yAxis.length != maxSamples / 2 - 2 &&
581
+ yAxis.length != maxSamples / 2 - 1 &&
542
582
laChannelFrequency != yAxis.length) {
543
583
laChannelFrequency = yAxis.length.toDouble ();
544
584
}
@@ -547,7 +587,7 @@ class ScienceLab {
547
587
548
588
Future <double > getFrequency (String ? channel) async {
549
589
channel ?? = 'LA1' ;
550
- HashMap <String , int >? data;
590
+ LinkedHashMap <String , int >? data;
551
591
try {
552
592
await startOneChannelLA (channel, 1 , channel, 3 );
553
593
await Future .delayed (const Duration (milliseconds: 250 ));
@@ -587,15 +627,111 @@ class ScienceLab {
587
627
dChannels[aqChannel].channelName = channel;
588
628
if (trMode == 3 || trMode == 4 || trMode == 5 ) {
589
629
dChannels[aqChannel].initialStateOverride = 2 ;
590
- } else {
630
+ } else if (trMode == 2 ) {
591
631
dChannels[aqChannel].initialStateOverride = 1 ;
592
632
}
593
633
} catch (e) {
594
634
logger.e ("Error starting logic analyzer: $e " );
595
635
}
596
636
}
597
637
598
- Future <HashMap <String , int >?> getLAInitialStates () async {
638
+ Future <void > startTwoChannelLA (
639
+ List <String >? channels,
640
+ List <int >? modes,
641
+ int ? maximumTime,
642
+ int ? trigger,
643
+ String ? edge,
644
+ String ? triggerChannel) async {
645
+ maximumTime ?? = 67 ;
646
+ trigger ?? = 0 ;
647
+ edge ?? = 'rising' ;
648
+ channels ?? = ['LA1' , 'LA2' ];
649
+ modes ?? = [1 , 1 ];
650
+ List <int > chans = [
651
+ calculateDigitalChannel (channels[0 ])! ,
652
+ calculateDigitalChannel (channels[1 ])!
653
+ ];
654
+ triggerChannel ?? = channels[0 ];
655
+ if (trigger != 0 ) {
656
+ trigger = 1 ;
657
+ if (edge == 'falling' ) {
658
+ trigger | = 2 ;
659
+ }
660
+ trigger | = (calculateDigitalChannel (triggerChannel)! << 4 );
661
+ }
662
+
663
+ try {
664
+ await clearBuffer (0 , maxSamples);
665
+ mPacketHandler.sendByte (mCommandsProto.timing);
666
+ mPacketHandler.sendByte (mCommandsProto.startTwoChanLa);
667
+ mPacketHandler.sendInt ((maxSamples / 4 ).toInt ());
668
+ mPacketHandler.sendByte (trigger);
669
+ mPacketHandler.sendByte (modes[0 ] | (modes[1 ] << 4 ));
670
+ mPacketHandler.sendByte (chans[0 ] | (chans[1 ] << 4 ));
671
+ await mPacketHandler.getAcknowledgement ();
672
+ for (int i = 0 ; i < 2 ; i++ ) {
673
+ DigitalChannel temp = dChannels[chans[i]];
674
+ temp.prescaler = 0 ;
675
+ temp.length = (maxSamples / 4 ).toInt ();
676
+ temp.dataType = "long" ;
677
+ temp.maxTime = (maximumTime * 1e6 ).toInt ();
678
+ temp.mode = modes[i];
679
+ temp.channelNumber = chans[i];
680
+ temp.channelName = channels[i];
681
+ }
682
+ digitalChannelsInBuffer = 2 ;
683
+ } catch (e) {
684
+ logger.e ("Error starting logic analyzer: $e " );
685
+ }
686
+ }
687
+
688
+ Future <void > startFourChannelLA (int ? trigger, double ? maximumTime,
689
+ List <int >? modes, String ? edge, List <bool >? triggerChannel) async {
690
+ trigger ?? = 1 ;
691
+ maximumTime ?? = 0.001 ;
692
+ modes ?? = [1 , 1 , 1 , 1 ];
693
+ edge ?? = '0' ;
694
+ await clearBuffer (0 , maxSamples);
695
+ int prescale = 0 ;
696
+ try {
697
+ mPacketHandler.sendByte (mCommandsProto.timing);
698
+ mPacketHandler.sendByte (mCommandsProto.startFourChanLa);
699
+ mPacketHandler.sendInt ((maxSamples / 4 ).toInt ());
700
+ mPacketHandler.sendInt (
701
+ modes[0 ] | (modes[1 ] << 4 ) | (modes[2 ] << 8 ) | (modes[3 ] << 12 ));
702
+ mPacketHandler.sendByte (prescale);
703
+ int triggerOptions = 0 ;
704
+ for (int i = 0 ; i < 3 ; i++ ) {
705
+ if (triggerChannel! [i]) {
706
+ triggerOptions | = (4 << i);
707
+ }
708
+ }
709
+ if (triggerOptions == 0 ) {
710
+ triggerOptions | = 4 ;
711
+ }
712
+ if (edge == 'rising' ) {
713
+ triggerOptions | = 2 ;
714
+ }
715
+ trigger | = triggerOptions;
716
+ mPacketHandler.sendByte (trigger);
717
+ await mPacketHandler.getAcknowledgement ();
718
+ digitalChannelsInBuffer = 4 ;
719
+ int i = 0 ;
720
+ for (DigitalChannel dChan in dChannels) {
721
+ dChan.prescaler = prescale;
722
+ dChan.dataType = "int" ;
723
+ dChan.length = (maxSamples / 4 ).toInt ();
724
+ dChan.maxTime = (maximumTime * 1e6 ).toInt ();
725
+ dChan.mode = modes[i];
726
+ dChan.channelName = DigitalChannel .digitalChannelNames[i];
727
+ i++ ;
728
+ }
729
+ } catch (e) {
730
+ logger.e ("Error starting logic analyzer: $e " );
731
+ }
732
+ }
733
+
734
+ Future <LinkedHashMap <String , int >?> getLAInitialStates () async {
599
735
try {
600
736
mPacketHandler.sendByte (mCommandsProto.timing);
601
737
mPacketHandler.sendByte (mCommandsProto.getInitialDigitalStates);
@@ -654,7 +790,7 @@ class ScienceLab {
654
790
D = 0 ;
655
791
}
656
792
657
- HashMap <String , int > retData = HashMap <String , int >();
793
+ LinkedHashMap <String , int > retData = LinkedHashMap <String , int >();
658
794
retData['A' ] = A ;
659
795
retData['B' ] = B ;
660
796
retData['C' ] = C ;
0 commit comments