-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGRFStateSystem.m
More file actions
151 lines (119 loc) · 4.76 KB
/
GRFStateSystem.m
File metadata and controls
151 lines (119 loc) · 4.76 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
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
//
// GRFStateSystem.m
// Experiment
//
// Copyright (c) 2006. All rights reserved.
//
#import "GRFStateSystem.h"
#import "UtilityFunctions.h"
#import "GaborRFMap.h"
#import "GRFBlockedState.h"
#import "GRFEndtrialState.h"
#import "GRFFixGraceState.h"
#import "GRFFixonState.h"
#import "GRFIdleState.h"
#import "GRFIntertrialState.h"
#import "GRFFixateState.h"
#import "GRFReactState.h"
#import "GRFSaccadeState.h"
#import "GRFStarttrialState.h"
#import "GRFStimulate.h"
#import "GRFStopState.h"
#import "GRFTooFastState.h"
#import "GRFEyesClosedState.h" // [Vinay] - added for the tfunc protocol
long eotCode; // End Of Trial code
BOOL fixated;
LLEyeWindow *fixWindow;
LLEyeWindow *respWindow;
LLEyeWindow *bigWindow; // [Vinay] - added for tfunc protocol
GRFStateSystem *stateSystem;
TrialDesc trial;
@implementation GRFStateSystem
- (void)dealloc {
[fixWindow release];
[respWindow release];
[super dealloc];
}
- (id)init;
{
if ((self = [super init]) != nil) {
// create & initialize the state system's states
[self addState:[[[GRFBlockedState alloc] init] autorelease]];
[self addState:[[[GRFEndtrialState alloc] init] autorelease]];
[self addState:[[[GRFFixonState alloc] init] autorelease]];
[self addState:[[[GRFFixGraceState alloc] init] autorelease]];
[self addState:[[[GRFIdleState alloc] init] autorelease]];
[self addState:[[[GRFIntertrialState alloc] init] autorelease]];
[self addState:[[[GRFStimulate alloc] init] autorelease]];
[self addState:[[[GRFFixateState alloc] init] autorelease]];
[self addState:[[[GRFTooFastState alloc] init] autorelease]];
[self addState:[[[GRFReactState alloc] init] autorelease]];
[self addState:[[[GRFSaccadeState alloc] init] autorelease]];
[self addState:[[[GRFStarttrialState alloc] init] autorelease]];
[self addState:[[[GRFStopState alloc] init] autorelease]];
[self addState:[[[GRFEyesClosedState alloc] init] autorelease]]; // [Vinay] - added for tfunc protocol
[self setStartState:[self stateNamed:@"GRFIdle"] andStopState:[self stateNamed:@"GRFStop"]];
[controller setLogging:YES];
fixWindow = [[LLEyeWindow alloc] init];
[fixWindow setWidthAndHeightDeg:[[task defaults] floatForKey:GRFFixWindowWidthDegKey]];
respWindow = [[LLEyeWindow alloc] init];
[respWindow setWidthAndHeightDeg:[[task defaults] floatForKey:GRFRespWindowWidthDegKey]];
// [Vinay] - now a big window to verify eyes closed condition. When eyes are closed the eye signal shouldn't be there in even a very big window
bigWindow = [[LLEyeWindow alloc] init];
[bigWindow setWidthAndHeightDeg:50.0]; // [Vinay] - using a 50 deg window here
// [Vinay] - till here
}
return self;
}
- (BOOL) running {
return [controller running];
}
- (BOOL) startWithCheckIntervalMS:(double)checkMS { // start the system running
return [controller startWithCheckIntervalMS:checkMS];
}
- (void) stop { // stop the system
[controller stop];
}
// Methods related to data events follow:
// Make a block status object that contains the number of blocks to do and how many
// trials of each type have been done (initialized to zero).
- (void) reset:(NSData *)eventData eventTime:(NSNumber *)eventTime;
{
long index;
updateBlockStatus();
blockStatus.blocksDone = blockStatus.sidesDone = blockStatus.instructDone = 0;
for (index = 0; index < blockStatus.changes; index++) {
blockStatus.validRepsDone[index] = blockStatus.invalidRepsDone[index] = 0;
}
[[(GaborRFMap *)task mapStimTable0] reset];
[[(GaborRFMap *)task mapStimTable1] reset];
mappingBlockStatus = [[(GaborRFMap *)task mapStimTable0] mappingBlockStatus];
trialCounter = 0;
}
#define kMaxRate 100.0
#define kSpontRate 1.0
// Adjust based only on stim 0
- (void)stimulus:(NSData *)eventData eventTime:(NSNumber *)eventTime;
{
float firingRateHz;
StimDesc *pSD = (StimDesc *)[eventData bytes];
if (pSD->gaborIndex != kMapGabor1) {
return; // do nothing with the task stimuli
}
firingRateHz = kMaxRate;
firingRateHz *= (fabs(pSD->directionDeg - 90.0) < 45.0) ? 1.0 : 0.5;
firingRateHz *= (fabs(fabs(pSD->azimuthDeg) - 5.0) < 2.5) ? 1.0 : 0.5;
firingRateHz *= (fabs(fabs(pSD->elevationDeg) - 5.0) < 2.5) ? 1.0 : 0.5;
firingRateHz *= (fabs(pSD->spatialFreqCPD - 1.0) < 0.5) ? 1.0 : 0.5;
firingRateHz *= (fabs(pSD->sigmaDeg - 0.5) < 0.25) ? 1.0 : 0.5;
[[task synthDataDevice] setSpikeRateHz:firingRateHz atTime:[LLSystemUtil getTimeS]];
}
- (void) stimulusOff:(NSData *)eventData eventTime:(NSNumber *)eventTime;
{
[[task synthDataDevice] setSpikeRateHz:kSpontRate atTime:[LLSystemUtil getTimeS]];
}
- (void) tries:(NSData *)eventData eventTime:(NSNumber *)eventTime {
long tries;
[eventData getBytes:&tries];
}
@end