Skip to content

Commit

Permalink
Linux joystick compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Aug 31, 2017
1 parent 8924178 commit 431059e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Unreal/Environments/Blocks/Blocks.uproject
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"FileVersion": 3,
"EngineAssociation": "{1E0B7D38-2007-110B-0029-02294AE308CD}",
"Category": "",
"Description": "",
"Modules": [
Expand All @@ -17,6 +18,5 @@
"Name": "AirSim",
"Enabled": true
}
],
"EngineAssociation": "4.16"
]
}
23 changes: 16 additions & 7 deletions Unreal/Plugins/AirSim/Source/SimJoyStick/SimJoyStick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct SimJoyStick::impl {
case AxisMap::AxisType::RightX: return di_state.rx;
case AxisMap::AxisType::RightY: return di_state.ry;
case AxisMap::AxisType::RightZ: return di_state.rz;
default:
default:
throw std::invalid_argument("Unsupported rc_axis in getMappedValue");
}
}
Expand All @@ -99,7 +99,7 @@ struct SimJoyStick::impl {
break;
case AxisMap::AxisDirection::Normal: break;
case AxisMap::AxisDirection::Reverse: val = 1 - val; break;
default:
default:
throw std::invalid_argument("Unsupported map.direction in getAxisValue");
}

Expand Down Expand Up @@ -203,32 +203,41 @@ struct SimJoyStick::impl {
close(fd_);
}

void getJoyStickState(unsigned int index, SimJoyStick::State& state)
void getJoyStickState(unsigned int index, SimJoyStick::State& state, const AxisMaps& maps)
{
unused(maps);

static constexpr bool blocking = false;

//if this is new indec
if (index != last_index_) {
//close previos one
if (fd_ >= 0)
close(fd_);

//open new device
std::stringstream devicePath;
devicePath << "/dev/input/js" << index;

fd_ = open(devicePath.str().c_str(), blocking ? O_RDONLY : O_RDONLY | O_NONBLOCK);

state.is_initialized = fd_ >= 0;
last_index_ = index;
}

//if open was sucessfull
if (fd_ >= 0) {
//read the device
int bytes = read(fd_, &event_, sizeof(event_));

//if we didn't had valid read
if (bytes == -1 || bytes != sizeof(event_)) {
// NOTE if this condition is not met, we're probably out of sync and this
// Joystick instance is likely unusable

//TODO: set below to false?
//state.is_valid = false;
}
else {
state.is_connected = true;
state.is_valid = true;

if (event_.isButton()) {
if (event_.value == 0)
Expand All @@ -249,7 +258,7 @@ struct SimJoyStick::impl {
}
}
else
state.is_connected = false;
state.is_valid = false;
}

private:
Expand Down

0 comments on commit 431059e

Please sign in to comment.