Ejemplo n.º 1
0
        public void TestNotificationReceived()
        {
            var connection = Mock.Create <IConnection>();

            _success = false;

            //setting mock
            Mock.Arrange(() => connection.WriteValue(Arg.IsAny <byte[]>())).Returns((byte[] b) => true);

            var sensor = new TiltSensor(connection, Ports.PORT_D);

            sensor.OnChange += Changes;

            _expectedResult = new TiltSensorEventArgs
            {
                Roll  = 1,
                Pitch = 1,
                Yaw   = 1
            };

            var data = new byte[] { 0, 0, 0, 0, (byte)_expectedResult.Roll, (byte)_expectedResult.Pitch, (byte)_expectedResult.Yaw, 0 };

            sensor.SetNotificationMode(SensorMode.SENSOR_3_AXIS_PRECISE);
            sensor.FireEvent(data);

            Assert.True(_success);
        }
Ejemplo n.º 2
0
        internal void FireEvent(byte[] data)
        {
            var handler = OnChange;

            if (handler == null)
            {
                return;
            }

            TiltSensorEventArgs args = new TiltSensorEventArgs();

            switch (_mode)
            {
            case SensorMode.SENSOR_2_AXIS_SIMPLE:
            case SensorMode.SENSOR_3_AXIS_SIMPLE:
            case SensorMode.SENSOR_BUMP_DETECT:
            {
                args.State = data[4];
                break;
            }

            case SensorMode.SENSOR_2_AXIS_PRECISE:
            {
                args.Roll  = data[4];
                args.Pitch = data[5];
                break;
            }

            case SensorMode.SENSOR_3_AXIS_PRECISE:
            {
                args.Roll  = data[4];
                args.Pitch = data[5];
                args.Yaw   = data[6];
                break;
            }
            }

            handler.Invoke(this, args);
            LoggerHelper.Instance.Debug($"TiltSensor::FireEvent {BitConverter.ToString(data)}");
        }
Ejemplo n.º 3
0
 private void Changes(object sender, TiltSensorEventArgs e)
 {
     _success = (e.Pitch == _expectedResult.Pitch) &&
                (e.Roll == _expectedResult.Roll) &&
                (e.Yaw == _expectedResult.Yaw);
 }