Exemplo n.º 1
0
FREObject saveToCameraRoll(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
    uint32_t name_size = 0;
    const uint8_t* name_val = NULL;
    
    FREGetObjectAsUTF8(argv[0], &name_size, &name_val);
    
    FREObject objectBA = argv[1];
    FREByteArray baData;
    FREAcquireByteArray(objectBA, &baData);
    uint8_t *ba = baData.bytes;
    
    int32_t _size;
    FREGetObjectAsInt32(argv[2], &_size);
    int32_t _orientation;
    FREGetObjectAsInt32(argv[3], &_orientation);
    
    int32_t res = captureSaveToCameraRoll( (const char *)name_val, (const uint8_t*)ba, _size, _orientation);
    
    FREReleaseByteArray(objectBA);
    
    FREObject res_obj;
    FRENewObjectFromInt32(res, &res_obj);
    
    return res_obj;
}
Exemplo n.º 2
0
	FREObject sendMIDIMessage(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
	{

		
		int pointer = 0;
		int status = 0;
		int data1 = 0;
		int data2 = 0;

		FREGetObjectAsInt32(argv[0],&pointer);
		FREGetObjectAsInt32(argv[1],&status);
		FREGetObjectAsInt32(argv[2],&data1);
		FREGetObjectAsInt32(argv[3],&data2);

		RtMidiOut* out = (RtMidiOut *)pointer;

		//printf("Send Message : %i %i %i %i\n",out,status,data1,data2);
		
		outMessage[0] = (unsigned char)status;
		outMessage[1] = (unsigned char)data1;
		outMessage[2] = (unsigned char)data2;

		bool sendResult = false;
		try
		{
			if(out->isPortOpen()) out->sendMessage(&outMessage);
		}catch(std::exception e)
		{
			printf("Error sending message : %s\n",e.what());
		}

		FREObject result;
		FRENewObjectFromBool(sendResult,&result);
		return result;
	}
Exemplo n.º 3
0
//设置并开启串口_wh
FREObject setupPort(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
	FREObject result;
	int comPortError = 0;
	int useDtrControl;

	FREGetObjectAsInt32(argv[0], &comPort);//从as获取信息_wh
	FREGetObjectAsInt32(argv[1], &baud);
	FREGetObjectAsInt32(argv[2], &useDtrControl);

	bufferSize = 0;

	comPortError = OpenComport(comPort, baud, useDtrControl);
	if (comPortError == 0)
	{
		//pthread_cancel(ptrToThread);//杀掉该线程,以免重新开启串口时之前线程残留_wh
		multiplatformSleep(20);//从100ms减到20ms,与as呼应,避免响应不对应_wh
		pthread_create(&ptrToThread, NULL, pollForData, NULL);
		FRENewObjectFromBool(1, &result);
	}
	else
	{
		FRENewObjectFromBool(0, &result);
	}

	return result;
}
FREObject loadScoresAtRank(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[])
{
	int aRank,aLength;
	FREGetObjectAsInt32(argv[0],&aRank);
	FREGetObjectAsInt32(argv[1],&aLength);
#if defined(BB10)
	SC_ScoresController_LoadScoresAtRank(scores_controller,aRank,aLength);
#else
	SC_ScoresController_LoadRangeAtRank(scores_controller,aRank,aLength);
#endif
	return NULL;
}
Exemplo n.º 5
0
 FREObject LeapNative_frameTranslationProbability(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
     leapnative::LNLeapDevice* device;
     FREGetContextNativeData(ctx, (void **) &device);
     
     int frameId;
     FREGetObjectAsInt32(argv[0], &frameId);
     
     int sinceFrameId;
     FREGetObjectAsInt32(argv[1], &sinceFrameId);
     
     return device->frameProbability(frameId, sinceFrameId, 2);
 }
Exemplo n.º 6
0
FREObject captureAndSaveImage(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
    int32_t id, orientation;
    FREGetObjectAsInt32(argv[0], &id);
    FREGetObjectAsInt32(argv[2], &orientation);

    CCapture* cap;
    cap = active_cams[id];
    
    if(cap) {
        captureAndSave(cap, orientation);
    }
    return NULL;
}
Exemplo n.º 7
0
 FREObject LeapNative_handScaleProbability(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
     leapnative::LNLeapDevice* device;
     FREGetContextNativeData(ctx, (void **) &device);
     
     int handId;
     FREGetObjectAsInt32(argv[0], &handId);
     
     int frameId;
     FREGetObjectAsInt32(argv[1], &frameId);
     
     int sinceFrameId;
     FREGetObjectAsInt32(argv[2], &sinceFrameId);
     
     return device->handProbability(handId, frameId, sinceFrameId, 1);
 }
Exemplo n.º 8
0
    FREObject LeapNative_isGestureEnabled(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
        leapnative::LNLeapDevice* device;
        FREGetContextNativeData(ctx, (void **) &device);
        
        int gestureClassType;
        FREGetObjectAsInt32(argv[0], &gestureClassType);
        
        bool gestureEnabled;

        switch (gestureClassType) {
            case 5:
                gestureEnabled = device->controller->isGestureEnabled(Gesture::TYPE_SWIPE);
                break;
            case 6:
                gestureEnabled = device->controller->isGestureEnabled(Gesture::TYPE_CIRCLE);
                break;
            case 7:
                gestureEnabled = device->controller->isGestureEnabled(Gesture::TYPE_SCREEN_TAP);
                break;
            case 8:
                gestureEnabled = device->controller->isGestureEnabled(Gesture::TYPE_KEY_TAP);
                break;
            default:
                std::cout << "LeapNative_isGestureEnabled: invalid argument" << std::endl;
                gestureEnabled = false;
                break;
        }
        
        return createFREObjectForBool(gestureEnabled);
    }
Exemplo n.º 9
0
 FREObject LeapNative_enableGesture(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
     leapnative::LNLeapDevice* device;
     FREGetContextNativeData(ctx, (void **) &device);
     
     int gestureClassType;
     FREGetObjectAsInt32(argv[0], &gestureClassType);
     
     bool gestureEnabled = createBoolFromFREObject(argv[1]);
     
     std::cout << "LeapNative_enableGesture called: " << gestureClassType << std::endl;
     
     switch (gestureClassType) {
         case 5:
             device->controller->enableGesture(Gesture::TYPE_SWIPE, gestureEnabled);
             break;
         case 6:
             device->controller->enableGesture(Gesture::TYPE_CIRCLE, gestureEnabled);
             break;
         case 7:
             device->controller->enableGesture(Gesture::TYPE_SCREEN_TAP, gestureEnabled);
             break;
         case 8:
             device->controller->enableGesture(Gesture::TYPE_KEY_TAP, gestureEnabled);
             break;
         default:
             std::cout << "LeapNative_enableGesture: invalid argument" << std::endl;
             break;
     }
     return NULL;
 }
Exemplo n.º 10
0
 FREObject LeapNative_getScreenProject(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
     leapnative::LNLeapDevice* device;
     FREGetContextNativeData(ctx, (void **) &device);
     
     int screenId;
     FREGetObjectAsInt32(argv[0], &screenId);
     
     double pX;
     FREGetObjectAsDouble(argv[1], &pX);
     
     double pY;
     FREGetObjectAsDouble(argv[2], &pY);
     
     double pZ;
     FREGetObjectAsDouble(argv[3], &pZ);
     
     bool normalize = createBoolFromFREObject(argv[4]);
     
     double clampRatio;
     FREGetObjectAsDouble(argv[5], &clampRatio);
     
     Vector position = Vector((float) pX, (float) pY, (float) pZ);
     
     return device->getScreenProject(screenId, position, normalize, (float) clampRatio);
 }
FREObject loadScores(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[])
{
	FREObject start=0,length=0;
	int aStart=0,aLength=0;
	FREGetObjectProperty(argv[0],(const uint8_t*)"start",start,NULL);
	FREGetObjectProperty(argv[0],(const uint8_t*)"length",length,NULL);
	FREGetObjectAsInt32(start,&aStart);
	FREGetObjectAsInt32(length,&aLength);
#if defined(BB10)
	SC_Range_t aRange = {aStart,aLength};
	SC_ScoresController_LoadScores(scores_controller,aRange); // TODO: This is different in bb10, there is a range object
#else
	SC_ScoresController_LoadRange(scores_controller,aStart,aLength);
#endif
	return NULL;
}
FREObject setSearchList(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[])
{
	int aSearchList;
	FREGetObjectAsInt32(argv[0],&aSearchList);
	switch(aSearchList)
	{
	case 0:
#if defined(BB10)
		SC_ScoresController_SetSearchList(scores_controller, SC_SCORES_SEARCH_LIST_ALL);
#else
		SC_ScoresController_SetSearchList(scores_controller, SC_SCORE_SEARCH_LIST_GLOBAL);
#endif
		break;
	case 1:
#if defined(BB10)
		SC_ScoresController_SetSearchList(scores_controller, SC_SCORES_SEARCH_LIST_24H);
#else
		SC_ScoresController_SetSearchList(scores_controller, SC_SCORE_SEARCH_LIST_24H);
#endif
		break;
	case 2:
#if defined(BB10)
		SC_ScoresController_SetSearchList(scores_controller, SC_SCORES_SEARCH_LIST_USER_COUNTRY);
#else
		SC_ScoresController_SetSearchList(scores_controller, SC_SCORE_SEARCH_LIST_USER_COUNTRY);
#endif
		break;
	default:
	    fprintf(stderr, "Invalid  searchlist value: %d\n", aSearchList);
	    break;
	}
	return NULL;
}
Exemplo n.º 13
0
	FREObject openOutputDevice(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
	{
		int index = 0;
		FREGetObjectAsInt32(argv[0],&index);

		//printf("Native MIDI :: open output device %i\n",index);

		int pointer = -1;
		
		try {
			RtMidiOut* out = new RtMidiOut();
			out->openPort(index);
			openMidiOut.push_back(out);

			pointer = (int)out;
			//printf("Open midi pointer : %i\n",pointer);
			// Don't ignore sysex, timing, or active sensing messages.

		}
		catch ( RtMidiError &error ) {
			error.printMessage();
		}	

		FREObject result;
		FRENewObjectFromInt32(pointer,&result);
		return result;
	}
Exemplo n.º 14
0
	FREObject openInputDevice(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
	{
		
		int index = 0;
		FREGetObjectAsInt32(argv[0],&index);

		//printf("Native MIDI :: open input device %i\n",index);
		
		int pointer = -1;
		try {
			RtMidiIn* in = new RtMidiIn();
			in->openPort(index);
			openMidiIn.push_back(in);

			pointer = (int)in;
			printf("Open midi pointer : %i (%s), num open devices :  %i\n",pointer,in->getPortName(index).c_str(),openMidiIn.size());
			// Don't ignore sysex, timing, or active sensing messages.
			midiin->ignoreTypes( false, false, false );

		}
		catch ( RtMidiError &error ) {
			error.printMessage();
		}		
		
		FREObject result;
		FRENewObjectFromInt32(pointer,&result);
		return result;
	}
Exemplo n.º 15
0
//检测当前串口是否可用,修改了原先功能_wh
FREObject isSupported(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
	HANDLE hCom;
	int32_t comPort_t;
	char  cPortName[11];
	FREObject result;
	FREGetObjectAsInt32(argv[0], &comPort_t);//从as获取信息_wh
	sprintf(cPortName, "\\\\.\\COM%i", comPort_t);
	hCom = CreateFileA(cPortName,
		GENERIC_READ | GENERIC_WRITE,
		0,                          /* no share  */
		NULL,                       /* no security */
		OPEN_EXISTING,
		0,                          /* no threads */
		NULL);                      /* no templates */;
	if (hCom == INVALID_HANDLE_VALUE)
	{
		FRENewObjectFromBool(0, &result);
	}
	else
	{
		FRENewObjectFromBool(1, &result);
		CloseHandle(hCom);
		hCom = INVALID_HANDLE_VALUE;
	}
	return result;
}
Exemplo n.º 16
0
FREObject setFlashMode(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
    int32_t id;
    int32_t mode;
    FREGetObjectAsInt32(argv[0], &id);
    FREGetObjectAsInt32(argv[1], &mode);
    
    CCapture *cap;
    cap = active_cams[id];
    
    if (cap)
    {
        captureSetFlashMode(cap, mode);
    }
    return NULL;
}
	FREObject setMousePosition(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
	{
		//AS3傳來的參數會存在argv[]裡
		int32_t x, y;

		//將AS3數據轉成C++
		FREGetObjectAsInt32(argv[0], &x);
		FREGetObjectAsInt32(argv[1], &y);

		//設定系統的座標,為Windows.h裡的方法
		SetCursorPos(x, y);

		//如果不在意回傳數值就回傳第一個參數
		//如果需要回傳經計算過的數值請記得利用FRE Object轉成AS3看得懂的數據
		return argv[0];
	}
FREObject setMode(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[])
{

	int aMode = 0;
	FREGetObjectAsInt32(argv[0],&aMode);
	SC_ScoresController_SetMode(scores_controller, aMode);
	return NULL;
}
Exemplo n.º 19
0
 FREObject LeapNative_getClosestScreenHitPointable(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
     leapnative::LNLeapDevice* device;
     FREGetContextNativeData(ctx, (void **) &device);
     
     int pointableId;
     FREGetObjectAsInt32(argv[0], &pointableId);
     
     return device->getClosestScreenHitPointable(pointableId);
 }
	FREObject keyDown(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
	{
		//觸發鍵盤事件
		int32_t keyNum;
		FREGetObjectAsInt32(argv[0], &keyNum);

		keybd_event(keyNum, 0, 0, 0);
		return argv[0];
	}
Exemplo n.º 21
0
 FREObject LeapNative_getScreenNormal(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
     leapnative::LNLeapDevice* device;
     FREGetContextNativeData(ctx, (void **) &device);
     
     int screenId;
     FREGetObjectAsInt32(argv[0], &screenId);
     
     return device->getScreenNormal(screenId);
 }
Exemplo n.º 22
0
FREObject setCursorPos(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
    int tx = 0;
    int ty = 0;
    FREGetObjectAsInt32(argv[0], &tx);
    FREGetObjectAsInt32(argv[1], &ty);

    //as3Print("Set cursor pos \n");//,tx,ty);

    CGPoint point;
    point.x = tx;
    point.y = ty;

    CGAssociateMouseAndMouseCursorPosition(true);
    
    //CGWarpMouseCursorPosition(point);
   // printf("Error : %i\n",error);
    CGDisplayMoveCursorToPoint(CGMainDisplayID(),point);

    CGAssociateMouseAndMouseCursorPosition(true);
    CGEventRef mouse = CGEventCreateMouseEvent (NULL, kCGEventMouseMoved, CGPointMake(tx, ty),0);
    CGEventPost(kCGHIDEventTap, mouse);
    CFRelease(mouse);
    
    
    CGEventRef event = CGEventCreate(NULL);
    CGPoint cursorGet = CGEventGetLocation(event);
    CFRelease(event);
    
    
    
    char msg[256];
    sprintf(msg,"After set, check pos %f %f\n",cursorGet.x, cursorGet.y);
    //as3Print(msg);
    
    FREObject result;
    FRENewObjectFromBool(1, &result);
    //FRENewObjectFromBool(true,&result);
    return result;
}
Exemplo n.º 23
0
 FREObject myoVibrate(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
     std::cout << "[NATIVE myoVibrate]" << std::endl;
     myonative::MyoDevice* device;
     FREGetContextNativeData(ctx, (void **) &device);
     
     int vibrationType;
     FREGetObjectAsInt32(argv[0], &vibrationType);
     myo::Myo::VibrationType vibrationEnum = static_cast<myo::Myo::VibrationType>(vibrationType);
     
     device->myo->vibrate(vibrationEnum);
     
     return NULL;
 }
Exemplo n.º 24
0
 FREObject hubRun(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
     std::cout << "[NATIVE hubRun]" << std::endl;
     myonative::MyoDevice* device;
     FREGetContextNativeData(ctx, (void **) &device);
     
     int durationMilliseconds;
     FREGetObjectAsInt32(argv[0], &durationMilliseconds);
     
     // Adding native listener
     device->hub->run(durationMilliseconds);
     
     return NULL;
 }
FREObject loadScoresAroundUser(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[])
{
	SC_Session_h session= SC_Client_GetSession(client);
	SC_User_h aUser = SC_Session_GetUser(session);
	int aRange;
	FREGetObjectAsInt32(argv[0],&aRange);
#if defined(BB10)
	SC_ScoresController_LoadScoresAroundUser(scores_controller,aUser,aRange);
#else
	SC_ScoresController_LoadRangeForUser(scores_controller,aUser,aRange);
#endif
	return NULL;
}
Exemplo n.º 26
0
FREObject captureStillImage(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
    int32_t _id;
    FREGetObjectAsInt32(argv[0], &_id);
    
    CCapture* cap;
    cap = active_cams[_id];
    
    if(cap)
    {
        captureGetStillImage(cap, stillImageCallback);
    }
    
    return NULL;
}
Exemplo n.º 27
0
FREObject toggleCapturing(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
    int32_t _id, _opt;
    FREGetObjectAsInt32(argv[0], &_id);
    FREGetObjectAsInt32(argv[1], &_opt);

    CCapture* cap;
    cap = active_cams[_id];

    if(cap)
    {
        if(_opt == 0)
        {
            captureStop(cap);
        }
        else if(_opt == 1)
        {
            // TODO can fail when starting after stop so we need to handle result
            captureStart(cap);
        }
    }

    return NULL;
}
Exemplo n.º 28
0
    //start screen class
    FREObject LeapNative_getScreenDistanceToPoint(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
        leapnative::LNLeapDevice* device;
        FREGetContextNativeData(ctx, (void **) &device);

        int screenId;
        double pX;
        double pY;
        double pZ;
        FREGetObjectAsInt32(argv[0], &screenId);
        FREGetObjectAsDouble(argv[1], &pX);
        FREGetObjectAsDouble(argv[2], &pY);
        FREGetObjectAsDouble(argv[3], &pZ);
        
        Vector point = Vector((float) pX, (float) pY, (float) pZ);

        return device->getScreenDistanceToPoint(screenId, point);
    }
Exemplo n.º 29
0
FREObject getFlashMode(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
    int32_t id;
    FREGetObjectAsInt32(argv[0], &id);
    
    CCapture *cap;
    cap = active_cams[id];
    
    if (cap)
    {
        int32_t mode = (int32_t)captureGetFlashMode(cap);
        FREObject ret;
        FRENewObjectFromInt32(mode, &ret);
        return ret;
    }
    return NULL;
}
Exemplo n.º 30
0
FREObject isAdjustingExposure(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
    int32_t id;
    FREGetObjectAsInt32(argv[0], &id);
    
    CCapture *cap;
    cap = active_cams[id];
    
    if (cap)
    {
        bool exposing = captureIsAdjustingExposure(cap);
        FREObject ret;
        FRENewObjectFromBool(exposing, &ret);
        return ret;
    }
    return NULL;
}