Device.isActive always false

May 21, 2011 at 10:04 PM

Hello Joshua and all other NUI addicts,

I'm trying to develop a TUIO to WPF Bridge based on the code from MouseTouchDevice.cs.

From my understanding it should be no big problem but I'm stuck with the TouchDevice.isActive status of my devices. My TUIOTouchDevice class has the same logic as the MouseTouchDevice , but i changed some stuff to inject the TUIO data. For example when a TUIOCursor is added my TUIOListener calls this Method in the TUIOTouchDevice class:

 public static void addTuioCursor(TuioCursor tcur)
        {
          
            lock (cursorSync)
            {
                var device = GetDevice(tcur);

                if (device != null &&
                    device.IsActive)
                {
                    device.ReportUp();
                    device.Deactivate();
                   TUIOTouchDevice.RemoveDevice(tcur);
                    device = null;
                }
                device = new TUIOTouchDevice((int)tcur.getSessionID());
                device.SetActiveSource(PresentationSource.FromVisual(Application.Current.MainWindow));
                device.Position = new Point(tcur.getScreenX((int)Application.Current.MainWindow.Width), tcur.getScreenY((int)Application.Current.MainWindow.Height));
                device.Activate();
                device.ReportDown();                
            }
          
        }

The AddCursor method works as expected, and I see a white circle as an visual hint in my WPF application for the TouchDevice.
My problem is that when i later try to update or remove the device I get strange results: The white circles persist on the screen and for every new position I get an additional circle.
I realized that the Touchdevice.isActive Property is false on my update/remove methods:
 public static void updateTuioCursor(TuioCursor tcur)
        {
            lock (cursorSync)
            {
                var device = GetDevice(tcur);

                if (device != null )
                {
                    // && device.IsActive
                    device.Position = new Point(tcur.getScreenX((int)Application.Current.MainWindow.Width), tcur.getScreenY((int)Application.Current.MainWindow.Height));
                    device.ReportMove();
                  
                }
              
            }
            
        }
As you see I removed the "&& device.IsActive" because this flag is always false.
This causes another problem: At the remove Method I get no chance to remove my Touchdevice via device.Deactivate because I get an InvalidOperationException



 public static void removeTuioCursor(TuioCursor tcur)
        {
            lock (cursorSync)
            {
                var device = GetDevice(tcur);
                if (device != null )
                {
                    //&& device.IsActive
                    device.Position = new Point(tcur.getScreenX((int)Application.Current.MainWindow.Width), tcur.getScreenY((int)Application.Current.MainWindow.Height));
                   
                    device.ReportUp();
                    try{
                     device.Deactivate();
                    } catch(InvalidOperationException e){}
                    
                    TUIOTouchDevice.RemoveDevice(tcur);
                    device = null;
                   
                  
                }
             
            }
        }

My TUIOListener calls these Methods via Dispatcher.Invoke

Has anybody some hints how I get my isActive status to true or why this doesn't work?

Regards




  

Coordinator
May 30, 2011 at 12:59 AM

Hi,

I'd recommend not using the MouseTouchDevice as a starting point because it has certain assumptions built in that depend upon only one mouse cursor. Look at how SurfaceTouchDevice works instead.

What is probably happening is that you are accidentally creating a new TUIOTouchDevice every time a new event comes in rather than looking up the TUIOTouchDevice that you already created based upon the finger id.

Josh