Skip to content

Commit

Permalink
振動機能に対応。エラー時にダイアログが出まくる問題に対処
Browse files Browse the repository at this point in the history
  • Loading branch information
gpsnmeajp committed Jun 29, 2020
1 parent 8835d1b commit 1334343
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 12 deletions.
5 changes: 5 additions & 0 deletions build/vmt/resources/input/vmt_profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,10 @@
"type" : "pose",
"binding_image_point" : [ 0, 0 ]
}
"/output/haptic" : {
"type" : "vibration",
"binding_image_point" : [ 0, 0 ],
"order" : 1
}
}
}
14 changes: 14 additions & 0 deletions vmt_driver/CommunicationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ namespace VMTDriver {
DirectOSC::OSC::GetInstance()->GetSocketTx()->Send(packet.Data(), packet.Size());
}

void OSCReceiver::SendHaptic(int index, float frequency, float amplitude, float duration)
{
const size_t bufsize = 8192;
char buf[bufsize];
osc::OutboundPacketStream packet(buf, bufsize);
packet << osc::BeginMessage("/VMT/Out/Haptic")
<< index
<< frequency
<< amplitude
<< duration
<< osc::EndMessage;
DirectOSC::OSC::GetInstance()->GetSocketTx()->Send(packet.Data(), packet.Size());
}


//別スレッド
void OSCReceiver::ProcessMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint)
Expand Down
2 changes: 1 addition & 1 deletion vmt_driver/CommunicationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace VMTDriver {
public:
static void OSCReceiver::SendLog(int stat, string msg);
static void OSCReceiver::SendAlive();

static void OSCReceiver::SendHaptic(int index, float frequency, float amplitude, float duration);
};

