Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Μ
µtrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Teckids
Projekt Hack-n-Fun
Libs
µtrix
Commits
22229457
Verified
Commit
22229457
authored
4 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Add fallback for unknown messages to LED cheese example
parent
a2c6d90d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/led_cheese.py
+9
-1
9 additions, 1 deletion
examples/led_cheese.py
with
9 additions
and
1 deletion
examples/led_cheese.py
+
9
−
1
View file @
22229457
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
import
re
import
re
import
time
import
time
from
collections
import
OrderedDict
from
machine
import
Pin
,
PWM
from
machine
import
Pin
,
PWM
from
credentials
import
*
from
credentials
import
*
from
wifi
import
Wifi
from
wifi
import
Wifi
...
@@ -79,6 +80,10 @@ def allow_user(matches, event):
...
@@ -79,6 +80,10 @@ def allow_user(matches, event):
f
.
write
(
user
+
"
\n
"
)
f
.
write
(
user
+
"
\n
"
)
matrix
.
send_room_message
(
ROOM_ID
,
"
%s darf mich jetzt leuchten lassen!
"
%
(
user
,))
matrix
.
send_room_message
(
ROOM_ID
,
"
%s darf mich jetzt leuchten lassen!
"
%
(
user
,))
def
fallback
(
matches
,
event
):
"""
Fallback fo unknown messages.
"""
sender
=
event
[
"
sender
"
]
matrix
.
send_room_message
(
ROOM_ID
,
"
Was willst du, %s?
"
%
(
sender
,))
# Define LED colour pins and PWM objects
# Define LED colour pins and PWM objects
pin_red
=
Pin
(
13
,
Pin
.
OUT
)
pin_red
=
Pin
(
13
,
Pin
.
OUT
)
...
@@ -96,7 +101,10 @@ network.connect()
...
@@ -96,7 +101,10 @@ network.connect()
matrix
=
Matrix
(
HOMESERVER
,
MATRIX_ID
,
ACCESS_TOKEN
)
matrix
=
Matrix
(
HOMESERVER
,
MATRIX_ID
,
ACCESS_TOKEN
)
# On which texts to react and which LEDs to turn on
# On which texts to react and which LEDs to turn on
cases
=
{
"
%s, leuchte (.*)
"
%
(
NICK
,):
set_colour
,
"
%s, hoer auf (.*)
"
%
(
NICK
,):
allow_user
}
cases
=
OrderedDict
()
cases
[
"
%s, leuchte (.*)
"
%
(
NICK
,)]
=
set_colour
cases
[
"
%s, hoer auf (.*)
"
%
(
NICK
,)]
=
allow_user
cases
[
"
%s.*
"
%
(
NICK
,)]
=
fallback
if
network
.
is_connected
():
if
network
.
is_connected
():
# Set my nickname
# Set my nickname
...
...
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