Yann Bouteiller commited on
Commit
11677c4
·
1 Parent(s): 20a3666

Added ability to pause stimulation and changed default duration

Browse files
Files changed (2) hide show
  1. portiloop/capture.py +36 -3
  2. portiloop/stimulation.py +1 -2
portiloop/capture.py CHANGED
@@ -436,7 +436,7 @@ class Capture:
436
  self._p_capture = None
437
  self.__capture_on = False
438
  self.frequency = 250
439
- self.duration = 10
440
  self.power_line = 60
441
  self.polyak_mean = 0.1
442
  self.polyak_std = 0.001
@@ -472,6 +472,9 @@ class Capture:
472
  self._test_stimulus_lock = Lock()
473
  self._test_stimulus = False
474
 
 
 
 
475
  try:
476
  mixers = alsaaudio.mixers()
477
  if len(mixers) <= 0:
@@ -582,6 +585,14 @@ class Capture:
582
  tooltips=['Stop capture', 'Start capture'],
583
  )
584
 
 
 
 
 
 
 
 
 
585
  self.b_clock = widgets.ToggleButtons(
586
  options=['Coral', 'ADS'],
587
  description='Clock:',
@@ -783,6 +794,7 @@ class Capture:
783
  self.b_radio_ch5.observe(self.on_b_radio_ch5, 'value')
784
  self.b_radio_ch6.observe(self.on_b_radio_ch6, 'value')
785
  self.b_radio_ch7.observe(self.on_b_radio_ch7, 'value')
 
786
  self.b_channel_detect.observe(self.on_b_channel_detect, 'value')
787
  self.b_power_line.observe(self.on_b_power_line, 'value')
788
  self.b_custom_fir.observe(self.on_b_custom_fir, 'value')
@@ -793,6 +805,7 @@ class Capture:
793
  self.b_epsilon.observe(self.on_b_epsilon, 'value')
794
  self.b_volume.observe(self.on_b_volume, 'value')
795
  self.b_test_stimulus.on_click(self.on_b_test_stimulus)
 
796
 
797
  self.display_buttons()
798
 
@@ -811,7 +824,8 @@ class Capture:
811
  widgets.HBox([self.b_threshold, self.b_test_stimulus]),
812
  self.b_volume,
813
  self.b_accordion_filter,
814
- self.b_capture]))
 
815
 
816
  def enable_buttons(self):
817
  self.b_frequency.disabled = False
@@ -829,6 +843,7 @@ class Capture:
829
  self.b_radio_ch5.disabled = False
830
  self.b_radio_ch6.disabled = False
831
  self.b_radio_ch7.disabled = False
 
832
  self.b_power_line.disabled = False
833
  self.b_channel_detect.disabled = False
834
  self.b_polyak_mean.disabled = False
@@ -842,6 +857,7 @@ class Capture:
842
  self.b_custom_fir_cutoff.disabled = not self.custom_fir
843
  self.b_stimulate.disabled = not self.detect
844
  self.b_threshold.disabled = not self.detect
 
845
  self.b_test_stimulus.disabled = True # only enabled when running
846
 
847
  def disable_buttons(self):
@@ -862,6 +878,7 @@ class Capture:
862
  self.b_radio_ch5.disabled = True
863
  self.b_radio_ch6.disabled = True
864
  self.b_radio_ch7.disabled = True
 
865
  self.b_channel_detect.disabled = True
866
  self.b_power_line.disabled = True
867
  self.b_polyak_mean.disabled = True
@@ -893,6 +910,9 @@ class Capture:
893
 
894
  def on_b_radio_ch7(self, value):
895
  self.channel_states[6] = value['new']
 
 
 
896
 
897
  def on_b_channel_detect(self, value):
898
  self.channel_detection = value['new']
@@ -934,6 +954,8 @@ class Capture:
934
  self._t_capture.join()
935
  self._t_capture = None
936
  self.enable_buttons()
 
 
937
 
938
  def on_b_custom_fir(self, value):
939
  val = value['new']
@@ -1068,6 +1090,15 @@ class Capture:
1068
  with self._test_stimulus_lock:
1069
  self._test_stimulus = True
1070
 
 
 
 
 
 
 
 
 
 
1071
  def open_recording_file(self):
1072
  nb_signals = self.nb_signals
1073
  samples_per_datarecord_array = self.samples_per_datarecord_array
@@ -1197,7 +1228,9 @@ class Capture:
1197
 
1198
  filtered_point = n_array.tolist()
1199
 
1200
- if detector is not None:
 
 
1201
  detection_signal = detector.detect(filtered_point)
1202
  if stimulator is not None:
1203
  stimulator.stimulate(detection_signal)
 
436
  self._p_capture = None
437
  self.__capture_on = False
438
  self.frequency = 250
439
+ self.duration = 28800
440
  self.power_line = 60
441
  self.polyak_mean = 0.1
442
  self.polyak_std = 0.001
 
472
  self._test_stimulus_lock = Lock()
473
  self._test_stimulus = False
474
 
