-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLPTController.m
More file actions
123 lines (107 loc) · 4.17 KB
/
LPTController.m
File metadata and controls
123 lines (107 loc) · 4.17 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
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
classdef LPTController < handle
properties( SetAccess = protected )
lptPortAddress % contains address of the parallel port
shockChannel % contains data byte to apply shock
pulseLength % pulse length in seconds
shockGap % gap between consecutive shock pulses
isEnabled % determines if class functionality is active
isDummy % dummy mode for testing without mex file
isParallel % run in parallel mode (NOT SUPPORTED)
ioObj % mex object to control LPT port
end
methods
%% CLASS CONSTRUCTOR
% called when an object is initialized
function this = LPTController(varargin)
this.lptPortAddress = 57376;
this.pulseLength = 0.005;
this.shockGap = 0.06;
this.shockChannel = 1;
this.isEnabled = 0;
this.isDummy = 0;
this.isParallel = 0;
for i=1:length(varargin)
switch varargin{i}
case 'dummy'
this.isDummy = 1;
case 'parallel'
fprintf('Not supported\n');
this.clean();
end
end
this.init();
end
%% PUBLIC METHODS
function sendMarker ( this,data )
if this.isParallel
% this.f = parfeval( @sendPulse,1,this,data );
else
this.sendPulse( data );
end
end
function sendShock ( this )
if this.isParallel
% this.f = parfeval( @sendPulse,1,this );
else
this.sendPulse( this.shockChannel );
WaitSecs( this.shockGap );
this.sendPulse( this.shockChannel );
WaitSecs( this.shockGap );
this.sendPulse( this.shockChannel );
WaitSecs( this.shockGap );
this.sendPulse( this.shockChannel );
end
end
function clean ( this )
if this.isEnabled
clear io64;
this.isEnabled = 0;
elseif this.isDummy
fprintf('LPT driver was in a dummy mode\n');
else
fprintf('LPT driver is already disabled\n');
end
end
function reenable ( this )
if this.isEnabled == 0 && this.isDummy == 0
this.init();
elseif this.isDummy
this.init();
fprintf('LPT driver in a dummy mode\n');
else
fprintf('LPT driver is already enabled\n');
end
end
end
%% PROTECTED METHODS
methods( Access = protected )
function init( this )
if ~this.isDummy
%create IO64 interface object
this.ioObj = io64();
if io64(this.ioObj) == 0
this.isEnabled = 1;
io64(this.ioObj,this.lptPortAddress,0);
fprintf('LPT driver enabled\n');
end
end
if this.isParallel
% clear parallel pool
% delete(gcp('nocreate'));
% this.p = parpool( 2,'IdleTimeout',Inf );
% init to avoid delays later
% this.sendMarker(0);
end
end
function status = sendPulse( this, data)
if this.isEnabled
io64( this.ioObj,this.lptPortAddress,data ); %pulse begin
WaitSecs( this.pulseLength ); %pulse length
io64( this.ioObj,this.lptPortAddress,0 ); %pulse end
elseif this.isDummy
WaitSecs( this.pulseLength ); %pulse length
end
status = 0;
end
end
end