Skip to content

Commit

Permalink
Make the driver care about tracker status messages. (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitlith authored Jul 4, 2022
1 parent a5cce86 commit b4d9afa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/IVRDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace SlimeVRDriver {

virtual int getDeviceId() = 0;
virtual void PositionMessage(messages::Position& position) = 0;
virtual void StatusMessage(messages::TrackerStatus& status) = 0;

~IVRDevice() = default;
};
Expand Down
27 changes: 27 additions & 0 deletions src/TrackerDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ void SlimeVRDriver::TrackerDevice::PositionMessage(messages::Position &position)
this->last_pose_ = pose;
}

void SlimeVRDriver::TrackerDevice::StatusMessage(messages::TrackerStatus &status)
{
auto pose = this->last_pose_;
switch (status.status())
{
case messages::TrackerStatus_Status_OK:
pose.deviceIsConnected = true;
pose.poseIsValid = true;
break;
case messages::TrackerStatus_Status_DISCONNECTED:
pose.deviceIsConnected = false;
pose.poseIsValid = false;
default:
case messages::TrackerStatus_Status_ERROR:
case messages::TrackerStatus_Status_BUSY:
pose.deviceIsConnected = true;
pose.poseIsValid = false;
break;
}

// TODO: send position/rotation of 0 instead of last pose?

GetDriver()->GetDriverHost()->TrackedDevicePoseUpdated(this->device_index_, pose, sizeof(vr::DriverPose_t));

// TODO: update this->last_pose_?
}

DeviceType SlimeVRDriver::TrackerDevice::GetDeviceType()
{
return DeviceType::TRACKER;
Expand Down
1 change: 1 addition & 0 deletions src/TrackerDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace SlimeVRDriver {
virtual vr::DriverPose_t GetPose() override;
virtual int getDeviceId() override;
virtual void PositionMessage(messages::Position &position) override;
virtual void StatusMessage(messages::TrackerStatus &status) override;
private:
vr::TrackedDeviceIndex_t device_index_ = vr::k_unTrackedDeviceIndexInvalid;
std::string serial_;
Expand Down
6 changes: 6 additions & 0 deletions src/VRDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ void SlimeVRDriver::VRDriver::RunFrame()
if(device != this->devices_by_id.end()) {
device->second->PositionMessage(pos);
}
} else if(message->has_tracker_status()) {
messages::TrackerStatus status = message->tracker_status();
auto device = this->devices_by_id.find(status.tracker_id());
if (device != this->devices_by_id.end()) {
device->second->StatusMessage(status);
}
}
}

Expand Down

0 comments on commit b4d9afa

Please sign in to comment.