-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpinbutton.py
40 lines (38 loc) · 1.52 KB
/
pinbutton.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#--------------------------------------------------------------------
#author : N.Pronk
#date : jan 2023
#licence: published under MIT licence
#
#Description
#--------------------------------------------------------------------
#Wrapper for pin
#--------------------------------------------------------------------
from machine import Pin
from debugableitem import DebugableItem
class PinButton(DebugableItem):
onclicked=None
ondoubleclicked=None
ondoubleclickcountdown=None
countdownperiodms:int = 500
dblclickcountdownfrom: int = 1
startdelay: int=200
repeatdelay:int =100
countdownvalue: int = 0
pin: Pin=None
def __init__(self, pin: Pin, onclicked, ondoubleclicked, ondoubleclickcountdown, countdownperiodms: int, dblclickcountdownfrom: int):
"""
@pin: Pin instance - irq based
#onclicked: function that has to be executed as a single click
@ondoubleclicked: function that has to be executed on double click
@ondoubleclickcountdown: function that has to be executed on countdown
@countdownperiodms: period in milliseconds between two counts
@dblclickcountdownfrom: countdown to start from
"""
self.pin=pin
self.onclicked=onclicked
self.ondoubleclicked=ondoubleclicked
self.ondoubleclickcountdown=ondoubleclickcountdown
if (countdownperiodms > 0):
self.countdownperiodms = countdownperiodms
if (dblclickcountdownfrom > 0):
self.dblclickcountdownfrom = dblclickcountdownfrom