Example #1
0
def get_pressure():
    def handler(_cmd, _data, _error):
        global pressure
        pressure = ObjCInstance(_data).pressure()

    handler_block = ObjCBlock(handler,
                              restype=None,
                              argtypes=[c_void_p, c_void_p, c_void_p])

    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)
    #print('Started altitude updates.')
    try:
        while pressure is None:
            pass
    finally:
        altimeter.stopRelativeAltitudeUpdates()
        #print('Updates stopped.')
        return pressure
Example #2
0
def get_pressure():
    ''' Obter a pressão atmosférica do barómetro do próprio dispositivo, se
    existir '''
    def handler(_cmd, _data, _error):
        global pressure
        pressure = ObjCInstance(_data).pressure()

    handler_block = ObjCBlock(handler,
                              restype=None,
                              argtypes=[c_void_p, c_void_p, c_void_p])

    CMAltimeter = ObjCClass('CMAltimeter')
    NSOperationQueue = ObjCClass('NSOperationQueue')
    if not CMAltimeter.isRelativeAltitudeAvailable():
        # print('This device has no barometer.')
        return None
    altimeter = CMAltimeter.new()
    main_q = NSOperationQueue.mainQueue()
    altimeter.startRelativeAltitudeUpdatesToQueue_withHandler_(
        main_q, handler_block)

    try:
        while pressure is None:
            pass
    finally:
        altimeter.stopRelativeAltitudeUpdates()
        return pressure.floatValue() * 7.5006375541921
Example #3
0
def main():
    num_samples = 1000000
    arrayA = []
    arrayM = []
    #arrayG = []
    arrayP = []
    arrayJ = []
    arrayGPS = []  #GPS
    dataArray = []

    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)
    motion.start_updates()
    location.start_updates()  # GPS
    print("Logging start...")
    sleep(1.0)
    for i in range(num_samples):
        sleep(0.05)
        a = motion.get_user_acceleration()
        m = motion.get_magnetic_field()
        j = motion.get_attitude()
        gps = location.get_location()  # GPS
        if a[1] > 0.8:
            break
        dataArray.append([relativeAltitude, a[2], m[0], m[1]])
        arrayA.append(a)
        arrayM.append(m)
        arrayJ.append(j)
        arrayP.append(relativeAltitude)
        arrayGPS.append(gps)  #GPS

    motion.stop_updates()
    location.stop_updates()  # GPS
    altimeter.stopRelativeAltitudeUpdates()
    print("Logging stop and Saving start...")
    import pickle
    f = open('yokohama.serialize', 'wb')
    #pickle.dump([arrayA, arrayM, arrayP],f)
    pickle.dump([arrayA, arrayM, arrayJ, arrayP, arrayGPS], f)  #GPS
    f.close
    print("Saving is finished.")
    x_values = [x * 0.05 for x in range(len(dataArray))]
    for i, color, label in zip(range(3), 'rgb', 'XYZ'):
        plt.plot(x_values, [g[i] for g in arrayM], color, label=label, lw=2)
    plt.grid(True)
    plt.xlabel('t')
    plt.ylabel('G')
    plt.gca().set_ylim([-100, 100])
    plt.legend()
    plt.show()
def main():
	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)
	print('Started altitude updates.')
	try:
		while True:
			pass
	finally:
		altimeter.stopRelativeAltitudeUpdates()
		print('Updates stopped.')