Example #1
0
        public void GetEventType_ValidState_EqualsConstructorParameter()
        {
            // Setup
            var eventType = MyoEventType.Emg;
            var args = new RouteMyoEventArgs(
                new IntPtr(123),
                new IntPtr(123),
                eventType,
                DateTime.UtcNow);

            // Execute
            var result = args.EventType;

            // Assert
            Assert.Equal(eventType, result);
        }
Example #2
0
        /// <summary>
        /// Called when an event has been received on the communication channel.
        /// </summary>
        /// <param name="myoHandle">The Myo handle.</param>
        /// <param name="evt">The event handle.</param>
        /// <param name="eventType">The type of the event.</param>
        /// <param name="timestamp">The timestamp of the event.</param>
        protected virtual void OnEventReceived(
            IntPtr myoHandle,
            IntPtr evt,
            MyoEventType eventType,
            DateTime timestamp)
        {
            var handler = EventReceived;

            if (handler != null)
            {
                var args = new RouteMyoEventArgs(
                    myoHandle,
                    evt,
                    eventType,
                    timestamp);
                handler.Invoke(this, args);
            }
        }
Example #3
0
        /// <summary>
        /// Called when an event has been received on the communication channel.
        /// </summary>
        /// <param name="myoHandle">The Myo handle.</param>
        /// <param name="evt">The event handle.</param>
        /// <param name="eventType">The type of the event.</param>
        /// <param name="timestamp">The timestamp of the event.</param>
        private void OnEventReceived(
            IntPtr myoHandle,
            IntPtr evt,
            MyoEventType eventType,
            DateTime timestamp)
        {
            ////Contract.Requires<ArgumentException>(myoHandle != IntPtr.Zero, "The handle to the Myo must be set.");
            ////Contract.Requires<ArgumentException>(evt != IntPtr.Zero, "The handle to the event must be set.");

            var handler = EventReceived;

            if (handler != null)
            {
                var args = new RouteMyoEventArgs(
                    myoHandle,
                    evt,
                    eventType,
                    timestamp);
                handler.Invoke(this, args);
            }
        }
Example #4
0
        public void EventReceived_EmgData_DoesNotTriggerPairedEvent()
        {
            // Setup
            var channel = new Mock<IChannelListener>();

            var deviceListener = DeviceListener.Create(channel.Object);

            var gotPairedEvent = false;
            deviceListener.Paired += (_, __) => gotPairedEvent = true;

            var routeEventArgs = new RouteMyoEventArgs(
                new IntPtr(123),
                new IntPtr(123),
                MyoEventType.Emg,
                DateTime.UtcNow);

            // Execute
            channel.Raise(x => x.EventReceived += null, routeEventArgs);

            // Assert
            Assert.False(
                gotPairedEvent,
                "Not expecting to get the paired event.");
        }
Example #5
0
        public void GetEvent_ValidState_EqualsConstructorParameter()
        {
            // Setup
            var eventHandle = new IntPtr(123);
            var args = new RouteMyoEventArgs(
                new IntPtr(789),
                eventHandle,
                MyoEventType.Paired,
                DateTime.UtcNow);

            // Execute
            var result = args.Event;

            // Assert
            Assert.Equal(eventHandle, result);
        }
Example #6
0
        public void GetTimestamp_ValidState_EqualsConstructorParameter()
        {
            // Setup
            var timestamp = DateTime.UtcNow;
            var args = new RouteMyoEventArgs(
                new IntPtr(123),
                new IntPtr(123),
                MyoEventType.Paired,
                timestamp);

            // Execute
            var result = args.Timestamp;

            // Assert
            Assert.Equal(timestamp, result);
        }
Example #7
0
        /// <summary>
        /// Called when an event has been received on the communication channel.
        /// </summary>
        /// <param name="myoHandle">The Myo handle.</param>
        /// <param name="evt">The event handle.</param>
        /// <param name="eventType">The type of the event.</param>
        /// <param name="timestamp">The timestamp of the event.</param>
        private void OnEventReceived(
            IntPtr myoHandle, 
            IntPtr evt, 
            MyoEventType eventType, 
            DateTime timestamp)
        {
            Contract.Requires<ArgumentException>(myoHandle != IntPtr.Zero, "The handle to the Myo must be set.");
            Contract.Requires<ArgumentException>(evt != IntPtr.Zero, "The handle to the event must be set.");

            var handler = EventReceived;
            if (handler != null)
            {
                var args = new RouteMyoEventArgs(
                    myoHandle,
                    evt,
                    eventType,
                    timestamp);
                handler.Invoke(this, args);
            }
        }
Example #8
0
        public void EventReceived_Paired_TriggersPairedEvent()
        {
            // Setup
            var channel = new Mock<IChannelListener>();

            var deviceListener = DeviceListener.Create(channel.Object);

            PairedEventArgs actualEventArgs = null;
            deviceListener.Paired += (_, args) => actualEventArgs = args;

            var myoHandle = new IntPtr(12345);
            var timestamp = DateTime.UtcNow;
            var routeEventArgs = new RouteMyoEventArgs(
                 myoHandle,
                 new IntPtr(123),
                 MyoEventType.Paired,
                 timestamp);

            // Execute
            channel.Raise(x => x.EventReceived += null, routeEventArgs);

            // Assert
            Assert.NotNull(actualEventArgs);
            Assert.Equal(myoHandle, actualEventArgs.MyoHandle);
            Assert.Equal(timestamp, actualEventArgs.Timestamp);
        }
Example #9
0
        private void Channel_EventReceived(object sender, RouteMyoEventArgs e)
        {
            Contract.Requires<ArgumentNullException>(sender != null, "sender");

            switch (e.EventType)
            {
                case MyoEventType.Paired:
                    OnPaired(e.MyoHandle, e.Timestamp);
                    break;

                case MyoEventType.Unpaired:
                    OnUnpaired(e.MyoHandle, e.Timestamp);
                    break;
            }
        }