Metadata-Version: 2.5
Name: pypulsepal
Version: 1.0.0
Summary: Python API for the PulsePal open-source pulse train generator
Project-URL: Homepage, https://github.com/murineshiftwork/pypulsepal
Project-URL: Documentation, https://murineshiftwork.github.io/pypulsepal/
Project-URL: Issue Tracker, https://github.com/murineshiftwork/pypulsepal/issues
Author-email: "Lars B. Rollik" <lars@rollik.me>
License: BSD 3-Clause License
        
        Copyright (c) 2022-present, Lars B. Rollik
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice,
           this list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its contributors
           may be used to endorse or promote products derived from this software
           without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
        LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        POSSIBILITY OF SUCH DAMAGE.
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: numpy
Requires-Dist: pydantic>=2.0
Requires-Dist: pyserial
Provides-Extra: dev
Requires-Dist: commitizen; extra == 'dev'
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: pytest-cov; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Requires-Dist: types-pyyaml; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=1.0.8; extra == 'docs'
Provides-Extra: yaml
Requires-Dist: pyyaml; extra == 'yaml'
Description-Content-Type: text/markdown

# PyPulsePal

[![PyPI](https://img.shields.io/pypi/v/pypulsepal.svg)](https://pypi.org/project/pypulsepal)

Python API for the PulsePal open-source pulse train generator.

**[→ Full documentation](https://murineshiftwork.github.io/pypulsepal)**

## Example usage

Load and apply a saved config file:

```python
from pypulsepal import PulsePal
from pypulsepal.config_io import load_config

cfg = load_config("my_params.json")   # or .yaml
with PulsePal.from_config(cfg, serial_port="/dev/ttyACM0") as pp:
    pp.trigger_selected_channels(channel_1=True)
```

Standard instantiation:

```python
import time
from pypulsepal import PulsePal

pp = PulsePal(serial_port="/dev/ttyACM0")
pp.channel_configs[0].phase1Voltage = 5.0
pp.channel_configs[0].pulseTrainDuration = 1.0
pp.sync_all_params()
pp.trigger_selected_channels(channel_1=True)
time.sleep(1)
pp.stop_all_outputs()
pp.close()
```

As a context manager (saves settings and closes on exit automatically):

```python
import time
from pypulsepal import PulsePal

with PulsePal(serial_port="/dev/ttyACM0") as pp:
    pp.channel_configs[0].phase1Voltage = 5.0
    pp.channel_configs[0].pulseTrainDuration = 1.0
    pp.sync_all_params()
    pp.trigger_selected_channels(channel_1=True)
    time.sleep(1)
    pp.stop_all_outputs()
```

## Installation

```shell
pip install pypulsepal
```

With YAML config file support:

```shell
pip install "pypulsepal[yaml]"
```

From source:

```shell
git clone https://github.com/murineshiftwork/pypulsepal.git
cd pypulsepal
pip install -e ".[yaml]"
```

## Citation

To cite PyPulsePal, reference the GitHub repository:

> Rollik, Lars B. PyPulsePal: Python API for the PulsePal open-source pulse train generator. https://github.com/murineshiftwork/pypulsepal

Please also cite the original [PulsePal](https://github.com/sanworks/PulsePal) hardware and [PyBpod](https://github.com/pybpod/pybpod) publications that this package builds on.

## License & sources

This software is licensed under the **[BSD 3-Clause License](LICENSE)**.

It implements the PulsePal USB serial protocol as documented on the PulsePal wiki: [USB interface v2.x](https://sites.google.com/site/pulsepalwiki/usb-serial-interface/usb-interface-v2-x), [USB interface v1.x](https://sites.google.com/site/pulsepalwiki/usb-serial-interface/usb-interface-v1-x) and the [parameter guide](https://sites.google.com/site/pulsepalwiki/parameter-guide).

Releases before 0.4.4 were published under the GNU GPL v3.0 and remain under that licence.

`src/pypulsepal/_arcom.py` is vendored from [pybpod-api](https://github.com/pybpod/pybpod-api) 1.8.2 (MIT, Copyright © 2016 Champalimaud Foundation) with minor adaptations.

## Useful references

- [PulsePal USB v2 serial interface](https://sites.google.com/site/pulsepalwiki/usb-serial-interface/usb-interface-v2-x)
- [PulsePal parameter guide](https://sites.google.com/site/pulsepalwiki/parameter-guide)
- [PyBpod ArCOM](https://github.com/pybpod/pybpod-api/blob/master/pybpodapi/com/arcom.py)
