# JSON Schema

<a id="state-machine"></a>

## State Machine

Definition of a Bpod finite-state machine.

|                               | [https://raw.githubusercontent.com/int-brain-lab/bpod-core/main/.schema/statemachine.json](https://raw.githubusercontent.com/int-brain-lab/bpod-core/main/.schema/statemachine.json)   |
|-------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| type                          | *object*                                                                                                                                                                               |
| properties                    |                                                                                                                                                                                        |
| - name                        | *State Machine Name*                                                                                                                                                                   |
| The name of the state machine |                                                                                                                                                                                        |
| type                          | *string*                                                                                                                                                                               |
| minLength                     | 1                                                                                                                                                                                      |
| default                       | State Machine                                                                                                                                                                          |
| - states                      | default                                                                                                                                                                                |
| [States]()                    |                                                                                                                                                                                        |
| - global_timers               | default                                                                                                                                                                                |
| [Global Timers]()             |                                                                                                                                                                                        |
| - global_counters             | default                                                                                                                                                                                |
| [Global Counters]()           |                                                                                                                                                                                        |
| - conditions                  | default                                                                                                                                                                                |
| [Conditions]()                |                                                                                                                                                                                        |
| additionalProperties          | False                                                                                                                                                                                  |

<a id="actions"></a>

### Actions

A collection of actions.

| type                 | *object*                               |
|----------------------|----------------------------------------|
| additionalProperties | The integer value of the output action |
| type                 | *integer*                              |
| maximum              | 255                                    |
| minimum              | 0                                      |

<a id="condition"></a>

### Condition

A condition in the state machine.

| type                                                       | *object*   |
|------------------------------------------------------------|------------|
| properties                                                 |            |
| - **channel**                                              | *Channel*  |
| The channel or global timer attached to the condition      |            |
| type                                                       | *string*   |
| minLength                                                  | 1          |
| - **value**                                                | *Value*    |
| The value of the condition channel if the condition is met |            |
| type                                                       | *boolean*  |
| additionalProperties                                       | False      |

<a id="conditions"></a>

### Conditions

A collection of conditions.

| type                 | *object*      |
|----------------------|---------------|
| patternProperties    |               |
| - ^\\d+$             | [Condition]() |
| additionalProperties | False         |

<a id="global-counter"></a>

### Global Counter

A global counter in the state machine.

| type                                     | *object*    |
|------------------------------------------|-------------|
| properties                               |             |
| - **event**                              | *Event*     |
| A state machine event                    |             |
| type                                     | *string*    |
| minLength                                | 1           |
| - **threshold**                          | *Threshold* |
| The count threshold to generate an event |             |
| type                                     | *integer*   |
| maximum                                  | 4294967295  |
| minimum                                  | 0           |
| additionalProperties                     | False       |

<a id="global-counters"></a>

### Global Counters

A collection of global counters.

| type                 | *object*           |
|----------------------|--------------------|
| patternProperties    |                    |
| - ^\\d+$             | [Global Counter]() |
| additionalProperties | False              |

<a id="global-timer"></a>

### Global Timer

A global timer in the state machine.

| type                                                                                     | *object*                |
|------------------------------------------------------------------------------------------|-------------------------|
| properties                                                                               |                         |
| - **duration**                                                                           | *Global Timer Duration* |
| The duration of the global timer in seconds                                              |                         |
| type                                                                                     | *number*                |
| minimum                                                                                  | 0.0                     |
| - onset_delay                                                                            | *Onset Delay*           |
| The onset delay of the global timer in seconds                                           |                         |
| type                                                                                     | *number*                |
| minimum                                                                                  | 0.0                     |
| default                                                                                  | 0.0                     |
| - channel                                                                                | *Channel*               |
| default                                                                                  | null                    |
| anyOf                                                                                    | *Channel*               |
| The channel affected by the global timer                                                 |                         |
| type                                                                                     | *string*                |
| minLength                                                                                | 1                       |
| type                                                                                     | *null*                  |
| - value_on                                                                               | *Channel Value*         |
| The value a channel is set to                                                            |                         |
| type                                                                                     | *integer*               |
| maximum                                                                                  | 255                     |
| minimum                                                                                  | 0                       |
| default                                                                                  | 0                       |
| - value_off                                                                              | *Channel Value*         |
| The value a channel is set to                                                            |                         |
| type                                                                                     | *integer*               |
| maximum                                                                                  | 255                     |
| minimum                                                                                  | 0                       |
| default                                                                                  | 0                       |
| - send_events                                                                            | *Send Events*           |
| Whether the global timer is sending events                                               |                         |
| type                                                                                     | *boolean*               |
| default                                                                                  | True                    |
| - loop                                                                                   | *Loop Mode*             |
| 0 = off, 1 = loop until canceled or trial end, >1 = fixed number of iterations (max 255) |                         |
| type                                                                                     | *integer*               |
| maximum                                                                                  | 255                     |
| minimum                                                                                  | 0                       |
| default                                                                                  | 0                       |
| - loop_interval                                                                          | *Loop Interval*         |
| Delay in seconds between the end of a loop iteration and the start of the next           |                         |
| type                                                                                     | *number*                |
| minimum                                                                                  | 0.0                     |
| default                                                                                  | 0.0                     |
| - onset_trigger                                                                          | *Onset Trigger*         |
| An integer whose bits indicate other global timers to trigger                            |                         |
| type                                                                                     | *integer*               |
| minimum                                                                                  | 0                       |
| default                                                                                  | 0                       |
| additionalProperties                                                                     | False                   |

<a id="global-timers"></a>

### Global Timers

A collection of global timers.

| type                 | *object*         |
|----------------------|------------------|
| patternProperties    |                  |
| - ^\\d+$             | [Global Timer]() |
| additionalProperties | False            |

<a id="state"></a>

### State

A state in the state machine.

| type                            | *object*      |
|---------------------------------|---------------|
| properties                      |               |
| - timer                         | *State Timer* |
| The state's timer in seconds    |               |
| type                            | *number*      |
| minimum                         | 0.0           |
| default                         | 0.0           |
| - transitions                   | default       |
| [State Transitions]()           |               |
| - actions                       | default       |
| [Actions]()                     |               |
| - comment                       | *Comment*     |
| default                         | null          |
| anyOf                           | *Comment*     |
| A comment describing the state. |               |
| type                            | *string*      |
| type                            | *null*        |
| additionalProperties            | False         |

<a id="states"></a>

### States

A collection of states.

| type                          | *object*   |
|-------------------------------|------------|
| patternProperties             |            |
| - ^(?!>)(?!exit$)(?!back$).+$ | [State]()  |
| additionalProperties          | False      |

<a id="state-transitions"></a>

### State Transitions

A collection of state transitions.

|                          | type                        | *object*     |
|--------------------------|-----------------------------|--------------|
| additionalProperties     | anyOf                       | *State Name* |
| The name of the state    |                             |              |
| type                     | *string*                    |              |
| minLength                | 1                           |              |
| pattern                  | ^(?!>)(?!exit$)(?!back$).+$ |              |
| *State Machine Operator* |                             |              |
| A state machine operator |                             |              |
| type                     | *string*                    |              |
| examples                 | >exit                       |              |
| >back                    |                             |              |
| minLength                | 2                           |              |
| pattern                  | ^>.+$                       |              |
