Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Add PSEye resolution control #400

Merged
merged 1 commit into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 111 additions & 31 deletions src/psmoveconfigtool/AppStage_ColorCalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ AppStage_ColorCalibration::AppStage_ColorCalibration(App *app)
, m_menuState(AppStage_ColorCalibration::inactive)
, m_video_buffer_state(nullptr)
, m_videoDisplayMode(AppStage_ColorCalibration::eVideoDisplayMode::mode_bgr)
, m_trackerFramerate(0)
, m_trackerFrameWidth(0)
, m_trackerFrameRate(0)
, m_trackerExposure(0)
, m_trackerGain(0)
, m_bTurnOnAllControllers(false)
Expand Down Expand Up @@ -386,7 +387,7 @@ void AppStage_ColorCalibration::renderUI()
if (m_bShowWindows)
{
ImGui::SetNextWindowPos(ImVec2(10.f, 10.f));
ImGui::SetNextWindowSize(ImVec2(k_panel_width, 260));
ImGui::SetNextWindowSize(ImVec2(k_panel_width, 280));
ImGui::Begin(k_window_title, nullptr, window_flags);

if (ImGui::Button("Return to Main Menu"))
Expand Down Expand Up @@ -417,36 +418,75 @@ void AppStage_ColorCalibration::renderUI()
}
ImGui::SameLine();
ImGui::Text("Video [F]ilter Mode: %s", k_video_display_mode_names[m_videoDisplayMode]);

if (ImGui::Button("-##FrameWidth"))
{
if (m_trackerFrameWidth == 640) request_tracker_set_frame_width(m_trackerFrameWidth - 320);
}
ImGui::SameLine();
if (ImGui::Button("+##FrameWidth"))
{
if (m_trackerFrameWidth == 320) request_tracker_set_frame_width(m_trackerFrameWidth + 320);
}
ImGui::SameLine();
ImGui::Text("Frame Width: %.0f", m_trackerFrameWidth);

int frame_rate_positive_change = 10;
int frame_rate_negative_change = -10;

double val = m_trackerFramerate;

if (val == 2) { frame_rate_positive_change = 1; frame_rate_negative_change = 0; }
else if (val == 3) { frame_rate_positive_change = 2; frame_rate_negative_change = -1; }
else if (val == 5) { frame_rate_positive_change = 3; frame_rate_negative_change = -0; }
else if (val == 8) { frame_rate_positive_change = 2; frame_rate_negative_change = -3; }
else if (val == 10) { frame_rate_positive_change = 5; frame_rate_negative_change = -2; }
else if (val == 15) { frame_rate_positive_change = 5; frame_rate_negative_change = -5; }
else if (val == 20) { frame_rate_positive_change = 5; frame_rate_negative_change = -5; }
else if (val == 25) { frame_rate_positive_change = 5; frame_rate_negative_change = -5; }
else if (val == 30) { { frame_rate_negative_change = -5; } }
else if (val == 60) { { frame_rate_positive_change = 15; } }
else if (val == 75) { frame_rate_positive_change = 0; frame_rate_negative_change = -15; }
else if (val == 83) { frame_rate_positive_change = 0; frame_rate_negative_change = -8; }

