Updated Pipfile, get-gpio

This commit is contained in:
Alexander Werner 2018-11-26 23:14:28 +01:00
parent 6aa304b24e
commit a2a33aedb4
5 changed files with 101 additions and 21 deletions

View File

@ -13,6 +13,7 @@ colorama = "*"
click-log = "*" click-log = "*"
click-didyoumean = "*" click-didyoumean = "*"
voluptuous = "*" voluptuous = "*"
terminaltables = "*"
[dev-packages] [dev-packages]
"flake8" = "*" "flake8" = "*"

45
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "07aac5a19e64863bc015b63d301912dc79586e7be06dd8056b60dd0e6fb26629" "sha256": "471710975bfaa4492e9efc5df510666744e783264972376f1c14860496a536b1"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -40,6 +40,7 @@
}, },
"click-didyoumean": { "click-didyoumean": {
"hashes": [ "hashes": [
"sha256:0b427ca37c9b85d92e75a915db95c1ac0d6efd65e8b89139eed398bbda074bd8",
"sha256:112229485c9704ff51362fe34b2d4f0b12fc71cc20f6d2b3afabed4b8bfa6aeb" "sha256:112229485c9704ff51362fe34b2d4f0b12fc71cc20f6d2b3afabed4b8bfa6aeb"
], ],
"index": "pypi", "index": "pypi",
@ -55,11 +56,11 @@
}, },
"colorama": { "colorama": {
"hashes": [ "hashes": [
"sha256:a3d89af5db9e9806a779a50296b5fdb466e281147c2c235e8225ecc6dbf7bbf3", "sha256:05eed71e2e327246ad6b38c540c4a3117230b19679b875190486ddd2d721422d",
"sha256:c9b54bebe91a6a803e0772c8561d53f2926bfeb17cd141fbabcb08424086595c" "sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48"
], ],
"index": "pypi", "index": "pypi",
"version": "==0.4.0" "version": "==0.4.1"
}, },
"gpiozero": { "gpiozero": {
"hashes": [ "hashes": [
@ -94,12 +95,19 @@
}, },
"rpi.gpio": { "rpi.gpio": {
"hashes": [ "hashes": [
"sha256:3a08d6ddf2fef5f82a8c981fa2e988a296c43e9c6755e8df691a89ad7620115d",
"sha256:a4210ad63bfe844e43995286de0d3950dfacfa0f3799bb9392770ac54a7d2e47" "sha256:a4210ad63bfe844e43995286de0d3950dfacfa0f3799bb9392770ac54a7d2e47"
], ],
"index": "pypi", "index": "pypi",
"version": "==0.6.5" "version": "==0.6.5"
}, },
"terminaltables": {
"hashes": [
"sha256:e24fb83140a5b04fac4f17e1996cc74809188de2896fb3a98eb1b670cc52bbdd",
"sha256:f3eb0eb92e3833972ac36796293ca0906e998dc3be91fbe1f8615b331b853b81"
],
"index": "pypi",
"version": "==3.1.0"
},
"urllib3": { "urllib3": {
"hashes": [ "hashes": [
"sha256:61bf29cada3fc2fbefad4fdf059ea4bd1b4a86d2b6d15e1c7c0b582b9752fe39", "sha256:61bf29cada3fc2fbefad4fdf059ea4bd1b4a86d2b6d15e1c7c0b582b9752fe39",
@ -161,11 +169,11 @@
}, },
"colorama": { "colorama": {
"hashes": [ "hashes": [
"sha256:a3d89af5db9e9806a779a50296b5fdb466e281147c2c235e8225ecc6dbf7bbf3", "sha256:05eed71e2e327246ad6b38c540c4a3117230b19679b875190486ddd2d721422d",
"sha256:c9b54bebe91a6a803e0772c8561d53f2926bfeb17cd141fbabcb08424086595c" "sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48"
], ],
"index": "pypi", "index": "pypi",
"version": "==0.4.0" "version": "==0.4.1"
}, },
"docutils": { "docutils": {
"hashes": [ "hashes": [
@ -227,7 +235,6 @@
}, },
"markupsafe": { "markupsafe": {
"hashes": [ "hashes": [
"sha256:5e0432a10c901c46e4de52574d1d396bdde0bec8715496961546099c4e0ff16d",
"sha256:048ef924c1623740e70204aa7143ec592504045ae4429b59c30054cb31e3c432", "sha256:048ef924c1623740e70204aa7143ec592504045ae4429b59c30054cb31e3c432",
"sha256:130f844e7f5bdd8e9f3f42e7102ef1d49b2e6fdf0d7526df3f87281a532d8c8b", "sha256:130f844e7f5bdd8e9f3f42e7102ef1d49b2e6fdf0d7526df3f87281a532d8c8b",
"sha256:19f637c2ac5ae9da8bfd98cef74d64b7e1bb8a63038a3505cd182c3fac5eb4d9", "sha256:19f637c2ac5ae9da8bfd98cef74d64b7e1bb8a63038a3505cd182c3fac5eb4d9",
@ -314,11 +321,11 @@
}, },
"pipenv": { "pipenv": {
"hashes": [ "hashes": [
"sha256:117b0015837578cef25ee09c9d38094245966cbff92f0984e0f0fbebdbb5bc75", "sha256:56ad5f5cb48f1e58878e14525a6e3129d4306049cb76d2f6a3e95df0d5fc6330",
"sha256:5f760d35de14982353437442d0d2c474bee139ffd69c01148abc11509f6422da", "sha256:7df8e33a2387de6f537836f48ac6fcd94eda6ed9ba3d5e3fd52e35b5bc7ff49e",
"sha256:7e4b827307e6070468284caa332fcba9c60e532afd2a8ff4c0d6df8be6b9fadb" "sha256:a673e606e8452185e9817a987572b55360f4d28b50831ef3b42ac3cab3fee846"
], ],
"version": "==2018.11.14" "version": "==2018.11.26"
}, },
"pluggy": { "pluggy": {
"hashes": [ "hashes": [
@ -350,10 +357,10 @@
}, },
"pygments": { "pygments": {
"hashes": [ "hashes": [
"sha256:78f3f434bcc5d6ee09020f92ba487f95ba50f1e3ef83ae96b9d5ffa1bab25c5d", "sha256:6301ecb0997a52d2d31385e62d0a4a4cf18d2f2da7054a5ddad5c366cd39cee7",
"sha256:dbae1046def0efb574852fab9e90209b23f556367b5a320c0bcb871c77c3e8cc" "sha256:82666aac15622bd7bb685a4ee7f6625dd716da3ef7473620c192c0168aae64fc"
], ],
"version": "==2.2.0" "version": "==2.3.0"
}, },
"pyparsing": { "pyparsing": {
"hashes": [ "hashes": [
@ -364,11 +371,11 @@
}, },
"pytest": { "pytest": {
"hashes": [ "hashes": [
"sha256:488c842647bbeb350029da10325cb40af0a9c7a2fdda45aeb1dda75b60048ffb", "sha256:1d131cc532be0023ef8ae265e2a779938d0619bb6c2510f52987ffcba7fa1ee4",
"sha256:c055690dfefa744992f563e8c3a654089a6aa5b8092dded9b6fafbd70b2e45a7" "sha256:ca4761407f1acc85ffd1609f464ca20bb71a767803505bd4127d0e45c5a50e23"
], ],
"index": "pypi", "index": "pypi",
"version": "==4.0.0" "version": "==4.0.1"
}, },
"pytz": { "pytz": {
"hashes": [ "hashes": [

View File

@ -5,6 +5,10 @@ from click_didyoumean import DYMGroup
import click_log import click_log
import logging import logging
from terminaltables import SingleTable
from carom.table import cleanup
logger = logging.getLogger('carom.cli') # hard coded module name to support directly called module logger = logging.getLogger('carom.cli') # hard coded module name to support directly called module
root_logger = logging.getLogger('') root_logger = logging.getLogger('')
click_log.basic_config(root_logger) click_log.basic_config(root_logger)
@ -21,7 +25,14 @@ def get_gpio():
""" """
Get the current status of all Tables. Get the current status of all Tables.
""" """
pass from carom.table import tables
table_data = [("Table #", "Port", "in use")]
for table in tables:
table_data.append((table.num, table.port, table.in_use))
st = SingleTable(table_data)
st.title = "Tables"
print(st.table)
@cli.command() @cli.command()
@ -55,4 +66,7 @@ def check_config():
if __name__ == "__main__": if __name__ == "__main__":
try:
cli() cli()
finally:
cleanup()

45
carom/table.py Normal file
View File

@ -0,0 +1,45 @@
import logging
from gpiozero import Button
from carom.config import config
from carom.utils import singleton
logger = logging.getLogger(__name__)
@singleton
class Table:
def __init__(self, num, port):
self.num = num
self.port = port
self.button = Button(port, pull_up=False)
def __repr__(self):
return "<Table num={} port={} in_use={}>".format(self.num, self.port, self.in_use)
def __del__(self):
self.close()
@property
def in_use(self):
return self.button.is_active
def close(self):
logger.debug("Closing GPIO {}".format(self.port))
self.button.close()
def cleanup():
for table in tables:
table.close()
def _populate_tables():
for num, port in config['mapping'].items():
yield Table(num, port)
tables = [table for table in _populate_tables()]
__all__ = ('Table', 'tables', 'cleanup')

13
carom/utils.py Normal file
View File

@ -0,0 +1,13 @@
def singleton(the_class):
""" decorator for a class to make a singleton out of it """
class_instances = {}
def get_instance(*args, **kwargs):
""" creating or just return the one and only class instance.
The singleton depends on the parameters used in __init__ """
key = (the_class, args, str(kwargs))
if key not in class_instances:
class_instances[key] = the_class(*args, **kwargs)
return class_instances[key]
return get_instance