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; }
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; }