Spaces:
Build error
Build error
Merge pull request #1 from Portiloop/milo/lead_off
Browse files- portiloop/capture.py +35 -13
portiloop/capture.py
CHANGED
|
@@ -82,6 +82,32 @@ FRONTEND_CONFIG = [
|
|
| 82 |
0x20, # Enable SRB1
|
| 83 |
]
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
EDF_PATH = Path.home() / 'workspace' / 'edf_recording'
|
| 86 |
|
| 87 |
|
|
@@ -116,16 +142,15 @@ def mod_config(config, datarate, channel_modes):
|
|
| 116 |
config[1] = new_cf1
|
| 117 |
|
| 118 |
# bias:
|
| 119 |
-
|
| 120 |
assert len(channel_modes) == 7
|
| 121 |
config[13] = 0x00 # clear BIAS_SENSP
|
| 122 |
config[14] = 0x00 # clear BIAS_SENSN
|
| 123 |
for chan_i, chan_mode in enumerate(channel_modes):
|
| 124 |
-
n =
|
| 125 |
mod = config[n] & 0x78 # clear PDn and MUX[2:0]
|
| 126 |
if chan_mode == 'simple':
|
| 127 |
# If channel is activated, we send the channel's output to the BIAS mechanism
|
| 128 |
-
bit_i = 1 << chan_i
|
| 129 |
config[13] = config[13] | bit_i
|
| 130 |
config[14] = config[14] | bit_i
|
| 131 |
elif chan_mode == 'disabled':
|
|
@@ -1183,7 +1208,11 @@ class Capture:
|
|
| 1183 |
try:
|
| 1184 |
frontend.write_regs(0x00, FRONTEND_CONFIG)
|
| 1185 |
frontend.start()
|
| 1186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1187 |
leadoff_p = new_config[18]
|
| 1188 |
leadoff_n = new_config[19]
|
| 1189 |
|
|
@@ -1347,15 +1376,8 @@ class Capture:
|
|
| 1347 |
point = p_data_i.recv()
|
| 1348 |
else:
|
| 1349 |
continue
|
| 1350 |
-
|
| 1351 |
-
|
| 1352 |
-
avg = 0
|
| 1353 |
-
for idx, p in enumerate(point):
|
| 1354 |
-
if idx > 0 and idx < 5:
|
| 1355 |
-
avg += p
|
| 1356 |
-
new_point[0] = avg // 4
|
| 1357 |
-
new_point[5] = new_point[1] - new_point[0]
|
| 1358 |
-
n_array = np.array([new_point])
|
| 1359 |
n_array = filter_np(n_array)
|
| 1360 |
|
| 1361 |
if filter:
|
|
|
|
| 82 |
0x20, # Enable SRB1
|
| 83 |
]
|
| 84 |
|
| 85 |
+
|
| 86 |
+
LEADOFF_CONFIG = [
|
| 87 |
+
0x3E, # ID (RO)
|
| 88 |
+
0x95, # CONFIG1 [95] [1, DAISY_EN(bar), CLK_EN, 1, 0, DR[2:0]] : Datarate = 500 SPS
|
| 89 |
+
0xC0, # CONFIG2 [C0] [1, 1, 0, INT_CAL, 0, CAL_AMP0, CAL_FREQ[1:0]]
|
| 90 |
+
0xFC, # CONFIG3 [E0] [PD_REFBUF(bar), 1, 1, BIAS_MEAS, BIASREF_INT, PD_BIAS(bar), BIAS_LOFF_SENS, BIAS_STAT] : Power-down reference buffer, no bias
|
| 91 |
+
0x00, # No lead-off
|
| 92 |
+
0x60, # CH1SET [60] [PD1, GAIN1[2:0], SRB2, MUX1[2:0]] set to measure BIAS signal
|
| 93 |
+
0x60, # CH2SET
|
| 94 |
+
0x60, # CH3SET
|
| 95 |
+
0x60, # CH4SET
|
| 96 |
+
0x60, # CH5SET
|
| 97 |
+
0x60, # CH6SET
|
| 98 |
+
0x60, # CH7SET
|
| 99 |
+
0x60, # CH8SET
|
| 100 |
+
0x00, # BIAS_SENSP 00
|
| 101 |
+
0x00, # BIAS_SENSN 00
|
| 102 |
+
0xFF, # LOFF_SENSP Lead-off on all positive pins?
|
| 103 |
+
0xFF, # LOFF_SENSN Lead-off on all negative pins?
|
| 104 |
+
0x00, # Normal lead-off
|
| 105 |
+
0x00, # Lead-off positive status (RO)
|
| 106 |
+
0x00, # Lead-off negative status (RO)
|
| 107 |
+
0x00, # All GPIOs as output ?
|
| 108 |
+
0x20, # Enable SRB1
|
| 109 |
+
]
|
| 110 |
+
|
| 111 |
EDF_PATH = Path.home() / 'workspace' / 'edf_recording'
|
| 112 |
|
| 113 |
|
|
|
|
| 142 |
config[1] = new_cf1
|
| 143 |
|
| 144 |
# bias:
|
|
|
|
| 145 |
assert len(channel_modes) == 7
|
| 146 |
config[13] = 0x00 # clear BIAS_SENSP
|
| 147 |
config[14] = 0x00 # clear BIAS_SENSN
|
| 148 |
for chan_i, chan_mode in enumerate(channel_modes):
|
| 149 |
+
n = 6 + chan_i
|
| 150 |
mod = config[n] & 0x78 # clear PDn and MUX[2:0]
|
| 151 |
if chan_mode == 'simple':
|
| 152 |
# If channel is activated, we send the channel's output to the BIAS mechanism
|
| 153 |
+
bit_i = 1 << chan_i + 1
|
| 154 |
config[13] = config[13] | bit_i
|
| 155 |
config[14] = config[14] | bit_i
|
| 156 |
elif chan_mode == 'disabled':
|
|
|
|
| 1208 |
try:
|
| 1209 |
frontend.write_regs(0x00, FRONTEND_CONFIG)
|
| 1210 |
frontend.start()
|
| 1211 |
+
start_time = time.time()
|
| 1212 |
+
current_time = time.time()
|
| 1213 |
+
while current_time - start_time < 2:
|
| 1214 |
+
current_time = time.time()
|
| 1215 |
+
new_config = frontend.read_regs(0x00, len(LEADOFF_CONFIG))
|
| 1216 |
leadoff_p = new_config[18]
|
| 1217 |
leadoff_n = new_config[19]
|
| 1218 |
|
|
|
|
| 1376 |
point = p_data_i.recv()
|
| 1377 |
else:
|
| 1378 |
continue
|
| 1379 |
+
|
| 1380 |
+
n_array = np.array([point])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1381 |
n_array = filter_np(n_array)
|
| 1382 |
|
| 1383 |
if filter:
|