Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
time-machine
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hugo Hörnquist
time-machine
Compare Revisions
b159e3cbc7d9d4b2e77b9ce02f3ee590b7f265b0...e99578786847bfa2470224ae4c2f74db5eec9887
Source
e99578786847bfa2470224ae4c2f74db5eec9887
Select Git revision
...
Target
b159e3cbc7d9d4b2e77b9ce02f3ee590b7f265b0
Select Git revision
Compare
Commits (4)
Made last_time local.
· 756098c2
Hugo Hörnquist
authored
Sep 23, 2018
756098c2
Fix double hit problem.
· 5dfa3efb
Hugo Hörnquist
authored
Sep 27, 2018
5dfa3efb
Add flask_raise mode.
· df29b164
Hugo Hörnquist
authored
Sep 27, 2018
df29b164
Add cmd line option for choosing mode.
· e9957878
Hugo Hörnquist
authored
Sep 27, 2018
e9957878
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
16 deletions
+41
-16
time_machine/machine.py
time_machine/machine.py
+41
-16
No files found.
time_machine/machine.py
View file @
e9957878
...
...
@@ -3,6 +3,7 @@
import
RPi.GPIO
as
g
import
time
import
threading
import
sys
import
Adafruit_CharLCD
as
LCD
...
...
@@ -36,8 +37,6 @@ lcd_rows = 2
lcd
=
LCD
.
Adafruit_CharLCD
(
lcd_rs
,
lcd_en
,
lcd_d4
,
lcd_d5
,
lcd_d6
,
lcd_d7
,
lcd_columns
,
lcd_rows
,
lcd_backlight
)
last_time
=
0
risewait
=
threading
.
Event
()
fallwait
=
threading
.
Event
()
...
...
@@ -97,7 +96,7 @@ def wait_for_bottle_place():
def
wait_for_bottle_remove
():
return
wait_fall
()
if
test
else
wait_rise
()
def
lcd_info
(
msg
):
def
lcd_info
(
msg
,
last_time
):
lcd
.
clear
()
lcd
.
home
()
lcd
.
set_cursor
(
0
,
0
)
...
...
@@ -109,45 +108,71 @@ def wait_btn():
return
g
.
wait_for_edge
(
btn_pin
,
g
.
RISING
,
bouncetime
=
500
)
#g.wait_for_edge(btn_pin, g.RISING)
class
Modes
:
button
=
0
flask_raise
=
1
def
main
():
global
state
,
pins
last_time
=
0
mode
=
Modes
.
button
if
(
sys
.
argv
+
[
False
])[
1
]
else
Modes
.
flask_raise
while
True
:
if
state
==
States
.
no_hafv
:
print
print
"Inget Hafv"
lcd_info
(
"Vilar"
)
lcd_info
(
"Vilar"
,
last_time
)
wait_for_bottle_place
()
state
=
States
.
hafv_ready
elif
state
==
States
.
hafv_ready
:
print
"Hafv redo"
lcd_info
(
"Starta med knapp"
)
wait_btn
()
if
mode
==
Modes
.
button
:
lcd_info
(
"Starta med knapp"
,
last_time
)
wait_btn
()
elif
mode
==
Modes
.
flask_raise
:
lcd_info
(
"Starta med lyft"
,
last_time
)
wait_for_bottle_remove
()
state
=
States
.
hafv_active
start_time
=
time_ms
()
elif
state
==
States
.
hafv_active
:
print
"currently Hafving"
lcd_info
(
"Klockar"
)
if
not
bottle_check
(
pins
):
lcd_info
(
"Klockar"
,
last_time
)
if
mode
==
Mode
.
button
and
not
bottle_check
(
pins
):
print
"Early start"
lcd_info
(
"Tjuvstart!"
)
lcd_info
(
"Tjuvstart!"
,
last_time
)
wait_btn
()
state
=
States
.
no_hafv
continue
print
"Raise the bottle"
wait_for_bottle_remove
()
print
"BOTTLE RAISED"
# TODO we actually don't need this, but it was
# here before so it stays until I refactor this.
if
mode
==
Modes
.
button
:
wait_for_bottle_remove
()
print
"BOTTLE RAISED"
print
"Place back bottle after hafv"
wait_for_bottle_place
()
print
"BOTTLE PLACED"
end_time
=
time_ms
()
# Wait for bottle placed is in a loop because if the time
# is under 1 secound then we want to wait again. This is
# to prevent a finger or similar from stopping the time.
while
True
:
wait_for_bottle_place
()
print
"BOTTLE PLACED"
end_time
=
time_ms
()
t
=
(
end_time
-
start_time
)
/
1000.0
if
t
>
1
:
# Allow timing to halt
break
t
=
(
end_time
-
start_time
)
/
1000.0
print
"Hafvtid: {0} s"
.
format
(
t
)
last_time
=
t
lcd_info
(
"Avvakta"
)
lcd_info
(
"Avvakta"
,
last_time
)
state
=
States
.
no_hafv
time
.
sleep
(
1
)
...
...