-
Notifications
You must be signed in to change notification settings - Fork 0
/
optical_gui.py
295 lines (168 loc) · 6.12 KB
/
optical_gui.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
from pylab import *
from tkinter import *
import math
import serial
import tkinter as tk
import pyfirmata
import time
import threading
import pandas as pd
from pyfirmata import Arduino
from os import system
from timeit import default_timer as timer
from datetime import timedelta
root = Tk()
root.title("DBS Trigger Control")
root.geometry("450x500")
e = Entry(root)
n = 0
recording_number = []
parameter = []
notes = []
o_duration = 0
o_delay = 0
pulse_number = 0
number_of_trains = 1;run_x_times = number_of_trains
time_between_pulses = 0
time_between_trains = 0
pulse_number = 0
# In[ ]:
entry = tk.Entry(root)
variable=StringVar()
# In[ ]:
path = '/Users/granthughes/Desktop/eo_stim/data_frames/1_gui_runs_csv/12_09_21_test/'
# In[ ]:
#Arduino port designation
board = Arduino('/dev/cu.usbmodem14101')
# In[ ]:
def do_train():
# Update vars
recording_number.append(recording_number_window.get())
parameter.append(parameter_window.get())
notes.append(notes_window.get())
o_duration = float(o_duration_entry.get())
o_delay = float(o_delay_entry.get())
train_number = float(run_x_times_entry.get())
pulse_number = float(pulse_num_entry.get())
time_between_pulses = float(time_between_pulses_entry.get())
time_between_trains = float(time_between_trains_entry.get())
all_data = {
'run': [recording_number[-1]]*int(train_number),
'parameter': [parameter[-1]]*int(train_number),
'notes': [notes[-1]]*int(train_number),
'o_duration': [o_duration] *int(train_number),
'o_delay': [o_delay]* int(train_number),
'number_of_trains': [train_number]*int(train_number),
'pulse_number': [pulse_number]*int(train_number),
'time_between_pulses': [time_between_pulses]* int(train_number),
'time_between_trains': [time_between_trains]*int(train_number),
}
for train in range(int(number_of_trains)):
for pulse in range(int(pulse_number)):
print("train "+str(train+1)+" pulse "+str(pulse+1))
#******start single pulse sequence
board.digital[1].write(1)
board.digital[2].write(1)
time.sleep(o_duration)
board.digital[1].write(0)
board.digital[2].write(0)
time.sleep(o_delay) #Add input in gooey for this time
board.digital[3].write(1)
board.digital[4].write(1)
time.sleep(o_duration)
board.digital[3].write(0)
board.digital[4].write(0)
time.sleep(o_delay)
board.digital[5].write(1)
board.digital[6].write(1)
time.sleep(o_duration)
board.digital[5].write(0)
board.digital[6].write(0)
time.sleep(o_delay)
board.digital[5].write(1)
board.digital[6].write(1)
time.sleep(o_duration)
board.digital[5].write(0)
board.digital[6].write(0)
time.sleep(o_delay)
board.digital[7].write(1)
board.digital[8].write(1)
time.sleep(o_duration)
board.digital[7].write(0)
board.digital[8].write(0)
train_counter = train+1
Current_Loop_Number.config(text="Train Number Completed: " + str(train_counter))
update_counter()
time.sleep(Time_between_pulses)
#********end single pulse sequence
time.sleep(time_between_trains)
return all_data_df
# In[ ]:
# # GUI window Control
#Tkinter Windows
app = Frame(root)
app.grid()
startx = Button(app, text='Run Train', command=do_train,fg='green')
## text_windows
recording_number_label = Label(app, text='run_number')
recording_number_window = Entry(app, text='')
parameter_label = Label(app, text='parameter')
parameter_window = Entry(app, text='')
notes_label = Label(app, text='Notes')
notes_window = Entry(app, text='')
### Int_windows
o_duration_label = Label(app, text= "Optical Pulse Duration (sec)")
o_duration_entry = Entry(app, text="Optical Duration Seconds")
o_duration_entry.insert(0,o_duration)
o_delay_label = Label(app, text= "o_delay")
o_delay_entry = Entry(app, text="o_delay")
o_delay_entry.insert(0,o_delay)
pulse_num_label = Label(app, text="(pulse_number) Number_of_pulses_per_train", fg='#9900ff')
pulse_num_entry = Entry(app, text="")
pulse_num_entry.insert(0,pulse_number)
time_between_trains_label = Label(app, text="Time_between_trains (sec)",fg='#9900ff')
time_between_trains_entry = Entry(app, text="")
time_between_trains_entry.insert(0,time_between_trains)
run_x_times_label = Label(app, text="Number_of_trains",fg='#9900ff')
run_x_times_entry = Entry(app, text= "")
run_x_times_entry.insert(0,run_x_times)
time_between_pulses_label = Label(app, text="Time_between_pulses (sec)")
time_between_pulses_entry = Entry(app, text="")
time_between_pulses_entry.insert(0,time_between_pulses)
Current_Loop_Number = Label(app, text = "Train Number Completed: " + str(n),fg='#9900ff')
e1 = tk.Entry(root)
# Gui Layout
startx.grid(row=1, column=0)
## text_windows
recording_number_label.grid(row=2, column=0)
recording_number_window.grid(row=3, column=0)
parameter_label.grid(row=4, column=0)
parameter_window.grid(row=5, column=0)
notes_label.grid(row=6, column=0)
notes_window.grid(row=7, column=0)
## int_windows
o_duration_label.grid(row=1, column=1)
o_duration_entry.grid(row=2, column=1)
o_delay_label.grid(row=3, column=1)
o_delay_entry.grid(row=4, column=1)
run_x_times_label.grid(row=5, column=1)
run_x_times_entry.grid(row=6, column=1)
pulse_num_label.grid(row=7, column=1)
pulse_num_entry.grid(row=8, column=1)
time_between_pulses_label.grid(row=9, column=1)
time_between_pulses_entry.grid(row=10, column=1)
time_between_trains_label.grid(row=11, column=1)
time_between_trains_entry.grid(row=12, column=1)
root.mainloop()
# In[ ]:
# In[ ]:
# In[ ]:
# In[ ]:
# In[ ]:
# In[ ]:
# In[ ]:
# In[ ]:
# In[ ]: