forked from jamieboyd/AutoHeadFix
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAHF_ContactCheck.py
More file actions
86 lines (69 loc) · 2.51 KB
/
AHF_ContactCheck.py
File metadata and controls
86 lines (69 loc) · 2.51 KB
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
#! /usr/bin/python3
#-*-coding: utf-8 -*-
from abc import ABCMeta, abstractmethod
from AHF_Base import AHF_Base
class AHF_ContactCheck(AHF_Base, metaclass = ABCMeta):
'''
Base class for ContactCheck. This class handles the detection of mice entering/exiting the trial area.
'''
@abstractmethod
def checkContact(self):
'''
Checks for contact.
:returns: :code:`bool` whether contact is made.
'''
return False
@abstractmethod
def waitForContact(self, timeoutSecs):
'''
Blocks execution until contact or timeout.
Note: do not call while logging via startLogging, as it could lead to deadlocks.
'''
return False
@abstractmethod
def waitForNoContact(self, timeoutSecs):
'''
Blocks execution until no contact or timeout.
Note: do not call while logging via startLogging, as it could lead to deadlocks.
'''
return False
def turnOn (self):
pass
def turnOff (self):
pass
@abstractmethod
def startLogging(self):
"""
Starts running background task, checking for contact.
Constantly updates gTask.contact variable in AHF_Task.
Note: do not use waitForContact or waitForNoContact while logging
"""
pass
@abstractmethod
def stopLogging(self):
"""
Stops contactChecker running background task.
"""
def hardwareTest(self):
print('To pass test, start with no contact. Make contact within 10 seconds, then hold contact for less than 10 seconds')
passed = False
if self.checkContact():
print('Contact is already made. F')
else:
print('Waiting for contact ....')
if not self.waitForContact(10):
print('No contact after waiting for 10 seconds. F')
else:
print('Contact Made! - Waiting for contact to be broken....')
if not self.waitForNoContact(10):
print('Contact maintained for more than 10 seconds. F')
else:
print('Contact Broken! test passed')
passed = True
self.stopLogging()
if not passed:
result = input('Would you like to edit settings for contact check, Y or N?')
if result[0] == 'Y' or result [0] == 'y':
self.setdown()
self.settingsDict = self.config_user_get(self.settingsDict)
self.setup()