/// <summary>
 /// Initializes a new instance of the <see cref="BrailleIO_Initialized_EventArgs"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 public BrailleIO_Initialized_EventArgs(BrailleIODevice device)
 {
     this.device = device;
 }
 public void setDevice(BrailleIODevice device) { this.device = device; }
Exemple #3
0
 public ShowOffBrailleIOButtonMediator(BrailleIODevice device) : base(device)
 {
 }
 public ShowOffBrailleIOButtonMediator(BrailleIODevice device) : base(device) { }
 public AbstractBrailleIOButtonMediatorBase(BrailleIODevice device) { this.device = device; }
        private void handleTouchEvent(Object sender, BrailleIODevice brailleIODevice, BrailleIO_TouchValuesChanged_EventArgs brailleIO_TouchValuesChanged_EventArgs)
        {
            if ((Mode & InteractionMode.Gesture) == InteractionMode.Gesture
                 || (Mode & InteractionMode.Manipulation) == InteractionMode.Manipulation
                )
            {
                BlobTracker blobTracker;
                blobTrackers.TryGetValue(brailleIODevice, out blobTracker);

                if (brailleIO_TouchValuesChanged_EventArgs != null && blobTracker != null)
                {
                    Frame f = GetFrameFromSampleSet(brailleIO_TouchValuesChanged_EventArgs.touches);
                    blobTracker.AddFrame(f);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="InteractionQueueItem"/> struct.
 /// </summary>
 /// <param name="timestamp">The timestamp when the input happens.</param>
 /// <param name="type">The type of the input.</param>
 /// <param name="device">The device from which ii was sent.</param>
 /// <param name="args">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 /// <param name="sender">The sending Adapter.</param>
 public InteractionQueueItem(DateTime timestamp, InteractionQueueObjectType type, BrailleIODevice device, EventArgs args, Object sender)
 {
     Timestamp = timestamp; Type = type; Device = device; Args = args; Sender = sender;
 }
 private void fireClassifiedGestureEvent(IClassificationResult result, BrailleIODevice device, List<BrailleIO_DeviceButton> releasedKeys, List<String> releasedGenKeys, List<BrailleIO_DeviceButton> pressedKeys, List<String> pressedGenKeys)
 {
     if (result != null)
     {
         System.Diagnostics.Debug.WriteLine("gesture recognized: " + result);
         Logger.Instance.Log(LogPriority.DEBUG, this, "[GESTURE] result " + result);
         fireGestureEvent(device, releasedKeys, releasedGenKeys, pressedKeys, pressedGenKeys, result);
     }
 }
        private IClassificationResult classifyGesture(BrailleIODevice device)
        {
            IClassificationResult result = null;
            GestureRecognizer gestureRecognizer;
            gestureRecognizers.TryGetValue(device, out gestureRecognizer);

            if (gestureRecognizer != null)
            {
                result = gestureRecognizer.FinishEvaluation();
            }
            return result;
        }
        private void startGesture(List<BrailleIO_DeviceButton> pressedKeys, List<String> pressedGenKeys, BrailleIODevice device)
        {
            //start gesture recording
            BlobTracker blobTracker;
            blobTrackers.TryGetValue(device, out blobTracker);
            GestureRecognizer gestureRecognizer;
            gestureRecognizers.TryGetValue(device, out gestureRecognizer);

            if (blobTracker != null && gestureRecognizer != null)
            {
                if (pressedKeys.Contains(BrailleIO_DeviceButton.Gesture) && pressedGenKeys.Count < 2)
                {
                    Mode |= InteractionMode.Gesture;
                    startGestureTracking(blobTracker, gestureRecognizer);
                }
                else if (pressedGenKeys.Contains("hbr")) // manipulation
                {
                    Mode |= InteractionMode.Manipulation;
                    startGestureTracking(blobTracker, gestureRecognizer);
                }
            }
            else
            {
                initalizeGestureRecognition(device);
            }
        }
        private void endGesture(List<BrailleIO_DeviceButton> releasedKeys, List<String> releasedGenKeys, List<BrailleIO_DeviceButton> pressedKeys, List<String> pressedGenKeys, BrailleIODevice device)
        {
            if ((Mode & InteractionMode.Gesture) == InteractionMode.Gesture
                && releasedKeys.Contains(BrailleIO_DeviceButton.Gesture)
                && releasedGenKeys.Count == 1 && pressedGenKeys.Count == 0)
            {
                Mode &= ~InteractionMode.Gesture;
                IClassificationResult result = classifyGesture(device);
                fireClassifiedGestureEvent(result, device, releasedKeys, releasedGenKeys, pressedKeys, pressedGenKeys);

            }
            else if ((Mode & InteractionMode.Manipulation) == InteractionMode.Manipulation
                && releasedGenKeys.Contains("hbr")
                )
            {
                Mode &= ~InteractionMode.Manipulation;
                IClassificationResult result = classifyGesture(device);
                fireClassifiedGestureEvent(result, device, releasedKeys, releasedGenKeys, pressedKeys, pressedGenKeys);
            }
        }
 private static bool updateGestureRecognizer(BrailleIODevice device, BlobTracker oldBt, BlobTracker newBt)
 {
     return true;
 }
 bool unregisterGestureRecognition(BrailleIODevice device)
 {
     int c = 0;
     BlobTracker trash;
     GestureRecognizer trash2;
     while (c++ < 10 && blobTrackers.TryRemove(device, out trash)) ;
     while (c++ < 20 && gestureRecognizers.TryRemove(device, out trash2)) ;
     return true;
 }
        private void initalizeGestureRecognition(BrailleIODevice device)
        {
            // gesture recognizer registration for the device
            var blobTracker = new BlobTracker();
            var gestureRecognizer = new GestureRecognizer(blobTracker);

            //int c = 0;

            // try to register blob tracker
            blobTrackers.AddOrUpdate(device, blobTracker,
                (key, existingBlobTracker) =>
                {
                    // If this delegate is invoked, then the key already exists.
                    return blobTracker;
                }
            );

            //while (!blobTrackers.TryAdd(device, blobTracker) && c++ < 20) { Thread.Sleep(5); };
            //if (c > 19) throw new AccessViolationException("Cannot add blob tracker to dictionary - access denied");

            // try to register gesture recognizer
            gestureRecognizers.AddOrUpdate(device, gestureRecognizer,
                (key, existingGestureRecognizer) =>
                {
                    // If this delegate is invoked, then the key already exists.
                    if (existingGestureRecognizer != null)
                    {
                        existingGestureRecognizer.FinishEvaluation();
                    }
                    return gestureRecognizer;
                }
            );

            //while (!gestureRecognizers.TryAdd(device, gestureRecognizer) && c++ < 40) { Thread.Sleep(5); };
            //if (c > 39) throw new AccessViolationException("Cannot add gesture recognizer to dictionary - access denied");

            var multitouchClassifier = new MultitouchClassifier();
            var tabClassifier = new TapClassifier();

            gestureRecognizer.AddClassifier(tabClassifier);
            gestureRecognizer.AddClassifier(multitouchClassifier);

            blobTracker.InitiateTracking();
        }
        private void checkForKeyCombination(BrailleIODevice device, List<BrailleIO_DeviceButton> pressedGeneralKeys, List<String> pressedGenericKeys, List<BrailleIO_DeviceButton> releaesedGeneralKeys, List<String> releasedGenericKeys)
        {
            if (keyCombinationTimerList.ContainsKey(device))
            {
                System.Timers.Timer t = keyCombinationTimerList[device];
                t.Stop();

                List<String> pGenButtonList = new List<String>();
                List<String> rGenButtonList = new List<String>();

                List<BrailleIO_DeviceButton> pGButtonList = new List<BrailleIO_DeviceButton>();
                List<BrailleIO_DeviceButton> rGButtonList = new List<BrailleIO_DeviceButton>();

                KeyCombinationItem kc;

                if (keyCombinationTimerButtonList.TryGetValue(t, out kc))
                {
                    pGenButtonList = kc.PressedGenericKeys;
                    pGButtonList = kc.PressedGeneralKeys;
                    rGenButtonList = kc.ReleasedGenericKeys;
                    rGButtonList = kc.ReleasedGeneralKeys;
                }
                else
                {
                    kc = new KeyCombinationItem(pGButtonList, pGenButtonList, rGButtonList, rGenButtonList);
                }
                List<String> nrbl = rGenButtonList.Union(releasedGenericKeys).ToList();
                List<BrailleIO_DeviceButton> nrgbl = rGButtonList.Union(releaesedGeneralKeys).ToList();

                kc.PressedGenericKeys = pressedGenericKeys;
                kc.PressedGeneralKeys = pressedGeneralKeys;
                kc.ReleasedGenericKeys = nrbl;
                kc.ReleasedGeneralKeys = nrgbl;

                //System.Diagnostics.Debug.WriteLine("\t\t\tnew list: '" + String.Join(", ", nbl) + "'");
                if (keyCombinationTimerButtonList.ContainsKey(t))
                {
                    keyCombinationTimerButtonList[t] = kc;
                }
                else
                {
                    keyCombinationTimerButtonList.Add(t, kc);
                }

                if (pressedGenericKeys.Count < 1)
                {
                    t_Elapsed(t, null);
                }
                else
                {
                    t.Start();
                }
            }
            else
            {
                System.Timers.Timer t = new System.Timers.Timer(_keyCombinationTimerInterval);
                keyCombinationTimerList.Add(device, t);
                keyCombinationTimerButtonList.Add(t, new KeyCombinationItem(pressedGeneralKeys, pressedGenericKeys, releaesedGeneralKeys, releasedGenericKeys));
                if (pressedGenericKeys.Count < 1)
                {
                    t_Elapsed(t, null);
                }
                else
                {
                    t.Elapsed += new ElapsedEventHandler(t_Elapsed);
                    t.Start();
                }
            }
        }
        private void handleKeyStateChangedEvent(Object sender, BrailleIODevice brailleIODevice, BrailleIO_KeyStateChanged_EventArgs brailleIO_KeyStateChanged_EventArgs)
        {
            List<String> pressedGenKeys = new List<String>();
            List<BrailleIO_DeviceButton> pressedKeys = new List<BrailleIO_DeviceButton>();
            List<String> releasedGenKeys = new List<String>();
            List<BrailleIO_DeviceButton> releasedKeys = new List<BrailleIO_DeviceButton>();

            var mediator = BrailleIOButtonMediatorFactory.GetMediator(sender as BrailleIO.Interface.IBrailleIOAdapter);
            if (mediator != null)
            {
                pressedGenKeys = mediator.GetAllPressedGenericButtons(brailleIO_KeyStateChanged_EventArgs);
                pressedKeys = mediator.GetAllPressedGeneralButtons(brailleIO_KeyStateChanged_EventArgs);
                releasedGenKeys = mediator.GetAllReleasedGenericButtons(brailleIO_KeyStateChanged_EventArgs);
                releasedKeys = mediator.GetAllReleasedGeneralButtons(brailleIO_KeyStateChanged_EventArgs);
            }
            if ((pressedKeys != null && pressedKeys.Count > 0) || (pressedGenKeys != null && pressedGenKeys.Count > 0)) fireButtonPressedEvent(brailleIODevice, pressedKeys, pressedGenKeys);
            if ((releasedKeys != null && releasedKeys.Count > 0) || (releasedGenKeys != null && releasedGenKeys.Count > 0)) fireButtonReleasedEvent(brailleIODevice, pressedKeys, pressedGenKeys, releasedKeys, releasedGenKeys);

            startGesture(pressedKeys, pressedGenKeys, brailleIODevice);
            endGesture(releasedKeys, releasedGenKeys, pressedKeys, pressedGenKeys, brailleIODevice);

        }