Skip to content
This repository was archived by the owner on Nov 20, 2022. It is now read-only.

K2API: (7) Other functions & methods

公彦赤屋先 edited this page Aug 30, 2021 · 1 revision

ktvr::refresh_tracker_pose

This will let you refresh a tracker (so call TrackedDevicePoseUpdated) and hold it from going into standby / sleep.
K2Driver doesn't update trackers on its own which may cause issues with old apps like OVRIE, which expect that.

KTVR refreshes trackers here, if they are frozen - to keep them from going into sleep.

ktvr::request_vr_restart

If you want to request a restart from SteamVR, just call this and provide some reason.
KTVR requests a restart here, after disabling or enabling a tracker.
Note that if the reason's empty, nothing will happen.

ktvr::test_connection

To test the connection with server, you'll likely need to ping it.
This function will ping the server and collect times of parsing, sending and return.
KTVR tests connection 3 times here, parses here and updates the label here.

Sample code to test the connection:

// Send a ping message and capture the data
const auto [test_response, send_time, full_time] = ktvr::test_connection();

// Dump data to variables
KinectSettings::pingTime = full_time;
KinectSettings::parsingTime = std::clamp( // Subtract message creation (got) time and send time
	test_response.messageTimestamp - test_response.messageManualTimestamp,
	static_cast<long long>(1), LLONG_MAX);

// Log ?success
LOG(INFO) <<
	"Connection test has ended, [result: " <<
	(test_response.success ? "success" : "fail") <<
	"], response code: " << test_response.result;

// Log some data if needed
LOG_IF(INFO, log) <<
	"\nTested ping time: " << full_time << " [micros], " <<

	"call time: " <<
	std::clamp( // Subtract message creation (got) time and send time
		send_time - test_response.messageManualTimestamp,
		static_cast<long long>(0), LLONG_MAX) <<
	" [micros], " <<

	"\nparsing time: " <<
	KinectSettings::parsingTime << // Just look at the k2api
	" [micros], "

	"flight-back time: " <<
	std::clamp( // Subtract message creation (got) time and send time
		K2API_GET_TIMESTAMP_NOW - test_response.messageManualTimestamp,
		static_cast<long long>(1), LLONG_MAX) <<
	" [micros]";

// Now this is if we've succeeded
test_response.success;

K2API_GET_TIMESTAMP_NOW

K2API_GET_TIMESTAMP_NOW is a macro which will return the current time since epoch in microseconds.
This is used for timestamping ping messages. (and some / all general messages too)

Clone this wiki locally