Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r firmware
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
Container 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dos
flow3r firmware
Commits
2359953f
Commit
2359953f
authored
May 24, 2023
by
iggy
Browse files
Options
Downloads
Patches
Plain Diff
singleton event engine and less boilerplate
parent
12183ee6
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
python_payload/event.py
+19
-8
19 additions, 8 deletions
python_payload/event.py
with
19 additions
and
8 deletions
python_payload/event.py
+
19
−
8
View file @
2359953f
...
@@ -16,6 +16,12 @@ class Engine():
...
@@ -16,6 +16,12 @@ class Engine():
self
.
next_timed
=
None
self
.
next_timed
=
None
self
.
last_input_state
=
None
self
.
last_input_state
=
None
def
add
(
self
,
event
):
if
isinstance
(
event
,
EventTimed
):
self
.
add_timed
(
event
)
elif
isinstance
(
event
,
Event
):
self
.
add_input
(
event
)
def
add_timed
(
self
,
event
):
def
add_timed
(
self
,
event
):
self
.
events_timed
.
append
(
event
)
self
.
events_timed
.
append
(
event
)
self
.
events_timed
=
sorted
(
self
.
events_timed
,
key
=
lambda
event
:
event
.
deadline
)
self
.
events_timed
=
sorted
(
self
.
events_timed
,
key
=
lambda
event
:
event
.
deadline
)
...
@@ -96,6 +102,8 @@ class Event():
...
@@ -96,6 +102,8 @@ class Event():
if
not
condition
:
if
not
condition
:
self
.
condition
=
lambda
x
:
True
self
.
condition
=
lambda
x
:
True
the_engine
.
add
(
self
)
#print (data)
#print (data)
def
trigger
(
self
,
triggerdata
=
{}):
def
trigger
(
self
,
triggerdata
=
{}):
...
@@ -109,21 +117,24 @@ class Event():
...
@@ -109,21 +117,24 @@ class Event():
class
EventTimed
(
Event
):
class
EventTimed
(
Event
):
def
__init__
(
self
,
ms
,
name
=
"
timer
"
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
ms
,
name
=
"
timer
"
,
*
args
,
**
kwargs
):
#super().__init__(name,data,action)
#super().__init__(name,data,action)
self
.
deadline
=
time
.
ticks_add
(
time
.
ticks_ms
(),
ms
)
super
().
__init__
(
*
args
,
**
kwargs
)
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
name
=
name
self
.
name
=
name
self
.
deadline
=
time
.
ticks_add
(
time
.
ticks_ms
(),
ms
)
self
.
type
=
EVENTTYPE_TIMED
self
.
type
=
EVENTTYPE_TIMED
def
__repr__
(
self
):
def
__repr__
(
self
):
return
(
"
event on tick {} ({})
"
.
format
(
self
.
deadline
,
self
.
name
))
return
(
"
event on tick {} ({})
"
.
format
(
self
.
deadline
,
self
.
name
))
e
=
Engine
()
global
the_engine
e
.
add_timed
(
EventTimed
(
200
,
name
=
"
bar
"
,
action
=
lambda
data
:
print
(
"
GNANGNAGNA
"
)))
the_engine
=
Engine
()
e
.
add_timed
(
EventTimed
(
100
,
name
=
"
foo
"
))
e
.
add_input
(
Event
(
name
=
"
baz
"
,
EventTimed
(
200
,
name
=
"
bar
"
,
action
=
lambda
data
:
print
(
"
GNANGNAGNA
"
))
EventTimed
(
100
,
name
=
"
foo
"
)
Event
(
name
=
"
baz
"
,
action
=
lambda
data
:
print
(
data
),
action
=
lambda
data
:
print
(
data
),
condition
=
lambda
data
:
data
.
get
(
'
type
'
)
==
"
captouch
"
)
condition
=
lambda
data
:
data
.
get
(
'
type
'
)
==
"
captouch
"
)
)
print
(
e
.
events_timed
)
print
(
the_engin
e
.
events_timed
)
#e.eventloop()
#e.eventloop()
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