forked from quinndiggity/hacking_slot_machines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpi_interface.py
executable file
·78 lines (66 loc) · 2.06 KB
/
pi_interface.py
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
#!/usr/bin/env python
import paramiko
import picamera
import os
import subprocess
from pygame import mixer
from time import sleep
def copyphoto(ssh):
ftp = ssh.open_sftp()
ftp.put('/slotbot/images/pi_frame.jpg', '/slotbot/images/pi_frame.jpg')
ftp.close()
def runapp(ssh):
stdin, stdout, stderr = ssh.exec_command("/home/slotbot_code/build/src/./slotbot")
output = stdout.readlines()
return output[0]
def readanswer(ssh):
stdin, stdout, stderr = ssh.exec_command("/slotbot/./read_answer")
return stdout.readlines()[0]
# set up audio output
mixer.init()
ansbeep = mixer.Sound('/slotbot/audio/ansbeep.wav')
errbeep = mixer.Sound('/slotbot/audio/error.wav')
bellbeep = mixer.Sound('/slotbot/audio/bell.wav')
noansbeep = mixer.Sound('/slotbot/audio/no_answer.wav')
ansbeep.play()
# set the mothership settings
mothership_ip = "..."
mothership_username = "..."
mothership_password = "..."
# create PiCamera class instance and change settings
camera = picamera.PiCamera()
camera.sharpness = 0
camera.resolution = (1000,800)
camera.contrast = 0
camera.brightness = 50
camera.saturation = 0
camera.ISO = 0
camera.video_stabilization = False
camera.exposure_compensation = 0
camera.exposure_mode = 'auto'
camera.meter_mode = 'average'
camera.awb_mode = 'auto'
camera.image_effect = 'negative'
camera.color_effects = None
camera.rotation = 0
camera.hflip = False
camera.vflip = False
camera.crop = (0.0, 0.0, 1.0, 1.0)
while True:
#try:
# connect with the mothership
print "\nConnecting with mothership..."
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(mothership_ip, username='...', password='...')
if ssh == False:
raise ValueError('Connection lost')
print "Successfully connected with mothership!\n\nPerforming operations..."
bellbeep.play()
# perform operations in infinite loop
while True:
camera.capture('/slotbot/images/pi_frame.jpg')
copyphoto(ssh)
answer = runapp(ssh)
command = "espeak -ven-us+f4 -a 200 -s 280 --stdout '" + answer + "' | aplay -Dplug:bluetooth &"
subprocess.Popen([command], shell=True)