At the moment I have a working Bluetooth connection with my gamecontroller. Now I am trying to catch the button events, but it's not that easy. I have the following code:
private Stream mmInStream;
private Stream mmOutStream;
public BluetoothController()
{
}
public void Read(BluetoothSocket socket)
{
Stream tmpIn = null;
Stream tmpOut = null;
try
{
tmpIn = socket.InputStream;
tmpOut = socket.OutputStream;
}
catch (IOException ex)
{
throw ex;
}
mmInStream = tmpIn;
mmOutStream = tmpOut;
Thread thread = new Thread(new ThreadStart(Run));
thread.Start();
}
protected void Run()
{
byte[] buffer = new byte[1024];
int bytes;
while (true)
{
try
{
// Thanks to @spaceplane
if (mmInStream.IsDataAvailable())
{
// Read from the InputStream
bytes = mmInStream.Read(buffer, 0, buffer.Length);
}
}
catch (Exception ex)
{
throw ex;
}
}
}
When I press a button on the gamecontroller, it's not going inside the next line:
if (mmInStream.IsDataAvailable())
What's wrong here?