-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlucidCUE.py
107 lines (70 loc) · 2.64 KB
/
lucidCUE.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# lucidLampCue
# System Libraries
import subprocess
import time
from time import localtime,strftime
import sys
#import winsound
#import pythoncom
# Zeo Libraries
from ZeoRawData import BaseLink, Parser
from ZeoRawData.Utility import *
# ActiveHome Libraries (Windows COM)
#from win32com.client import Dispatch
# User customizable variables
#audio_file = "/User/walterhinds/Desktop/ZEO/audio.wav"
audio_file = '/Users/kronkite/Downloads/PrettyLights-TakingUpYourPreciousTime/04 Finally Moving.mp3'
port = '/dev/tty.usbserial'
stage_num = 0 #initialize the consecutive-stage counter
con_stage = 7 #define how many consecutive stages needed
soi = 'REM' #define the 'stage of interest'
blinks = 9 #how many screen flashes for CUE
class lucidCue:
def updateSlice(self, slice):
if not slice['SleepStage'] == None:
self.updateCue(slice['SleepStage'])
def updateCue(self, stage):
global stage_num
print stage, str(time.ctime())
if not stage == soi:
stage_num=0 #reset the stage counter
if stage == soi:
stage_num+=1
def sendCue(self):
t0=time.time()
#PLAY AUDIO
# return_code = subprocess.call(["afplay", audio_file])
# killall -STOP afplay
# killall -CONT afplay
#FLASH SCREEN
for i in range(1, blinks): #play the light cue 10 times?
#initiate a flashing screen
return_code = subprocess.call(["brightness", "1"]) #flash on
time.sleep(1) #wait one second
return_code = subprocess.call(["brightness", "0"]) #flash off
time.sleep(1) #wait one second
print time.time()-t0
if __name__ == "__main__":
# Initialize Serial Link
return_code = subprocess.call(["afplay", audio_file])
link = BaseLink.BaseLink(port)
parser = Parser.Parser()
cue = lucidCue()
# Add Callbacks and Start the Link
link.addCallback(parser.update)
parser.addSliceCallback(cue.updateSlice)
link.start()
# Wait a little bit before becoming lucid
print 'Waiting to drift off...'
time.sleep(2700) #wait 45 minutes before starting callbacks
print 'Lucidity check started...'
print time.ctime
# Infinitely loop to allow the lucidity check to run continuously
while(True):
if stage_num>= con_stage: #must be in stage for ~ 5 mins
cue.sendCue()
print time.ctime()
stage_num=0 #reset the stage counter
sys.exit()
#time.sleep(5) #why is this here?
#end of program