Skip to content

Commit

Permalink
Add ability to trigger based on proximity sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
taixzo committed May 25, 2015
1 parent 4cac43c commit 50be008
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 1 addition & 2 deletions FirstPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Page {
page.activate_morning()
});
});
setHandler('start',page.speak)
}
onError: console.log('Python error: ' + traceback)
}
Expand Down Expand Up @@ -196,5 +197,3 @@ Page {
size: BusyIndicatorSize.Large
}
}


18 changes: 18 additions & 0 deletions sailfish_hw.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import queue as Queue
import time
import random
import threading

import ast # for safely parsing timed stuff

Expand Down Expand Up @@ -69,6 +70,21 @@ def __init__(self, **kwargs):
client.start()
client.send("TERMINATE\n")

detected = False

def watch_proximity():
global detected
while True:
prox_detect = open("/sys/devices/virtual/input/input10/prx_detect").read()
if bool(int(prox_detect)) and not detected:
detected = True
print ("Detected proximity input")
pyotherside.send('start')
time.sleep(1)

prox_thread = threading.Thread(target=watch_proximity)
prox_thread.start()

def listen():
print ("Listening...")
# purge message queue
Expand Down Expand Up @@ -235,6 +251,7 @@ def check(self):
self.messages[i] = email.message_from_file(open(os.getenv("HOME")+"/.qmf/mail/"+i))

def speak(string):
global detected
try:
is_string = isinstance(string,basestring)
except NameError:
Expand All @@ -244,6 +261,7 @@ def speak(string):
else:
spoken_str = '\n'.join([i[0] for i in string])
os.system('espeak --stdout -v +f2 "' + spoken_str.replace(":00"," o'clock").replace("\n",". ") + '" | gst-launch-0.10 -v fdsrc ! wavparse ! audioconvert ! alsasink &')
detected = False
return string

def quit():
Expand Down

0 comments on commit 50be008

Please sign in to comment.