From 8cd11992c47f894b42c9c27643cd684b85c67eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ben=C3=AD=C4=8Dek?= Date: Tue, 14 Jan 2025 19:41:53 +0100 Subject: [PATCH] First speed reader test #2 --- pdm.lock | 41 ++++++++++++++++++++++++++++++++++++----- pyproject.toml | 2 +- scripts/speed_reader.py | 10 ++++------ 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/pdm.lock b/pdm.lock index b1609eb..a422e6c 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:2c6777666234648e5ed3ca6ed92de71161a091b6c1d1b5f38f72529dc52e9caf" +content_hash = "sha256:b23452099622a07a2d978cf257f8002c508fd6da50f49ef7dbcabd4ec0903596" [[metadata.targets]] requires_python = ">=3.12" @@ -83,6 +83,19 @@ files = [ {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] +[[package]] +name = "colorzero" +version = "2.0" +summary = "Yet another Python color library" +groups = ["default"] +dependencies = [ + "setuptools", +] +files = [ + {file = "colorzero-2.0-py2.py3-none-any.whl", hash = "sha256:0e60d743a6b8071498a56465f7719c96a5e92928f858bab1be2a0d606c9aa0f8"}, + {file = "colorzero-2.0.tar.gz", hash = "sha256:e7d5a5c26cd0dc37b164ebefc609f388de24f8593b659191e12d85f8f9d5eb58"}, +] + [[package]] name = "fastapi" version = "0.115.5" @@ -99,6 +112,22 @@ files = [ {file = "fastapi-0.115.5.tar.gz", hash = "sha256:0e7a4d0dc0d01c68df21887cce0945e72d3c48b9f4f79dfe7a7d53aa08fbb289"}, ] +[[package]] +name = "gpiozero" +version = "2.0.1" +requires_python = ">=3.9" +summary = "A simple interface to GPIO devices with Raspberry Pi" +groups = ["default"] +dependencies = [ + "colorzero", + "importlib-metadata~=4.6; python_version < \"3.10\"", + "importlib-resources~=5.0; python_version < \"3.10\"", +] +files = [ + {file = "gpiozero-2.0.1-py3-none-any.whl", hash = "sha256:8f621de357171d574c0b7ea0e358cb66e560818a47b0eeedf41ce1cdbd20c70b"}, + {file = "gpiozero-2.0.1.tar.gz", hash = "sha256:d4ea1952689ec7e331f9d4ebc9adb15f1d01c2c9dcfabb72e752c9869ab7e97e"}, +] + [[package]] name = "h11" version = "0.14.0" @@ -211,12 +240,14 @@ files = [ ] [[package]] -name = "rpi-gpio" -version = "0.7.1" -summary = "A module to control Raspberry Pi GPIO channels" +name = "setuptools" +version = "75.8.0" +requires_python = ">=3.9" +summary = "Easily download, build, install, upgrade, and uninstall Python packages" groups = ["default"] files = [ - {file = "RPi.GPIO-0.7.1.tar.gz", hash = "sha256:cd61c4b03c37b62bba4a5acfea9862749c33c618e0295e7e90aa4713fb373b70"}, + {file = "setuptools-75.8.0-py3-none-any.whl", hash = "sha256:e3982f444617239225d675215d51f6ba05f845d4eec313da4418fdbb56fb27e3"}, + {file = "setuptools-75.8.0.tar.gz", hash = "sha256:c5afc8f407c626b8313a86e10311dd3f661c6cd9c09d4bf8c15c0e11f9f2b0e6"}, ] [[package]] diff --git a/pyproject.toml b/pyproject.toml index 8076e6a..2faa499 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ dependencies = [ "python-dotenv>=1.0.1", "SMmegaind>=1.0.3", "apscheduler>=3.11.0", - "RPi-GPIO>=0.7.1", + "gpiozero>=2.0.1", ] requires-python = ">=3.12" readme = "README.md" diff --git a/scripts/speed_reader.py b/scripts/speed_reader.py index 55d5f64..6c8a26c 100644 --- a/scripts/speed_reader.py +++ b/scripts/speed_reader.py @@ -1,15 +1,13 @@ from src.variables.service import get_variable, set_variable -import RPi.GPIO as GPIO +from gpiozero import Button import datetime -pin = 7 -GPIO.setmode(GPIO.BOARD) -GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) +reader = Button(4) set_variable("speed_reader_last_impulse_time", datetime.datetime.now(), False) -def event(pin): +def event(): actual = datetime.datetime.now() last = get_variable("speed_reader_last_impulse_time") difference = (actual - last).total_seconds() @@ -22,4 +20,4 @@ def event(pin): -GPIO.add_event_detect(pin, GPIO.RISING, callback=event) \ No newline at end of file +reader.when_pressed = event \ No newline at end of file