#Event: Update (AltitudeChange As Float, Pressure As Float)
Sub Class_Globals
Private mCallback As Object
Private mEventName As String
Private alt As NativeObject
Private isSupported As Boolean
Public AUTH_NOT_DETERMINED = 0, AUTH_RESTRICTED = 1, AUTH_DENIED = 2, AUTH_AUTHORIZED = 3 As Int
End Sub
Public Sub Initialize (Callback As Object, EventName As String)
mCallback = Callback
mEventName = EventName
alt.Initialize("CMAltimeter")
isSupported = alt.RunMethod("isRelativeAltitudeAvailable", Null).AsBoolean
If isSupported Then
alt = alt.RunMethod("new", Null)
End If
End Sub
Public Sub getAuthorizationStatus As Int
Dim no As NativeObject
Return no.Initialize("CMAltimeter").GetField("authorizationStatus").AsNumber
End Sub
Public Sub getSupported As Boolean
Return isSupported
End Sub
Public Sub Start
Dim no As NativeObject = Me
no.RunMethod("startNative:", Array(alt))
End Sub
Private Sub Event_Handler(altitude As Float, pressure As Float)
CallSub3(mCallback, mEventName & "_update", altitude, pressure)
End Sub
#if OBJC
- (void) startNative:(CMAltimeter*)alt {
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[alt startRelativeAltitudeUpdatesToQueue:queue withHandler:^(CMAltitudeData *altitudeData, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^ {
if (error != nil) {
NSLog(@"Altimeter error: %@", error);
} else {
[self.bi raiseEvent:nil event:@"event_handler::" params:@[altitudeData.relativeAltitude, altitudeData.pressure]];
}
});
}];
}
#end if