From 8428bb7906904020062967482553622b3c9d84d9 Mon Sep 17 00:00:00 2001 From: Benjamin Braatz Date: Wed, 11 Nov 2020 14:27:56 +0100 Subject: [PATCH] Initial commit of version 0.1.0 --- .gitignore | 2 + LICENSE | 19 ++++++++++ README.md | 7 ++++ doc/index.md | 15 ++++++++ iocardtest.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++ iocardtest.service | 12 ++++++ setup.py | 32 ++++++++++++++++ 7 files changed, 178 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 doc/index.md create mode 100644 iocardtest.py create mode 100644 iocardtest.service create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92afa22 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +venv/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..86da0a6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2020 Graph-IT GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..178c62a --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Raspberry Pi PCF8574 I/O Card Test + +This package contains a script to test I/O cards with a PCF8574(A) chip on +a raspberry pi. + +A more detailed documentation can be found in [doc/index.md](doc/index.md), +which can also be found at [http://docs.graph-it.com/graphit/pin-py](http://docs.graph-it.com/graphit/pin-py). diff --git a/doc/index.md b/doc/index.md new file mode 100644 index 0000000..f697925 --- /dev/null +++ b/doc/index.md @@ -0,0 +1,15 @@ +# Raspberry Pi PCF8574 I/O Card Test + +This package contains a script to test I/O cards with a PCF8574(A) chip on +a raspberry pi. + +## Installation + +The package can be installed with `pip` directly from our git repository: +```sh +$ pip install git+git://git.graph-it.com/graphit/iocardtest-py.git +``` + +## Usage + +TODO diff --git a/iocardtest.py b/iocardtest.py new file mode 100644 index 0000000..8743f5d --- /dev/null +++ b/iocardtest.py @@ -0,0 +1,91 @@ +import pigpio +import asyncio +import signal +from graphit.pin.gpio import GPIOInputPin +from graphit.pin.pcf8574 import PCF8574Input, PCF8574Output + +delay = 0.1 + + +async def board_test(loop: asyncio.events.AbstractEventLoop, pi: pigpio.pi, + direction: str, output_address: int, + input_address: int, input_pin: int): + success = True + try: + output_board = PCF8574Output(pi, output_address) + except pigpio.error as err: + print(f"{direction} board test: output board not found ({err})") + return + try: + input_board = PCF8574Input(pi, input_address, + GPIOInputPin(loop, pi, input_pin, up=True)) + except pigpio.error as err: + print(f"{direction} board test: input board not found ({err})") + output_board.close() + return + output_board.setValues(0) + for pin in range(8): + output_board.setValue(pin, True) + await asyncio.sleep(delay) + if not input_board.getValue(pin): + input_board._fetchValues() + output_values = output_board.getValues() + input_values = input_board.getValues() + if not input_board.getValue(pin): + print(f"{direction} pin {pin} on failed " + f"(out: {output_values}, in: {input_values})") + else: + print(f"{direction} pin {pin} on did not send interrupt " + f"(out: {output_values}, in: {input_values})") + success = False + output_board.setValues(255) + for pin in range(8): + output_board.setValue(pin, False) + await asyncio.sleep(delay) + if input_board.getValue(pin): + input_board._fetchValues() + output_values = output_board.getValues() + input_values = input_board.getValues() + if input_board.getValue(pin): + print(f"{direction} pin {pin} off failed " + f"(out: {output_values}, in: {input_values})") + else: + print(f"{direction} pin {pin} off did not send interrupt " + f"(out: {output_values}, in: {input_values})") + success = False + if success: + print(f"{direction} board test succeeded") + output_board.setValues(255) + else: + print(f"{direction} board test failed") + output_board.setValues(0) + await asyncio.sleep(delay) + output_board.close() + input_board.close() + + +async def setup(loop: asyncio.events.AbstractEventLoop, pi: pigpio.pi): + loop.add_signal_handler(signal.SIGTERM, lambda: loop.stop()) + + def _green(value): + if value: + loop.create_task(board_test(loop, pi, "Input", 57, 32, 17)) + GPIOInputPin(loop, pi, 27).on('change', _green) + + def _red(value): + if value: + loop.create_task(board_test(loop, pi, "Output", 56, 33, 4)) + GPIOInputPin(loop, pi, 22).on('change', _red) + + +if __name__ == '__main__': + pi = pigpio.pi() + loop = asyncio.get_event_loop() + loop.create_task(setup(loop, pi)) + try: + loop.run_forever() + except KeyboardInterrupt: + pass + finally: + print("Exiting") + loop.close() diff --git a/iocardtest.service b/iocardtest.service new file mode 100644 index 0000000..a4e8264 --- /dev/null +++ b/iocardtest.service @@ -0,0 +1,12 @@ +[Unit] +Description=I/O card testing +Requires=pigpiod.service +After=pigpiod.service + +[Service] +User=pi +Environment=PYTHONUNBUFFERED=1 +ExecStart=/home/pi/iocardtest/bin/python3 /home/pi/iocardtest/bin/iocardtest.py + +[Install] +WantedBy=multi-user.target diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..4c69eb2 --- /dev/null +++ b/setup.py @@ -0,0 +1,32 @@ +import setuptools + +with open("README.md", "r") as readme_file: + long_description = readme_file.read() + +setuptools.setup( + name="graphit-pin", + version="0.1.0", + author="Graph-IT GmbH", + author_email="info@graph-it.com", + description="Raspberry Pi PCF8574 I/O Card Test", + long_description=long_description, + long_description_content_type="text/markdown", + url="http://docs.graph-it.com/graphit/iocardtest-py", + packages=setuptools.find_packages(), + scripts=[ + "iocardtest.py", + "iocardtest.service", + ], + setup_requires=[ + "wheel", + ], + install_requires=[ + "pigpio", + "graphit-pin @ git+git://git.graph-it.com/graphit/pin-py.git", + ], + classifiers=[ + "Programming Language :: Python", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], +) -- 2.34.1