- Home /
5DTgloves integration possible?
"Why is there nothing appearing in the Unity GUI? 5DTgloves-Unity integration attempt, is it possible to integrate these two?"
I've been trying to integrate my 5DT gloves with Unity using the GloveSampleApp C# (Monodevelop) code provided in the 5dt website. Here are the code, splitted into 2 parts:
FIRST PART:
using UnityEngine;
using System.Collections;
using System;
using System.Timers;
using Gtk;
using FDTGloveUltraCSharpWrapper;
public class NewBehaviourScript : MonoBehaviour
{
//do not modify
public partial class MainWindow
{
private global::Gtk.Fixed fixed1;
private global::Gtk.Button btnConnect;
private global::Gtk.Entry txtGlovePort;
private global::Gtk.Label label2;
private global::Gtk.Label label3;
private global::Gtk.Label label4;
private global::Gtk.Label label5;
private global::Gtk.Entry txtPacketRate;
private global::Gtk.Entry txtFirmWareVersion;
private global::Gtk.Entry txtLR;
private global::Gtk.Entry txtType;
private global::Gtk.Label label1;
private global::Gtk.CheckButton chkUseCallback;
private global::Gtk.TextView lstSensors;
private global::Gtk.Label label6;
private global::Gtk.Entry txtGesture;
private global::Gtk.Button btnQuit;
protected virtual void Build ()
{
global::Stetic.Gui.Initialize (this);
// Widget MainWindow
this.Name = "MainWindow";
this.Title = global::Mono.Unix.Catalog.GetString ("5DT C# Glove Sample App");
this.WindowPosition = ((global::Gtk.WindowPosition)(4));
// Container child MainWindow.Gtk.Container+ContainerChild
this.fixed1 = new global::Gtk.Fixed ();
this.fixed1.Name = "fixed1";
this.fixed1.HasWindow = false;
// Container child fixed1.Gtk.Fixed+FixedChild
this.btnConnect = new global::Gtk.Button ();
this.btnConnect.CanFocus = true;
this.btnConnect.Name = "btnConnect";
this.btnConnect.UseUnderline = true;
this.btnConnect.Label = global::Mono.Unix.Catalog.GetString ("Connect");
this.fixed1.Add (this.btnConnect);
global::Gtk.Fixed.FixedChild w1 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.btnConnect]));
w1.X = 180;
w1.Y = 20;
// Container child fixed1.Gtk.Fixed+FixedChild
this.txtGlovePort = new global::Gtk.Entry ();
this.txtGlovePort.CanFocus = true;
this.txtGlovePort.Name = "txtGlovePort";
this.txtGlovePort.Text = global::Mono.Unix.Catalog.GetString ("USB0");
this.txtGlovePort.IsEditable = true;
this.txtGlovePort.InvisibleChar = '*';
this.fixed1.Add (this.txtGlovePort);
global::Gtk.Fixed.FixedChild w2 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.txtGlovePort]));
w2.X = 15;
w2.Y = 21;
// Container child fixed1.Gtk.Fixed+FixedChild
this.label2 = new global::Gtk.Label ();
this.label2.Name = "label2";
this.label2.LabelProp = global::Mono.Unix.Catalog.GetString ("Type:");
this.fixed1.Add (this.label2);
global::Gtk.Fixed.FixedChild w3 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.label2]));
w3.X = 21;
w3.Y = 80;
// Container child fixed1.Gtk.Fixed+FixedChild
this.label3 = new global::Gtk.Label ();
this.label3.Name = "label3";
this.label3.LabelProp = global::Mono.Unix.Catalog.GetString ("Left/Right:");
this.fixed1.Add (this.label3);
global::Gtk.Fixed.FixedChild w4 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.label3]));
w4.X = 20;
w4.Y = 107;
// Container child fixed1.Gtk.Fixed+FixedChild
this.label4 = new global::Gtk.Label ();
this.label4.Name = "label4";
this.label4.LabelProp = global::Mono.Unix.Catalog.GetString ("Packet Rate:");
this.fixed1.Add (this.label4);
global::Gtk.Fixed.FixedChild w5 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.label4]));
w5.X = 22;
w5.Y = 130;
// Container child fixed1.Gtk.Fixed+FixedChild
this.label5 = new global::Gtk.Label ();
this.label5.Name = "label5";
this.label5.LabelProp = global::Mono.Unix.Catalog.GetString ("FW Version:");
this.fixed1.Add (this.label5);
global::Gtk.Fixed.FixedChild w6 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.label5]));
w6.X = 20;
w6.Y = 155;
// Container child fixed1.Gtk.Fixed+FixedChild
this.txtPacketRate = new global::Gtk.Entry ();
this.txtPacketRate.CanFocus = true;
this.txtPacketRate.Name = "txtPacketRate";
this.txtPacketRate.IsEditable = true;
this.txtPacketRate.InvisibleChar = '*';
this.fixed1.Add (this.txtPacketRate);
global::Gtk.Fixed.FixedChild w7 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.txtPacketRate]));
w7.X = 98;
w7.Y = 134;
// Container child fixed1.Gtk.Fixed+FixedChild
this.txtFirmWareVersion = new global::Gtk.Entry ();
this.txtFirmWareVersion.CanFocus = true;
this.txtFirmWareVersion.Name = "txtFirmWareVersion";
this.txtFirmWareVersion.IsEditable = true;
this.txtFirmWareVersion.InvisibleChar = '*';
this.fixed1.Add (this.txtFirmWareVersion);
global::Gtk.Fixed.FixedChild w8 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.txtFirmWareVersion]));
w8.X = 98;
w8.Y = 159;
// Container child fixed1.Gtk.Fixed+FixedChild
this.txtLR = new global::Gtk.Entry ();
this.txtLR.CanFocus = true;
this.txtLR.Name = "txtLR";
this.txtLR.IsEditable = true;
this.txtLR.InvisibleChar = '*';
this.fixed1.Add (this.txtLR);
global::Gtk.Fixed.FixedChild w9 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.txtLR]));
w9.X = 98;
w9.Y = 108;
// Container child fixed1.Gtk.Fixed+FixedChild
this.txtType = new global::Gtk.Entry ();
this.txtType.CanFocus = true;
this.txtType.Name = "txtType";
this.txtType.IsEditable = true;
this.txtType.InvisibleChar = '*';
this.fixed1.Add (this.txtType);
global::Gtk.Fixed.FixedChild w10 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.txtType]));
w10.X = 98;
w10.Y = 84;
// Container child fixed1.Gtk.Fixed+FixedChild
this.label1 = new global::Gtk.Label ();
this.label1.Name = "label1";
this.label1.LabelProp = global::Mono.Unix.Catalog.GetString ("Sensors:");
this.fixed1.Add (this.label1);
global::Gtk.Fixed.FixedChild w11 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.label1]));
w11.X = 290;
w11.Y = 64;
// Container child fixed1.Gtk.Fixed+FixedChild
this.chkUseCallback = new global::Gtk.CheckButton ();
this.chkUseCallback.CanFocus = true;
this.chkUseCallback.Name = "chkUseCallback";
this.chkUseCallback.Label = global::Mono.Unix.Catalog.GetString ("Use Callback instead of 250ms timer");
this.chkUseCallback.DrawIndicator = true;
this.chkUseCallback.UseUnderline = true;
this.fixed1.Add (this.chkUseCallback);
global::Gtk.Fixed.FixedChild w12 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.chkUseCallback]));
w12.X = 286;
w12.Y = 19;
// Container child fixed1.Gtk.Fixed+FixedChild
this.lstSensors = new global::Gtk.TextView ();
this.lstSensors.WidthRequest = 228;
this.lstSensors.HeightRequest = 247;
this.lstSensors.CanFocus = true;
this.lstSensors.Name = "lstSensors";
this.lstSensors.Editable = false;
this.fixed1.Add (this.lstSensors);
global::Gtk.Fixed.FixedChild w13 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.lstSensors]));
w13.X = 290;
w13.Y = 80;
// Container child fixed1.Gtk.Fixed+FixedChild
this.label6 = new global::Gtk.Label ();
this.label6.Name = "label6";
this.label6.LabelProp = global::Mono.Unix.Catalog.GetString ("Current Gesture:");
this.fixed1.Add (this.label6);
global::Gtk.Fixed.FixedChild w14 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.label6]));
w14.X = 290;
w14.Y = 333;
// Container child fixed1.Gtk.Fixed+FixedChild
this.txtGesture = new global::Gtk.Entry ();
this.txtGesture.CanFocus = true;
this.txtGesture.Name = "txtGesture";
this.txtGesture.IsEditable = false;
this.txtGesture.WidthChars = 3;
this.txtGesture.InvisibleChar = '*';
this.fixed1.Add (this.txtGesture);
global::Gtk.Fixed.FixedChild w15 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.txtGesture]));
w15.X = 376;
w15.Y = 331;
// Container child fixed1.Gtk.Fixed+FixedChild
this.btnQuit = new global::Gtk.Button ();
this.btnQuit.CanFocus = true;
this.btnQuit.Name = "btnQuit";
this.btnQuit.UseUnderline = true;
this.btnQuit.Label = global::Mono.Unix.Catalog.GetString ("Quit");
this.fixed1.Add (this.btnQuit);
global::Gtk.Fixed.FixedChild w16 = ((global::Gtk.Fixed.FixedChild)(this.fixed1[this.btnQuit]));
w16.X = 486;
w16.Y = 337;
this.Add (this.fixed1);
if ((this.Child != null)) {
this.Child.ShowAll ();
}
this.DefaultWidth = 549;
this.DefaultHeight = 380;
this.Show ();
this.DeleteEvent += new global::Gtk.DeleteEventHandler (this.OnDeleteEvent);
this.btnConnect.Clicked += new global::System.EventHandler (this.OnBtnConnectClicked);
this.chkUseCallback.Toggled += new global::System.EventHandler (this.OnChkUseCallbackToggled);
this.btnQuit.Clicked += new global::System.EventHandler (this.OnBtnQuitClicked);
}
}
//until here
public static void Main (string[] args)
{
{
Gtk.Application.Init ();
MainWindow win = new MainWindow ();
win.Show ();
Gtk.Application.Run ();
}
}
public partial class MainWindow : Gtk.Window
{
CfdGlove fdGlove;
private static System.Timers.Timer tmrUpdate;
public MainWindow () : base(Gtk.WindowType.Toplevel)
{
Build ();
// creat the glove
fdGlove = new CfdGlove();
// setup the timer
tmrUpdate = new System.Timers.Timer();
tmrUpdate.Elapsed += new ElapsedEventHandler(OurTimerCallback);
tmrUpdate.Disposed += new EventHandler(OurTimerDisposed);
tmrUpdate.Interval = 250;
tmrUpdate.Enabled = true;
}
delegate void UpdateListDelegate(); // used by Update function to create delegate to update sensor list
public void OurTimerCallback(object source, ElapsedEventArgs e)
{
Update(this,new EventArgs());
}
public void OurTimerDisposed(object source, EventArgs e)
{
}
private void Update(object sender, EventArgs e)
{
Gtk.Application.Invoke (delegate {UpdateDataOnForm();});
}
private void UpdateDataOnForm()
{
if (fdGlove == null)
return;
lstSensors.Buffer.Text = "";
ushort[] arr = new ushort[20];
float[] farr = new float[20];
// Get all the scaled values
fdGlove.GetSensorScaledAll(ref farr);
fdGlove.GetSensorRawAll(ref arr);
//for (int i = 0; i < fdGlove.GetNumSensors(); ++i)
if (fdGlove.IsOpen())
{
for (int i = 0; i < 18; ++i)
{
lstSensors.Buffer.Text += "Sensor " + i + " - Scaled: " + String.Format("{0:0.00}", farr[i]) + " ( Raw: " + arr[i] + ")\n";
}
}
txtGesture.Text = fdGlove.GetGesture().ToString();
txtPacketRate.Text = fdGlove.GetPacketRate().ToString();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Gtk.Application.Quit ();
a.RetVal = true;
}
protected virtual void OnBtnConnectClicked (object sender, System.EventArgs e)
{
chkUseCallback.Active = false;
fdGlove.Open(txtGlovePort.Text);
//tmrUpdate.Enabled = true;
switch(fdGlove.GetGloveType())
{
case (int)EGloveTypes.FD_GLOVE14UW: txtType.Text = "Data Glove 14 Ultra Wireless"; break;
case (int)EGloveTypes.FD_GLOVE14U_USB: txtType.Text = "Data Glove 14 Ultra USB"; break;
case (int)EGloveTypes.FD_GLOVE14U: txtType.Text = "Data Glove 14 Ultra"; break;
case (int)EGloveTypes.FD_GLOVE16: txtType.Text = "Data Glove 16-sensor"; break;
case (int)EGloveTypes.FD_GLOVE16W: txtType.Text = "Data Glove 16-sensor Wireless"; break;
case (int)EGloveTypes.FD_GLOVE5U: txtType.Text = "Data Glove 5 Ultra"; break;
case (int)EGloveTypes.FD_GLOVE5U_USB: txtType.Text = "Data Glove 5 Ultra USB"; break;
case (int)EGloveTypes.FD_GLOVE5UW: txtType.Text = "Data Glove 5 Ultra Wireless"; break;
case (int)EGloveTypes.FD_GLOVE7: txtType.Text = "Data Glove 7-sensor"; break;
case (int)EGloveTypes.FD_GLOVE7W: txtType.Text = "Data Glove 7-sensor Wireless"; break;
case (int)EGloveTypes.FD_GLOVENONE: txtType.Text = "No Glove"; break;
default: txtType.Text = "Unknown"; break;
}
switch(fdGlove.GetGloveHand())
{
case (int)EGloveHand.FD_HAND_RIGHT: txtLR.Text = "Right"; break;
case (int)EGloveHand.FD_HAND_LEFT: txtLR.Text = "Left"; break;
}
txtFirmWareVersion.Text = fdGlove.fdGetFWVersionMajor() + "." + fdGlove.fdGetFWVersionMinor();
}
protected virtual void OnBtnQuitClicked (object sender, System.EventArgs e)
{
if (fdGlove != null)
fdGlove.Close();
Gtk.Application.Quit();
}
protected virtual void OnChkUseCallbackToggled (object sender, System.EventArgs e)
{
if (chkUseCallback.Active)
{
fdGlove.SetCallBack(new EventHandler(Update));
tmrUpdate.Enabled = false;
}
else
{
fdGlove.RemoveCallBack(new EventHandler(Update));
tmrUpdate.Enabled = true;
}
}
}
}
SECOND PART:
using Gtk;
// This file has been generated by the GUI designer. Do not modify.
namespace Stetic
{
internal class Gui
{
private static bool initialized;
static internal void Initialize (Gtk.Widget iconRenderer)
{
if ((Stetic.Gui.initialized == false)) {
Stetic.Gui.initialized = true;
}
}
}
internal class ActionGroups
{
public static Gtk.ActionGroup GetActionGroup (System.Type type)
{
return Stetic.ActionGroups.GetActionGroup (type.FullName);
}
public static Gtk.ActionGroup GetActionGroup (string name)
{
return null;
}
}
}
And I'm putting the FIRST PART script (NewBehaviourScript) into an empty gameobject but why there's no response in the GUI Layout?
oh and I'm also using a Windows Form provided by Gtk.gui and from the "shredder2500" UnityAnswer, I know it's possible to do it, so why is there nothing in my Unity GUI now?
I am very grateful for anyone who could help me, and thanks for the answer.. I've been doing this for about 6 months and I've got no clue at all now..
also, is it even possible to integrate Unity and 5DT technologies? if it's possible, please give some clue / specific place to learn how to integrate these two technology
I would also very thankful if "Dewald" from 5DT could give some specific help, not just redirecting to download the C# file (again) in 5dt's website, because it's useless..
Answer by Dewalddp · Oct 16, 2012 at 05:43 PM
Hi d3m0n_X,
Please find the attached example of how to use the 5DT Glove with Unity. Please note that you would need a Unity Pro license because the glove driver is a plugin that Unity needs to load.
It will also be available on our website shortly. Let me know if I can help with anything else.
Best Regards,
Dewald (dewald.duplooy@5dt.com)
The example project is also available now from our website download section. 5DT Glove Unity Example
AH! this is the answer that I've been waiting for so long, so actually we need to BUY unity PRO in order to use 5dt gloves then.. maybe you guys should mention it in your website in advance :D
anyway, thanks a lot! now I've been able to use and check all 5dt gloves function!
Answer by Dewalddp · Oct 05, 2012 at 01:12 PM
Hi d3m0n_X,
As far as I know a number of our clients have integrated these 2 technologies with success. I myself have very little knowledge of Unity, but I think what would be a good idea is to have a downloadable Unity example on our website.
I've contacted one of our previous customers who have used the 5DT Glove in their Unity project to ask for a basic example. When I have received the example I will post the link to it here, otherwise I will create an example and post it on our website (but that might take a bit of time because my boss needs to give me permission to spend time on it)
In the meantime my suggestion is to go about testing each functional part of your program separately to make sure every subset works. For example first check if you can connect to the glove using the Mono example. After this check if your GUI approach is working 100% by trying to create a simple textbox and button and see if you can interact with them. Continue to make small additions, working towards your final target until you can pinpoint the exact problem. When you have a more detailed idea of what component works and what does not work I would love to give you more specific help.
You should also maybe consider if you need the GUI in there at all? Why not just work with the driver directly and move some primitives around as a function of the glove sensor values?
Best Regards, Dewald (dewald.duplooy@5dt.com)
ok thanks for the explanation, i will try my best to test all the function first then, still, i'm waiting for the links to the 5dt-unity example, thanks a lot!
Your answer
![](https://koobas.hobune.stream/wayback/20220613081725im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Making a bubble level (not a game but work tool) 1 Answer
Why can't I edit C# script although I have monodevelop installed? PLEASE HELP 1 Answer
Automatic caching in Mono? 0 Answers