Skip to content

Commit

Permalink
finally fix haptics
Browse files Browse the repository at this point in the history
like it says in the tin
  • Loading branch information
mm0zct committed Jun 23, 2023
1 parent 7d2ea35 commit a2c5784
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 46 deletions.
Binary file modified ReleasePackage/OculusTouchLink.7z
Binary file not shown.
Binary file modified ReleasePackage/OculusTouchLink/ovr_test.exe
Binary file not shown.
Binary file modified ovr_test/.vs/ovr_test/v16/.suo
Binary file not shown.
Binary file modified ovr_test/.vs/ovr_test/v16/Browse.VC.db
Binary file not shown.
33 changes: 31 additions & 2 deletions ovr_test/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <tuple>
#define _USE_MATH_DEFINES
#include <math.h>

#define DEBUG_VIB 1

class unique_window_id {
public:
unique_window_id() {
Expand Down Expand Up @@ -392,7 +395,7 @@ std::vector<config_window_object> config_windows = {

, { L"World Rotation Offset Euler Yaw Pitch Roll",L"EDIT", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_FLAT | BS_TEXT | ES_READONLY,
default_wm_command, default_init }
, { L"1.0000 0.0000 0.0000 0.0000",L"EDIT", WS_VISIBLE | WS_CHILD | ES_NUMBER,
, { L"0.0000 0.0000 0.0000",L"EDIT", WS_VISIBLE | WS_CHILD | ES_NUMBER,
[](HWND window, WPARAM wp, LPARAM lp, shared_buffer* comm_buffer) {
switch (HIWORD(wp))
{
Expand All @@ -403,7 +406,7 @@ std::vector<config_window_object> config_windows = {
const size_t len = 64;
WCHAR Buffer[len];
WCHAR CompBuffer[len];
double offset[4];
double offset[3];
GetWindowText((HWND)lp, Buffer, len);
swscanf_s(Buffer, L"%lf %lf %lf", &offset[0], &offset[1], &offset[2]);
std::wcout << L"control text is: " << Buffer << std::endl;
Expand Down Expand Up @@ -500,6 +503,32 @@ std::vector<config_window_object> config_windows = {
GUI_Manager::self->reset_settings_window();
return;
}, default_init }
#ifdef DEBUG_VIB
, { L"frequency amplitude duration",L"EDIT", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_FLAT | BS_TEXT | ES_READONLY,
default_wm_command, default_init }
, { L"0.0000 0.0000 0.0000",L"EDIT", WS_VISIBLE | WS_CHILD | ES_NUMBER,
[](HWND window, WPARAM wp, LPARAM lp, shared_buffer* comm_buffer) {
switch (HIWORD(wp))
{
case EN_CHANGE:
{
const size_t len = 64;
WCHAR Buffer[len];
double offset[3];
GetWindowText((HWND)lp, Buffer, len);
swscanf_s(Buffer, L"%lf %lf %lf", &offset[0], &offset[1], &offset[2]);
std::wcout << L"control text is: " << Buffer << std::endl;
std::cout << "parsed vib " << offset[0] << " " << offset[1] << " " << offset[2] << std::endl;

comm_buffer->vib_frequency[0] = offset[0];
comm_buffer->vib_amplitude[0] = offset[1];
comm_buffer->vib_duration_s[0] = offset[2];
comm_buffer->vib_valid[0] = true;
}
}
return;
}, default_init }
#endif
};

std::map<HWND, config_window_object*> config_window_map;
Expand Down
93 changes: 53 additions & 40 deletions ovr_test/ovr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ void main_loop(ovrSession mSession, HANDLE comm_mutex, shared_buffer* comm_buffe
comm_buffer->input_state.IndexTrigger[i] = inputState.IndexTrigger[i];
comm_buffer->input_state.Thumbstick[i] = inputState.Thumbstick[i];

if (comm_buffer->vib_valid[i]) {
if (comm_buffer->vib_valid[i] && comm_buffer->vib_amplitude[i]) {
add_vibration(i == 1, comm_buffer->vib_frequency[i], comm_buffer->vib_amplitude[i], comm_buffer->vib_duration_s[i]);
comm_buffer->vib_valid[i] = 0;
//printf("vib[%u] dur %f=%f | freq %f | amp %f\n", i, comm_buffer->vib_duration_s[i], comm_buffer->vib_duration_s[i]*320, comm_buffer->vib_frequency[i], comm_buffer->vib_amplitude[i]);
printf("vib[%u] dur %f=%f | freq %f | amp %f\n", i, comm_buffer->vib_duration_s[i], comm_buffer->vib_duration_s[i]*320, comm_buffer->vib_frequency[i], comm_buffer->vib_amplitude[i]);
#if 0
int duration = comm_buffer->vib_duration_s[i] * 320;
if (duration > 128) duration = 128;
Expand Down Expand Up @@ -237,9 +237,9 @@ void reset_config_settings(config_data& config) {
config.external_tracking = false;
config.track_hmd = false;
config.min_amplitude = 64;
config.amplitude_scale = 10.0;
config.amplitude_scale = 1.0;
config.sqrt_pre_filter = false;
config.sqrt_post_filter = false;
config.sqrt_post_filter = true;
config.do_rendering = false;
config.do_world_transformation = false;
config.world_translation[0] = 0.0;
Expand Down Expand Up @@ -467,20 +467,25 @@ std::vector<uint8_t> pulse_patterns[17] = {
{},
{255},
{255,0},
{},
{196,255,128,0},
{},
{196,255,196,128,0,0,0},
{},
{196,255,255,128,64,0,0,0},
{},
{196,255,255,196,128,0,0,0,0,0},
{},
{},
{},
{},
{},
{64,128,196,255,255,128,64,32,0,0,0,0,0,0,0,0}
{255,0,0},
//{196,255,128,0},
{255,0,0,0},
{255,0,0,0,0},
//{196,255,196,128,0,0,0},
{255,0,0,0,0,0},
{255,0,0,0,0,0,0},
//{196,255,255,128,64,0,0,0},
{255,0,0,0,0,0,0,0},
{255,0,0,0,0,0,0,0,0},
{255,0,0,0,0,0,0,0,0,0},
//{196,255,255,196,128,0,0,0,0,0},
{255,0,0,0,0,0,0,0,0,0,0},
{255,0,0,0,0,0,0,0,0,0,0,0},
{255,0,0,0,0,0,0,0,0,0,0,0,0},
{255,0,0,0,0,0,0,0,0,0,0,0,0,0},
{255,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
//{64,128,196,255,255,128,64,32,0,0,0,0,0,0,0,0}
};


Expand Down Expand Up @@ -513,51 +518,59 @@ void add_vib_sample_part1(bool isRightHand, uint8_t pulse_pattern_index, uint32_
}
}


printf("\n");
for (int i = 0; i < sample_count; i++) {
uint8_t sample_value = pulse_patterns[pulse_pattern_index][(sample_offset + i) % pulse_pattern_index];
printf("0x%02x ", (unsigned int)clamp_scale(sample_value, amplitude));
add_vib_sample(isRightHand, clamp_scale(sample_value, amplitude), next_index + i, pulse_pattern_index, (sample_offset + i) % pulse_pattern_index);

}

printf("\n");
}

void add_vibration(bool isRightHand, float amplitude, float frequency, float duration) {
void add_vibration(bool isRightHand, float frequency, float amplitude, float duration) {

//std::cout << " adding haptic for amplitude " << amplitude << " frequency " << frequency << " duration " << duration << std::endl;

if ((amplitude <= 0) || (frequency <= 0) /*|| (duration <= 0)*/) return;

if (frequency > 1.0)frequency = 1.0;
float amp = amplitude/100.0f;
float freq = frequency * 320.0f;
uint32_t requested_duration = duration * 320; // 320 Hz processing rate
if (requested_duration < 2) requested_duration = 2;
uint32_t requested_duration = duration * 160; // 320 Hz processing rate? seems to be 160
//if (requested_duration < 2) requested_duration = 2;
if (requested_duration < 1) requested_duration = 1;
uint32_t min_duration = 1;
uint32_t pulse_width = 1;
if (freq < 160) {
// uint32_t pulse_width = 1;
min_duration = 320 / freq;
if (min_duration < 1) min_duration = 1;
if (min_duration > 16)min_duration = 16;
/* if (freq <= 160) {
min_duration = 2;
pulse_width = 1;
// pulse_width = 1;
}
if (freq <= 120) {
min_duration = 3;
// pulse_width = 1;
}
if (freq < 80) {
if (freq <= 80) {
min_duration = 4;
pulse_width = 2;
// pulse_width = 2;
}
if (freq < 60) {
if (freq <= 60) {
min_duration = 6;
pulse_width = 3;
// pulse_width = 3;
}
if (freq < 40) {
if (freq <= 40) {
min_duration = 8;
pulse_width = 4;
// pulse_width = 4;
}
if (freq < 32) {
if (freq <= 32) {
min_duration = 10;
pulse_width = 5;
// pulse_width = 5;
}
if (freq < 20) {
if (freq <= 20) {
min_duration = 16;
pulse_width = 8;
}
// pulse_width = 8;
}*/

if (min_duration > requested_duration) requested_duration = min_duration;

Expand All @@ -566,7 +579,7 @@ void add_vibration(bool isRightHand, float amplitude, float frequency, float dur


std::cout << " adding haptic for amplitude " << amplitude << " -> " << amp << " frequency " << frequency << " -> " << freq << " duration " << duration << " ->" << requested_duration
<<" pulse_width " << pulse_width << std::endl;
<<" pulse_width " << min_duration << std::endl;

add_vib_sample_part1(isRightHand, min_duration, requested_duration, amp);

Expand Down
8 changes: 4 additions & 4 deletions ovr_test/x64/Release/config.dat
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ Oculus_link
0
0
64
10
1
0
1
0
0
0
0
0
1
0
0
0.292372
0
0.956305
0
0
146
0
Binary file modified ovr_test/x64/Release/ovr_test.exe
Binary file not shown.

0 comments on commit a2c5784

Please sign in to comment.