-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunner.py
More file actions
85 lines (68 loc) · 2.29 KB
/
Runner.py
File metadata and controls
85 lines (68 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import threading
from robot.Buttons import Buttons
from robot.Fan import Fan
from robot.Motors import gpio_cleanup, motor_off
from robot.RemoteControlsHandler import *
# What messages to listen for (LEDB on an LCD)
portListen = 9038
# remoteThread = None
isRunning = True
def all_off():
Motors.all_off()
Lights.all_off()
# remoteThread.stop()
def local_controls():
global isRunning
# Loop until terminated remotely
# Infinite loop that will not end until the user presses the exit key
while isRunning:
buttons_pressed = Buttons.pressed_buttons()
for pressedPin in buttons_pressed:
# print("Pin: ", pressedPin)
if pressedPin == 23:
print(pressedPin)
# os.system('sudo reboot')
# isRunning = False
elif pressedPin == 24:
# isRunning = False
# os.system('sudo poweroff')
print("power Off")
print(pressedPin)
try:
global isRunning
# global remoteThread
isRunning = True
# Start by turning all drives off
motor_off()
# raw_input('You can now turn on the power, press ENTER to continue')
# Setup the UDP listener
# Say("Controls Initialized")
Fan.start_fan()
uberSocketServer = socketserver.TCPServer(('', portListen), RemoteControlsHandler)
# Can't see debug logging.
# remoteThread = threading.Thread(None, remoteKeyBorgServer.serve_forever)
# remoteThread.daemon = True
# remoteThread.start()
print('UberPi Started')
while isRunning:
uberSocketServer.handle_request()
print("Stopped", isRunning)
# "Runner.py", line
# 24 in local_controls
# File
# "/usr/lib/python3.4/threading.pSegmentation fault
# local_controls_thread = threading.Thread(None, local_controls, "local_controls")
# local_controls_thread.daemon = True
# local_controls_thread.start()
input('threads running')
# Turn off the drives and release the GPIO pins
all_off()
gpio_cleanup()
except KeyboardInterrupt:
# CTRL+C exit, turn off the drives and release the GPIO pins
print('Terminated')
# Say("Robot Terminated. Keyboard Interrupt")
all_off()
input('Turn the power off now, press ENTER to continue')
gpio_cleanup()
exit()