Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
valve-control
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
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
Corby Schmitz
valve-control
Commits
10957a13
Commit
10957a13
authored
4 months ago
by
Corby Schmitz
Browse files
Options
Downloads
Patches
Plain Diff
code cleanup
parent
ec02a2c3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gui-orchestrator.py
+0
-57
0 additions, 57 deletions
gui-orchestrator.py
valve-control-ble.py
+0
-117
0 additions, 117 deletions
valve-control-ble.py
with
0 additions
and
174 deletions
gui-orchestrator.py
+
0
−
57
View file @
10957a13
<<<<<<<
HEAD
import
tkinter
as
tk
from
tkinter
import
ttk
import
random
...
...
@@ -51,59 +50,3 @@ def custom_mainloop():
window
.
after
(
0
,
custom_mainloop
)
window
.
mainloop
()
=======
import
tkinter
as
tk
from
tkinter
import
ttk
import
random
import
serial
statusOptions
=
[
"
opening
"
,
"
Open
"
,
"
closing
"
,
"
closed
"
,
"
starting
"
,
"
initiating
"
,
"
done
"
]
valves
=
[
"
Valve01
"
,
"
Valve02
"
,
"
Valve03
"
,
"
Valve04
"
]
s
=
serial
.
Serial
(
'
COM22
'
)
window
=
tk
.
Tk
()
window
.
title
(
"
Valve Orchestrator
"
)
label
=
tk
.
Label
(
window
,
text
=
"
Valve Orchestrator
"
)
label
.
pack
()
valveStatus
=
ttk
.
Treeview
(
window
,
columns
=
(
"
ValveName
"
,
"
ValveState
"
,
"
ValvePosition
"
),
show
=
"
headings
"
)
valveStatus
.
pack
()
valveStatus
.
heading
(
"
ValveName
"
,
text
=
"
Valve
"
)
valveStatus
.
heading
(
"
ValveState
"
,
text
=
"
State
"
)
valveStatus
.
heading
(
"
ValvePosition
"
,
text
=
"
Status
"
)
iid
=
0
for
instance
in
valves
:
valveStatus
.
insert
(
""
,
tk
.
END
,
iid
=
iid
,
values
=
(
instance
,
"
Pending
"
,
"
0%
"
))
iid
+=
1
button
=
tk
.
Button
(
window
,
text
=
"
Start Program
"
,
command
=
lambda
:
print
(
"
Starting
"
))
button
.
pack
()
def
custom_mainloop
():
count
=
0
inputData
=
s
.
read
()
while
inputData
:
(
valveID
,
pctOpen
,
cycleTime
,
runTime
,
openTime
,
closeTime
,
cycle
,
repeats
,
status
)
=
inputData
.
split
(
'
,
'
)
for
instance
in
valves
:
randomState
=
random
.
randint
(
0
,
5
)
randomValue
=
random
.
randint
(
0
,
100
)
if
statusOptions
[
randomState
]
==
"
Closed
"
:
valveStatus
.
set
(
count
,
column
=
1
,
value
=
statusOptions
[
randomState
])
valveStatus
.
set
(
count
,
column
=
2
,
value
=
"
0%
"
)
elif
statusOptions
[
randomState
]
==
"
Offline
"
:
valveStatus
.
set
(
count
,
column
=
1
,
value
=
statusOptions
[
randomState
])
valveStatus
.
set
(
count
,
column
=
2
,
value
=
"
n/a
"
)
else
:
randomPct
=
str
(
randomValue
)
+
"
%
"
valveStatus
.
set
(
count
,
column
=
1
,
value
=
statusOptions
[
randomState
])
valveStatus
.
set
(
count
,
column
=
2
,
value
=
randomPct
)
count
+=
1
window
.
after
(
5000
,
custom_mainloop
)
window
.
after
(
0
,
custom_mainloop
)
window
.
mainloop
()
>>>>>>>
21
fcc409ab4225189adb29d78550ae99287163ce
This diff is collapsed.
Click to expand it.
valve-control-ble.py
+
0
−
117
View file @
10957a13
<<<<<<<
HEAD
from
adafruit_ble
import
BLERadio
from
adafruit_ble.advertising.standard
import
ProvideServicesAdvertisement
from
adafruit_ble.services.nordic
import
UARTService
...
...
@@ -113,120 +112,4 @@ while True:
if
stop
:
sys
.
exit
()
else
:
=======
from
adafruit_ble
import
BLERadio
from
adafruit_ble.advertising.standard
import
ProvideServicesAdvertisement
from
adafruit_ble.services.nordic
import
UARTService
import
sys
import
datetime
ble
=
BLERadio
()
uart_connection
=
None
uart_service
=
None
stop
=
False
output
=
""
runningOperation
=
""
cycle
=
0
currentCycle
=
0
startTime
=
0
endTime
=
0
overallStart
=
0
overallStop
=
0
cycleStart
=
0
cycleStop
=
0
while
True
:
if
not
uart_connection
:
print
(
"
Trying to connect...
"
)
for
adv
in
ble
.
start_scan
(
ProvideServicesAdvertisement
):
# , interval=0.1, window=0.1, extended=True, buffer_size=4096):
# print(adv)
if
UARTService
in
adv
.
services
and
adv
.
complete_name
==
"
Valve01
"
:
# print(adv)
uart_connection
=
ble
.
connect
(
adv
)
uart_service
=
uart_connection
[
UARTService
]
print
(
"
Connected
"
)
break
ble
.
stop_scan
()
try
:
if
uart_connection
and
uart_connection
.
connected
:
# uart_service = uart_connection[UARTService]
while
uart_connection
.
connected
:
runningOperation
=
"
startup
"
s
=
input
(
"
Valve directive:
"
)
if
s
.
strip
()
==
"
quit
"
:
sys
.
exit
()
else
:
uart_service
.
write
(
s
.
encode
(
"
utf-8
"
))
uart_service
.
write
(
b
'
\n
'
)
print
(
"
Running directive
"
)
startTime
=
datetime
.
datetime
.
now
()
cycleStart
=
startTime
overallStart
=
startTime
uart_service
.
reset_input_buffer
()
if
uart_service
.
in_waiting
==
0
:
output
=
""
elif
uart_service
.
in_waiting
<
50
:
output
=
""
uart_service
.
reset_input_buffer
()
else
:
output
=
uart_service
.
readline
().
decode
(
"
utf-8
"
)
try
:
(
drop1
,
drop2
,
operationCycle
,
drop4
,
operationValue
)
=
output
.
split
(
"
,
"
)
(
drop1
,
currentOperation
)
=
operationValue
.
split
(
"
=
"
)
(
drop1
,
currentCycleString
)
=
operationCycle
.
split
(
"
=
"
)
currentCycle
=
int
(
currentCycleString
)
except
ValueError
:
currentOperation
=
runningOperation
currentCycle
=
cycle
if
not
currentOperation
==
runningOperation
:
endTime
=
datetime
.
datetime
.
now
()
print
(
runningOperation
,
"
completed in
"
,
endTime
-
startTime
,
"
seconds
"
)
runningOperation
=
currentOperation
startTime
=
datetime
.
datetime
.
now
()
if
not
cycle
==
currentCycle
:
cycleStop
=
datetime
.
datetime
.
now
()
print
(
"
cycle
"
,
cycle
,
"
completed in
"
,
cycleStop
-
cycleStart
,
"
seconds
"
)
cycle
=
currentCycle
cycleStart
=
datetime
.
datetime
.
now
()
if
not
currentOperation
==
runningOperation
or
not
cycle
==
currentCycle
:
print
(
output
)
while
"
done
"
not
in
output
:
if
uart_service
.
in_waiting
==
0
:
output
=
""
elif
uart_service
.
in_waiting
<
50
:
output
=
""
else
:
try
:
output
=
uart_service
.
readline
().
decode
(
"
utf-8
"
)
(
drop1
,
drop2
,
operationCycle
,
drop4
,
operationValue
)
=
output
.
split
(
"
,
"
)
(
drop1
,
currentOperation
)
=
operationValue
.
split
(
"
=
"
)
(
drop1
,
currentCycleString
)
=
operationCycle
.
split
(
"
=
"
)
currentCycle
=
int
(
currentCycleString
)
except
ValueError
:
currentOperation
=
runningOperation
currentCycle
=
cycle
if
not
currentOperation
==
runningOperation
:
endTime
=
datetime
.
datetime
.
now
()
print
(
runningOperation
,
"
completed in
"
,
endTime
-
startTime
,
"
seconds
"
)
print
(
output
)
runningOperation
=
currentOperation
startTime
=
datetime
.
datetime
.
now
()
if
not
cycle
==
currentCycle
:
cycleStop
=
datetime
.
datetime
.
now
()
print
(
"
cycle
"
,
cycle
,
"
completed in
"
,
cycleStop
-
cycleStart
,
"
seconds
"
)
print
(
output
)
cycle
=
currentCycle
cycleStart
=
datetime
.
datetime
.
now
()
if
currentOperation
==
"
opening
"
or
currentOperation
==
"
closing
"
:
print
(
output
)
print
(
output
)
overallStop
=
datetime
.
datetime
.
now
()
print
(
"
runcycle completed in
"
,
overallStop
-
overallStart
,
"
seconds
"
)
except
KeyboardInterrupt
:
if
stop
:
sys
.
exit
()
else
:
>>>>>>>
21
fcc409ab4225189adb29d78550ae99287163ce
stop
=
True
\ No newline at end of file
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