diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..306f58e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 527df71..8d24eaf 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # Pulses -Pulses is a python module to drive LEDs on RPi using PWM (Pulse Width Modulation) \ No newline at end of file +Pulses is a python module to drive LEDs on RPi using PWM (Pulse Width Modulation) diff --git a/pulses/__init__.py b/pulses/__init__.py index e69de29..6de3088 100644 --- a/pulses/__init__.py +++ b/pulses/__init__.py @@ -0,0 +1,2 @@ +from .pulses import ledPulse +VERSION = "0.90" diff --git a/pulses/cli.py b/pulses/cli.py new file mode 100644 index 0000000..974a580 --- /dev/null +++ b/pulses/cli.py @@ -0,0 +1,74 @@ +""" +Usage: + pulses [--gpio ] [--initial ] [--loop ] + [--final ] [--delay ] + [--min ] [--max ] [--delay-val ] + [--verbose] + +Options: + -g --gpio= GPIO to use [default: 12] + -i --initial= Initial method + -l --loop= Loop method [default: sin] + -f --final= Final method + -d --delay= Delay method [default: constant] + + -m --min= Minimum value [default: 2] + -M --max= Maximum value [default: 50] + -D --delay-val= Base delay value [default: 0.01] + + -V --verbose Verbose mode [default: True] + + -h --help Show help. + -v --version Show version. + +""" # NOQA + +import sys +import time +import logging +import signal +from docopt import docopt +from pulses import VERSION, ledPulse + +logging.basicConfig(format="%(name)s %(msg)s", stream=sys.stdout) + + +def signal_handler(sig, frame): + print('pulse-cli: bailing out...') + sys.exit(0) + + +def main(): + args = docopt(__doc__, version=f'pulses {VERSION}') + signal.signal(signal.SIGINT, signal_handler) + + log = logging.getLogger() + log.setLevel('WARNING') + if args.get('--verbose'): + log.setLevel('DEBUG') + log.info('setting verbose mode') + + params = {} + for method in ['initial', 'loop', 'final', 'delay']: + params[f"{method}Method"] = args.get(f"--{method}") + + params['min'] = int(args.get('--min')) + params['max'] = int(args.get('--max')) + params['delay'] = float(args.get('--delay-val')) + + print("-" * 20) + print("pulses CLI test tool") + print("-" * 20) + print("\n> loop parameters") + for param, value in params.items(): + print(f" {param}: {value}") + led = ledPulse(args.get('--gpio')) + led.set(**params) + print('\nstarting loop, press Ctrl-C to stop...') + led.start() + while True: + time.sleep(4) + + +if __name__ == "__main__": + main() diff --git a/pulses/pulses.py b/pulses/pulses.py index 888e7b2..2901ff1 100644 --- a/pulses/pulses.py +++ b/pulses/pulses.py @@ -6,9 +6,6 @@ import threading from queue import Queue from .methods import * # NOQA -# if sys.platform == "linux": -# import RPi.GPIO as GPIO - class ledPulse(threading.Thread): @@ -92,7 +89,7 @@ class ledPulse(threading.Thread): else: # Platform not supported, set # a dummy setValue function - if self.log.level == logging.DEBUG: + if self.log.root.level == logging.DEBUG: self.setValue = print else: self.setValue = lambda x: x diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e5ed2a0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +docopt diff --git a/setup.cfg b/setup.cfg index 9c66c0e..4bb0890 100644 --- a/setup.cfg +++ b/setup.cfg @@ -13,9 +13,9 @@ license = BSD 3-Clause License packages = pulses python_requires = >=3 include_package_data = True -# install_requires = - # PyYAML +install_requires = + docopt -# [options.package_data] -# * = -# config.yaml.example +[options.entry_points] +console_scripts = + pulses = pulses.cli:main