Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
plushkatze
foobarpay
Commits
0eb1ffda
Commit
0eb1ffda
authored
Apr 19, 2016
by
anthraxx
Browse files
implemented pacman screensaver
parent
7cf5fbff
Changes
2
Hide whitespace changes
Inline
Side-by-side
foobarpay.py
View file @
0eb1ffda
...
...
@@ -12,6 +12,7 @@ from foobarpay.scanner import EvdevScanner, FifoScanner
from
foobarpay.logic
import
Logic
from
foobarpay.model.product
import
Product
from
foobarpay.tokens
import
TokenGenerator
from
foobarpay.screensaver
import
Screensaver
class
FooBarPay
:
...
...
@@ -19,7 +20,7 @@ class FooBarPay:
DEFAULT_DISPLAY
=
'/dev/hidraw1'
DEFAULT_DATABASE
=
'sqlite:///foobarpay.sqlite'
ALLOW_CUSTOMER_CREATION
=
False
I
NPUT_BLO
CK_TIME
=
0.
5
T
ICK_TIME
=
0.
1
IDLE_TIMEOUT
=
10
def
__init__
(
self
,
cli_arguments
):
...
...
@@ -38,6 +39,7 @@ class FooBarPay:
self
.
logic
=
Logic
(
self
.
display
,
self
.
database
,
allow_customer_creation
=
self
.
ALLOW_CUSTOMER_CREATION
,
idle_timeout
=
self
.
IDLE_TIMEOUT
)
self
.
screensaver
=
Screensaver
(
self
.
display
,
self
.
TICK_TIME
)
def
initialize_products
(
self
):
self
.
database
.
get_or_create
(
Product
,
id
=
4100060009503
,
name
=
"Extaler Mineralquell"
,
price
=
100
)
...
...
@@ -63,12 +65,15 @@ class FooBarPay:
logging
.
info
(
"Welcome to foobarpay"
)
signal
(
SIGINT
,
lambda
s
,
f
:
exit
(
0
))
while
True
:
sleep
(
self
.
I
NPUT_BLO
CK_TIME
)
sleep
(
self
.
T
ICK_TIME
)
line
=
self
.
scanner
.
read
()
if
line
:
self
.
logic
.
handle_scanned_text
(
line
)
self
.
screensaver
.
reset
()
continue
self
.
logic
.
tick
()
if
self
.
logic
.
tick
():
continue
self
.
screensaver
.
tick
()
if
__name__
==
"__main__"
:
parser
=
ArgumentParser
()
...
...
foobarpay/screensaver.py
0 → 100644
View file @
0eb1ffda
from
time
import
sleep
class
Screensaver
(
object
):
def
__init__
(
self
,
display
,
tick_time
):
self
.
display
=
display
self
.
screensavers
=
[
PacmanScreensaver
(
display
,
tick_time
)]
self
.
active_screensaver
=
self
.
screensavers
[
0
]
def
get_active_screensaver
(
self
):
return
self
.
screensavers
[
self
.
active_screensaver
].
reset
()
def
reset
(
self
):
self
.
active_screensaver
.
reset
()
def
tick
(
self
):
if
not
self
.
active_screensaver
.
tick
():
self
.
active_screensaver
.
reset
()
class
PacmanScreensaver
(
object
):
def
__init__
(
self
,
display
,
tick_time
):
self
.
display
=
display
self
.
tick_time
=
tick_time
self
.
pacman
=
[
'c'
,
'C'
]
self
.
reset
()
def
reset
(
self
):
self
.
pacman_index
=
0
self
.
pacman_position
=
-
1
self
.
line_index
=
0
self
.
lines
=
[
self
.
generate_line
(
init_pacman
=
True
),
self
.
generate_line
()]
def
generate_line
(
self
,
width
=
24
,
init_pacman
=
False
):
line
=
list
(
" "
*
width
)
for
i
in
range
(
1
,
width
,
3
):
line
[
i
]
=
'o'
if
init_pacman
:
line
[
0
]
=
self
.
pacman
[
self
.
pacman_index
]
return
""
.
join
(
line
)
def
show
(
self
):
self
.
display
.
show_two_messages
(
self
.
lines
[
0
],
self
.
lines
[
1
])
sleep
(
0.5
-
self
.
tick_time
)
""" Returns True while active and False when finished """
def
tick
(
self
):
# just show the first frame and return
if
self
.
pacman_position
<
0
:
self
.
pacman_position
+=
1
self
.
show
()
return
True
# unset last position and increment counters
line
=
list
(
self
.
lines
[
self
.
line_index
])
line
[
self
.
pacman_position
]
=
' '
self
.
pacman_index
=
(
self
.
pacman_index
+
1
)
%
len
(
self
.
pacman
)
self
.
pacman_position
+=
1
# switch line after reaching the end
if
self
.
pacman_position
>=
len
(
line
):
line
[
self
.
pacman_position
-
1
]
=
' '
self
.
pacman_position
=
0
self
.
lines
[
self
.
line_index
]
=
""
.
join
(
line
)
self
.
line_index
=
(
self
.
line_index
+
1
)
# finish if last line reached the end
if
self
.
line_index
>=
len
(
self
.
lines
):
self
.
lines
[
self
.
line_index
-
1
]
=
""
.
join
(
line
)
self
.
show
()
return
False
line
=
list
(
self
.
lines
[
self
.
line_index
])
# assign pacman char and show on display
line
[
self
.
pacman_position
]
=
self
.
pacman
[
self
.
pacman_index
]
self
.
lines
[
self
.
line_index
]
=
""
.
join
(
line
)
self
.
show
()
return
True
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment