Skip to content

Commit

Permalink
Improvement: added a second touchpad touch and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
r57zone committed Oct 26, 2021
1 parent a0caa39 commit 4430553
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ Uncharted 3: Иллюзии Дрейка (2011) | Кнопка "Share" (F12) д

## Гироскоп
1. Проверьте брандмауэр Windows, разрешены ли входящие подключения у вашего типа сети (частной) и разрешите если отключены.
2. Измените параметр `Activate` на `1`, в разделе `Motion`, в конфигурационном файле.
3. Установите FreePieIMU на ваш Android телефон, введите IP адрес вашего компьютера, отметьте пункт "Send raw data", если не отмечен, выберите скорость передачи данных "Fastest" или "Fast".
4. Уменьшите чувствительность при необходимости (параметр `Sens`, в разделе `Motion`, где 100 это 100% чувствительности) в конфигурационном файле.
2. Установите FreePieIMU на ваш Android телефон, введите IP адрес вашего компьютера, отметьте пункт "Send raw data", если не отмечен, выберите скорость передачи данных "Fastest" или "Fast".
3. Уменьшите чувствительность при необходимости (параметр `Sens`, в разделе `Motion`, где 100 это 100% чувствительности) в конфигурационном файле.



Expand Down Expand Up @@ -78,6 +77,7 @@ L3 (нажатие стика) | Shift
R3 (нажатие стика) | Средняя кнопка мыши
Touchpad свайп вверх, вниз, влево, вправо | 7, 8, 9, 0
Touchpad вверх, вниз, влево, вправо, вниз | U, J, H, K, N
Touchpad второе касание справа | I
Потрясти геймпад | T
PS | F2

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ You can use swipes for the keyboard, the button codes are described below.

## Gyroscope
1. Check Windows Firewall to see if incoming connections are allowed on your network type (private) and allow if disabled.
2. Change the parameter `Activate` to `1`, in the section `Motion`, in the configuration file.
3. Install FreePieIMU on your Android phone, enter the IP address of your computer, select "Send raw data", if not selected, select the data rate "Fastest" or "Fast".
4. Reduce the sensitivity if necessary (the `Sens` parameter, in the `Motion` section, where `100` is 100% sensitivity) in configuration file.
2. Install FreePieIMU on your Android phone, enter the IP address of your computer, select "Send raw data", if not selected, select the data rate "Fastest" or "Fast".
3. Reduce the sensitivity if necessary (the `Sens` parameter, in the `Motion` section, where `100` is 100% sensitivity) in configuration file.



Expand Down Expand Up @@ -79,6 +78,7 @@ L3 (pressing the stick) | Shift
R3 (pressing the stick) | Middle mouse button
Touchpad swipe up, down, left, right | 7, 8, 9, 0
Touchpad up, center, left, right, down | U, J, H, K, N
Touchpad second touch on the right | I
Shake the gamepad | T
PS | F2

Expand Down
39 changes: 28 additions & 11 deletions Source/DS4Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ bool SocketActivated = false;
std::thread *pSocketThread = NULL;
unsigned char freePieIMU[50];
float AccelX = 0, AccelY = 0, AccelZ = 0, GyroX = 0, GyroY = 0, GyroZ = 0;
int curTimeStamp;

float bytesToFloat(unsigned char b3, unsigned char b2, unsigned char b1, unsigned char b0)
{
Expand All @@ -118,6 +119,7 @@ float bytesToFloat(unsigned char b3, unsigned char b2, unsigned char b1, unsigne
return result;
}

int SleepTimeOutMotion = 1;
void MotionReceiver()
{
while (SocketActivated) {
Expand All @@ -131,7 +133,8 @@ void MotionReceiver()
GyroX = bytesToFloat(freePieIMU[14], freePieIMU[15], freePieIMU[16], freePieIMU[17]);
GyroY = bytesToFloat(freePieIMU[18], freePieIMU[19], freePieIMU[20], freePieIMU[21]);
GyroZ = bytesToFloat(freePieIMU[22], freePieIMU[23], freePieIMU[24], freePieIMU[25]);
}
} else
Sleep(SleepTimeOutMotion); // Don't overload the CPU with reading
}
}

Expand Down Expand Up @@ -193,7 +196,7 @@ SHORT DeadZoneXboxAxis(SHORT StickAxis, float Percent)

int main(int argc, char **argv)
{
SetConsoleTitle("DS4Emulator 1.7.3");
SetConsoleTitle("DS4Emulator 1.7.4");

CIniReader IniFile("Config.ini"); // Config

Expand All @@ -218,24 +221,21 @@ int main(int argc, char **argv)
if (iResult != SOCKET_ERROR) {
SocketActivated = true;
pSocketThread = new std::thread(MotionReceiver);
}
else {
} else {
WSACleanup();
SocketActivated = false;
}
}
else {
} else {
WSACleanup();
SocketActivated = false;
}
}
else
{
} else {
WSACleanup();
SocketActivated = false;
}
}
float MotionSens = IniFile.ReadFloat("Motion", "Sens", 100) * 0.01;
SleepTimeOutMotion = IniFile.ReadInteger("Motion", "SleepTimeOut", 1);