475
+ self._pause_detect_lock = Lock()
476
+ self._pause_detect = True
477
+
478
  try:
479
  mixers = alsaaudio.mixers()
480
  if len(mixers) <= 0:
 
585
  tooltips=['Stop capture', 'Start capture'],
586
  )
587
 
588
+ self.b_pause = widgets.ToggleButtons(
589
+ options=['Paused', 'Active'],
590
+ description='Detection',
591
+ disabled=True,
592
+ button_style='', # 'success', 'info', 'warning', 'danger' or ''
593
+ tooltips=['Detector and stimulator active', 'Detector and stimulator paused'],
594
+ )
595
+
596
  self.b_clock = widgets.ToggleButtons(
597
  options=['Coral', 'ADS'],
598
  description='Clock:',
 
794
  self.b_radio_ch5.observe(self.on_b_radio_ch5, 'value')
795
  self.b_radio_ch6.observe(self.on_b_radio_ch6, 'value')
796
  self.b_radio_ch7.observe(self.on_b_radio_ch7, 'value')
797
+ self.b_radio_ch8.observe(self.on_b_radio_ch8, 'value')
798
  self.b_channel_detect.observe(self.on_b_channel_detect, 'value')
799
  self.b_power_line.observe(self.on_b_power_line, 'value')
800
  self.b_custom_fir.observe(self.on_b_custom_fir, 'value')
 
805
  self.b_epsilon.observe(self.on_b_epsilon, 'value')
806
  self.b_volume.observe(self.on_b_volume, 'value')
807
  self.b_test_stimulus.on_click(self.on_b_test_stimulus)
808
+ self.b_pause.observe(self.on_b_pause, 'value')
809
 
810
  self.display_buttons()
811
 
 
824
  widgets.HBox([self.b_threshold, self.b_test_stimulus]),
825
  self.b_volume,
826
  self.b_accordion_filter,
827
+ self.b_capture,
828
+ self.b_pause]))
829
 
830
  def enable_buttons(self):
831
  self.b_frequency.disabled = False
 
843
  self.b_radio_ch5.disabled = False
844
  self.b_radio_ch6.disabled = False
845
  self.b_radio_ch7.disabled = False
846
+ self.b_radio_ch8.disabled = False
847
  self.b_power_line.disabled = False
848
  self.b_channel_detect.disabled = False
849
  self.b_polyak_mean.disabled = False
 
857
  self.b_custom_fir_cutoff.disabled = not self.custom_fir
858
  self.b_stimulate.disabled = not self.detect
859
  self.b_threshold.disabled = not self.detect
860
+ self.b_pause.disabled = not self.detect
861
  self.b_test_stimulus.disabled = True # only enabled when running
862
 
863
  def disable_buttons(self):
 
878
  self.b_radio_ch5.disabled = True
879
  self.b_radio_ch6.disabled = True
880
  self.b_radio_ch7.disabled = True
881
+ self.b_radio_ch8.disabled = True
882
  self.b_channel_detect.disabled = True
883
  self.b_power_line.disabled = True
884
  self.b_polyak_mean.disabled = True
 
910
 
911
  def on_b_radio_ch7(self, value):
912
  self.channel_states[6] = value['new']
913
+
914
+ def on_b_radio_ch8(self, value):
915
+ self.channel_states[7] = value['new']
916
 
917
  def on_b_channel_detect(self, value):
918
  self.channel_detection = value['new']
 
954
  self._t_capture.join()
955
  self._t_capture = None
956
  self.enable_buttons()
957
+
958
+
959
 
960
  def on_b_custom_fir(self, value):
961
  val = value['new']
 
1090
  with self._test_stimulus_lock:
1091
  self._test_stimulus = True
1092
 
1093
+ def on_b_pause(self, value):
1094
+ val = value['new']
1095
+ if val == 'Active':
1096
+ with self._pause_detect_lock:
1097
+ self._pause_detect = False
1098
+ elif val == 'Paused':
1099
+ with self._pause_detect_lock:
1100
+ self._pause_detect = True
1101
+
1102
  def open_recording_file(self):
1103
  nb_signals = self.nb_signals
1104
  samples_per_datarecord_array = self.samples_per_datarecord_array
 
1228
 
1229
  filtered_point = n_array.tolist()
1230
 
1231
+ with self._pause_detect_lock:
1232
+ pause = self._pause_detect
1233
+ if detector is not None and not pause:
1234
  detection_signal = detector.detect(filtered_point)
1235
  if stimulator is not None:
1236
  stimulator.stimulate(detection_signal)
portiloop/stimulation.py CHANGED
@@ -75,8 +75,7 @@ class SleepSpindleRealTimeStimulator(Stimulator):
75
  self.wav_list = [data]
76
  while data:
77
  self.wav_list.append(data)
78
- data = f.readframes(self.periodsize)
79
-
80
 
81
  def play_sound(self):
82
  '''
 
75
  self.wav_list = [data]
76
  while data:
77
  self.wav_list.append(data)
78
+ data = f.readframes(self.periodsize)
 
79
 
80
  def play_sound(self):
81
  '''