You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorials/send_trigger.md
+16-32Lines changed: 16 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,9 @@
1
-
# ⏱ Trigger System for EEG/MEG: `TriggerBank` + `TriggerSender`
1
+
# ⏱ Trigger System for EEG/MEG: Trigger Dictionary + `TriggerSender`
2
2
3
-
This system separates **trigger definition** (`TriggerBank`) from **trigger sending** (`TriggerSender`), allowing you to maintain clean logic, central config, and robust signal dispatch for EEG/MEG experiments.
3
+
Store your event codes in a plain dictionary and let `TriggerSender` handle the dispatch. This keeps your configuration centralized and your send logic simple.
4
4
5
5
### 🧵 Summary of Key Methods
6
6
7
-
#### `TriggerBank`
8
-
9
-
| Purpose | Method |
10
-
|--|--|
11
-
| Add one event-code |`.add(event, code)`|
12
-
| Add from dict |`.add_from_dict(dict)`|
13
-
| Add from YAML file |`.add_from_yaml(path)`|
14
-
| Retrieve code |`.get(event)`|
15
-
16
7
#### `TriggerSender`
17
8
18
9
| Purpose | Method |
@@ -23,40 +14,34 @@ This system separates **trigger definition** (`TriggerBank`) from **trigger send
23
14
| Control post-delay |`post_delay=0.001`|
24
15
25
16
26
-
### 🗂 1. Defining Triggers with `TriggerBank`
17
+
### 🗂 1. Prepare a Trigger Dictionary
27
18
28
-
TriggerBank maps event labels (e.g., "cue_onset", "response") to integer codes.
19
+
Store event labels (e.g., "cue_onset", "response") as keys in a dictionary with integer codes as values.
29
20
30
21
#### A. Define manually
31
22
32
-
from your_package import TriggerBank
33
-
34
-
tb = TriggerBank()
35
-
tb.add("cue_onset", 32)
36
-
tb.add("key_press", 33)
37
-
38
-
#### B. Load from a dictionary
39
-
40
-
tb.add_from_dict({
23
+
triggers = {
41
24
"cue_onset": 32,
42
-
"key_press": [33] # also accepts single-item list (YAML-safe)
43
-
})
25
+
"key_press": 33,
26
+
}
44
27
45
-
#### C. Load from YAML
28
+
#### B. Load from YAML
46
29
47
30
YAML format:
48
31
49
32
triggers:
50
33
cue_onset: 32
51
-
key_press: [33]
34
+
key_press: 33
52
35
53
36
Code:
54
37
55
-
tb.add_from_yaml("trigger_config.yaml")
38
+
import yaml
39
+
with open("trigger_config.yaml") as f:
40
+
triggers = yaml.safe_load(f)["triggers"]
56
41
57
-
#### D. Get a code
42
+
#### C. Get a code
58
43
59
-
code = tb.get("key_press") # returns 33 or None
44
+
code = triggers["key_press"] # returns 33
60
45
61
46
62
47
@@ -77,7 +62,7 @@ TriggerSender handles the dispatch logic. It wraps your actual send function (e.
77
62
78
63
#### C. Sending a trigger
79
64
80
-
sender.send(tb.get("cue_onset"))
65
+
sender.send(triggers["cue_onset"])
81
66
82
67
This prints:
83
68
@@ -104,7 +89,6 @@ Here we used mock mode for testing and a serial port for real device communicati
104
89
trigger_config = {
105
90
**config.get('triggers', {})
106
91
}
107
-
triggerbank = TriggerBank(trigger_config)
108
92
ser = serial.serial_for_url("loop://", baudrate=115200, timeout=1)
Using `TriggerBank` and `TriggerSender`gives you a clean separation of config and logic, making your experiment easier to debug, replicate, and maintain.
101
+
Using a trigger dictionary with `TriggerSender`keeps configuration and logic separated, making your experiment easier to debug, replicate, and maintain.
0 commit comments