~ubuntu-branches/debian/experimental/gpac/experimental

« back to all changes in this revision

Viewing changes to modules/ios_mpegv/SensorAcces.m

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2014-02-22 18:15:00 UTC
  • mfrom: (1.2.2) (3.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140222181500-b4phupo05gjpmopa
Tags: 0.5.0+svn5104~dfsg1-1
* New  upstream version 0.5.0+svn5104~dfsg1:
  - src/utils/sha1.c is relicensed under LGPLv2.1, Closes: #730759
* Don't install modules in multi-arch directories, Closes: #730497
* Add libusb-1.0.0-dev headers because libfreenect requires this
* Fix install rule
* Follow upstream soname bump
  - Drop the symbols file for now until it has been revised thourougly
* Let binaries produce the correct svn revision
* Refresh patches
* Patch and build against libav10, Closes: #739321
* Bump standards version, no changes necessary

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
//  ios_mpegv.m
 
3
//  ios_mpegv
 
4
//
 
5
//  Created by mac on 3/8/13.
 
6
//
 
7
//
 
8
 
 
9
#import "SensorAccess.h"
 
10
 
 
11
@implementation SensorAccess
 
12
 
 
13
- (id)init {
 
14
        if ((self = [super init])) {
 
15
        @autoreleasepool {
 
16
            self.motionManager = [[[CMMotionManager alloc] init] autorelease];
 
17
            self.queue = [[[NSOperationQueue alloc] init] autorelease];
 
18
            
 
19
            self.locMngr = [[[CLLocationManager alloc] init] autorelease];
 
20
            self.locMngr.delegate = self;
 
21
            self.locMngr.desiredAccuracy = kCLLocationAccuracyBest;
 
22
            self.locMngr.distanceFilter = 2;
 
23
            
 
24
            sensorCallbak = NULL;
 
25
            userData = NULL;
 
26
            sensorType = -1;
 
27
            gpsActive = 0;
 
28
        }
 
29
        }
 
30
        return self;
 
31
}
 
32
 
 
33
- (void)dealloc{
 
34
    self.locMngr.delegate = NULL;
 
35
    [super dealloc];
 
36
}
 
37
 
 
38
- (int) setSensorType :(int) type
 
39
{
 
40
    sensorType = type;
 
41
    return 0;
 
42
}
 
43
 
 
44
- (int) getSensorType
 
45
{
 
46
    return sensorType;
 
47
}
 
48
 
 
49
- (int) setSensorCallback:(SensorDataCallback*)callback :(void*)user
 
50
{
 
51
    sensorCallbak = callback;
 
52
    userData = user;
 
53
    return 0;
 
54
}
 
55
 
 
56
- (int) startSensor
 
57
{
 
58
    switch (sensorType) {
 
59
        case SENSOR_ACCELEROMETER:
 
60
            if ( ![[self motionManager] isAccelerometerAvailable] )
 
61
                return 1;
 
62
            [[self motionManager] startAccelerometerUpdatesToQueue:[self queue] withHandler:^(CMAccelerometerData* data, NSError* error) {
 
63
                    if ( sensorCallbak ) {
 
64
                        char cdata[100];
 
65
                        sprintf(cdata, "%f;%f;%f;", data.acceleration.x, data.acceleration.y, data.acceleration.z);
 
66
                        sensorCallbak(userData, cdata);
 
67
                    }
 
68
                }
 
69
             ];
 
70
            return 0;
 
71
            break;
 
72
        case SENSOR_GYROSCOPE:
 
73
            if ( ![[self motionManager] isGyroAvailable] )
 
74
                return 1;
 
75
            [[self motionManager] startGyroUpdatesToQueue:[self queue] withHandler:^(CMGyroData* data, NSError* error) {
 
76
                if ( sensorCallbak ) {
 
77
                    char cdata[100];
 
78
                    sprintf(cdata, "%f;%f;%f;", data.rotationRate.x, data.rotationRate.y, data.rotationRate.z);
 
79
                    sensorCallbak(userData, cdata);
 
80
                }
 
81
            }
 
82
             ];
 
83
            return 0;
 
84
            break;
 
85
        case SENSOR_MAGNETOMETER:
 
86
            if ( ![[self motionManager] isMagnetometerAvailable] )
 
87
                return 1;
 
88
            [[self motionManager] startMagnetometerUpdatesToQueue:[self queue] withHandler:^(CMMagnetometerData* data, NSError* error) {
 
89
                if ( sensorCallbak ) {
 
90
                    char cdata[100];
 
91
                    sprintf(cdata, "%f;%f;%f;", data.magneticField.x, data.magneticField.y, data.magneticField.z);
 
92
                    sensorCallbak(userData, cdata);
 
93
                }
 
94
            }
 
95
             ];
 
96
            return 0;
 
97
            break;
 
98
        case SENSOR_GPS:
 
99
            [self.locMngr startUpdatingLocation];
 
100
            gpsActive = 1;
 
101
            return 0;
 
102
            break;
 
103
    }
 
104
 
 
105
    return 1;
 
106
}
 
107
 
 
108
- (int) stopSensor
 
109
{
 
110
    switch (sensorType) {
 
111
        case SENSOR_ACCELEROMETER:
 
112
            [[self motionManager] stopAccelerometerUpdates];
 
113
            return 0;
 
114
            break;
 
115
        case SENSOR_GYROSCOPE:
 
116
            [[self motionManager] stopGyroUpdates];
 
117
            return 0;
 
118
            break;
 
119
        case SENSOR_MAGNETOMETER:
 
120
            [[self motionManager] stopMagnetometerUpdates];
 
121
            return 0;
 
122
        case SENSOR_GPS:
 
123
            [self.locMngr stopUpdatingLocation];
 
124
            gpsActive = 0;
 
125
            return 0;
 
126
            break;
 
127
    }
 
128
    return 1;
 
129
}
 
130
 
 
131
- (int) isSensorStarted
 
132
{
 
133
    switch (sensorType) {
 
134
        case SENSOR_ACCELEROMETER:
 
135
            return [[self motionManager] isAccelerometerActive];
 
136
            break;
 
137
        case SENSOR_GYROSCOPE:
 
138
            return [[self motionManager] isGyroActive];
 
139
            break;
 
140
        case SENSOR_MAGNETOMETER:
 
141
            return [[self motionManager] isMagnetometerActive];
 
142
        case SENSOR_GPS:
 
143
            return gpsActive;
 
144
            break;
 
145
    }
 
146
    return 0;
 
147
}
 
148
 
 
149
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)location fromLocation:(CLLocation *)oldLocation {
 
150
    char cdata[100];
 
151
    sprintf(cdata, "%f;%f;%f;%f;%f;", (float)location.coordinate.latitude, (float)location.coordinate.longitude, (float)location.altitude,
 
152
            (float)location.horizontalAccuracy, 0.f);
 
153
    sensorCallbak(userData, cdata);
 
154
}
 
