Beispiel #1
0
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
  int I;
  String LGuid;
  int LMajor;
  int LMinor;

  Timer1->Enabled = False;
  if (FBeaconManager != NULL)
  {
	FBeaconManager->StopScan();
	FBeaconManager->Free();
	FBeaconManager = NULL;
	FCurrentBeaconList.Length = 0;
  };
	CheckManager();
	for(I = 0; I < ListBox1->Count; I++)
	{
	  StringToRegion(ListBox1->Items->Strings[I], LGuid, LMajor, LMinor);
	  if (LMajor == -1)
		FBeaconManager->RegisterBeacon(StringToGUID(LGuid));
	  else if (LMinor == -1)
		FBeaconManager->RegisterBeacon(StringToGUID(LGuid), LMajor);
	  else
		FBeaconManager->RegisterBeacon(StringToGUID(LGuid), LMajor, LMinor);
	};
}
Beispiel #2
0
//---------------------------------------------------------------------------
void __fastcall TfrmProximityForm::FormShow(TObject *Sender)
{
	LINK_LOSS_SERVICE = StringToGUID("{00001803-0000-1000-8000-00805F9B34FB}");
	IMMEDIATE_ALERT_SERVICE = StringToGUID("{00001802-0000-1000-8000-00805F9B34FB}");
	TX_POWER_SERVICE = StringToGUID("{00001804-0000-1000-8000-00805F9B34FB}");
	ALERT_LEVEL_CHARACTERISTIC = StringToGUID("{00002A06-0000-1000-8000-00805F9B34FB}");
	TX_POWER_LEVEL_CHARACTERISTIC = StringToGUID("{00002A07-0000-1000-8000-00805F9B34FB}");

	FBLEManager = TBluetoothLEManager::Current;
	FBLEManager->OnDiscoveryEnd = DoDiscoveryEndEvent;
	FCurrentPosition = poUnknown;
	ProximityDeviceName = CProximityDeviceName;
	DoScan();
}
Beispiel #3
0
bool Config::ReadPadConfig(Controller* pController, const std::string& section, SWIP* pSWIP)
{
    std::string buffer;

    if (pSWIP->Get(section, "ProductGUID", &buffer))
        StringToGUID(&pController->m_productid, buffer);

    if (pSWIP->Get(section, "InstanceGUID", &buffer))
        StringToGUID(&pController->m_instanceid, buffer);

    if (IsEqualGUID(pController->m_productid, GUID_NULL) || IsEqualGUID(pController->m_instanceid, GUID_NULL))
    {
        std::string message = StringFormat("[PAD%u] Misconfigured device, check GUIDs", pController->m_user);
        PrintLog(message.c_str());
        MessageBoxA(NULL, message.c_str(), "x360ce", MB_ICONERROR);
        return false;
    }
    pSWIP->Get(section, "PassThrough", &pController->m_passthrough);
    if (pController->m_passthrough)
        return false;

    // Device type
    pSWIP->Get(section, "ControllerType", &pController->m_gamepadtype, 1);

    // FFB options
    pSWIP->Get(section, "UseForceFeedback", &pController->m_useforce);
    if (pController->m_useforce)
    {
        pSWIP->Get(section, "ForcePercent", &pController->m_ForceFeedback.m_ForcePercent, 100);
        pController->m_ForceFeedback.m_ForcePercent *= 0.01f;

        pSWIP->Get(section, "LeftMotorType", &pController->m_ForceFeedback.m_LeftMotor.type, 0);
        pSWIP->Get(section, "LeftMotorPeriod", &pController->m_ForceFeedback.m_LeftMotor.period, 100);
        pSWIP->Get(section, "LeftMotorActuator", &pController->m_ForceFeedback.m_LeftMotor.actuator, 0);
        pSWIP->Get(section, "LeftMotorStrength", &pController->m_ForceFeedback.m_LeftMotor.strength, 100);
        pController->m_ForceFeedback.m_LeftMotor.strength *= 0.01f;

        pSWIP->Get(section, "RightMotorType", &pController->m_ForceFeedback.m_RightMotor.type, 0);
        pSWIP->Get(section, "RightMotorPeriod", &pController->m_ForceFeedback.m_RightMotor.period, 100);
        pSWIP->Get(section, "RightMotorActuator", &pController->m_ForceFeedback.m_RightMotor.actuator, 1);
        pSWIP->Get(section, "RightMotorStrength", &pController->m_ForceFeedback.m_RightMotor.strength, 100);
        pController->m_ForceFeedback.m_RightMotor.strength *= 0.01f;

        pSWIP->Get(section, "FFUpdateInterval", &pController->m_ForceFeedback.m_UpdateInterval, 20);
    }

    return true;
}
Beispiel #4
0
void __fastcall TForm1::ButtonOpenReadingSocketClick(TObject *Sender)
{

	if (ButtonOpenReadingSocket->IsPressed) {
		if((ServerConnectionTH == NULL) && (ManagerConnected())) {
			try {
				FAdapter = FBluetoothManager->CurrentAdapter;
				ServerConnectionTH = new TServerConnectionTH(true);
				ServerConnectionTH->FServerSocket = FAdapter->CreateServerSocket(ServiceName, StringToGUID(ServiceGUI), false);
				ServerConnectionTH->Start();
				DisplayR->Lines->Add(" - Service created: '"+ServiceName+"'");
				DisplayR->GoToTextEnd();
				ButtonOpenReadingSocket->Text = "Stop Text Service";
			}
			catch(Exception &Ex) {
				DisplayR->Lines->Add(Ex.Message);
				DisplayR->GoToTextEnd();
				ButtonOpenReadingSocket->IsPressed = False;
			}
		}
	}
	else
		if(ServerConnectionTH != NULL) {
		ServerConnectionTH->Terminate();
		ServerConnectionTH->WaitFor();
		delete ServerConnectionTH;
		ServerConnectionTH = NULL;
		DisplayR->Lines->Add(" - Service removed -");
		DisplayR->GoToTextEnd();
		ButtonOpenReadingSocket->Text = "Start Text Service";
	}
}
Beispiel #5
0
//---------------------------------------------------------------------------
void __fastcall TForm1::SendData(void)
{
	TBytes ToSend;
	if((FSocket == NULL) || (ItemIndex != ComboBoxPaired->ItemIndex)) {
		if(ComboBoxPaired->ItemIndex > -1) {
			TBluetoothDevice * LDevice = FPairedDevices->Items[ComboBoxPaired->ItemIndex];
			DisplayR->Lines->Add(GetServiceName(ServiceGUI));
			DisplayR->GoToTextEnd();
			FSocket = LDevice->CreateClientSocket(StringToGUID(ServiceGUI), false);
			if(FSocket != NULL) {
				ItemIndex = ComboBoxPaired->ItemIndex;
				FSocket->Connect();
				ToSend = TEncoding::UTF8->GetBytes(Edit1->Text);
				FSocket->SendData(ToSend);
				DisplayR->Lines->Add("Text Sent");
				DisplayR->GoToTextEnd();
			}
			else {
				ShowMessage("Out of time ~15s~");
			}
		}
		else {
			ShowMessage("No paired device selected");
		}
	}
	else {
		ToSend = TEncoding::UTF8->GetBytes(Edit1->Text);
		FSocket->SendData(ToSend);
		DisplayR->Lines->Add("Text Sent");
		DisplayR->GoToTextEnd();
	}
}
Beispiel #6
0
DEBUG_LOCAL OSStatus	EnableNSP( const char *inGUID, BOOL inEnable )
{
	OSStatus		err;
	WSADATA			wsd;
	GUID			guid;
	
	require_action( inGUID && ( *inGUID != '\0' ), exit, err = kParamErr );
	
	err = StringToGUID( inGUID, &guid );
	require_noerr( err, exit );
	
	err = WSAStartup( MAKEWORD( 2, 2 ), &wsd );
	err = translate_errno( err == 0, errno_compat(), WSAEINVAL );
	require_noerr( err, exit );
	
	err = WSCEnableNSProvider( &guid, inEnable );
	err = translate_errno( err == 0, errno_compat(), WSAEINVAL );
	WSACleanup();
	require_noerr( err, exit );
	
	if (!gToolQuietMode)
	{
		fprintf( stderr, "Removed NSP %s\n", inGUID );
	}
		
exit:
	if( err != kNoErr )
	{
		fprintf( stderr, "### FAILED (%d) to remove %s Name Space Provider\n", err, inGUID );
	}
	return( err );
}
Beispiel #7
0
//---------------------------------------------------------------------------
void __fastcall TForm1::BtnAddRegionClick(TObject *Sender)
{
  CheckManager();
  if (sbMajor->Value > -1)
  {
	if (sbMinor->Value > -1)
	{
	 if (FBeaconManager->RegisterBeacon(StringToGUID(EdGuid->Text), int(sbMajor->Value), int(sbMinor->Value)))
		ListBox1->Items->Add(EdGuid->Text + ";" + IntToStr(int(sbMajor->Value)) + ";" + IntToStr(int(sbMinor->Value)));
	}
	else
	 if (FBeaconManager->RegisterBeacon(StringToGUID(EdGuid->Text), int(sbMajor->Value)))
	   ListBox1->Items->Add(EdGuid->Text + ";" + IntToStr(int(sbMajor->Value)) + ";" + IntToStr(int(sbMinor->Value)) );
  }
  else if (FBeaconManager->RegisterBeacon(StringToGUID(EdGuid->Text)))
	  ListBox1->Items->Add(EdGuid->Text + ";" + IntToStr(int(sbMajor->Value)) + ";" + IntToStr(int(sbMinor->Value)) );
}
Beispiel #8
0
//---------------------------------------------------------------------------
void __fastcall TForm1::BtnDeleteRegionClick(TObject *Sender)
{
  String LStringGuid;
  int LMajor;
  int LMinor;
  CheckManager();
  if (ListBox1->ItemIndex >= 0)
  {
	StringToRegion(ListBox1->Items->Strings[ListBox1->ItemIndex], LStringGuid, LMajor, LMinor);
	if (FBeaconManager->UnregisterBeacon(StringToGUID(LStringGuid), LMajor, LMinor))
	  ListBox1->Items->Delete(ListBox1->ItemIndex);
  };
}
//---------------------------------------------------------------------------
bool __fastcall TForm8::CheckUUID()
{
	try
	{
		FGuid = StringToGUID("{" + EdtBeaconUUID->Text + "}");
		return True;
	}
	catch (EConvertError &e)
	{
	  ShowMessage(EdtBeaconUUID->Text + " is not a valid UUID value");
	  return False;
	}
}
Beispiel #10
0
//---------------------------------------------------------------------------
String __fastcall TForm1::GetServiceName(String GUID)
{
	String _return = "";
	TBluetoothDevice * ADevice = FPairedDevices->Items[ComboBoxPaired->ItemIndex];
	TBluetoothServiceList * LServices = ADevice->GetServices();
	for(int i = 0; i < LServices->Count; i++)
	{
		if(StringToGUID(GUID) == LServices->Items[i].UUID) {
			_return = LServices->Items[i].Name;
			break;
		}
	}
	return _return;
}
Beispiel #11
0
OSStatus	InstallNSP( const char *inName, const char *inGUID, const char *inPath )
{
	OSStatus		err;
	size_t			size;
	WSADATA			wsd;
	WCHAR			name[ 256 ];
	GUID			guid;
	WCHAR			path[ MAX_PATH ];
	
	require_action( inName && ( *inName != '\0' ), exit, err = kParamErr );
	require_action( inGUID && ( *inGUID != '\0' ), exit, err = kParamErr );
	require_action( inPath && ( *inPath != '\0' ), exit, err = kParamErr );
	
	size = strlen( inName );
	require_action( size < sizeof_array( name ), exit, err = kSizeErr );
	CharToWCharString( inName, name );
	
	err = StringToGUID( inGUID, &guid );
	require_noerr( err, exit );
	
	size = strlen( inPath );
	require_action( size < sizeof_array( path ), exit, err = kSizeErr );
	CharToWCharString( inPath, path );
	
	err = WSAStartup( MAKEWORD( 2, 2 ), &wsd );
	err = translate_errno( err == 0, errno_compat(), WSAEINVAL );
	require_noerr( err, exit );
	
	err = WSCInstallNameSpace( name, path, NS_DNS, 1, &guid );
	err = translate_errno( err == 0, errno_compat(), WSAEINVAL );
	WSACleanup();
	require_noerr( err, exit );
	
	if (!gToolQuietMode)
	{
		fprintf( stderr, "Installed NSP \"%s\" (%s) at %s\n", inName, inGUID, inPath );
	}
	
exit:
	if( err != kNoErr )
	{
		fprintf( stderr, "### FAILED (%d) to install \"%s\" (%s) Name Space Provider at %s\n", err, inName, inGUID, inPath );
	}
	return( err );
}
//---------------------------------------------------------------------------
bool __fastcall TForm8::CheckValues()
{
	try
	{
		FGuid = StringToGUID("{" + EdtBeaconUUID->Text + "}");
	}
	catch (EConvertError &e)
	{
	  ShowMessage(EdtBeaconUUID->Text + " is not a valid UUID value");
	  return False;
	}
	FMajor = StrToIntDef(EdtBeaconMajor->Text, 0);
	EdtBeaconMajor->Text = IntToStr(FMajor);
	FMinor = StrToIntDef(EdtBeaconMinor->Text, 0);
	EdtBeaconMinor->Text = IntToStr(FMinor);
	FTxPower = StrToIntDef(EdTxPower->Text, -56);
	EdTxPower->Text = IntToStr(FTxPower);
	return True;
}
Beispiel #13
0
void ofxMultiplexerManager::readSettingsFromXML(char* fileName)
{
	ofxXmlSettings* xmlSettings = new ofxXmlSettings();
	if (xmlSettings->loadFile(fileName))
	{
		cameraGridWidth			= xmlSettings->getValue("MULTIPLEXER:CAMERAGRID:WIDTH", 1);
		cameraGridHeight		= xmlSettings->getValue("MULTIPLEXER:CAMERAGRID:HEIGHT", 1);
		calibrationGridWidth	= xmlSettings->getValue("MULTIPLEXER:CALIBRATIONGRID:WIDTH", 4);
		calibrationGridHeight	= xmlSettings->getValue("MULTIPLEXER:CALIBRATIONGRID:HEIGHT", 3);
		interleaveMode			= xmlSettings->getValue("MULTIPLEXER:INTERLEAVE", 0);
		xmlSettings->pushTag("MULTIPLEXER", 0);
		xmlSettings->pushTag("CAMERAS", 0);
		int numCamerasTags = xmlSettings->getNumTags("CAMERA");
		//if (numCamerasTags==cameraGridWidth*cameraGridHeight)
		{
			for (int i=0;i<numCamerasTags;i++)
			{
				ofxCameraBaseCalibration* cameraBaseCalibration = new ofxCameraBaseCalibration();
				cameraBaseCalibration->camera = NULL;
				xmlSettings->pushTag("CAMERA", i);
				std::string cameraTypeName = xmlSettings->getValue("TYPE", "NONE");
				GUID newGuid = StringToGUID(xmlSettings->getValue("GUID", "{00000000-0000-0000-0000-000000000000}"));
				for (int j=0;j<cameraBases.size();j++)
				{
					if ((cameraTypeName == cameraBases[j]->getBaseCameraTypeName()) && (newGuid == cameraBases[j]->getBaseCameraGuid()))
					{
						cameraBaseCalibration->camera = cameraBases[j];
					}
				}
				cameraBaseCalibration->index = 	xmlSettings->getValue("INDEX", i);
				xmlSettings->pushTag("POINTARRAY", 0);
				int numPointTags = xmlSettings->getNumTags("POINT");

				int calibrationPointWidth = calibrationGridWidth + 1;
				int calibrationPointHeight = calibrationGridHeight + 1;
			
				float cameraCellWidth = 1.0f / calibrationGridWidth;
				float cameraCellHeight = 1.0f / calibrationGridHeight;
				
				for (int j = 0;j<calibrationPointWidth*calibrationPointHeight;j++)
				{
					if (numPointTags==calibrationPointWidth*calibrationPointHeight)
						xmlSettings->pushTag("POINT", j);
					vector2df newPoint;
					newPoint.X = xmlSettings->getValue("X",cameraCellWidth * (j%(calibrationGridWidth+1)));
					newPoint.Y = xmlSettings->getValue("Y",cameraCellHeight * (j/(calibrationGridWidth+1)));
					cameraBaseCalibration->calibrationPoints.push_back(newPoint);
					if (numPointTags==calibrationPointWidth*calibrationPointHeight)
						xmlSettings->popTag();
				}
				xmlSettings->popTag();

				xmlSettings->popTag();
				if (cameraBaseCalibration->camera != NULL)
					cameraBasesCalibration.push_back(cameraBaseCalibration);
			}

		}
	}
	xmlSettings->popTag();
	xmlSettings->popTag();
	delete xmlSettings;
}
Beispiel #14
0
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
	ServiceImages.push_back(ServiceImg("LAN Access Using PPP", StringToGUID("{00001102-0000-1000-8000-00805F9B34FB}"), 7));
	ServiceImages.push_back(ServiceImg("DialupNetworking", StringToGUID("{00001103-0000-1000-8000-00805F9B34FB}"), 7));
	ServiceImages.push_back(ServiceImg("OBEXObjectPush", StringToGUID("{00001105-0000-1000-8000-00805F9B34FB}"), 8));
	ServiceImages.push_back(ServiceImg("OBEXFileTransfer", StringToGUID("{00001106-0000-1000-8000-00805F9B34FB}"), 8));
	ServiceImages.push_back(ServiceImg("Cordless Telephony", StringToGUID("{00001109-0000-1000-8000-00805F9B34FB}"), 5));
	ServiceImages.push_back(ServiceImg("Audio Source", StringToGUID("{0000110A-0000-1000-8000-00805F9B34FB}"), 1));
	ServiceImages.push_back(ServiceImg("Audio Sink", StringToGUID("{0000110B-0000-1000-8000-00805F9B34FB}"), 1));
	ServiceImages.push_back(ServiceImg("AV Remote Control Target", StringToGUID("{0000110C-0000-1000-8000-00805F9B34FB}"), 2));
	ServiceImages.push_back(ServiceImg("Advanced Audio Distribution", StringToGUID("{0000110D-0000-1000-8000-00805F9B34FB}"), 1));
	ServiceImages.push_back(ServiceImg("AV Remote Control", StringToGUID("{0000110E-0000-1000-8000-00805F9B34FB}"), 2));
	ServiceImages.push_back(ServiceImg("Headset Audio Gateway", StringToGUID("{00001112-0000-1000-8000-00805F9B34FB}"), 6));
	ServiceImages.push_back(ServiceImg("WAP", StringToGUID("{00001113-0000-1000-8000-00805F9B34FB}"), 7));
	ServiceImages.push_back(ServiceImg("WAP Client", StringToGUID("{00001114-0000-1000-8000-00805F9B34FB}"), 7));
	ServiceImages.push_back(ServiceImg("Personal Area Network User (PANU)", StringToGUID("{00001115-0000-1000-8000-00805F9B34FB}"), 9));
	ServiceImages.push_back(ServiceImg("Network Access Point (NAP)", StringToGUID("{00001116-0000-1000-8000-00805F9B34FB}"), 7));
	ServiceImages.push_back(ServiceImg("Group Ad-hoc Network (GN)", StringToGUID("{00001117-0000-1000-8000-00805F9B34FB}"), 7));
	ServiceImages.push_back(ServiceImg("Handsfree", StringToGUID("{0000111E-0000-1000-8000-00805F9B34FB}"), 5));
	ServiceImages.push_back(ServiceImg("Handsfree Audio Gateway", StringToGUID("{0000111F-0000-1000-8000-00805F9B34FB}"), 5));
	ServiceImages.push_back(ServiceImg("SIM Access", StringToGUID("{0000112D-0000-1000-8000-00805F9B34FB}"), 10));
	ServiceImages.push_back(ServiceImg("Phonebook Access - PCE", StringToGUID("{0000112E-0000-1000-8000-00805F9B34FB}"), 0));
	ServiceImages.push_back(ServiceImg("Phonebook Access - PSE", StringToGUID("{0000112F-0000-1000-8000-00805F9B34FB}"), 0));
	ServiceImages.push_back(ServiceImg("Phonebook Access", StringToGUID("{00001130-0000-1000-8000-00805F9B34FB}"), 0));
	ServiceImages.push_back(ServiceImg("Headset headset", StringToGUID("{00001131-0000-1000-8000-00805F9B34FB}"), 6));
	ServiceImages.push_back(ServiceImg("Message Access Server", StringToGUID("{00001132-0000-1000-8000-00805F9B34FB}"), 4));
	ServiceImages.push_back(ServiceImg("Message Notification Server", StringToGUID("{00001133-0000-1000-8000-00805F9B34FB}"), 4));
	ServiceImages.push_back(ServiceImg("Message Access Profile", StringToGUID("{00001134-0000-1000-8000-00805F9B34FB}"), 4));
	ServiceImages.push_back(ServiceImg("Generic Networking", StringToGUID("{00001201-0000-1000-8000-00805F9B34FB}"), 7));
	ServiceImages.push_back(ServiceImg("Generic Audio", StringToGUID("{00001203-0000-1000-8000-00805F9B34FB}"), 1));
}
// and is subject to that software license agreement.

