示例#1
0
文件: phdcontrol.cpp 项目: rwg0/phd2
bool PhdController::Dither(double pixels, bool raOnly, const SettleParams& settle, wxString *errMsg)
{
    if (ctrl.state != STATE_IDLE)
    {
        Debug.AddLine("PhdController::Dither reentrancy state = %d op = %d", ctrl.state, ctrl.settleOp);
        *errMsg = ReentrancyError("dither");
        return false;
    }

    Debug.AddLine("PhdController::Dither begins");

    bool error = pFrame->Dither(pixels, raOnly);
    if (error)
    {
        Debug.AddLine("PhdController::Dither pFrame->Dither failed");
        *errMsg = _T("Dither error");
        return false;
    }

    ctrl.settleOp = OP_DITHER;
    ctrl.settle = settle;
    SETSTATE(STATE_SETTLE_BEGIN);
    UpdateControllerState();

    return true;
}
示例#2
0
文件: phdcontrol.cpp 项目: rwg0/phd2
void PhdController::AbortController(const wxString& reason)
{
    if (ctrl.state != STATE_IDLE)
    {
        do_fail(reason);
        UpdateControllerState();
    }
}
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point for the application.  Since we use a simple dialog for 
//       user interaction we don't need to pump messages.
//-----------------------------------------------------------------------------
int WINAPI wWinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE, _In_ LPWSTR, _In_ int )
{
    // Initialize COM
    HRESULT hr;
    if( FAILED( hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED) ) )
        return 1;

    // Register the window class
    HBRUSH hBrush = CreateSolidBrush( 0xFF0000 );
    WNDCLASSEX wc =
    {
        sizeof( WNDCLASSEX ), 0, MsgProc, 0L, 0L, hInstance, nullptr,
        LoadCursor( nullptr, IDC_ARROW ), hBrush,
        nullptr, L"XInputSample", nullptr
    };
    RegisterClassEx( &wc );

    // Create the application's window
    g_hWnd = CreateWindow( L"XInputSample", L"XInput Sample: RumbleController",
                           WS_OVERLAPPED | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
                           CW_USEDEFAULT, CW_USEDEFAULT, 600, 600,
                           nullptr, nullptr, hInstance, nullptr );

    // Init state
    ZeroMemory( g_Controllers, sizeof( CONTROLLER_STATE ) * MAX_CONTROLLERS );

    // Enter the message loop
    bool bGotMsg;
    MSG msg;
    msg.message = WM_NULL;

    while( WM_QUIT != msg.message )
    {
        // Use PeekMessage() so we can use idle time to render the scene and call pEngine->DoWork()
        bGotMsg = ( PeekMessage( &msg, nullptr, 0U, 0U, PM_REMOVE ) != 0 );

        if( bGotMsg )
        {
            // Translate and dispatch the message
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
        else
        {
            UpdateControllerState();
            RenderFrame();
        }
    }

    // Clean up 
    UnregisterClass( L"XInputSample", nullptr );

    CoUninitialize();

    return 0;
}
示例#4
0
文件: phdcontrol.cpp 项目: rwg0/phd2
bool PhdController::Guide(bool recalibrate, const SettleParams& settle, wxString *error)
{
    if (ctrl.state != STATE_IDLE)
    {
        Debug.AddLine("PhdController::Guide reentrancy state = %d op = %d", ctrl.state, ctrl.settleOp);
        *error = ReentrancyError("guide");
        return false;
    }

    Debug.AddLine("PhdController::Guide begins");
    ctrl.forceCalibration = recalibrate;
    ctrl.settleOp = OP_GUIDE;
    ctrl.settle = settle;
    SETSTATE(STATE_SETUP);
    UpdateControllerState();
    return true;
}
示例#5
0
bool Input::Frame()
{
	bool result;

	result = ReadKeyboard();
	if (!result)
		return false;

	result = UpdateControllerState();

	if(!result)
		return false;

	



	return true;
}
示例#6
0
文件: xinput.cpp 项目: h406/project
void xInput::init(Input* input) {
	for (int nId = 0; nId < CONTROL_DEVICE_NUMBER_MAX; nId++)
	{
		//コントローラーの情報を更新
		UpdateControllerState(nId);
	}
	// キーボードデバイスオブジェクト生成
	if (FAILED(input->getInputDevice()->CreateDevice(
		GUID_SysKeyboard,
		&_pKeyboradDevice,
		NULL))) {
		// 生成失敗
		MessageBox(NULL, "キーボードデバイスオブジェクトの生成に失敗しました", "エラー", MB_OK | MB_ICONHAND);
		return;
	}

	// データフォーマットの設定
	if (FAILED(_pKeyboradDevice->SetDataFormat(&c_dfDIKeyboard))) {
		// 設定失敗
		MessageBox(NULL, "キーボードデータフォーマットの設定に失敗しました", "エラー", MB_OK | MB_ICONHAND);
		return;
	}

	// 協調モードの設定
	if (FAILED(_pKeyboradDevice->SetCooperativeLevel(App::instance().getHWnd(), (DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)))) {
		// 生成失敗
		MessageBox(NULL, "キーボード協調モードの設定に失敗しました", "エラー", MB_OK | MB_ICONHAND);
		return;
	}

	// キーボードへのアクセス権の取得
	_pKeyboradDevice->Acquire();

	memset(_aButtons, 0, sizeof(_aButtons));
	memset(_aButtonsTrigger, 0, sizeof(_aButtonsTrigger));
	memset(_aButtonsRelease, 0, sizeof(_aButtonsRelease));
	memset(_aButtonsRepeat, 0, sizeof(_aButtonsRepeat));
}
示例#7
0
文件: ROV_Drive.cpp 项目: Sarasa1/ROV
int main()
{
	Leap::Controller controller;
	Leap::Frame frame;
	Leap::HandList hands;
	Leap::Hand h1;
	Leap::FingerList fingers;
	Leap::Finger index;
	Leap::Finger thumb;
	Leap::PointableList pointables;
	float indexX = 0, indexY = 0, indexZ = 0, thumbX = 0, thumbY = 0, thumbZ = 0, sum = 0, supersample[20];

	int i = 0;

	// Setup serial port connection and needed variables.
	HANDLE hSerial = CreateFile(L"COM6", GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

	if (hSerial != INVALID_HANDLE_VALUE)
	{
		printf("Port opened! \n");

		DCB dcbSerialParams;
		GetCommState(hSerial, &dcbSerialParams);

		dcbSerialParams.BaudRate = CBR_14400;
		dcbSerialParams.ByteSize = 8;
		dcbSerialParams.Parity = NOPARITY;
		dcbSerialParams.StopBits = ONESTOPBIT;

		SetCommState(hSerial, &dcbSerialParams);

		Sleep(1000);
	}

	else
	{
		if (GetLastError() == ERROR_FILE_NOT_FOUND)
		{
			printf("Serial port doesn't exist! \n");
		}

		printf("Error while setting up serial port! \n");
	}

	Controller[20].value = 9;	//Verification Byte sent to make sure everything else ends up in the right location
	FillByteSize();

	while (true)
	{
		UpdateControllerState();	//Updates all values on the controller
		WORD wButtons = g_Controllers[CONTROLLER1].state.Gamepad.wButtons;

		//Stores all of the values from the controller into the controller structure
		Controller[0].value = g_Controllers[CONTROLLER1].state.Gamepad.sThumbRX;
		Controller[1].value = g_Controllers[CONTROLLER1].state.Gamepad.sThumbRY;
		Controller[2].value = g_Controllers[CONTROLLER1].state.Gamepad.sThumbLX;
		Controller[3].value = g_Controllers[CONTROLLER1].state.Gamepad.sThumbLY;
		Controller[4].value = (g_Controllers[CONTROLLER1].state.Gamepad.bRightTrigger);
		Controller[5].value = (g_Controllers[CONTROLLER1].state.Gamepad.bLeftTrigger);
		Controller[6].value = (wButtons & XINPUT_GAMEPAD_RIGHT_THUMB);
		Controller[7].value = (wButtons & XINPUT_GAMEPAD_LEFT_THUMB);
		Controller[8].value = (wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER);
		Controller[9].value = (wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER);
		Controller[10].value = (wButtons & XINPUT_GAMEPAD_DPAD_UP);
		Controller[11].value = (wButtons & XINPUT_GAMEPAD_DPAD_DOWN);
		Controller[12].value = (wButtons & XINPUT_GAMEPAD_DPAD_LEFT);
		Controller[13].value = (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT);
		Controller[14].value = (wButtons & XINPUT_GAMEPAD_A);
		Controller[15].value = (wButtons & XINPUT_GAMEPAD_B);
		Controller[16].value = (wButtons & XINPUT_GAMEPAD_Y);
		Controller[17].value = (wButtons & XINPUT_GAMEPAD_X);
		Controller[18].value = (wButtons & XINPUT_GAMEPAD_START);
		Controller[19].value = (wButtons & XINPUT_GAMEPAD_BACK);

		CheckDeadZone();

		if (controller.isConnected() == true)
		{
			sum = 0;
			frame = controller.frame();
			hands = frame.hands();
			h1 = hands[0];
			fingers = frame.fingers();
			thumb = fingers[0];
			index = fingers[1];
			pointables = frame.pointables();

			Leapvalues[0].value = h1.palmVelocity().x;
			Leapvalues[1].value = h1.palmVelocity().y;
			Leapvalues[2].value = h1.palmVelocity().z;
			Leapvalues[3].value = h1.direction().pitch()*Leap::RAD_TO_DEG;
			Leapvalues[4].value = h1.direction().yaw()*Leap::RAD_TO_DEG;

			indexX = index.tipPosition().x;
			indexY = index.tipPosition().y;
			indexZ = index.tipPosition().z;

			thumbX = thumb.tipPosition().x;
			thumbY = thumb.tipPosition().y;
			thumbZ = thumb.tipPosition().z;

			Leapvalues[5].value = sqrt(pow((indexX - thumbX), 2) + pow((indexY - thumbY), 2) + pow((indexZ - thumbZ), 2));

			leapConnected = true;
			CheckLeapDeadZone();
		}



		for (i = 6; i < NUMBER_OF_BUTTONS; i++)	//DO NOT SET TO <= NUMBER_OF_BUTTONS, NOT A MISTAKE. Verification bit should always keep its value
		{
			{
				Controller[i].value = AnalogToDigital(Controller[i].value);	//converts all of the button presses on the controller to a binary value
			}
		}

		//turns all of the numerical values into buffers that can be passed to the arduino
		for (i = 0; i <= NUMBER_OF_BUTTONS; i++)
		{
			_itoa_s(Controller[i].value, Controller[i].passedValue, 10);
		}

		for (i = 0; i < NUMBER_OF_LEAP_INPUTS; i++)
		{
			_itoa_s(Leapvalues[i].value, Leapvalues[i].passedValue, 10);
		}

		SendData(hSerial);

		std::cout << Controller[8].value << std::endl;
	}
	return 0;
}
示例#8
0
文件: xinput.cpp 项目: h406/project
void xInput::update() {
	//コントローラーの数分ループ
	for (int nId = 0; nId < CONTROL_DEVICE_NUMBER_MAX; nId++)
	{
		//コントローラーの情報を更新
		UpdateControllerState(nId);
		//コントローラーが接続中かどうか 
		if (_controlDevice[nId].bConnected){
			// 入力情報格納ワーク
			WORD wButtons = _controlDevice[nId].state.Gamepad.wButtons;
			SHORT sThumbLX = _controlDevice[nId].state.Gamepad.sThumbLX;
			SHORT sThumbLY = _controlDevice[nId].state.Gamepad.sThumbLY;

			// 入力情報をステート毎に分離して管理
			BYTE aKeyState[CONTROL_DEVICE_KEY_MAX];
			int nCntKey = 0;
			//方向キー 受け取り
			aKeyState[0] = (wButtons & XINPUT_GAMEPAD_DPAD_LEFT) ? 1 : 0;
			aKeyState[1] = (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) ? 1 : 0;
			aKeyState[2] = (wButtons & XINPUT_GAMEPAD_DPAD_UP) ? 1 : 0;
			aKeyState[3] = (wButtons & XINPUT_GAMEPAD_DPAD_DOWN) ? 1 : 0;

			//アナログスティック 受け取り(方向キーとOR制御で取る) アナログスティック半倒し以上で取る
			aKeyState[0] = aKeyState[0] | ((sThumbLX < -CONTROL_STICK_RANGE_MAX / 2) ? 1 : 0);
			aKeyState[1] = aKeyState[1] | ((sThumbLX > CONTROL_STICK_RANGE_MAX / 2) ? 1 : 0);
			aKeyState[2] = aKeyState[2] | ((sThumbLY > CONTROL_STICK_RANGE_MAX / 2) ? 1 : 0);
			aKeyState[3] = aKeyState[3] | ((sThumbLY < -CONTROL_STICK_RANGE_MAX / 2) ? 1 : 0);

			//ABXYボタン受け取り ABXYの順
			aKeyState[4] = (wButtons & XINPUT_GAMEPAD_A) ? 1 : 0;
			aKeyState[5] = (wButtons & XINPUT_GAMEPAD_B) ? 1 : 0;
			aKeyState[6] = (wButtons & XINPUT_GAMEPAD_X) ? 1 : 0;
			aKeyState[7] = (wButtons & XINPUT_GAMEPAD_Y) ? 1 : 0;

			//L1 R1受け取り
			aKeyState[8] = (wButtons & XINPUT_GAMEPAD_LEFT_THUMB) ? 1 : 0;
			aKeyState[9] = (wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) ? 1 : 0;

			//左右スティックボタン行けとり
			aKeyState[10] = (wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) ? 1 : 0;
			aKeyState[11] = (wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) ? 1 : 0;

			//start backボタン受け取り
			aKeyState[12] = (wButtons & XINPUT_GAMEPAD_START) ? 1 : 0;
			aKeyState[13] = (wButtons & XINPUT_GAMEPAD_BACK) ? 1 : 0;

			for (nCntKey = 0; nCntKey < CONTROL_DEVICE_KEY_MAX; nCntKey++) {
				// トリガー作成 現在トリガーが押している間常にON
				_aButtonsTrigger[nId][nCntKey] = (aKeyState[nCntKey] ^ _aButtons[nId][nCntKey]) & aKeyState[nCntKey];

				// リリース作成 現在離した後他のキーが押されるまでON
				_aButtonsRelease[nId][nCntKey] = (aKeyState[nCntKey] ^ _aButtons[nId][nCntKey]) & ~aKeyState[nCntKey];

				// グローバルへ移す
				_aButtons[nId][nCntKey] = aKeyState[nCntKey];

				// リピート作成
				if (_aButtons[nId][nCntKey] & 0x01) {
					//0x20になったら0に戻す
					(_aButtonsRepeat[nId][nCntKey] < 0x20) ? _aButtonsRepeat[nId][nCntKey]++ : _aButtonsRepeat[nId][nCntKey] = 0;
				}
				else {
					_aButtonsRepeat[nId][nCntKey] = 0;
				}
			}//for

		}//if 接続確認
		//接続が切れていたら
		else{
			// 配列のクリア

		}//else
	}//for コントローラー分のループ
}
示例#9
0
int main()
{

	unsigned long cycles = 0;


	int i = 0;

	// ********************************************************************************************************************
	// IMPORTANT: The serial port numbers here must correspond to those of the arduino on the ROV. The first number is the 
	// COM # and the second number is the baud rate set on the arduino.
	SerialPort.Open(8, 115200);
	// ********************************************************************************************************************

	Controller[20].value = 9;	//Verification Byte sent to make sure everything else ends up in the right location
	FillByteSize();

	while (true)
	{
		cycles++;
		UpdateControllerState();	//Updates all values on the controller
		WORD wButtons = g_Controllers[CONTROLLER1].state.Gamepad.wButtons;

		//Stores all of the values from the controller into the controller structure
		Controller[0].value = g_Controllers[CONTROLLER1].state.Gamepad.sThumbRX;
		Controller[1].value = g_Controllers[CONTROLLER1].state.Gamepad.sThumbRY;
		Controller[2].value = g_Controllers[CONTROLLER1].state.Gamepad.sThumbLX;
		Controller[3].value = g_Controllers[CONTROLLER1].state.Gamepad.sThumbLY;
		Controller[4].value = (g_Controllers[CONTROLLER1].state.Gamepad.bRightTrigger);
		Controller[5].value = (g_Controllers[CONTROLLER1].state.Gamepad.bLeftTrigger);
		Controller[6].value = (wButtons & XINPUT_GAMEPAD_RIGHT_THUMB);
		Controller[7].value = (wButtons & XINPUT_GAMEPAD_LEFT_THUMB);
		Controller[8].value = (wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER);
		Controller[9].value = (wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER);
		Controller[10].value = (wButtons & XINPUT_GAMEPAD_DPAD_UP);
		Controller[11].value = (wButtons & XINPUT_GAMEPAD_DPAD_DOWN);
		Controller[12].value = (wButtons & XINPUT_GAMEPAD_DPAD_LEFT);
		Controller[13].value = (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT);
		Controller[14].value = (wButtons & XINPUT_GAMEPAD_A);
		Controller[15].value = (wButtons & XINPUT_GAMEPAD_B);
		Controller[16].value = (wButtons & XINPUT_GAMEPAD_Y);
		Controller[17].value = (wButtons & XINPUT_GAMEPAD_X);
		Controller[18].value = (wButtons & XINPUT_GAMEPAD_START);
		Controller[19].value = (wButtons & XINPUT_GAMEPAD_BACK);

		CheckDeadZone();
		

		for (i = 6; i < NUMBER_OF_BUTTONS; i++)	//DO NOT SET TO <= NUMBER_OF_BUTTONS, NOT A MISTAKE. Verification bit should always keep its value
		{
			{
				Controller[i].value = AnalogToDigital(Controller[i].value);	//converts all of the button presses on the controller to a binary value
			}
		}

		//turns all of the numerical values into buffers that can be passed to the arduino
		for (i = 0; i <= NUMBER_OF_BUTTONS; i++)
		{
			_itoa_s(Controller[i].value, Controller[i].passedValue, 10);
		}

		
		if (SendData() == 1)
		{
			//SerialPort.ReadData(recieved[0], 3);
		}

		std::cout << Controller[5].value << Controller[4].value << Controller[1].value << std::endl;  // This shows the value being passed to the arduino from the selected controller button (#3 = Left stick Y position)
		
	}
	return 0;
}