Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Denellyne/PCXSense
Browse files Browse the repository at this point in the history
  • Loading branch information
Denellyne committed Jan 26, 2024
2 parents 4a2374e + a8d50a5 commit c1bf3a1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/ControllerIO/controllerIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
#include <tchar.h>
#include "User Settings/Adaptive Triggers/Adaptive Triggers.h"
#include "User Settings/Game Profiles/gameProfile.h"
#ifdef _DEBUG
#include <iostream>
#define DEBUG(x) do { std::cout << x << '\n'; } while (0)
#else
#define DEBUG(x) do ; while(0)
#endif // _DEBUG


unsigned char outputHID[547]{};
Expand All @@ -15,15 +20,15 @@ int initializeFakeController(PVIGEM_TARGET& emulateX360, VIGEM_ERROR& target, PV

if (client == nullptr)
{
std::cerr << "Uh, not enough memory to do that?!" << std::endl;
DEBUG("Uh, not enough memory to do that?!");
return -1;
}

const auto retval = vigem_connect(client);

if (!VIGEM_SUCCESS(retval))
{
std::cerr << "ViGEm Bus connection failed with error code: 0x" << std::hex << retval << std::endl;
DEBUG("ViGEm Bus connection failed with error code: 0x" << std::hex << retval);
return -1;
}

Expand Down Expand Up @@ -119,7 +124,7 @@ void extern inline sendOutputReport(controller& x360Controller) {
switch (x360Controller.batteryLevel) { //Chooses Lightbar Profile
case 0: x360Controller.RGB[0].Index = 1; break;
case 12: x360Controller.RGB[0].Index = 2; break;
case 27: x360Controller.RGB[0].Index = 3; break;
case 25: x360Controller.RGB[0].Index = 3; break;
case 37: x360Controller.RGB[0].Index = 4; break;
case 50: x360Controller.RGB[0].Index = 5; break;
case 62: x360Controller.RGB[0].Index = 6; break;
Expand Down
18 changes: 18 additions & 0 deletions src/User Settings/Adaptive Triggers/Adaptive Triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ void triggerToProfile(std::vector<gameProfile>& gameProfiles) {

void triggerEditor(bool& makerOpen, unsigned char* trigger,bool& rumbleTriggers) {

rumble[0] = 0;
rumble[1] = 0;

static const short int triggerModes[9] = { 0x0, //Off
0x1, //Rigid
0x2, //Pulse
Expand All @@ -51,8 +54,11 @@ void triggerEditor(bool& makerOpen, unsigned char* trigger,bool& rumbleTriggers)
0x2 | 0x20 | 0x04 }; //Pulse AB

if (ImGui::Begin("Adaptive Trigger Maker", &makerOpen)) {
static int motor1{}, motor2{};

gameProfileSet = true;
memcpy(&ptrCurrentTriggerProfile, &*trigger, 8);


if (ImGui::BeginCombo("Trigger Mode", std::format("{}", (int)trigger[0]).c_str())) {
for (short int i = 0; i < IM_ARRAYSIZE(triggerModes); i++) if (ImGui::Selectable(std::format("{}", triggerModes[i]).c_str())) trigger[0] = triggerModes[i];
Expand All @@ -72,6 +78,18 @@ void triggerEditor(bool& makerOpen, unsigned char* trigger,bool& rumbleTriggers)
ImGui::SliderInt("##2", (int*)&trigger[1], 0, 15);
ImGui::SliderInt("##3", (int*)&trigger[2], 0, 200);

ImGui::Text("Rumble Edit");
ImGui::SliderInt("##4", &motor1, 0, 255);
ImGui::SliderInt("##5", &motor2, 0, 255);

rumble[0] = motor1;
rumble[1] = motor2;

ptrCurrentTriggerProfile[1] += (int)rumble[0] >> 4;
ptrCurrentTriggerProfile[2] += (int)rumble[1] >> 4;
if ((int)rumble[0] >= 252) ptrCurrentTriggerProfile[3] = 220;


ImGui::End();
return;
}
Expand Down
18 changes: 10 additions & 8 deletions src/User Settings/Game Profiles/gameProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void saveProfiles(const std::vector<gameProfile> gameProfiles) {
}
}


void inline writeProfiles(std::string dirEntry, gameProfile& currentProfile) {

//Write strings and TriggerProfile
Expand All @@ -81,13 +82,16 @@ void inline writeProfiles(std::string dirEntry, gameProfile& currentProfile) {
RGB Lightbar{};

while (writeStrings.good()) {
std::getline(writeStrings, profileName,'\n');
memcpy(&currentProfile.profileName[0], &profileName[0], profileName.length());

//It just works if I add this idk

writeStrings >> profileName;
writeStrings.get();
currentProfile.profileName = profileName;
writeStrings.ignore();
writeStrings.unget();
//
std::getline(writeStrings, appName,'\n');

writeStrings >> appName;
writeStrings.get();
currentProfile.appName = std::wstring(&appName[0], &appName[appName.length()]);
currentProfile.appNameLiteral = appName;

Expand Down Expand Up @@ -171,14 +175,12 @@ void inline checkMacro(Macros& macro, const controller& x360Controller) {
void asyncGameProfile(std::vector<gameProfile>& gameProfiles,controller& x360Controller){

while (true) {
while (profileEdit) Sleep(1000);
while (profileEdit) Sleep(500);
Sleep(500);

for (int i = 0; i < gameProfiles.size();i++) {
while (gameProfiles[i].isOpen()) {

//Set profile

memcpy(&ptrCurrentTriggerProfile, &gameProfiles[i].gameTriggerProfile, 8);
gameProfileSet = true;
x360Controller.RGB[0].Index = 0;
Expand Down

0 comments on commit c1bf3a1

Please sign in to comment.