if (ImGui::Button("-##Framerate"))
double val = m_trackerFrameRate;
if (m_trackerFrameWidth == 320)
{
if (val == 2) { frame_rate_positive_change = 1; frame_rate_negative_change = 0; }
else if (val == 3) { frame_rate_positive_change = 2; frame_rate_negative_change = -1; }
else if (val == 5) { frame_rate_positive_change = 2; frame_rate_negative_change = -0; }
else if (val == 7) { frame_rate_positive_change = 3; frame_rate_negative_change = -2; }
else if (val == 10) { frame_rate_positive_change = 2; frame_rate_negative_change = -3; }
else if (val == 12) { frame_rate_positive_change = 3; frame_rate_negative_change = -2; }
else if (val == 15) { frame_rate_positive_change = 4; frame_rate_negative_change = -3; }
else if (val == 17) { frame_rate_positive_change = 13; frame_rate_negative_change = -4; }
else if (val == 30) { frame_rate_positive_change = 7; frame_rate_negative_change = -13; }
else if (val == 37) { frame_rate_positive_change = 3; frame_rate_negative_change = -7; }
else if (val == 40) { frame_rate_positive_change = 10; frame_rate_negative_change = -3; }
else if (val == 50) { frame_rate_positive_change = 10; frame_rate_negative_change = -10; }
else if (val == 60) { frame_rate_positive_change = 15; frame_rate_negative_change = -10; }
else if (val == 75) { frame_rate_positive_change = 15; frame_rate_negative_change = -15; }
else if (val == 90) { frame_rate_positive_change = 10; frame_rate_negative_change = -15; }
else if (val == 100) { frame_rate_positive_change = 25; frame_rate_negative_change = -10; }
else if (val == 125) { frame_rate_positive_change = 12; frame_rate_negative_change = -25; }
else if (val == 137) { frame_rate_positive_change = 13; frame_rate_negative_change = -12; }
else if (val == 150) { frame_rate_positive_change = 37; frame_rate_negative_change = -13; }
else if (val == 187) { frame_rate_positive_change = 0; frame_rate_negative_change = -37; }
else if (val == 205) { frame_rate_positive_change = 0; frame_rate_negative_change = -18; }
else if (val == 290) { frame_rate_positive_change = 0; frame_rate_negative_change = -85; }
}
else
{
request_tracker_set_frame_rate(m_trackerFramerate + frame_rate_negative_change);
if (val == 2) { frame_rate_positive_change = 1; frame_rate_negative_change = 0; }
else if (val == 3) { frame_rate_positive_change = 2; frame_rate_negative_change = -1; }
else if (val == 5) { frame_rate_positive_change = 3; frame_rate_negative_change = -0; }
else if (val == 8) { frame_rate_positive_change = 2; frame_rate_negative_change = -3; }
else if (val == 10) { frame_rate_positive_change = 5; frame_rate_negative_change = -2; }
else if (val == 15) { frame_rate_positive_change = 5; frame_rate_negative_change = -5; }
else if (val == 20) { frame_rate_positive_change = 5; frame_rate_negative_change = -5; }
else if (val == 25) { frame_rate_positive_change = 5; frame_rate_negative_change = -5; }
else if (val == 30) { { frame_rate_negative_change = -5; } }
else if (val == 60) { { frame_rate_positive_change = 15; } }
else if (val == 75) { frame_rate_positive_change = 0; frame_rate_negative_change = -15; }
else if (val == 83) { frame_rate_positive_change = 0; frame_rate_negative_change = -8; }
}

if (ImGui::Button("-##FrameRate"))
{
request_tracker_set_frame_rate(m_trackerFrameRate + frame_rate_negative_change);
}
ImGui::SameLine();
if (ImGui::Button("+##Framerate"))
if (ImGui::Button("+##FrameRate"))
{
request_tracker_set_frame_rate(m_trackerFramerate + frame_rate_positive_change);
request_tracker_set_frame_rate(m_trackerFrameRate + frame_rate_positive_change);
}
ImGui::SameLine();
ImGui::Text("Framerate: %.0f", m_trackerFramerate);
ImGui::Text("Frame Rate: %.0f", m_trackerFrameRate);

if (ImGui::Button("-##Exposure"))
{
Expand Down Expand Up @@ -768,14 +808,10 @@ void AppStage_ColorCalibration::renderUI()
} break;

case eMenuState::blank1:
setState(eMenuState::blank3);
std::this_thread::sleep_for(std::chrono::milliseconds(auto_calib_sleep));
break;
case eMenuState::blank2:
setState(eMenuState::blank2);
std::this_thread::sleep_for(std::chrono::milliseconds(auto_calib_sleep));
break;
case eMenuState::blank3:
case eMenuState::blank2:
setState(eMenuState::autoConfig);
std::this_thread::sleep_for(std::chrono::milliseconds(auto_calib_sleep));
break;
Expand Down Expand Up @@ -1026,11 +1062,54 @@ void AppStage_ColorCalibration::release_video_buffers()
m_video_buffer_state = nullptr;
}