//---------------------------------------------------------------------------

#include <fmx.h>
#pragma hdrstop

#include "UHeartRateForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"

TfrmHeartMonitor *frmHeartMonitor;

const TBluetoothUUID HRSERVICE =
	StringToGUID("{0000180D-0000-1000-8000-00805F9B34FB}");
const TBluetoothUUID HRMEASUREMENT_CHARACTERISTIC =
	StringToGUID("{00002A37-0000-1000-8000-00805F9B34FB}");
const TBluetoothUUID BODY_SENSOR_LOCATION_CHARACTERISTIC =
	StringToGUID("{00002A38-0000-1000-8000-00805F9B34FB}");

const String BodySensorLocations[] =
	{"Other", "Chest", "Wrist", "Finger", "Hand", "Ear Lobe", "Foot"};

const int HR_VALUE_FORMAT_MASK        = 0x01;
const int SENSOR_CONTACT_STATUS_MASK  = 0x06;
const int ENERGY_EXPANDED_STATUS_MASK = 0x08;
const int RR_INTERVAL_MASK            = 0x10;

//---------------------------------------------------------------------------
String BytesToString(const TBytes &B)
Beispiel #16
0
int PERDXInitControlConfig(HWND hWnd, u8 padnum, int *controlmap, const char *inifilename)
{
   char tempstr[MAX_PATH];
   char string1[20];
   GUID guid;
   u32 i;
   int idlist[] = { IDC_UPTEXT, IDC_RIGHTTEXT, IDC_DOWNTEXT, IDC_LEFTTEXT,
                    IDC_RTEXT, IDC_LTEXT, IDC_STARTTEXT,
                    IDC_ATEXT, IDC_BTEXT, IDC_CTEXT,
                    IDC_XTEXT, IDC_YTEXT, IDC_ZTEXT
                  };

   sprintf(string1, "Peripheral%d%C", ((padnum/6)+1), 'A'+(padnum%6));

   // Let's first fetch the guid of the device and see if we can get a match
   if (GetPrivateProfileStringA(string1, "GUID", "", tempstr, MAX_PATH, inifilename) == 0)
   {
      if (padnum == 0)
      {
         // Let's use default values
         SendDlgItemMessage(hWnd, IDC_DXDEVICECB, CB_SETCURSEL, 1, 0);

         controlmap[0] = DIK_UP;
         controlmap[1] = DIK_RIGHT;
         controlmap[2] = DIK_DOWN;
         controlmap[3] = DIK_LEFT;
         controlmap[4] = DIK_Z;
         controlmap[5] = DIK_X;
         controlmap[6] = DIK_J;
         controlmap[7] = DIK_K;
         controlmap[8] = DIK_L;
         controlmap[9] = DIK_M;
         controlmap[10] = DIK_U;
         controlmap[11] = DIK_I;
         controlmap[12] = DIK_O;
         for (i = 0; i < 13; i++)
         {
            ConvertKBIDToName(controlmap[i], tempstr);
            SetDlgItemText(hWnd, idlist[i], _16(tempstr));
         }
      }
      else
      {
         SendDlgItemMessage(hWnd, IDC_DXDEVICECB, CB_SETCURSEL, 0, 0);
         return -1;
      }
   }
   else
   {
      LPDIRECTINPUT8 lpDI8temp = NULL;
      LPDIRECTINPUTDEVICE8 lpDIDevicetemp;
      DIDEVCAPS didc;
      int buttonid;

      StringToGUID(tempstr, &guid);

      // Let's find a match
      for (i = 0; i < numguids; i++)
      {
         if (memcmp(&guid, &GUIDDevice[i], sizeof(GUID)) == 0)
         {
            SendDlgItemMessage(hWnd, IDC_DXDEVICECB, CB_SETCURSEL, i+1, 0);
            break;
         }
      }

      if (FAILED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION,
          &IID_IDirectInput8, (LPVOID *)&lpDI8temp, NULL)))
         return -1;

      if (FAILED(IDirectInput8_CreateDevice(lpDI8temp, &GUIDDevice[i], &lpDIDevicetemp,
          NULL)))
      {
         IDirectInput8_Release(lpDI8temp);
         return -1;
      }

      didc.dwSize = sizeof(DIDEVCAPS);

      if (FAILED(IDirectInputDevice8_GetCapabilities(lpDIDevicetemp, &didc)))
      {
         IDirectInputDevice8_Release(lpDIDevicetemp);       
         IDirectInput8_Release(lpDI8temp);
         return -1;
      }

      if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_KEYBOARD)
      {
         sprintf(string1, "Peripheral%d%C", ((padnum/6)+1), 'A'+(padnum%6));

         for (i = 0; i < 13; i++)
         {
            buttonid = GetPrivateProfileIntA(string1, PerPadNames[i], 0, inifilename);
            printf("%2d: %d\n", i, buttonid);
            controlmap[i] = buttonid;
            ConvertKBIDToName(buttonid, tempstr);
            SetDlgItemText(hWnd, idlist[i], _16(tempstr));
         }
      }       
      else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_GAMEPAD ||
              GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_JOYSTICK)
      {
         sprintf(string1, "Peripheral%d%C", ((padnum/6)+1), 'A'+(padnum%6));

         for (i = 0; i < 13; i++)
         {
            buttonid = GetPrivateProfileIntA(string1, PerPadNames[i], 0, inifilename);
            controlmap[i] = buttonid;
            ConvertJoyIDToName(buttonid, tempstr);
            SetDlgItemText(hWnd, idlist[i], _16(tempstr));
         }
      }
      else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_MOUSE)
      {
         for (i = 0; i < 13; i++)
         {
            buttonid = GetPrivateProfileIntA(string1, PerPadNames[i], 0, inifilename);
            controlmap[i] = buttonid;
            ConvertMouseIDToName(buttonid, tempstr);
            SetDlgItemText(hWnd, idlist[i], _16(tempstr));
         }
      }

      IDirectInputDevice8_Release(lpDIDevicetemp);       
      IDirectInput8_Release(lpDI8temp);
   }

   return 0;
}
Beispiel #17
0
void PERDXLoadDevices(char *inifilename)
{
   char tempstr[MAX_PATH];
   char string1[20];
   char string2[20];
   GUID guid;
   DIDEVCAPS didc;
   u32 i;
   int j, i2;
   int buttonid;
   DIPROPDWORD dipdw;
   int id;
   DWORD coopflags=DISCL_FOREGROUND | DISCL_NONEXCLUSIVE;
   BOOL loaddefault=TRUE;
   int numpads;
   HRESULT hr;

   if (!PERCore)
      return;
   PerPortReset();
   memset(pad, 0, sizeof(pad));

   // Check Connection Type
   if (GetPrivateProfileStringA("Input", "Port1Type", "", tempstr, MAX_PATH, inifilename) == 0)
   {
      // Check if it's using the old ini settings for peripherals
      if (GetPrivateProfileStringA("Peripheral1", "GUID", "", tempstr, MAX_PATH, inifilename) != 0)
      {
         // Convert to the newer type of settings
         for (i = 0; i < 2; i++)
         {
            sprintf(string1, "Port%dType", (int)i+1);
            WritePrivateProfileStringA("Input", string1, "1", inifilename);

            sprintf(string1, "Peripheral%d", (int)i+1);
            sprintf(string2, "Peripheral%dA", (int)i+1);

            if (GetPrivateProfileStringA(string1, "GUID", "", tempstr, MAX_PATH, inifilename))
               WritePrivateProfileStringA(string2, "GUID", tempstr, inifilename);

            if (GetPrivateProfileStringA(string1, "EmulateType", "", tempstr, MAX_PATH, inifilename))
               WritePrivateProfileStringA(string2, "EmulateType", tempstr, inifilename);

            for (i2 = 0; i2 < 13; i2++)
            {
               if (GetPrivateProfileStringA(string1, PerPadNames[i2], "", tempstr, MAX_PATH, inifilename))
                  WritePrivateProfileStringA(string2, PerPadNames[i2], tempstr, inifilename);
            }
         }

         // Remove old ini entries
         for (i = 0; i < 12; i++)
         {
            sprintf(string1, "Peripheral%d", (int)i+1);
            WritePrivateProfileStringA(string1, NULL, NULL, inifilename);
         }

         loaddefault = FALSE;
      }
   }
   else 
      loaddefault = FALSE;

   if (loaddefault)
   {
      LoadDefaultPort1A();
      return;
   }

   // Load new type settings
   for (i = 0; i < 2; i++)
   {
      sprintf(string1, "Port%dType", (int)i+1);

      if (GetPrivateProfileStringA("Input", string1, "", tempstr, MAX_PATH, inifilename) != 0)
      {
         porttype[i] = atoi(tempstr);

         switch(porttype[i])
         {
            case 1:
               numpads = 1;
               break;
            case 2:
               numpads = 6;
               break;
            default:
               numpads = 0;
               break;
         }

         // Load new type settings
         for (j = 0; j < numpads; j++)
         {
            int padindex=(6*i)+j;
            padconf_struct *curdevice=&paddevice[padindex];
            sprintf(string1, "Peripheral%d%C", (int)i+1, 'A' + j);

            // Let's first fetch the guid of the device
            if (GetPrivateProfileStringA(string1, "GUID", "", tempstr, MAX_PATH, inifilename) == 0)
               continue;

            if (GetPrivateProfileStringA(string1, "EmulateType", "0", string2, MAX_PATH, inifilename))
            {
               curdevice->emulatetype = atoi(string2);
               if (curdevice->emulatetype == 0)
                  continue;
            }

            if (curdevice->lpDIDevice)
            {
               // Free the default keyboard, etc.
               IDirectInputDevice8_Unacquire(curdevice->lpDIDevice);
               IDirectInputDevice8_Release(curdevice->lpDIDevice);
            }

            StringToGUID(tempstr, &guid);

            // Ok, now that we've got the GUID of the device, let's set it up
            if (FAILED(IDirectInput8_CreateDevice(lpDI8, &guid, &lpDIDevice[padindex],
               NULL) ))
            {
               curdevice->lpDIDevice = NULL;
               curdevice->emulatetype = 0;
               continue;
            }

            curdevice->lpDIDevice = lpDIDevice[padindex];

            didc.dwSize = sizeof(DIDEVCAPS);

            if (FAILED(IDirectInputDevice8_GetCapabilities(lpDIDevice[padindex], &didc) ))
               continue;

            if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_KEYBOARD)
            {
               if (FAILED(IDirectInputDevice8_SetDataFormat(lpDIDevice[padindex], &c_dfDIKeyboard) ))
                  continue;
               curdevice->type = TYPE_KEYBOARD;
               coopflags |= DISCL_NOWINKEY;
            }       
            else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_GAMEPAD ||
               GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_JOYSTICK)
            {
               if (FAILED(IDirectInputDevice8_SetDataFormat(lpDIDevice[padindex], &c_dfDIJoystick2) ))
                  continue;
               curdevice->type = TYPE_JOYSTICK;
            }
            else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_MOUSE)
            {
               if (FAILED(IDirectInputDevice8_SetDataFormat(lpDIDevice[padindex], &c_dfDIMouse2) ))
                  continue;
               curdevice->type = TYPE_MOUSE;
               coopflags = DISCL_FOREGROUND | DISCL_EXCLUSIVE;
            }

            hr = IDirectInputDevice8_SetCooperativeLevel(lpDIDevice[i], DXGetWindow(), coopflags);
            if (FAILED(hr))
               continue;

            dipdw.diph.dwSize = sizeof(DIPROPDWORD);
            dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
            dipdw.diph.dwObj = 0;
            dipdw.diph.dwHow = DIPH_DEVICE;
            dipdw.dwData = 8; // should be enough

            // Setup Buffered input
            if (FAILED(IDirectInputDevice8_SetProperty(lpDIDevice[padindex], DIPROP_BUFFERSIZE, &dipdw.diph)))
               continue;

            IDirectInputDevice8_Acquire(lpDIDevice[padindex]);

            switch(curdevice->emulatetype)
            {
               case 1: // Standard Pad
                  id = PERPAD;
                  break;
               case 2: // Analog Pad
               case 3: // Stunner
               case 5: // Keyboard
                  id = 0;
                  break;
               case 4: // Mouse
                  id = PERMOUSE;
                  break;
               default: break;
            }

            // Make sure we're added to the smpc list
            if (i == 0)
               pad[padindex] = PerAddPeripheral(&PORTDATA1, id);
            else
               pad[padindex] = PerAddPeripheral(&PORTDATA2, id);

            // Now that we're all setup, let's fetch the controls from the ini
            if (curdevice->emulatetype != 3 &&
               curdevice->emulatetype != 4)
            {
               for (i2 = 0; i2 < 13; i2++)
               {
                  buttonid = GetPrivateProfileIntA(string1, PerPadNames[i2], 0, inifilename);
                  PerSetKey(buttonid, i2, pad[padindex]);
               }
            }
            else if (curdevice->emulatetype == 4)
            {
               for (i2 = 0; i2 < 4; i2++)
               {
                  buttonid = GetPrivateProfileIntA(string1, mouse_names[i2], 0, inifilename);
                  PerSetKey(buttonid, PERMOUSE_LEFT+i2, pad[padindex]);
               }
            }
         }
      }
   }
}
Beispiel #18
0
InputHook::InputHook() :
m_hookmask(HOOK_COM),
m_fakepidvid(MAKELONG(0x045E, 0x028E)),
m_timeout(0),
m_timeout_thread(INVALID_HANDLE_VALUE)
{
	IniFile ini;
	std::string inipath("x360ce.ini");
	if (!ini.Load(inipath))
		CheckCommonDirectory(&inipath, "x360ce");
	if (!ini.Load(inipath)) return;

	bool read_from_database = ReadGameDatabase();

	if (!read_from_database)
	{
		if (!ini.Get("InputHook", "HookMask", &m_hookmask, HOOK_COM))
		{
			bool check = false;
			ini.Get("InputHook", "HookLL", &check);
			if (check) m_hookmask |= HOOK_LL;

			ini.Get("InputHook", "HookCOM", &check);
			if (check) m_hookmask |= HOOK_COM;

			ini.Get("InputHook", "HookDI", &check);
			if (check) m_hookmask |= HOOK_DI;

			ini.Get("InputHook", "HookPIDVID", &check);
			if (check) m_hookmask |= HOOK_PIDVID;

			ini.Get("InputHook", "HookSA", &check);
			if (check) m_hookmask |= HOOK_SA;

			ini.Get("InputHook", "HookNAME", &check);
			if (check) m_hookmask |= HOOK_NAME;

			ini.Get("InputHook", "HookSTOP", &check);
			if (check) m_hookmask |= HOOK_STOP;

			ini.Get("InputHook", "HookWT", &check);
			if (check) m_hookmask |= HOOK_WT;
		}

		if (GetState(HOOK_PIDVID))
		{
			u32 vid;
			u32 pid;
			ini.Get<u32>("InputHook", "FakeVID", &vid, 0x045E);
			ini.Get<u32>("InputHook", "FakePID", &pid, 0x028E);

			if (vid != 0x045E || pid != 0x28E)
				m_fakepidvid = MAKELONG(vid, pid);
		}
	}

	if (m_hookmask)
	{
		PrintLog("InputHook starting...");

		// Initalize InputHook Devices
		for (u32 i = 0; i < XUSER_MAX_COUNT; ++i)
		{
			std::string section;
			std::string key = StringFormat("PAD%u", i + 1);
			if (!ini.Get("Mappings", key, &section))
				continue;

			u32 index = 0;
			if (!ini.Get(section, "UserIndex", &index))
				index = i;

			std::string buffer;
			GUID productid = GUID_NULL;
			GUID instanceid = GUID_NULL;

			if (ini.Get(section, "ProductGUID", &buffer))
				StringToGUID(&productid, buffer);

			if (ini.Get(section, "InstanceGUID", &buffer))
				StringToGUID(&instanceid, buffer);

			if (!IsEqualGUID(productid, GUID_NULL) && !IsEqualGUID(instanceid, GUID_NULL))
			{
				m_devices.push_back(InputHookDevice(index, productid, instanceid));
			}
		}
	}

	if (!m_devices.empty())
	{
		if (!read_from_database)
			ini.Get<u32>("InputHook", "Timeout", &m_timeout, 45);

		std::string maskname;
		if (MaskToName(&maskname, m_hookmask))
			PrintLog("HookMask 0x%08X: %s", m_hookmask, maskname.c_str());

		MH_Initialize();

		if (GetState(HOOK_LL))
			HookLL();

		if (GetState(HOOK_COM))
			HookCOM();

		if (GetState(HOOK_DI))
			HookDI();

		if (GetState(HOOK_SA))
			HookSA();

		if (GetState(HOOK_WT))
			HookWT();

		MH_EnableHook(MH_ALL_HOOKS);
	}
}