pybpodapi
¶
-
class
pybpod_soundcard_module.module.
SoundCommandType
[source]¶ Enumeration for the commands that can be sent through the Sound Card module, when connected through the BPod’s State Machine.
-
PLAY
= 1¶ Plays a specific sound index
-
STOP_SPECIFIC
= 2¶ Stops playing a specific sound index
-
STOP_ALL
= 3¶ Stops all sounds
-
-
class
pybpod_soundcard_module.module.
SoundCard
(connected=False, module_name='', firmware_version=0, events_names=[], n_serial_events=0, serial_port=None)[source]¶ Bases:
pybpodapi.bpod_modules.bpod_module.BpodModule
-
static
get_command
(command_type, sound_index=None)[source]¶ Returns the proper bytes to send as output_actions in the BPod StateMachine’s states. In the case of the Play and StopSpecific command_types, it is required to use the BPod’s load_serial_message method to be able to send to the module more than 1 byte properly.
Note
This might not be required in a future version of BPod’s firmware
Parameters: - command_type – Instruction of type
SoundCommandType
to generate the command - sound_index – The sound index to play or stop
- command_type – Instruction of type
-
static
Usage Example¶
from pybpodapi.protocol import Bpod, StateMachine
from pybpod_soundcard_module.module import SoundCard, SoundCommandType
# sound index to play
sound_index = 2
my_bpod = Bpod(serial_port='/dev/ttyACM0')
# get first SoundBoard module connected to a Bpod serial port
sound_module = [x for x in my_bpod.modules if x.name == 'SoundCard1'][0]
sound_module_play = 1
card = (SoundCard)(sound_module)
# define serial message to be used in the states with the sound_module_play id
my_bpod.load_serial_message(sound_module, sound_module_play,
card.get_command(SoundCommandType.PLAY, sound_index))
sma = StateMachine(my_bpod)
sma.add_state(
state_name='myState',
state_timer=2,
state_change_conditions={Bpod.Events.Tup: 'myState2'},
output_actions=[(Bpod.OutputChannels.Serial1, sound_module_play)])
sma.add_state(
state_name='myState2',
state_timer=3,
state_change_conditions={Bpod.Events.Tup: 'exit'},
output_actions=[(Bpod.OutputChannels.Serial1, card.get_command(SoundCommandType.STOP_ALL))])
my_bpod.send_state_machine(sma)
my_bpod.run_state_machine(sma)
print("Current trial info: {0}".format(my_bpod.session.current_trial))
my_bpod.close()