Beispiel #1
0
        private Task <ButtplugMessage> HandleFleshlightLaunchCmd(ButtplugDeviceMessage aMsg)
        {
            if (!(aMsg is FleshlightLaunchFW12Cmd cmdMsg))
            {
                return(Task.FromResult <ButtplugMessage>(BpLogger.LogErrorMsg(aMsg.Id, Error.ErrorClass.ERROR_DEVICE, "Wrong Handler")));
            }

            lock (_movementLock)
            {
                _speed    = (Convert.ToDouble(cmdMsg.Speed) / 99) * 100;
                _position = (Convert.ToDouble(cmdMsg.Position) / 99) * 100;

                _position = _position < 0 ? 0 : _position;
                _position = _position > 100 ? 100 : _position;
                _speed    = _speed < 20 ? 20 : _speed;
                _speed    = _speed > 100 ? 100 : _speed;

                // This is @funjack's algorithm for converting Fleshlight Launch
                // commands into absolute distance (percent) / duration (millisecond) values
                var distance = Math.Abs(_position - _currentPosition);
                var duration = FleshlightHelper.GetDuration(distance / 100, _speed / 100);

                // We convert those into "position" increments for our OnUpdate() timer event.
                _increment = 1.5 * (distance / (duration / _updateInterval));

                return(Task.FromResult <ButtplugMessage>(new Ok(aMsg.Id)));
            }
        }
Beispiel #2
0
        private Task <ButtplugMessage> HandleFleshlightLaunchFW12Cmd([NotNull] ButtplugDeviceMessage aMsg, CancellationToken aToken)
        {
            var cmdMsg = CheckMessageHandler <FleshlightLaunchFW12Cmd>(aMsg);

            var pos = Convert.ToDouble(cmdMsg.Position) / 99.0;
            var dur = Convert.ToUInt32(FleshlightHelper.GetDuration(Math.Abs((1 - pos) - _currentPosition), cmdMsg.Speed / 99.0));

            return(HandleLinearCmd(LinearCmd.Create(cmdMsg.DeviceIndex, cmdMsg.Id, dur, pos, 1), aToken));
        }
Beispiel #3
0
 public void TestOutOfBounds()
 {
     (Math.Abs(FleshlightHelper.GetSpeed(0, 500) - FleshlightHelper.GetSpeed(-1, 500)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetSpeed(1, 500) - FleshlightHelper.GetSpeed(2, 500)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetDistance(100, 0) - FleshlightHelper.GetDistance(100, -1)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetDistance(100, 1) - FleshlightHelper.GetDistance(100, 2)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetDistance(1000, 0.17379819904439015016403395523936)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetDuration(0.5, 0) - FleshlightHelper.GetDuration(0.5, -1)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetDuration(0.5, 1) - FleshlightHelper.GetDuration(0.5, 2)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetDuration(0, 0.5) - FleshlightHelper.GetDuration(-1, 0.5)) < 0.0001).Should().BeTrue();
     (Math.Abs(FleshlightHelper.GetDuration(1, 0.5) - FleshlightHelper.GetDuration(2, 0.5)) < 0.0001).Should().BeTrue();
 }
Beispiel #4
0
        private Task <ButtplugMessage> HandleFleshlightLaunchCmd(ButtplugDeviceMessage aMsg, CancellationToken aToken)
        {
            var cmdMsg = CheckMessageHandler <FleshlightLaunchFW12Cmd>(aMsg);

            _speed    = (Convert.ToDouble(cmdMsg.Speed) / 99) * 100;
            _position = (Convert.ToDouble(cmdMsg.Position) / 99) * 100;

            _position = _position < 0 ? 0 : _position;
            _position = _position > 100 ? 100 : _position;
            _speed    = _speed < 20 ? 20 : _speed;
            _speed    = _speed > 100 ? 100 : _speed;

            // This is @funjack's algorithm for converting Fleshlight Launch commands into absolute
            // distance (percent) / duration (millisecond) values
            var distance = Math.Abs(_position - _currentPosition);
            var duration = FleshlightHelper.GetDuration(distance / 100, _speed / 100);

            // We convert those into "position" increments for our OnUpdate() timer event.
            _increment = 1.5 * (distance / (duration / _updateInterval));

            return(Task.FromResult <ButtplugMessage>(new Ok(aMsg.Id)));
        }
Beispiel #5
0
        public void TestRoundTrip()
        {
            var delta = FleshlightHelper.GetDistance(100, 0.5);
            var speed = FleshlightHelper.GetSpeed(delta, 100);
            var time  = FleshlightHelper.GetDuration(delta, 0.5);

            (Math.Abs(0.5 - speed) < 0.01).Should().BeTrue();
            (Math.Abs(100 - time) < 0.01).Should().BeTrue();

            var speed2 = FleshlightHelper.GetSpeed(0.5, 500);
            var delta2 = FleshlightHelper.GetDistance(500, speed2);
            var time2  = FleshlightHelper.GetDuration(0.5, speed2);

            (Math.Abs(0.5 - delta2) < 0.01).Should().BeTrue();
            (Math.Abs(500 - time2) < 10).Should().BeTrue();

            var time3  = Convert.ToUInt32(FleshlightHelper.GetDuration(0.5, 0.5));
            var speed3 = FleshlightHelper.GetSpeed(0.5, time3);
            var delta3 = FleshlightHelper.GetDistance(time3, 0.5);

            (Math.Abs(0.5 - delta3) < 0.01).Should().BeTrue();
            (Math.Abs(0.5 - speed3) < 0.01).Should().BeTrue();
        }