Packaging and CLI tool
This commit is contained in:
parent
e9fefee6f0
commit
5d1aed44b9
|
@ -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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,3 +1,3 @@
|
||||||
# Pulses
|
# Pulses
|
||||||
|
|
||||||
Pulses is a python module to drive LEDs on RPi using PWM (Pulse Width Modulation)
|
Pulses is a python module to drive LEDs on RPi using PWM (Pulse Width Modulation)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
from .pulses import ledPulse
|
||||||
|
VERSION = "0.90"
|
|
@ -0,0 +1,74 @@
|
||||||
|
"""
|
||||||
|
Usage:
|
||||||
|
pulses [--gpio <gpio>] [--initial <initialMethod>] [--loop <loopMethod>]
|
||||||
|
[--final <finalMethod>] [--delay <delayMethod>]
|
||||||
|
[--min <min>] [--max <max>] [--delay-val <delay>]
|
||||||
|
[--verbose]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-g --gpio=<gpio> GPIO to use [default: 12]
|
||||||
|
-i --initial=<method> Initial method
|
||||||
|
-l --loop=<method> Loop method [default: sin]
|
||||||
|
-f --final=<method> Final method
|
||||||
|
-d --delay=<method> Delay method [default: constant]
|
||||||
|
|
||||||
|
-m --min=<min> Minimum value [default: 2]
|
||||||
|
-M --max=<max> Maximum value [default: 50]
|
||||||
|
-D --delay-val=<delay> 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()
|
|
@ -6,9 +6,6 @@ import threading
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from .methods import * # NOQA
|
from .methods import * # NOQA
|
||||||
|
|
||||||
# if sys.platform == "linux":
|
|
||||||
# import RPi.GPIO as GPIO
|
|
||||||
|
|
||||||
|
|
||||||
class ledPulse(threading.Thread):
|
class ledPulse(threading.Thread):
|
||||||
|
|
||||||
|
@ -92,7 +89,7 @@ class ledPulse(threading.Thread):
|
||||||
else:
|
else:
|
||||||
# Platform not supported, set
|
# Platform not supported, set
|
||||||
# a dummy setValue function
|
# a dummy setValue function
|
||||||
if self.log.level == logging.DEBUG:
|
if self.log.root.level == logging.DEBUG:
|
||||||
self.setValue = print
|
self.setValue = print
|
||||||
else:
|
else:
|
||||||
self.setValue = lambda x: x
|
self.setValue = lambda x: x
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
docopt
|
10
setup.cfg
10
setup.cfg
|
@ -13,9 +13,9 @@ license = BSD 3-Clause License
|
||||||
packages = pulses
|
packages = pulses
|
||||||
python_requires = >=3
|
python_requires = >=3
|
||||||
include_package_data = True
|
include_package_data = True
|
||||||
# install_requires =
|
install_requires =
|
||||||
# PyYAML
|
docopt
|
||||||
|
|
||||||
# [options.package_data]
|
[options.entry_points]
|
||||||
# * =
|
console_scripts =
|
||||||
# config.yaml.example
|
pulses = pulses.cli:main
|
||||||
|
|
Loading…
Reference in New Issue