--- /dev/null
+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.
--- /dev/null
+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()
--- /dev/null
+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",
+ ],
+)