Skip to content

4 add a jsonyaml config loader to specify port channels and params #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[bumpversion]
current_version = 0.0.2.dev0
commit = True
tag = True
tag_name = {new_version}
sign_tags = False
message = "Upgrade: {current_version} → {new_version}"
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>[a-z]+)(?P<build>\d+))?
serialize =
{major}.{minor}.{patch}.{release}{build}
{major}.{minor}.{patch}

[bumpversion:part:release]
optional_value = rc
first_value = dev
values =
dev
rc

[bumpversion:part:build]

[bumpversion:file:setup.cfg]
search = version = {current_version}
replace = version = {new_version}

[bumpversion:file:README.md]
search = Version: "{current_version}"
replace = Version: "{new_version}"

[bumpversion:file:pypulsepal/__init__.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ repos:
rev: v2.3.0
hooks:
- id: end-of-file-fixer
exclude: 'setup.cfg'
exclude: '.bumpversion.cfg'
- id: trailing-whitespace
exclude: 'setup.cfg'
exclude: '.bumpversion.cfg'
- id: check-case-conflict
- id: check-merge-conflict
- id: check-yaml
Expand Down
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Contributing

Contributions are absolutely encouraged, for bug fixes, new features, etc.

If you are not sure where to start, check out the [issues](https://github.com/larsrollik/pypulsepal/issues).

Please get in touch via [email](mailto:L.B.Rollik@protonmail.com) for other queries.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ the above requirements apply either way.

You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
modify it is void, and will automatically terminate_remote your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).

Expand All @@ -426,7 +426,7 @@ received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.

Termination of your rights under this section does not terminate the
Termination of your rights under this section does not terminate_remote the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
Expand Down
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
[//]: # (links)
[Pulsepal]: https://github.com/sanworks/PulsePal
[PyBpod]: https://github.com/pybpod/pybpod
[PyBpod com ArCOM]: https://github.com/pybpod/pybpod-api/blob/master/pybpodapi/com/arcom.py
[PyBpod com protocol]: https://github.com/pybpod/pybpod-api/blob/master/pybpodapi/bpod/bpod_com_protocol.py
[PyBpod message headers]: https://github.com/pybpod/pybpod-api/blob/master/pybpodapi/com/protocol/send_msg_headers.py
[PulsePal Python 3 API]: https://github.com/sanworks/PulsePal/blob/develop/Python/Python3/PulsePal.py
[PulsePal .ino file]: https://github.com/sanworks/PulsePal/blob/develop/Firmware/PulsePal_2_0_1/PulsePal_2_0_1.ino
[PulsePal param definitions]: https://sites.google.com/site/pulsepalwiki/matlab-gnu-octave/functions/programpulsepalparam
[PulsePal USB v2 opcode list]: https://sites.google.com/site/pulsepalwiki/usb-serial-interface/usb-interface-v2-x

[//]: # (badges)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.6379627.svg)](https://doi.org/10.5281/zenodo.6379627)
[![Website](https://img.shields.io/website?up_message=online&url=https%3A%2F%2Fgithub.com/larsrollik/pypulsepal)](https://github.com/larsrollik/pypulsepal)
[![PyPI](https://img.shields.io/pypi/v/pypulsepal.svg)](https://pypi.org/project/pypulsepal)
[![Wheel](https://img.shields.io/pypi/wheel/pypulsepal.svg)](https://pypi.org/project/pypulsepal)
[![Contributions](https://img.shields.io/badge/Contributions-Welcome-brightgreen.svg)](https://github.com/larsrollik/pypulsepal/blob/main/CONTRIBUTING.md)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)


# PyPulsePal
Python API for the PulsePal open-source pulse train generator
---
This package provides an API to the [PulsePal] hardware.
This API is a re-implementation of the original [PulsePal Python 3 API] that draws from the `pybpod-api` communication protoool.
It is an alternative implementation of the original [PulsePal Python 3 API]
and draws from the [PyBpod com ArCOM] communication classes.

## Example usage

Expand Down Expand Up @@ -143,13 +157,5 @@ For changes from the original implementation, see the git history since [commit
- to make overwrites on channels to get from value-based logic to channel parameter sets
- add write function to save all settings to json for documentation

[//]: # (links)
[Pulsepal]: https://github.com/sanworks/PulsePal
[PyBpod]: https://github.com/pybpod/pybpod
[PyBpod com ArCOM]: https://github.com/pybpod/pybpod-api/blob/master/pybpodapi/com/arcom.py
[PyBpod com protocol]: https://github.com/pybpod/pybpod-api/blob/master/pybpodapi/bpod/bpod_com_protocol.py
[PyBpod message headers]: https://github.com/pybpod/pybpod-api/blob/master/pybpodapi/com/protocol/send_msg_headers.py
[PulsePal Python 3 API]: https://github.com/sanworks/PulsePal/blob/develop/Python/Python3/PulsePal.py
[PulsePal .ino file]: https://github.com/sanworks/PulsePal/blob/develop/Firmware/PulsePal_2_0_1/PulsePal_2_0_1.ino
[PulsePal param definitions]: https://sites.google.com/site/pulsepalwiki/matlab-gnu-octave/functions/programpulsepalparam
[PulsePal USB v2 opcode list]: https://sites.google.com/site/pulsepalwiki/usb-serial-interface/usb-interface-v2-x
---
Version: "0.0.2.dev0"
26 changes: 26 additions & 0 deletions examples/config_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from pathlib import Path

from configobj import ConfigObj
from validate import Validator


def run_example(
config_path="pypulsepal.config.test",
config_spec_path="pypulsepal.config.spec",
):
config = ConfigObj(
infile=str(config_path),
configspec=str(config_spec_path),
unrepr=True,
list_values=True,
)
v = Validator()
validation_success = config.validate(v, copy=True)
print(config.dict(), validation_success)

c2 = ConfigObj(configspec=config_spec_path)
c2.validate(Validator(), copy=True)


if __name__ == "__main__":
run_example()
42 changes: 42 additions & 0 deletions examples/pypulsepal.config.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
serial_port = string(default="")
baudrate = integer(default=115200)
cycle_frequency = integer(default=20000)
nr_output_channels = integer(default=4)
nr_trigger_channels = integer(default=2)
firmware_opcode = integer(default=213)

# https://sites.google.com/site/pulsepalwiki/matlab-gnu-octave/functions/programpulsepalparam

custom_pulse_train_1 = float_list(default=list())
custom_pulse_train_2 = float_list(default=list())

[channels]
[[ __many__]]
# channel ID
channel = integer(default=0, min=0, max=3)

# channel params
isBiphasic = boolean(default=False)
phase1Voltage = float(default=5, min=-10, max=10)
phase2Voltage = float(default=-5, min=-10, max=10)

phase1Duration = float(default=0.001, min=0.001, max=3600)
interPhaseInterval = float(default=0.001)
phase2Duration = float(default=0.001)
interPulseInterval = float(default=0.01)
burstDuration = float(default=0)

interBurstInterval = float(default=0)
pulseTrainDuration = float(default=1)
pulseTrainDelay = float(default=0)

linkTriggerChannel1 = integer(default=1, min=0, max=1)
linkTriggerChannel2 = integer(default=0, min=0, max=1)
customTrainID = integer(default=0, min=0, max=2)
customTrainTarget = integer(default=0, min=0, max=1)
restingVoltage = integer(default=0, min=-10, max=10)


[triggers]
[[__many__]]
triggerMode = integer(default=0, min=0, max=2)
9 changes: 9 additions & 0 deletions examples/pypulsepal.config.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
nr_trigger_channels = 14

[channels]
[[0]]
isBiphasic = True
phase1Voltage = 6

[[1]]
phase1Voltage = 4
17 changes: 17 additions & 0 deletions examples/run_ppp_with_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from pathlib import Path

from pypulsepal import PulsePal


def run_example():
config_path = "pypulsepal.config.test"
serial_port = "/dev/ttyACM0"

p = PulsePal(serial_port=serial_port)
p.load_from_config(config_path=config_path)

print(p)


if __name__ == "__main__":
run_example()
4 changes: 4 additions & 0 deletions .toml → pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ exclude = '''
| dist
)/
'''

[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"
6 changes: 6 additions & 0 deletions pypulsepal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
__version__ = "0.0.2.dev0"

from pypulsepal.pulsepal import PulsePal


def run():
raise NotImplementedError(
"placeholder for commandline interface to program from given config file"
)
Empty file added pypulsepal/config/__init__.py
Empty file.
Loading