Skip to content

Commit

Permalink
Add API to set spike hoops and example call in print_rates.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
cboulay committed Mar 10, 2024
1 parent 5976e1c commit 6bf46a4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pycbsdk/cbhw/device/nsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,29 @@ def _configure_channel_autothreshold(self, chid: int, attr_value: int):
pkt.spkopts |= CBAInpSpk.THRAUTO.value if attr_value else 0
self._send_packet(pkt)

def _configure_channel_hoops(self, chid: int, attr_value: dict):
"""
Args:
chid: 1-based channel index
attr_value: a dictionary of dictionaries of dictionaries.
The outer dictionary keys are the 1-based unit ids.
The middle dictionary keys are the 1-based hoop ids.
The inner dictionary has fields 'time', 'min', and 'max'.
e.g. attr_value = {1: {
1: {'time': 13, 'min': -975, 'max': -646},
2: {'time': 6, 'min': 108, 'max': 342}
}
This will set the first two hoops for unit-1.
"""
pkt = copy.copy(self._config["channel_infos"][chid])
pkt.header.type = CBPacketType.CHANSETSPKHPS
for un_id, hoop_dicts in attr_value.items():
for hp_id, hp in hoop_dicts.items():
pkt.spkhoops[un_id-1][hp_id-1] = CBHoop(
valid=1, time=hp["time"], min=hp["min"], max=hp["max"]
)
self._send_packet(pkt)

def _configure_channel_label(self, chid: int, attr_value: str):
pkt = copy.copy(self._config["channel_infos"][chid])
pkt.header.type = CBPacketType.CHANSETLABEL
Expand Down Expand Up @@ -587,6 +610,8 @@ def configure_channel_spike(self, chid: int, attr_name: str, attr_value):
self._configure_channel_enable_spike(chid, attr_value)
elif attr_name.lower().startswith("autothresh"):
self._configure_channel_autothreshold(chid, attr_value)
elif attr_name.lower().startswith("hoops"):
self._configure_channel_hoops(chid, attr_value)
# self._config_events["chaninfo"].wait(timeout=0.02)

def configure_all_channels_spike(
Expand Down
19 changes: 19 additions & 0 deletions pycbsdk/examples/print_rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def main(
loglevel: str = "debug",
skip_startup: bool = False,
update_interval: float = 1.0,
set_hoops: bool = False
):
"""
Run the application:
Expand All @@ -87,6 +88,7 @@ def main(
:param loglevel: debug, info, or warning
:param skip_startup: Skip the initial handshake as well as the attempt to set the device to RUNNING.
:param update_interval: Interval between updates. This determines how big the queues can grow.
:param set_hoops: set True to enable hoop-based sorting on channel 2.
:return:
"""
# Handle logger arguments
Expand Down Expand Up @@ -152,6 +154,23 @@ def main(
cbsdk.set_all_channels_disable(nsp_obj, ch_type)
cbsdk.set_all_channels_spk_config(nsp_obj, ch_type, "enable", True)

if set_hoops:
spk_hoops = {
1: {
1: {"time": 13, "min": -975, "max": -646},
2: {"time": 6, "min": 108, "max": 342},
},
2: {
1: {"time": 21, "min": 675, "max": 1033},
2: {"time": 31, "min": -538, "max": -185},
},
3: {
1: {"time": 17, "min": 481, "max": 820},
2: {"time": 35, "min": -23, "max": 262},
},
}
cbsdk.set_channel_spk_config(nsp_obj, 2, "hoops", spk_hoops)

# Count the number of FrontEnd | AnalogIn channels.
b_spk = [
_ in [CBChannelType.FrontEnd, CBChannelType.AnalogIn]
Expand Down

0 comments on commit 6bf46a4

Please sign in to comment.