forked from tidev/titanium-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccelerometerModule.m
46 lines (36 loc) · 1.15 KB
/
AccelerometerModule.m
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
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#ifdef USE_TI_ACCELEROMETER
#import "AccelerometerModule.h"
@implementation AccelerometerModule
-(void)_listenerAdded:(NSString *)type count:(int)count
{
if (count == 1 && [type isEqualToString:@"update"])
{
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
}
}
-(void)_listenerRemoved:(NSString *)type count:(int)count
{
if (count == 0 && [type isEqualToString:@"update"])
{
[[UIAccelerometer sharedAccelerometer] setDelegate:nil];
}
}
#pragma mark Accelerometer Delegate
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
NSDictionary *event = [NSDictionary dictionaryWithObjectsAndKeys:
NUMFLOAT([acceleration x]), @"x",
NUMFLOAT([acceleration y]), @"y",
NUMFLOAT([acceleration z]), @"z",
NUMLONGLONG([acceleration timestamp] * 1000), @"timestamp",
nil];
[self fireEvent:@"update" withObject:event];
}
@end
#endif