155
 
 
156
@end
 
157
 
 
158
void* SENS_CreateInstance() {
 
159
    void* obj = [[SensorAccess alloc] init];
 
160
    return obj;
 
161
}
 
162
 
 
163
int SENS_DestroyInstance(void** inst) {
 
164
    [(id)*inst dealloc];
 
165
    *inst = NULL;
 
166
    return 0;
 
167
}
 
168
 
 
169
int SENS_SetSensorType(void* inst, int type) {
 
170
    if ( !inst )
 
171
        return 1;
 
172
    
 
173
    return [(id)inst setSensorType:type];
 
174
}
 
175
 
 
176
int SENS_GetCurrentSensorType(void* inst) {
 
177
    if ( !inst )
 
178
        return 1;
 
179
    
 
180
    return [(id)inst getSensorType];
 
181
}
 
182
 
 
183
int SENS_Start(void* inst) {
 
184
    if ( !inst )
 
185
        return 1;
 
186
    
 
187
    return [(id)inst startSensor];
 
188
}
 
189
 
 
190
int SENS_Stop(void* inst) {
 
191
    if ( !inst )
 
192
        return 1;
 
193
    
 
194
    return [(id)inst stopSensor];
 
195
}
 
196
 
 
197
int SENS_IsStarted(void* inst) {
 
198
    if ( !inst )
 
199
        return 1;
 
200
    
 
201
    return [(id)inst isSensorStarted];
 
202
}
 
203
 
 
204
int SENS_SetCallback(void* inst, SensorDataCallback *callback, void* user) {
 
205
    if ( !inst )
 
206
        return 1;
 
207
    
 
208
    return [(id)inst setSensorCallback:callback :user];
 
209
}