void AppStage_ColorCalibration::request_tracker_set_frame_width(double value)
{
// Tell the psmove service that we want to change frame width.
RequestPtr request(new PSMoveProtocol::Request());
request->set_type(PSMoveProtocol::Request_RequestType_SET_TRACKER_FRAME_WIDTH);
request->mutable_request_set_tracker_frame_width()->set_tracker_id(m_trackerView->tracker_info.tracker_id);
request->mutable_request_set_tracker_frame_width()->set_value(static_cast<float>(value));
request->mutable_request_set_tracker_frame_width()->set_save_setting(true);

PSMRequestID request_id;
PSM_SendOpaqueRequest(&request, &request_id);
PSM_RegisterCallback(request_id, AppStage_ColorCalibration::handle_tracker_set_frame_width_response, this);

// Exit and re-enter Color Calibration
m_app->getAppStage<AppStage_TrackerSettings>()->gotoColorCalib();
request_exit_to_app_stage(AppStage_TrackerSettings::APP_STAGE_NAME);
}

void AppStage_ColorCalibration::handle_tracker_set_frame_width_response(
const PSMResponseMessage *response,
void *userdata)
{
PSMResult ResultCode = response->result_code;
PSMResponseHandle response_handle = response->opaque_response_handle;
AppStage_ColorCalibration *thisPtr = static_cast<AppStage_ColorCalibration *>(userdata);

switch (ResultCode)
{
case PSMResult_Success:
{
const PSMoveProtocol::Response *response = GET_PSMOVEPROTOCOL_RESPONSE(response_handle);
thisPtr->m_trackerFrameWidth = response->result_set_tracker_frame_width().new_frame_width();
} break;
case PSMResult_Error:
case PSMResult_Canceled:
case PSMResult_Timeout:
{
//###HipsterSloth $TODO - Replace with C_API style log
//CLIENT_LOG_INFO("AppStage_ColorCalibration") << "Failed to set the tracker frame width!";
} break;
}
}