class CommunicationManager {
Expand Down
8 changes: 8 additions & 0 deletions vmt_driver/ServerTrackedDeviceProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ namespace VMTDriver {
{
m_devices[i].UpdatePoseToVRSystem();
}

//イベントポンプ
VREvent_t VREvent;
VRServerDriverHost()->PollNextEvent(&VREvent, sizeof(VREvent_t));
for (int i = 0; i < m_devicesNum; i++)
{
m_devices[i].ProcessEvent(VREvent);
}
}

//スタンバイをブロックするか
Expand Down
17 changes: 16 additions & 1 deletion vmt_driver/TrackedDeviceServerDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ namespace VMTDriver {
if (!m_alreadyRegistered) { return; }
if (0 <= index && index <= 7)
{
Log::printf("Boolean %d->%d", index, value ? 1 : 0);
VRDriverInput()->UpdateBooleanComponent(ButtonComponent[index], value, timeoffset);
}
}
Expand Down Expand Up @@ -115,6 +114,20 @@ namespace VMTDriver {
UpdateJoystickInput(i, 0, 0, 0);
}
}
void TrackedDeviceServerDriver::ProcessEvent(VREvent_t& VREvent)
{
switch (VREvent.eventType)
{
case EVREventType::VREvent_Input_HapticVibration:
//バイブレーション
if (VREvent.data.hapticVibration.componentHandle == HapticComponent) {
OSCReceiver::SendHaptic(m_index, VREvent.data.hapticVibration.fFrequency, VREvent.data.hapticVibration.fAmplitude, VREvent.data.hapticVibration.fDurationSeconds);
}
break;
default:
break;
}
}
EVRInitError TrackedDeviceServerDriver::Activate(uint32_t unObjectId)
{
m_deviceIndex = unObjectId;
Expand Down Expand Up @@ -152,6 +165,8 @@ namespace VMTDriver {
VRDriverInput()->CreateScalarComponent(m_propertyContainer, "/input/Joystick0/x", &JoystickComponent[0], EVRScalarType::VRScalarType_Absolute, EVRScalarUnits::VRScalarUnits_NormalizedTwoSided);
VRDriverInput()->CreateScalarComponent(m_propertyContainer, "/input/Joystick0/y", &JoystickComponent[1], EVRScalarType::VRScalarType_Absolute, EVRScalarUnits::VRScalarUnits_NormalizedTwoSided);

VRDriverInput()->CreateHapticComponent(m_propertyContainer, "/output/haptic", &HapticComponent);

return EVRInitError::VRInitError_None;
}
void TrackedDeviceServerDriver::Deactivate()
Expand Down
3 changes: 3 additions & 0 deletions vmt_driver/TrackedDeviceServerDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace VMTDriver {
VRInputComponentHandle_t ButtonComponent[8];
VRInputComponentHandle_t TriggerComponent[2];
VRInputComponentHandle_t JoystickComponent[2];
VRInputComponentHandle_t HapticComponent;

public:
TrackedDeviceServerDriver();
Expand All @@ -57,6 +58,8 @@ namespace VMTDriver {
void UpdateJoystickInput(int index, float x, float y, double timeoffset);
void Reset();

void ProcessEvent(VREvent_t &VREvent);

//---------------

virtual EVRInitError Activate(uint32_t unObjectId) override;
Expand Down
10 changes: 8 additions & 2 deletions vmt_manager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@
</DockPanel>
</TabItem>
<TabItem Header="Input">
<DockPanel>
<DockPanel LastChildFill="False">
<DockPanel DockPanel.Dock="Top" Margin="1">
<TextBlock VerticalAlignment="Center" Text="VMT:" DockPanel.Dock="Left" />
<TextBox Name="InputVMTNoTextBox" Text="0"/>
</DockPanel>
<Grid>
<Grid DockPanel.Dock="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
Expand Down Expand Up @@ -132,6 +132,12 @@
<Button Content="Input Reset" Margin="1" Click="InputResetButton" DockPanel.Dock="Top"/>
</DockPanel>
</Grid>

<Button Content="Haptic Test" Margin="1" Click="HapticTestButton" DockPanel.Dock="Bottom"/>
<DockPanel DockPanel.Dock="Bottom" Margin="1">
<TextBlock VerticalAlignment="Center" Text="Haptic:" DockPanel.Dock="Left" />
<TextBox Name="InputVMTHapticTextBox" Text="-" IsReadOnly="True" IsEnabled="False" />
</DockPanel>
</DockPanel>
</TabItem>
</TabControl>
Expand Down
52 changes: 44 additions & 8 deletions vmt_manager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public partial class MainWindow : Window
bool detectOtherVersion = false;

int aliveCnt = 0;
bool ReceiveError = false;
EasyOpenVRUtil util;
OSC osc;

Expand Down Expand Up @@ -100,7 +101,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, title);
MessageBox.Show(ex.Message + "\n" + ex.StackTrace, title);
Close();
return;
}
Expand All @@ -124,6 +125,10 @@ private void Window_Loaded(object sender, RoutedEventArgs e)

private void OnMessage(OscMessage message)
{
//エラー時はそれ以上受信しない
if (ReceiveError) {
return;
}
try
{
if (message.Address == "/VMT/Out/Log")
Expand All @@ -149,6 +154,7 @@ private void OnMessage(OscMessage message)
}
else if (message.Address == "/VMT/Out/Alive")
{
//Keep Alive
this.Dispatcher.Invoke(() =>
{
DriverVersion.Text = (string)message[0];
Expand All @@ -159,23 +165,37 @@ private void OnMessage(OscMessage message)
DriverVersion.Foreground = new SolidColorBrush(Color.FromRgb(255, 100, 100));
detectOtherVersion = true;
}
else {
else
{
DriverVersion.Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 0));
}
aliveCnt = 0;
});
//Keep Alive
}
else {
else if (message.Address == "/VMT/Out/Haptic")
{
//振動
this.Dispatcher.Invoke(() =>
{
InputVMTHapticTextBox.Text = string.Format("VMT_{0,0} f:{1:0.0}Hz A:{2:0.0} d:{3:0.0}s", (int)message[0], (float)message[1], (float)message[2], (float)message[3]);
InputVMTHapticTextBox.Background = new SolidColorBrush(Color.FromRgb(0, 255, 0));
});
}
else
{
//Do noting
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message, title);
Close();
ReceiveError = true;
MessageBox.Show(ex.Message+"\n"+ex.StackTrace, title);
this.Dispatcher.Invoke(() =>
{
Close();
});
return;
}
}
Expand Down Expand Up @@ -253,6 +273,8 @@ private void GenericTimer(object sender, EventArgs e)
else {
aliveCnt++;
}

InputVMTHapticTextBox.Background = new SolidColorBrush(Color.FromRgb(255,255,255));
}


Expand Down Expand Up @@ -324,7 +346,9 @@ private void InstallButton(object sender, RoutedEventArgs e)
MessageBox.Show("OK (ExitCode=" + process.ExitCode + ")", title);
}
catch (Exception ex) {
MessageBox.Show(ex.Message, title);
MessageBox.Show(ex.Message + "\n" + ex.StackTrace, title);
Close();
return;
}
}

Expand Down Expand Up @@ -358,7 +382,9 @@ private void UninstallButton(object sender, RoutedEventArgs e)
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, title);
MessageBox.Show(ex.Message + "\n" + ex.StackTrace, title);
Close();
return;
}
}

Expand Down Expand Up @@ -502,5 +528,15 @@ private void InputResetButton(object sender, RoutedEventArgs e)
SliderX.Value = 0f;
SliderY.Value = 0f;
}
private void HapticTestButton(object sender, RoutedEventArgs e)
{
var index = GetInputIndex();
if (index.ok) {
var deviceIndex = util.GetDeviceIndexBySerialNumber("VMT_" + index.i);
if (deviceIndex != EasyOpenVRUtil.InvalidDeviceIndex) {
util.TriggerHapticPulse(deviceIndex);
}
}
}
}
}

0 comments on commit 1334343

Please sign in to comment.