Example #1
0
//Waits for a connection from a psp:
void doServer()
{
    int skip = 0;
	int quit = 0;
	char message[100] = "";
	int dialog = OSL_DIALOG_NONE;
	int connected = 0;

	int init = oslAdhocInit("ULUS99999");
	if (init)
	{
		snprintf(message, sizeof(message), "adhocInit error: %i", init);
		oslMessageBox(message, "Debug",  oslMake3Buttons(OSL_KEY_CROSS, OSL_MB_OK , 0, 0, 0, 0));
		return;
	}

    while(!osl_quit && !quit){
		struct remotePsp *reqPsp = oslAdhocGetConnectionRequest();

        if (!skip){
            oslStartDrawing();

			printInfo();
			oslDrawString(10, 40, "Press O to abort");
			if (reqPsp == NULL)
			{
				oslDrawString(10, 100, "Waiting for a connection request...");
			}
			else
			{
				snprintf(message, sizeof(message), "Accept request from psp : %s", reqPsp->name);
				oslDrawString(10, 100, message);
				if (oslGetDialogType() == OSL_DIALOG_NONE)
					oslInitMessageDialog(message, 1);
			}

            dialog = oslGetDialogType();
            if (dialog){
                oslDrawDialog();
                if (oslGetDialogStatus() == PSP_UTILITY_DIALOG_NONE){
                    if (dialog == OSL_DIALOG_MESSAGE){
                        int button = oslGetDialogButtonPressed();
                        if (button == PSP_UTILITY_MSGDIALOG_RESULT_YES)
						{
							oslAdhocAcceptConnection(reqPsp);
							connected = 1;
						}
                        else if (button == PSP_UTILITY_MSGDIALOG_RESULT_NO)
						{
							oslAdhocRejectConnection(reqPsp);
						}
                    }
                    oslEndDialog();
                }
			}

            oslEndDrawing();
        }
        oslEndFrame();
        skip = oslSyncFrame();

		if (connected)
			serverConnected(reqPsp);

		oslReadKeys();
		if (dialog == OSL_DIALOG_NONE)
		{
			if (osl_keys->released.circle)
			{
				quit = 1;
			}
		}
	}
	oslAdhocTerm();
}
Example #2
0
void Menu(){
    static char message[100] = "";
    static int dialog = OSL_DIALOG_NONE;

    dialog = oslGetDialogType();
    if (dialog){
        oslDrawDialog();
        if (oslGetDialogStatus() == PSP_UTILITY_DIALOG_NONE){
            if (oslDialogGetResult() == OSL_DIALOG_CANCEL)
                sprintf(message, "Cancel");
            else if (dialog == OSL_DIALOG_MESSAGE){
                int button = oslGetDialogButtonPressed();
                if (button == PSP_UTILITY_MSGDIALOG_RESULT_YES)
                    sprintf(message, "You pressed YES");
                else if (button == PSP_UTILITY_MSGDIALOG_RESULT_NO)
                    sprintf(message, "You pressed NO");
                else sprintf(message, "IDK what was pressed");
			}
            oslEndDialog();
        }
    }
    if (dialog == OSL_DIALOG_NONE){
        //oslReadKeys();
        if (osl_pad.held.triangle && osl_pad.held.down){
            runningFlag = 0;
        }else if (osl_pad.pressed.square){
            //oslInitMessageDialog("Test message dialog", 1);
            //memset(message, 0, sizeof(message));
            oslInitNetDialog();
            oslDialogDrawAndWait(OSL_DIALOG_NETCONF);
            HRESULT=oslDialogGetResult();
            if (HRESULT==OSL_DIALOG_CANCEL) {
            	sprintf(message, "Connection canceled(%d)",HRESULT);}
            	else {
            	sprintf(message, "Connection OK(%d)",HRESULT);
    			Connected = 1;
    			showjoypad=1;showfire=1;
    			drawMenu=0;
                snprintf(netbuf,1024,"AT*COMWDG=%d%c",AT_SEQ++,CR);//XY
    			sendto(DroneUdp, netbuf, strlen(netbuf), 0, (struct sockaddr*)&dest, sizeof(dest));
    		    //Connected = oslNetSocketConnect(DroneSck, DRONE_IP, FTP_PORT);//For V1 TCP?
    		    //sprintf(message, "Connect: %d",Connected);
				//HResult = oslNetSocketSend(DroneSck, "TEST", 4);
            }
            oslEndDialog();
            //memset(message, 0, sizeof(message));
        }else if (osl_pad.pressed.start){
			drawMenu=0;
        }else if (osl_pad.pressed.select){
            //oslInitErrorDialog(0x80020001);
            //memset(message, 0, sizeof(message));
			snprintf(netbuf,1024,"AT*REF=%d,%d%c",AT_SEQ++,AT_REF|256,CR);//NO EMERGENCY
			sendto(DroneUdp, netbuf, strlen(netbuf), 0, (struct sockaddr*)&dest, sizeof(dest));
		}else if (osl_pad.held.up && osl_pad.held.cross){
			runningFlag=0;
		}else if (osl_pad.pressed.up){
			if (mscale<1) mscale=mscale+0.05;
		}else if (osl_pad.pressed.down){
			if (mscale>0) mscale=mscale-0.05;
		}else if (osl_pad.pressed.left){
			snprintf(netbuf,1024,"AT*LED=%d,%d,%d,2%c",AT_SEQ++,LedAnim++,LedAnimFreq.i,CR);
			sendto(DroneUdp, netbuf, strlen(netbuf), 0, (struct sockaddr*)&dest, sizeof(dest));
			if (LedAnim == ARDRONE_LED_NB_ANIMATION) LedAnim=0;
			//Drone.AddCmd "AT*LED=", CStr(Seq) & "," & CStr(Single2Long(2)) & ",2" vbcode
		}else if (osl_pad.pressed.right){
			snprintf(netbuf,1024,"AT*ANIM=%d,%d,%d%c",AT_SEQ++,MoveAnim,MAYDAY_TIMEOUT[MoveAnim],CR);
			MoveAnim++;
			sendto(DroneUdp, netbuf, strlen(netbuf), 0, (struct sockaddr*)&dest, sizeof(dest));
			if (MoveAnim == ARDRONE_NB_ANIM_MAYDAY) MoveAnim=0;
		}
        oslDrawString(30, 50, "[] - Connect to ARDrone");
        oslDrawStringf(30, 70, "Left - LED animation %d/%d",LedAnim,ARDRONE_LED_NB_ANIMATION);
        oslDrawStringf(30, 90, "Right - Move animation %d/%d",MoveAnim,ARDRONE_NB_ANIM_MAYDAY);
        oslDrawString(30, 110, "Up/Down Change mov. scale");
        oslDrawString(30, 130, "Select - Emergency cutoff");
        oslDrawString(30, 150, "Start - Exit menu");
        oslDrawString(30, 170, "Up+X - Exit program");

        oslDrawString(30, 200, message);

    }

}