#define OCR_NORMAL 32512
HCURSOR CurCursor = CopyCursor(LoadCursor(0, IDC_ARROW));
Expand Down Expand Up @@ -313,6 +313,7 @@ int main(int argc, char **argv)
int KEY_ID_TOUCHPAD_LEFT = IniFile.ReadInteger("Keys", "TOUCHPAD_LEFT", 'H');
int KEY_ID_TOUCHPAD_RIGHT = IniFile.ReadInteger("Keys", "TOUCHPAD_RIGHT", 'K');
int KEY_ID_TOUCHPAD_CENTER = IniFile.ReadInteger("Keys", "TOUCHPAD_CENTER", 'J');
int KEY_ID_TOUCHPAD_SECOND_RIGHT = IniFile.ReadInteger("Keys", "TOUCHPAD_SECOND_RIGHT", 'J');

const auto client = vigem_alloc();
auto ret = vigem_connect(client);
Expand Down Expand Up @@ -691,6 +692,13 @@ int main(int argc, char **argv)
}
}

if ((GetAsyncKeyState(KEY_ID_TOUCHPAD_SECOND_RIGHT) & 0x8000) != 0) { // Bad temporary solution for Infamous: Second Son https://youtu.be/i7w4G1CIdog?t=667
report.sCurrentTouch.bIsUpTrackingNum2 = 0;
report.sCurrentTouch.bTouchData2[0] = 1600 & 0xFF;
report.sCurrentTouch.bTouchData2[1] = ((1600 >> 8) & 0x0F) | ((471 & 0x0F) << 4);
report.sCurrentTouch.bTouchData2[2] = (471 >> 4) & 0xFF;
}

if (BuffPreviousTouch[1].bIsUpTrackingNum1 == 0) {
//printf("2: prev 2 touched\r\n");
report.sPreviousTouch[1] = BuffPreviousTouch[1];
Expand All @@ -707,7 +715,6 @@ int main(int argc, char **argv)
}

// Probably the wrong way, but it works, temporary workaround / Âåðîÿòíî íåâåðíûé ïóòü, íî îí ðàáîòàåò, ïîäîéäåò êàê âðåìåííîå ðåøåíèå
report.sCurrentTouch.bIsUpTrackingNum1 = 0x80;
if (TouchX != 0 || TouchY != 0) {
report.bTouchPacketsN = 1;

Expand Down Expand Up @@ -739,7 +746,7 @@ int main(int argc, char **argv)
report.wAccelZ = trunc( Clamp(AccelZ * 1638.35, -32767, 32767) ) * 1 * MotionSens;
report.wGyroX = trunc( Clamp(GyroX * 2376.7, -32767, 32767) ) * 1 * MotionSens; // freepie max gyro 10, min -10.09
report.wGyroY = trunc( Clamp(GyroY * 2376.7, -32767, 32767) ) * -1 * MotionSens;
report.wGyroZ = trunc( Clamp(GyroZ * 2376.7, -32767, 32767) ) * 1 * MotionSens; //if ((GetAsyncKeyState(VK_NUMPAD1) & 0x8000) != 0) printf("%d\t%d\t%d\t%d\t%d\t%d\t\n", report.wAccelX, report.wAccelY, report.wAccelZ, report.wGyroX, report.wGyroY, report.wGyroZ);
report.wGyroZ = trunc( Clamp(GyroZ * 2376.7, -32767, 32767) ) * 1 * MotionSens; // if ((GetAsyncKeyState(VK_NUMPAD1) & 0x8000) != 0) printf("%d\t%d\t%d\t%d\t%d\t%d\t\n", report.wAccelX, report.wAccelY, report.wAccelZ, report.wGyroX, report.wGyroY, report.wGyroZ);

// Motion shaking
if (MotionShaking) {
Expand All @@ -756,8 +763,18 @@ int main(int argc, char **argv)
// Multi mode keys
if ((GetAsyncKeyState(KEY_ID_PS) & 0x8000) != 0)
report.bSpecial |= DS4_SPECIAL_BUTTON_PS;
if ((GetAsyncKeyState(KEY_ID_TOUCHPAD_SECOND_RIGHT) & 0x8000) != 0) { // Bad temporary solution for Infamous: Second Son https://youtu.be/i7w4G1CIdog?t=667
report.bTouchPacketsN = 2;
report.sCurrentTouch.bIsUpTrackingNum2 = 0;
report.sCurrentTouch.bTouchData2[0] = 1600 & 0xFF;
report.sCurrentTouch.bTouchData2[1] = ((1600 >> 8) & 0x0F) | ((471 & 0x0F) << 4);
report.sCurrentTouch.bTouchData2[2] = (471 >> 4) & 0xFF;
}

// if ((GetAsyncKeyState(VK_NUMPAD0) & 0x8000) != 0) system("cls");

curTimeStamp++; if (curTimeStamp > 65535) curTimeStamp = 0; // ?
report.wTimestamp = curTimeStamp;

ret = vigem_target_ds4_update_ex(client, ds4, report);

Expand Down

0 comments on commit 4430553

Please sign in to comment.