void AppStage_ColorCalibration::request_tracker_set_frame_rate(double value)
{
// Tell the psmove service that we want to change frame rate.
RequestPtr request(new PSMoveProtocol::Request());
request->set_type(PSMoveProtocol::Request_RequestType_SET_TRACKER_FRAMERATE);
request->set_type(PSMoveProtocol::Request_RequestType_SET_TRACKER_FRAME_RATE);
request->mutable_request_set_tracker_frame_rate()->set_tracker_id(m_trackerView->tracker_info.tracker_id);
request->mutable_request_set_tracker_frame_rate()->set_value(static_cast<float>(value));
request->mutable_request_set_tracker_frame_rate()->set_save_setting(true);
Expand All @@ -1053,7 +1132,7 @@ void AppStage_ColorCalibration::handle_tracker_set_frame_rate_response(
case PSMResult_Success:
{
const PSMoveProtocol::Response *response = GET_PSMOVEPROTOCOL_RESPONSE(response_handle);
thisPtr->m_trackerFramerate = response->result_set_tracker_frame_rate().new_frame_rate();
thisPtr->m_trackerFrameRate = response->result_set_tracker_frame_rate().new_frame_rate();
} break;
case PSMResult_Error:
case PSMResult_Canceled:
Expand Down Expand Up @@ -1307,7 +1386,8 @@ void AppStage_ColorCalibration::handle_tracker_get_settings_response(
case PSMResult_Success:
{
const PSMoveProtocol::Response *response = GET_PSMOVEPROTOCOL_RESPONSE(response_handle);
thisPtr->m_trackerFramerate = response->result_tracker_settings().frame_rate();
thisPtr->m_trackerFrameWidth = response->result_tracker_settings().frame_width();
thisPtr->m_trackerFrameRate = response->result_tracker_settings().frame_rate();
thisPtr->m_trackerExposure = response->result_tracker_settings().exposure();
thisPtr->m_trackerGain = response->result_tracker_settings().gain();

Expand Down Expand Up @@ -1496,7 +1576,7 @@ void AppStage_ColorCalibration::request_change_controller(int step)
void AppStage_ColorCalibration::request_change_tracker(int step)
{
m_app->getAppStage<AppStage_ColorCalibration>()->
set_autoConfig(m_bAutoChangeColor, m_bAutoChangeController, m_bAutoChangeTracker);
set_autoConfig(m_bAutoChangeColor, m_bAutoChangeController, m_bAutoChangeTracker);
//int TrackerId = m_trackerView->tracker_info.tracker_id;
if (tracker_index + step < tracker_count && tracker_index + step >= 0)
{
Expand Down
10 changes: 8 additions & 2 deletions src/psmoveconfigtool/AppStage_ColorCalibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class AppStage_ColorCalibration : public AppStage
autoConfig,
blank1,
blank2,
blank3,
changeController,
changeTracker,

Expand Down Expand Up @@ -107,6 +106,11 @@ class AppStage_ColorCalibration : public AppStage
const PSMResponseMessage *response,
void *userdata);

void request_tracker_set_frame_width(double value);
static void handle_tracker_set_frame_width_response(
const PSMResponseMessage *response,
void *userdata);

void request_tracker_set_frame_rate(double value);
static void handle_tracker_set_frame_rate_response(
const PSMResponseMessage *response,
Expand Down Expand Up @@ -150,6 +154,7 @@ class AppStage_ColorCalibration : public AppStage

void request_change_controller(int step);
void request_change_tracker(int step);
void request_refresh_tracker();

inline TrackerColorPreset getColorPreset()
{ return m_colorPresets[m_masterTrackingColorType]; }
Expand All @@ -176,7 +181,8 @@ class AppStage_ColorCalibration : public AppStage
eVideoDisplayMode m_videoDisplayMode;

// Tracker Settings state
double m_trackerFramerate;
double m_trackerFrameWidth;
double m_trackerFrameRate;
double m_trackerExposure;
double m_trackerGain;
std::vector<TrackerOption> m_trackerOptions;
Expand Down
3 changes: 2 additions & 1 deletion src/psmoveconfigtool/AppStage_TrackerSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ AppStage_TrackerSettings::AppStage_TrackerSettings(App *app)
, m_selectedTrackerIndex(-1)
, m_selectedControllerIndex(-1)
, m_selectedHmdIndex(-1)
, m_gotoColorCalib(false)
{ }

void AppStage_TrackerSettings::enter()
Expand Down Expand Up @@ -329,7 +330,7 @@ void AppStage_TrackerSettings::renderUI()

if (m_app->getIsLocalServer())
{
if (ImGui::Button("Calibrate Controller Tracking Colors"))
if (ImGui::Button("Calibrate Controller Tracking Colors") || m_gotoColorCalib)
{
const ControllerInfo *controller = get_selected_controller();
if (controller != NULL) {
Expand Down
4 changes: 4 additions & 0 deletions src/psmoveconfigtool/AppStage_TrackerSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class AppStage_TrackerSettings : public AppStage

static const char *APP_STAGE_NAME;

void gotoColorCalib() { m_gotoColorCalib = true; }

protected:
virtual bool onClientAPIEvent(
PSMEventMessage::eEventType event,
Expand Down Expand Up @@ -97,6 +99,8 @@ class AppStage_TrackerSettings : public AppStage
int m_selectedTrackerIndex;
int m_selectedControllerIndex;
int m_selectedHmdIndex;

bool m_gotoColorCalib;
};

#endif // APP_STAGE_TRACKER_SETTINGS_H
50 changes: 42 additions & 8 deletions src/psmoveprotocol/PSMoveProtocol.proto
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ message Request {

GET_SERVICE_VERSION= 39;

SET_TRACKER_FRAMERATE = 40;
SET_TRACKER_FRAME_RATE = 40;
SET_TRACKER_FRAME_WIDTH = 41;
SET_TRACKER_FRAME_HEIGHT = 42;
}
RequestType type = 2;

Expand Down Expand Up @@ -439,13 +441,29 @@ message Request {
}
RequestSetHMDPredictionTime request_set_hmd_prediction_time = 37;

// Parameters for SET_TRACKER_FRAMERATE
message RequestSetTrackerFramerate {
// Parameters for SET_TRACKER_FRAME_RATE
message RequestSetTrackerFrameRate {
int32 tracker_id = 1;
float value = 2;
bool save_setting= 3;
}
RequestSetTrackerFramerate request_set_tracker_frame_rate = 38;
RequestSetTrackerFrameRate request_set_tracker_frame_rate = 38;

// Parameters for SET_TRACKER_FRAME_WIDTH
message RequestSetTrackerFrameWidth {
int32 tracker_id = 1;
float value = 2;
bool save_setting= 3;
}
RequestSetTrackerFrameWidth request_set_tracker_frame_width = 39;

// Parameters for SET_TRACKER_FRAME_HEIGHT
message RequestSetTrackerFrameHeight {
int32 tracker_id = 1;
float value = 2;
bool save_setting= 3;
}
RequestSetTrackerFrameHeight request_set_tracker_frame_height = 40;
}

// Reliable (TCP) responses to requests
Expand All @@ -471,7 +489,9 @@ message Response {
HMD_LIST= 16;
HMD_LIST_UPDATED= 17;
SERVICE_VERSION= 18;
TRACKER_FRAMERATE_UPDATED= 19;
TRACKER_FRAME_RATE_UPDATED= 19;
TRACKER_FRAME_WIDTH_UPDATED= 20;
TRACKER_FRAME_HEIGHT_UPDATED= 21;
}

enum ResultCode {
Expand Down Expand Up @@ -584,6 +604,8 @@ message Response {
repeated OptionSet option_sets= 3;
repeated TrackingColorPreset color_presets = 4;
float frame_rate= 5;
float frame_width= 6;
float frame_height= 7;
}
ResultTrackerSettings result_tracker_settings = 25;

Expand Down Expand Up @@ -642,11 +664,23 @@ message Response {
}
ResultServiceVersion result_service_version = 32;

// This is returned in response to a SET_TRACKER_FRAMERATE request
message ResultSetTrackerFramerate {
// This is returned in response to a SET_TRACKER_FRAME_RATE request
message ResultSetTrackerFrameRate {
float new_frame_rate= 1;
}
ResultSetTrackerFramerate result_set_tracker_frame_rate = 33;
ResultSetTrackerFrameRate result_set_tracker_frame_rate = 33;

// This is returned in response to a SET_TRACKER_FRAME_WIDTH request
message ResultSetTrackerFrameWidth {
float new_frame_width= 1;
}
ResultSetTrackerFrameWidth result_set_tracker_frame_width = 34;

// This is returned in response to a SET_TRACKER_FRAME_HEIGHT request
message ResultSetTrackerFrameHeight {
float new_frame_height= 1;
}
ResultSetTrackerFrameHeight result_set_tracker_frame_height = 35;
}

// Unreliable (UDP) device data packet sent from service to clients
Expand Down
10 changes: 8 additions & 2 deletions src/psmoveservice/Device/Interface/DeviceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,14 @@ class ITrackerInterface : public IDeviceInterface
virtual void loadSettings() = 0;
virtual void saveSettings() = 0;

virtual void setFramerate(double value, bool bUpdateConfig) = 0;
virtual double getFramerate() const = 0;
virtual void setFrameWidth(double value, bool bUpdateConfig) = 0;
virtual double getFrameWidth() const = 0;

virtual void setFrameHeight(double value, bool bUpdateConfig) = 0;
virtual double getFrameHeight() const = 0;

virtual void setFrameRate(double value, bool bUpdateConfig) = 0;
virtual double getFrameRate() const = 0;

virtual void setExposure(double value, bool bUpdateConfig) = 0;
virtual double getExposure() const = 0;
Expand Down
Loading