Exemple #1
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
Exemple #2
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
Exemple #3
0
def getNowPlayingInfo():
    e=Event()
    nowPlayingInfo = None
    def info_cb(_blk,info):
        nonlocal nowPlayingInfo
        try:
            if info:
                nowPlayingInfo = nsDicToPyDic(ObjCInstance(info))
        finally:
            e.set()
    cb=ObjCBlock(info_cb,argtypes=[c_void_p,c_void_p], restype=None)
    MRMediaRemoteGetNowPlayingInfo(c.dispatch_get_current_queue(), cb)
    e.wait()
    return nowPlayingInfo
Exemple #4
0
 def __init__(self, argtypes=[c_void_p, c_void_p], restype=None):
     self.block = ObjCBlock(self.handler,
                            argtypes=argtypes,
                            restype=restype)
Exemple #5
0
# Read barometer data, print to the screen
from objc_util import ObjCInstance, ObjCClass, ObjCBlock, c_void_p
from datetime import datetime

logfile = open("homelog", "a")


def handler(_cmd, _data, _error):
    obj = ObjCInstance(_data)
    print(obj)
    logfile.write(str(datetime.now()) + '\t' + str(obj) + '\n')


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


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:
Exemple #6
0
import motion

import location  # GPS

from objc_util import ObjCInstance, ObjCClass, ObjCBlock, c_void_p

relativeAltitude = 0.0


def altimeterHandler(_cmd, _data, _error):
    global relativeAltitude
    relativeAltitude = ObjCInstance(_data).relativeAltitude().floatValue()


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


def main():
    num_samples = 1000000
    arrayA = []
    arrayM = []
    #arrayG = []
    arrayP = []
    arrayJ = []
    arrayGPS = []  #GPS
    dataArray = []

    CMAltimeter = ObjCClass('CMAltimeter')
    NSOperationQueue = ObjCClass('NSOperationQueue')
Exemple #7
0
            return None

    @property
    def album(self):
        pass


def bhandle(_cmd, d):
    global nowplaying
    nowplaying = chandle(d, None, None)


queue = dispatch.dispatch_get_global_queue(0, 0)
MRMediaRemoteGetNowPlayingInfo = c.MRMediaRemoteGetNowPlayingInfo
MRMediaRemoteGetNowPlayingInfo.argtypes = [c_void_p, ObjCBlock]
handler = ObjCBlock(bhandle, argtypes=[c_void_p, c_void_p])


def update_global():
    MRMediaRemoteGetNowPlayingInfo(queue, handler)


def set_route(route, pw):
    MRMediaRemoteSetPickedRouteWithPassword = c.MRMediaRemoteSetPickedRouteWithPassword
    MRMediaRemoteSetPickedRouteWithPassword.argtypes = [c_void_p, c_void_p]
    MRMediaRemoteSetPickedRouteWithPassword(ns(route).ptr, ns(pw).ptr)


def play_pause():
    MRMediaRemoteSendCommand(Commands.TogglePlayPause, c_void_p())
Exemple #8
0
            ns(_dragged_item_path), os.path.isdir(_dragged_item_path))

        _dragged_item_path = None
    else:
        url = None

    if not url:
        error = NSError.errorWithDomain_code_userInfo_(
            'com.robertvojta.blackmamba', 1, None)
        handler(None, None, error)
    else:
        handler(url.ptr, False, None)


_load_data = ObjCBlock(_load_data_imp,
                       restype=ctypes.c_void_p,
                       argtypes=[ctypes.c_void_p, ctypes.c_void_p])


def tableView_itemsForBeginningDragSession_atIndexPath_(
        _self, _cmd, tv_ptr, session_ptr, index_path_ptr):
    global _dragged_item_path

    if not _path_items:
        return ns([]).ptr

    section = ObjCInstance(index_path_ptr).section()
    row = ObjCInstance(index_path_ptr).row()

    if section >= 0 and section < len(_path_items) and row >= 0 and row < len(
            _path_items[section]):
from objc_util import ObjCClass, ObjCBlock, c_void_p, ns, ObjCInstance


def getData(_cmd, pedometerData, error):
    ped = ObjCInstance(pedometerData)

    if not error == None:
        err = ObjCInstance(error)
        print('error====' + str(err))
    else:
        print('Steps====' + str(ped.numberOfSteps()))
        print('Distance====' + str(ped.distance()))


ped_block = ObjCBlock(getData,
                      restype=None,
                      argtypes=[c_void_p, c_void_p, c_void_p])
CMPedometer = ObjCClass('CMPedometer')
NSDate = ObjCClass('NSDate')

ped = CMPedometer.alloc().init()

if CMPedometer.isStepCountingAvailable():
    fromDate = NSDate.dateWithTimeIntervalSinceNow_(-60 * 60 * 24 * 2)
    toDate = NSDate.dateWithTimeIntervalSinceNow_(-60 * 60 * 24 * 1)
    ped.queryPedometerDataFromDate_toDate_withHandler_(ns(fromDate),
                                                       ns(toDate), ped_block)
else:
    print('Unavailable')