Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
hauptbahnhof
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
stustanet
hauptbahnhof
Commits
aa1e5255
Commit
aa1e5255
authored
6 years ago
by
Johannes Walcher
Browse files
Options
Downloads
Patches
Plain Diff
Optimized party mode
parent
6c3b093e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
babel/babel.py
+12
-8
12 additions, 8 deletions
babel/babel.py
hackerman/hackerman.py
+127
-2
127 additions, 2 deletions
hackerman/hackerman.py
with
139 additions
and
10 deletions
babel/babel.py
+
12
−
8
View file @
aa1e5255
...
...
@@ -18,14 +18,13 @@ class Babel:
self
.
ledstrip_states
=
[[
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
]]
self
.
espids
=
[
'
a9495a00
'
,
'
c14e5a00
'
]
# TODO create this mapping:
# mapps from (color, id) ==> (self.ledstrip indexes)
self
.
idxpair
=
{
# The first one has cold and warm swapped...
(
'
c
'
,
1
):(
0
,
1
),
(
'
w
'
,
1
):(
0
,
0
),
(
'
c
'
,
2
):(
0
,
3
),
(
'
w
'
,
2
):(
0
,
2
),
(
'
w
'
,
2
):(
0
,
0
),
(
'
c
'
,
2
):(
0
,
1
),
(
'
w
'
,
1
):(
0
,
2
),
(
'
c
'
,
1
):(
0
,
3
),
# This one has cold and warm right
(
'
c
'
,
3
):(
1
,
0
),
(
'
w
'
,
3
):(
1
,
1
),
...
...
@@ -72,18 +71,23 @@ class Babel:
self
.
ledstrip_states
[
idx
[
0
]][
idx
[
1
]]
=
int
(
value
)
elif
len
(
tmp
)
==
3
and
tmp
[
1
]
in
(
'
c
'
,
'
w
'
)
and
abs
(
int
(
tmp
[
2
]))
<=
4
:
idx
=
self
.
idxpair
[(
tmp
[
1
],
abs
(
int
(
tmp
[
2
])))]
idx
=
self
.
idxpair
[(
tmp
[
1
],
abs
(
int
(
tmp
[
2
])))]
group_changed
|=
self
.
ledstrip_states
[
idx
[
0
]][
idx
[
1
]]
!=
int
(
value
)
self
.
ledstrip_states
[
idx
[
0
]][
idx
[
1
]]
=
int
(
value
)
self
.
hbf
.
log
.
info
(
"
Done mapping:
"
)
self
.
hbf
.
log
.
info
(
self
.
ledstrip_states
)
if
group_changed
:
for
idx
,
e
in
enumerate
(
self
.
espids
):
msg
[
e
]
=
self
.
ledstrip_states
[
idx
]
for
idx
,
ledidx
in
enumerate
(
self
.
espids
):
msg
[
ledidx
]
=
self
.
ledstrip_states
[
idx
]
await
self
.
hbf
.
publish
(
'
/haspa/led
'
,
msg
)
print
(
"
MSG:
"
,
msg
)
async
def
command_requestinfo
(
self
,
client
,
msg
,
_
):
"""
Request details about configured led mappings
"""
del
client
,
msg
await
self
.
hbf
.
publish
(
'
/haspa/power/info
'
,
{
'
documentation
'
:
'
too lazy to implement
'
})
This diff is collapsed.
Click to expand it.
hackerman/hackerman.py
+
127
−
2
View file @
aa1e5255
import
asyncio
import
requests
import
random
from
hauptbahnhof
import
Hauptbahnhof
...
...
@@ -14,6 +16,7 @@ class Hackerman:
self
.
loop
=
loop
self
.
hbf
=
Hauptbahnhof
(
loop
)
self
.
hbf
.
subscribe
(
'
/haspa/status
'
,
self
.
command_status
)
self
.
hbf
.
subscribe
(
'
/haspa/action
'
,
self
.
command_action
)
async
def
teardown
(
self
):
await
self
.
hbf
.
teardown
()
...
...
@@ -30,13 +33,135 @@ class Hackerman:
'
table
'
:
1023
,
'
fan
'
:
1023
,
'
ledstrip
'
:
400
,
})
})
await
self
.
hbf
.
publish
(
'
/haspa/music/control
'
,
{
'
play
'
:
True
})
elif
message
[
'
haspa
'
]
in
[
'
close
'
,
'
zu
'
,
'
closed
'
]:
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
table
'
:
0
,
'
fan
'
:
0
,
'
ledstrip
'
:
0
,
'
alarm
'
:
0
,
})
})
await
self
.
hbf
.
publish
(
'
/haspa/music/control
'
,
{
'
play
'
:
False
})
except
KeyError
:
raise
# because - fuck you sender! i will die now, silently.
async
def
command_action
(
self
,
client
,
message
,
_
):
"""
Handle actions like alarm or party
"""
del
client
if
'
action
'
in
message
:
if
message
[
'
action
'
]
==
'
alarm
'
:
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
alarm
'
:
1023
})
await
asyncio
.
sleep
(
2
)
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
alarm
'
:
0
})
elif
message
[
'
action
'
]
==
'
party
'
:
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
alarm
'
:
0
,
'
table
'
:
0
,
'
ledstrip
'
:
0
})
delay
=
0.05
sounds
=
[
(
'
56
'
,
3.5
),
# führer
(
'
97
'
,
4.7
),
# sonnenschein
(
'
63
'
,
5
),
#epische musik
(
'
110
'
,
3.7
),
#dota
(
'
113
'
,
9
),
# skrillex
]
sound
=
random
.
choice
(
sounds
)
if
sound
[
0
]
==
'
97
'
:
await
asyncio
.
sleep
(
1
)
for
i
in
range
(
0
,
300
):
if
i
==
100
:
requests
.
get
(
"
https://bot.stusta.de/set/
"
+
sound
[
0
])
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
ledstrip-w
'
:
i
*
10
/
3
})
await
asyncio
.
sleep
(
0.01
)
elif
sound
[
0
]
==
'
113
'
:
requests
.
get
(
"
https://bot.stusta.de/set/
"
+
sound
[
0
])
for
i
in
range
(
2
):
await
asyncio
.
sleep
(
1.5
)
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
ledstrip-c-1
'
:
1023
,
'
ledstrip-c-3
'
:
1023
,
'
alarm
'
:
1023
})
await
asyncio
.
sleep
(
0.01
)
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
ledstrip-c-1
'
:
0
,
'
ledstrip-c-3
'
:
0
})
for
o
in
range
(
40
):
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
ledstrip-c-2
'
:
20
*
o
,
'
ledstrip-w-4
'
:
20
*
o
})
await
asyncio
.
sleep
(
0.01
)
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
Ledstrip-c-2
'
:
0
,
'
ledstrip-w-4
'
:
0
})
#await asyncio.sleep(1.49)
for
o
in
range
(
20
):
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
ledstrip-c-2
'
:
1023
,
'
ledstrip-w-4
'
:
0
})
await
asyncio
.
sleep
(
0.01
)
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
ledstrip-c-2
'
:
0
,
'
ledstrip-w-4
'
:
1023
})
await
asyncio
.
sleep
(
0.01
)
else
:
requests
.
get
(
"
https://bot.stusta.de/set/
"
+
sound
[
0
])
for
_
in
range
(
int
(
sound
[
1
]
/
(
delay
*
4
))):
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
ledstrip-c-1
'
:
0
,
'
ledstrip-c-2
'
:
1023
})
print
(
"
1->2
"
)
await
asyncio
.
sleep
(
delay
)
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
ledstrip-c-2
'
:
0
,
'
ledstrip-c-3
'
:
1023
})
print
(
"
2->3
"
)
await
asyncio
.
sleep
(
delay
)
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
ledstrip-c-3
'
:
0
,
'
ledstrip-c-4
'
:
1023
})
print
(
"
3->4
"
)
await
asyncio
.
sleep
(
delay
)
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
ledstrip-c-4
'
:
0
,
'
ledstrip-c-1
'
:
1023
})
print
(
"
4->1
"
)
await
asyncio
.
sleep
(
delay
)
print
(
"
round
"
)
await
self
.
hbf
.
publish
(
'
/haspa/power
'
,
{
'
alarm
'
:
0
,
'
table
'
:
1023
,
'
ledstrip
'
:
500
})
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