-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaltimeter.py
More file actions
43 lines (36 loc) · 1.26 KB
/
altimeter.py
File metadata and controls
43 lines (36 loc) · 1.26 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
# coding: utf-8
from rubicon.objc import Block, ObjCClass, ObjCInstance, py_from_ns
from rubicon.objc.runtime import objc_id
pressure = None
# solution with @Block
@Block
def handlerb(altitudeData:ObjCInstance, err:ObjCInstance) -> None:
print(ObjCInstance(altitudeData).pressure)
# solution with block() function
#def handler(_data) -> None:
# nspressure = ObjCInstance(_data).pressure
# global pressure
# pressure = py_from_ns(nspressure)
#handler_block = Block(handler, None, (objc_id))
def get_pressure():
CMAltimeter = ObjCClass('CMAltimeter')
NSOperationQueue = ObjCClass('NSOperationQueue')
if not CMAltimeter.isRelativeAltitudeAvailable():
print('This device has no barometer.')
return
altimeter = CMAltimeter.new()
main_q = NSOperationQueue.mainQueue
#altimeter.startRelativeAltitudeUpdatesToQueue_withHandler_(main_q, handler_block)
altimeter.startRelativeAltitudeUpdatesToQueue_withHandler_(main_q, handlerb)
print('Started altitude updates.')
try:
while pressure is None:
pass
finally:
altimeter.stopRelativeAltitudeUpdates()
print('Updates stopped.')
return pressure
if __name__ == '__main__':
result = get_pressure()
print(result)
del pressure