Skip to content

Commit

Permalink
dev mode option to simulate data while sending to speaker
Browse files Browse the repository at this point in the history
  • Loading branch information
remrama committed Jul 10, 2019
1 parent 19ccb8e commit 3730dfc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"serial_name": "/dev/cu.usbmodem53254001",
"data_directory": "../data/",
"development_mode": 0,

"max_analog_volts": 3.3,
"analog_read_resolution": 13,
Expand Down
3 changes: 2 additions & 1 deletion src/runall.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
PARAMS['lrlr_window_secs'],
PARAMS['n_peaks_for_flick_detection'],
data_fname=data_fname,
saving=True)
saving=True,
development_mode=bool(PARAMS['development_mode']))

# initialize detector as a <worker> attribute
worker.detector = myDetector(PARAMS['internal_sampling_rate_hz'],
Expand Down
19 changes: 12 additions & 7 deletions src/workerClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def __init__(self,serial_name, # of Arduino
lrlr_window_secs, # secs that n peaks must occur within for detection
n_peaks_for_lrlr_detection, # n peaks required to trigger detection
data_fname,
saving):
saving,
development_mode):

super(self.__class__,self).__init__()

Expand All @@ -60,6 +61,7 @@ def __init__(self,serial_name, # of Arduino
self.N_PEAKS_FOR_LRLR_DETECTION = n_peaks_for_lrlr_detection
self.DATA_FNAME = data_fname
self.SAVING = saving
self.DEV_MODE = development_mode

self.COLUMNS = ['timestamp','volts'] # of data output file

Expand Down Expand Up @@ -98,7 +100,7 @@ def keep_grabbingData_and_checking4flick(self):
while True: # run until GUI closes

# pull from Arduino or simulate data
if self.duino:
if self.duino and not self.DEV_MODE:
volt = self._grabData()
else:
volt = self._generateSimulatedData()
Expand Down Expand Up @@ -155,7 +157,7 @@ def _check4lrlr(self):
self.detector.update_status(list(self.data),list(self.stamps),self.gain)
# if a peak, add to the running list of peaks
if self.detector.status == 'rising':
print 'rising'
# print 'rising'
# add the most recent timestamp indicating the time of detection
self.lrlr.append(self.stamps[-1])
# check if the timepassed between all 4 is within range
Expand All @@ -165,9 +167,9 @@ def _check4lrlr(self):
self.signal4log.emit('Flick detected',False,self.stamps[-1])
# clear the flick record, preventing rapid consecutive detections
self.lrlr.clear()
# # send to duino if wanna trigger something
# if self.duino is not None:
# self.duino.write(bytes(1))
# send to duino if wanna trigger something
if self.duino is not None:
self.duino.write(bytes(1))


def _connect2arduino(self):
Expand All @@ -178,6 +180,9 @@ def _connect2arduino(self):
try:
## TODO: add timeout and baudrate args
self.duino = serial.Serial(self.SERIAL_NAME)
if self.DEV_MODE:
self.signal4log.emit('Connected to duino but simulating data for development mode',True,0)
self.initializeSimulation()
except serial.serialutil.SerialException:
self.duino = None
self.signal4log.emit('No serial connection, simulating data',True,0)
Expand Down Expand Up @@ -226,7 +231,7 @@ def _grabData(self):
rawvals = [ float(x) for x in list_str_vals if x.isalnum() ]
# sometimes Arduino sends nothing so make sure there is at least 1 value
if len(rawvals) > 0:
volts = self.__raw2volts(rawvals[-1])
volts = self._raw2volts(rawvals[-1])
return volts

def _generateSimulatedData(self):
Expand Down

0 comments on commit 3730dfc

Please sign in to comment.