Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
python-mqtt-gpio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Alexander Wellbrock
python-mqtt-gpio
Commits
0d077058
Verified
Commit
0d077058
authored
4 years ago
by
Alexander Wellbrock
Browse files
Options
Downloads
Patches
Plain Diff
Revert "Remove interrupt functionality"
This reverts commit
6300cc54
.
parent
6300cc54
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pi_mqtt_gpio/modules/gpiod.py
+57
-0
57 additions, 0 deletions
pi_mqtt_gpio/modules/gpiod.py
with
57 additions
and
0 deletions
pi_mqtt_gpio/modules/gpiod.py
+
57
−
0
View file @
0d077058
...
@@ -66,6 +66,28 @@ class GPIO(GenericGPIO):
...
@@ -66,6 +66,28 @@ class GPIO(GenericGPIO):
pin
.
request
(
config
)
pin
.
request
(
config
)
self
.
pins
[
offset
]
=
pin
self
.
pins
[
offset
]
=
pin
def
setup_interrupt
(
self
,
handle
,
pin
,
edge
,
callback
,
bouncetime
=
100
):
"""
install interrupt callback function
handle: is returned in the callback function as identification
pin: gpio to watch for interrupts
edge: triggering edge: RISING, FALLING or BOTH
callback: the callback function to be called, when interrupt occurs
bouncetime: minimum time between two interrupts
"""
config
=
self
.
io
.
line_request
()
config
.
consumer
=
'
pi-mqtt-gpio
'
config
.
request_type
=
INTERRUPT
[
edge
]
t
=
GpioThread
(
chip
=
self
.
chip
,
offset
=
pin
,
config
=
config
,
callback
=
callback
,
bouncetime
=
bouncetime
)
t
.
start
()
self
.
watchers
[
offset
]
=
t
self
.
GPIO_INTERRUPT_CALLBACK_LOOKUP
[
offset
]
=
{
"
handle
"
:
t
.
handle
,
"
callback
"
:
callback
}
def
set_pin
(
self
,
pin
,
value
):
def
set_pin
(
self
,
pin
,
value
):
offset
=
pin
offset
=
pin
self
.
pins
[
offset
].
set_value
(
value
)
self
.
pins
[
offset
].
set_value
(
value
)
...
@@ -76,3 +98,38 @@ class GPIO(GenericGPIO):
...
@@ -76,3 +98,38 @@ class GPIO(GenericGPIO):
def
cleanup
(
self
):
def
cleanup
(
self
):
pass
pass
class
GpioThread
(
threading
.
Thread
):
def
__init__
(
self
,
chip
,
offset
,
config
,
callback
,
bouncetime
):
super
().
__init__
()
self
.
daemon
=
True
self
.
_queue
=
queue
.
Queue
()
self
.
pin
=
chip
.
get_line
(
offset
)
self
.
pin
.
request
(
config
)
self
.
callback
=
callback
self
.
bouncetime
=
timedelta
(
microseconds
=
bouncetime
)
def
run
(
self
):
previous_event_time
=
datetime
.
now
()
while
True
:
if
self
.
pin
.
event_wait
():
event
=
self
.
pin
.
event_read
()
if
event
.
timestamp
-
previous_event_time
>
self
.
bouncetime
:
previous_event_time
=
event
.
timestamp
ret
=
self
.
callback
()
self
.
_queue
.
put
(
{
"
type
"
:
event
.
event_type
,
"
time
"
:
event
.
timestamp
,
"
result
"
:
ret
,
}
)
@property
def
handle
(
self
):
if
self
.
_queue
.
empty
():
return
None
return
self
.
_queue
.
get
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment