RSS

(root)/iphone/tappity : 49 : tappity/source/TappityClient.m

To get this branch, use:
bzr branch /browse/iphone/tappity

« back to all changes in this revision

Viewing changes to tappity/source/TappityClient.m

Dömötör Gulyás
2009-10-28 22:34:56
Revision ID: dognotdog@gmail.com-20091028213456-9pjbddhboknsf5w8
tappity now no longer eating some events

Show diffs side-by-side

added added

removed removed

15
15
#include <netinet/in.h>
16
16
#include <sys/time.h>
17
17
 
 
18
#import <CoreLocation/CoreLocation.h>
 
19
 
18
20
@implementation TappityClient
19
21
 
20
22
- (id) init
24
26
        
25
27
        receiveDataOnMainThread = NO;
26
28
        
 
29
        enableFeedbackVideoDisplay = YES;
 
30
 
27
31
        return self;
28
32
}
29
33
 
30
 
- (void) runThreadWithSelector: (SEL) selector
31
 
{
32
 
        @synchronized(self)
33
 
        {
34
 
                if (!activeThreads)
35
 
                        activeThreads = [[NSMutableDictionary alloc] init];
36
 
                id number = [NSNumber numberWithInt: threadIds++];
37
 
 
38
 
                [activeThreads setObject: [NSNumber numberWithBool: YES] forKey: number];
39
 
                [NSThread detachNewThreadSelector: selector toTarget: self withObject: [number retain]];
40
 
        }
41
 
}
42
 
 
43
34
 
44
35
- (void) connectToService: (NSNetService*) service
45
36
{
108
99
        [self runThreadWithSelector: @selector(sendingThread:)];
109
100
        [self runThreadWithSelector: @selector(receivingThread:)];
110
101
        
111
 
 
112
 
        UIAccelerometer* accm = [UIAccelerometer sharedAccelerometer];
113
 
        
114
 
        //[accm setDelegate: self];
115
 
        //[accm setUpdateInterval: 0.01];
116
 
 
 
102
        [self performSelectorOnMainThread: @selector(enableSensors) withObject: self waitUntilDone: NO];
 
103
 
 
104
}
 
105
 
 
106
 
 
107
- (void) enableSensors
 
108
{
 
109
        
 
110
        if (enableAccelerometer)
 
111
        {
 
112
                UIAccelerometer* accm = [UIAccelerometer sharedAccelerometer];
 
113
                [accm setDelegate: self];
 
114
                [accm setUpdateInterval: 0.02];
 
115
        }
 
116
        if (enableLocation)
 
117
        {
 
118
                CLLocationManager* lm = [[CLLocationManager alloc] init];
 
119
                [lm setDelegate: self];
 
120
                [lm setDistanceFilter: kCLDistanceFilterNone];
 
121
                [lm setDesiredAccuracy: kCLLocationAccuracyBest];
 
122
                [lm startUpdatingLocation];
 
123
        }
 
124
        if (enableCompass)
 
125
        {
 
126
                CLLocationManager* lm = [[CLLocationManager alloc] init];
 
127
                [lm setDelegate: self];
 
128
                [lm setHeadingFilter: kCLHeadingFilterNone];
 
129
                [lm startUpdatingHeading];
 
130
        }
 
131
}
 
132
 
 
133
- (void)locationManager:(CLLocationManager *)manager
 
134
        didUpdateToLocation:(CLLocation *)newLoc
 
135
        fromLocation:(CLLocation *)oldLocation
 
136
{
 
137
        NSMutableDictionary* touchDict = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: kTapLocation], TapIdKey, nil];
 
138
 
 
139
/*
 
140
        NSArray* ary = [NSArray arrayWithObjects:
 
141
                [NSNumber numberWithDouble: [newLoc coordinate].longitude],
 
142
                [NSNumber numberWithDouble: [newLoc coordinate].latitude],
 
143
                [NSNumber numberWithDouble: [newLoc altitude]],
 
144
                [NSNumber numberWithDouble: [newLoc horizontalAccuracy]],
 
145
                [NSNumber numberWithDouble: [newLoc verticalAccuracy]],
 
146
                [NSNumber numberWithDouble: [newLoc course]],
 
147
                [NSNumber numberWithDouble: [newLoc speed]],
 
148
                nil];
 
149
*/
 
150
        [touchDict setObject: [NSKeyedArchiver archivedDataWithRootObject: newLoc] forKey: TapLocationKey];
 
151
 
 
152
        NSData* data = [NSPropertyListSerialization dataFromPropertyList: touchDict format: NSPropertyListBinaryFormat_v1_0 errorDescription: nil];
 
153
        assert(data);
 
154
 
 
155
        [self sendData: data];
 
156
        
 
157
}
 
158
 
 
159
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)heading
 
160
{
 
161
        NSMutableDictionary* touchDict = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: kTapCompass], TapIdKey, nil];
 
162
 
 
163
/*
 
164
        NSArray* ary = [NSArray arrayWithObjects: [NSNumber numberWithDouble: [heading x]], [NSNumber numberWithDouble: [heading y]], [NSNumber numberWithDouble: [heading z]], [NSNumber numberWithDouble: [heading magneticHeading]], [NSNumber numberWithDouble: [heading trueHeading]], [NSNumber numberWithDouble: [heading headingAccuracy]], nil];
 
165
 
 
166
        [touchDict setObject: ary forKey: TapCompassKey];
 
167
*/
 
168
        [touchDict setObject: [NSKeyedArchiver archivedDataWithRootObject: heading] forKey: TapCompassKey];
 
169
 
 
170
        NSData* data = [NSPropertyListSerialization dataFromPropertyList: touchDict format: NSPropertyListBinaryFormat_v1_0 errorDescription: nil];
 
171
        assert(data);
 
172
 
 
173
        [self sendData: data];
117
174
}
118
175
 
119
176
- (void) accelerometer: (UIAccelerometer *) accelerometer didAccelerate: (UIAcceleration*) acceleration
178
235
        memcpy(buf, &v, 4);
179
236
        return 4;
180
237
}
181
 
 
 
238
/*
182
239
static size_t _write_gspoint(void* buf, GSTouchPointRef p)
183
240
{
184
241
        size_t bc = 0;
192
249
        
193
250
        return bc;
194
251
}
195
 
 
 
252
*/
196
253
/*
197
254
- (id) plistWithTouches: (NSSet*) touches
198
255
{
214
271
- (void) sendTouch: (UIEvent*) event inPhase: (int) phase
215
272
{
216
273
        return;
 
274
/*
217
275
        NSMutableDictionary* touchDict = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: kTapTouchEvent], TapIdKey, nil];
218
276
 
219
277
//      [touchDict setObject: [self touchesAsPlist: [event allTouches]] forKey: TapTouchesKey];
259
317
        NSData* data = [NSPropertyListSerialization dataFromPropertyList: touchDict format: NSPropertyListBinaryFormat_v1_0 errorDescription: nil];
260
318
        assert(data);
261
319
        [self sendData: data];
262
 
 
 
320
*/
263
321
}
264
322
 
265
323
- (void) dataReceived: (NSData*) data
266
324
{
 
325
        if (!enableFeedbackVideoDisplay)
 
326
                return;
 
327
 
267
328
        UIImage* img = [UIImage imageWithData: data];
268
329
//      NSLog(@"got image %@", img);
269
330
 
284
345
        [super dealloc];
285
346
}
286
347
 
287
 
@synthesize delegate;
 
348
@synthesize delegate, enableAccelerometer, enableCompass, enableLocation, enableFeedbackVideoDisplay;
288
349
 
289
350
@end

Loggerhead 1.17 is a web-based interface for Bazaar branches