First speed reader test #2
This commit is contained in:
parent
3fa0e0f8f6
commit
8cd11992c4
3 changed files with 41 additions and 12 deletions
41
pdm.lock
generated
41
pdm.lock
generated
|
@ -5,7 +5,7 @@
|
||||||
groups = ["default"]
|
groups = ["default"]
|
||||||
strategy = ["inherit_metadata"]
|
strategy = ["inherit_metadata"]
|
||||||
lock_version = "4.5.0"
|
lock_version = "4.5.0"
|
||||||
content_hash = "sha256:2c6777666234648e5ed3ca6ed92de71161a091b6c1d1b5f38f72529dc52e9caf"
|
content_hash = "sha256:b23452099622a07a2d978cf257f8002c508fd6da50f49ef7dbcabd4ec0903596"
|
||||||
|
|
||||||
[[metadata.targets]]
|
[[metadata.targets]]
|
||||||
requires_python = ">=3.12"
|
requires_python = ">=3.12"
|
||||||
|
@ -83,6 +83,19 @@ files = [
|
||||||
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
|
{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]]
|
[[package]]
|
||||||
name = "fastapi"
|
name = "fastapi"
|
||||||
version = "0.115.5"
|
version = "0.115.5"
|
||||||
|
@ -99,6 +112,22 @@ files = [
|
||||||
{file = "fastapi-0.115.5.tar.gz", hash = "sha256:0e7a4d0dc0d01c68df21887cce0945e72d3c48b9f4f79dfe7a7d53aa08fbb289"},
|
{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]]
|
[[package]]
|
||||||
name = "h11"
|
name = "h11"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
|
@ -211,12 +240,14 @@ files = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rpi-gpio"
|
name = "setuptools"
|
||||||
version = "0.7.1"
|
version = "75.8.0"
|
||||||
summary = "A module to control Raspberry Pi GPIO channels"
|
requires_python = ">=3.9"
|
||||||
|
summary = "Easily download, build, install, upgrade, and uninstall Python packages"
|
||||||
groups = ["default"]
|
groups = ["default"]
|
||||||
files = [
|
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]]
|
[[package]]
|
||||||
|
|
|
@ -13,7 +13,7 @@ dependencies = [
|
||||||
"python-dotenv>=1.0.1",
|
"python-dotenv>=1.0.1",
|
||||||
"SMmegaind>=1.0.3",
|
"SMmegaind>=1.0.3",
|
||||||
"apscheduler>=3.11.0",
|
"apscheduler>=3.11.0",
|
||||||
"RPi-GPIO>=0.7.1",
|
"gpiozero>=2.0.1",
|
||||||
]
|
]
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
from src.variables.service import get_variable, set_variable
|
from src.variables.service import get_variable, set_variable
|
||||||
import RPi.GPIO as GPIO
|
from gpiozero import Button
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
pin = 7
|
reader = Button(4)
|
||||||
GPIO.setmode(GPIO.BOARD)
|
|
||||||
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
|
||||||
set_variable("speed_reader_last_impulse_time", datetime.datetime.now(), False)
|
set_variable("speed_reader_last_impulse_time", datetime.datetime.now(), False)
|
||||||
|
|
||||||
|
|
||||||
def event(pin):
|
def event():
|
||||||
actual = datetime.datetime.now()
|
actual = datetime.datetime.now()
|
||||||
last = get_variable("speed_reader_last_impulse_time")
|
last = get_variable("speed_reader_last_impulse_time")
|
||||||
difference = (actual - last).total_seconds()
|
difference = (actual - last).total_seconds()
|
||||||
|
@ -22,4 +20,4 @@ def event(pin):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GPIO.add_event_detect(pin, GPIO.RISING, callback=event)
|
reader.when_pressed = event
|
Loading…
Add table
Reference in a new issue