add comments to clarify piuio inputdriver
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ InputHandler_Linux_PIUIO::InputHandler_Linux_PIUIO()
|
|||||||
{
|
{
|
||||||
LOG->Trace( "InputHandler_Linux_PIUIO::InputHandler_Linux_PIUIO" );
|
LOG->Trace( "InputHandler_Linux_PIUIO::InputHandler_Linux_PIUIO" );
|
||||||
|
|
||||||
|
// Open device file and make sure it's actually a device...
|
||||||
fd = open( "/dev/piuio0", O_RDONLY );
|
fd = open( "/dev/piuio0", O_RDONLY );
|
||||||
if( fd < 0 )
|
if( fd < 0 )
|
||||||
{
|
{
|
||||||
@@ -43,6 +45,7 @@ InputHandler_Linux_PIUIO::InputHandler_Linux_PIUIO()
|
|||||||
|
|
||||||
LOG->Info("Opened PIUIO device for input");
|
LOG->Info("Opened PIUIO device for input");
|
||||||
|
|
||||||
|
// Set up a flag we can use to stop the input thread gracefully
|
||||||
m_bShutdown = false;
|
m_bShutdown = false;
|
||||||
|
|
||||||
m_InputThread.SetName( "PIUIO thread" );
|
m_InputThread.SetName( "PIUIO thread" );
|
||||||
@@ -51,12 +54,13 @@ InputHandler_Linux_PIUIO::InputHandler_Linux_PIUIO()
|
|||||||
|
|
||||||
InputHandler_Linux_PIUIO::~InputHandler_Linux_PIUIO()
|
InputHandler_Linux_PIUIO::~InputHandler_Linux_PIUIO()
|
||||||
{
|
{
|
||||||
|
// Shut down the thread if it's running
|
||||||
if( m_InputThread.IsCreated() )
|
if( m_InputThread.IsCreated() )
|
||||||
{
|
{
|
||||||
m_bShutdown = true;
|
m_bShutdown = true;
|
||||||
LOG->Trace( "Shutting down PIUIO thread ..." );
|
LOG->Trace( "Shutting down PIUIO thread ..." );
|
||||||
m_InputThread.Wait();
|
m_InputThread.Wait();
|
||||||
LOG->Trace( "PIUIO thread shut down." );
|
LOG->Info( "PIUIO thread shut down." );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
@@ -74,6 +78,14 @@ void InputHandler_Linux_PIUIO::InputThread()
|
|||||||
unsigned char inputs[32];
|
unsigned char inputs[32];
|
||||||
while( !m_bShutdown )
|
while( !m_bShutdown )
|
||||||
{
|
{
|
||||||
|
// To get input from the PIUIO driver, just read from the
|
||||||
|
// device. This returns 32 bytes:
|
||||||
|
// 8 bytes/64 bits - first set of sensors (e.g. top sensor in
|
||||||
|
// each panel)
|
||||||
|
// 8 bytes/64 bits - second set of sensors
|
||||||
|
// 8 bytes/64 bits - third set of sensors
|
||||||
|
// 8 bytes/64 bits - fourth set of sensors
|
||||||
|
|
||||||
int ret = read(fd, &inputs, sizeof(inputs));
|
int ret = read(fd, &inputs, sizeof(inputs));
|
||||||
if (ret != sizeof(inputs))
|
if (ret != sizeof(inputs))
|
||||||
{
|
{
|
||||||
@@ -84,17 +96,33 @@ void InputHandler_Linux_PIUIO::InputThread()
|
|||||||
|
|
||||||
InputDevice id = InputDevice(DEVICE_JOY1);
|
InputDevice id = InputDevice(DEVICE_JOY1);
|
||||||
|
|
||||||
|
// The device reads *low* for an input that's pressed. So to
|
||||||
|
// combine the data from the sensors, we AND them together; if
|
||||||
|
// any sensor was pressed (0), the result will show pressed (0).
|
||||||
|
// Here we combine the second, third, and fourth sensors into
|
||||||
|
// the first set.
|
||||||
int i;
|
int i;
|
||||||
for (i = 8; i < 32; i++)
|
for (i = 8; i < 32; i++)
|
||||||
inputs[i % 8] &= inputs[i];
|
inputs[i % 8] &= inputs[i];
|
||||||
|
|
||||||
|
// To figure out if anything has changed since the last time we
|
||||||
|
// read input, we XOR the current readings with the previous
|
||||||
|
// readings.
|
||||||
for (i = 0; i < 8; i++)
|
for (i = 0; i < 8; i++)
|
||||||
lastInputs[i] ^= inputs[i];
|
lastInputs[i] ^= inputs[i];
|
||||||
|
|
||||||
|
// Iterate through the first 64 bits of the array one at a time,
|
||||||
|
// and generate an event for each one that has changed.
|
||||||
for (i = 0; i < 64; i++)
|
for (i = 0; i < 64; i++)
|
||||||
|
// Bit is set = status changed
|
||||||
if (lastInputs[i / 8] & (128 >> (i % 8)))
|
if (lastInputs[i / 8] & (128 >> (i % 8)))
|
||||||
|
// Make a "pressed" event if the current reading
|
||||||
|
// is 0, and a "released" event if it's 1.
|
||||||
ButtonPressed(DeviceInput(id, enum_add2(JOY_BUTTON_1, i),
|
ButtonPressed(DeviceInput(id, enum_add2(JOY_BUTTON_1, i),
|
||||||
!(inputs[i / 8] & (128 >> (i % 8))), now));
|
!(inputs[i / 8] & (128 >> (i % 8))), now));
|
||||||
for (i = 0; i < 8; i++)
|
|
||||||
lastInputs[i] = inputs[i];
|
// Save the current reading to use next time
|
||||||
|
memcpy(lastInputs, inputs, sizeof(lastInputs));
|
||||||
}
|
}
|
||||||
|
|
||||||
InputHandler::UpdateTimer();
|
InputHandler::UpdateTimer();
|
||||||
|
|||||||
Reference in New Issue
Block a user