Пример #1
0
        public SimulatedButtplugDevice(
            SimulatorManager aManager,
            [NotNull] IButtplugLogManager aLogManager,
            [NotNull] DeviceSimulator.PipeMessages.DeviceAdded da)
            : base(aLogManager, da.Name, da.Id)
        {
            _manager = aManager;
            if (da.HasLinear)
            {
                MsgFuncs.Add(typeof(FleshlightLaunchFW12Cmd), new ButtplugDeviceWrapper(HandleFleshlightLaunchFW12Cmd));
                MsgFuncs.Add(typeof(LinearCmd), new ButtplugDeviceWrapper(HandleLinearCmd, new MessageAttributes()
                {
                    FeatureCount = 1
                }));
            }

            if (da.VibratorCount > 0)
            {
                _vibratorCount = da.VibratorCount;
                MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
                MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes()
                {
                    FeatureCount = da.VibratorCount
                }));
            }

            if (da.HasRotator)
            {
                MsgFuncs.Add(typeof(VorzeA10CycloneCmd), new ButtplugDeviceWrapper(HandleVorzeA10CycloneCmd));
            }

            MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
        }
Пример #2
0
        public ET312Device(SerialPort port, IButtplugLogManager aLogManager, string name, string id)
            : base(aLogManager, name, id)
        {
            _movementLock = new object();

            // Handshake with the box
            _serialPort = port;
            _boxkey     = 0;
            Synch();

            try
            {
                // Setup box for remote control
                Execute((byte)BoxCommand.FavouriteMode);
                Poke((uint)RAM.ChannelAGateSelect, (byte)Gate.Off);
                Poke((uint)RAM.ChannelBGateSelect, (byte)Gate.Off);
                Poke((uint)RAM.ChannelAIntensitySelect, (byte)Select.Static);
                Poke((uint)RAM.ChannelBIntensitySelect, (byte)Select.Static);
                Poke((uint)RAM.ChannelAIntensity, 0);
                Poke((uint)RAM.ChannelBIntensity, 0);
                Poke((uint)RAM.ChannelARampValue, 255);
                Poke((uint)RAM.ChannelAFrequencySelect, (byte)Select.MA);
                Poke((uint)RAM.ChannelBFrequencySelect, (byte)Select.MA);
                Poke((uint)RAM.ChannelAWidthSelect, (byte)Select.Advanced);
                Poke((uint)RAM.ChannelBWidthSelect, (byte)Select.Advanced);

                // Let the user know we're in control now
                WriteLCD("B******g", 8);
                WriteLCD("----------------", 64);
            }
            catch (Exception ex)
            {
                AbandonShip();

                if (ex is ET312CommunicationException ||
                    ex is InvalidOperationException ||
                    ex is TimeoutException)
                {
                    // If anything goes wrong during the setup
                    // consider the entire handshake failed
                    throw new ET312HandshakeException("Failed to set up initial device parameters.");
                }

                throw;
            }

            // We're now ready to receive events
            MsgFuncs.Add(typeof(FleshlightLaunchFW12Cmd), HandleFleshlightLaunchFW12Cmd);
            MsgFuncs.Add(typeof(StopDeviceCmd), HandleStopDeviceCmd);

            // Start update timer
            _updateInterval = 20;                        // <- Change this value to adjust box update frequency in ms
            _updateTimer    = new Timer()
            {
                Interval  = _updateInterval,
                AutoReset = true,
                Enabled   = true,
            };
            _updateTimer.Elapsed += OnUpdate;
        }
Пример #3
0
        public VorzeSA(IButtplugLogManager aLogManager,
                       IBluetoothDeviceInterface aInterface,
                       IBluetoothDeviceInfo aInfo)
            : base(aLogManager,
                   "Vorze SA Unknown",
                   aInterface,
                   aInfo)
        {
            if (aInterface.Name == "CycSA")
            {
                _deviceType = DeviceType.CycloneOrUnknown;
                Name        = "Vorze A10 Cyclone SA";
            }
            else if (aInterface.Name == "UFOSA")
            {
                _deviceType = DeviceType.UFO;
                Name        = "Vorze UFO SA";
            }
            else
            {
                // If the device doesn't identify, warn and try sending it Cyclone packets.
                BpLogger.Warn($"Vorze product with unrecognized name ({Name}) found. This product may not work with B******g. Contact the developers for more info.");
            }

            MsgFuncs.Add(typeof(VorzeA10CycloneCmd), new ButtplugDeviceWrapper(HandleVorzeA10CycloneCmd));
            MsgFuncs.Add(typeof(RotateCmd), new ButtplugDeviceWrapper(HandleRotateCmd, new MessageAttributes()
            {
                FeatureCount = 1
            }));
            MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
        }
 public XInputGamepadDevice(IButtplugLogManager aLogManager, Controller aDevice)
     : base(aLogManager, "XBox Compatible Gamepad (XInput)", aDevice.UserIndex.ToString())
 {
     _device = aDevice;
     MsgFuncs.Add(typeof(SingleMotorVibrateCmd), HandleSingleMotorVibrateCmd);
     MsgFuncs.Add(typeof(StopDeviceCmd), HandleStopDeviceCmd);
 }
Пример #5
0
        public Lovense(IButtplugLogManager aLogManager,
                       IBluetoothDeviceInterface aInterface,
                       IBluetoothDeviceInfo aInfo)
            : base(aLogManager,
                   $"Lovense Device ({FriendlyNames[aInterface.Name]})",
                   aInterface,
                   aInfo)
        {
            if (FriendlyNames[aInterface.Name] == "Edge")
            {
                _vibratorCount++;
            }

            MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
            MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes()
            {
                FeatureCount = _vibratorCount
            }));
            MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));

            if (FriendlyNames[aInterface.Name] == "Nora")
            {
                MsgFuncs.Add(typeof(RotateCmd), new ButtplugDeviceWrapper(HandleRotateCmd, new MessageAttributes()
                {
                    FeatureCount = 1
                }));
            }
        }
Пример #6
0
        public KiirooGen2Vibe([NotNull] IButtplugLogManager aLogManager,
                              [NotNull] IBluetoothDeviceInterface aInterface,
                              [NotNull] IBluetoothDeviceInfo aInfo)
            : base(aLogManager,
                   "Kiiroo Unknown",
                   aInterface,
                   aInfo)
        {
            if (DevInfos.ContainsKey(aInterface.Name))
            {
                Name     = $"{DevInfos[aInterface.Name].Brand} {aInterface.Name}";
                _devInfo = DevInfos[aInterface.Name];
            }
            else
            {
                BpLogger.Warn($"Cannot identify device {Name}, defaulting to Pearl2 settings.");
                _devInfo = DevInfos["Unknown"];
            }

            MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
            MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes {
                FeatureCount = _devInfo.VibeCount
            }));
            MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
        }
 public RezTranceVibratorDevice(IButtplugLogManager aLogManager, USBDevice aDevice, uint aIndex)
     : base(aLogManager, "Trancevibrator " + aIndex, "Trancevibrator " + aIndex)
 {
     _device = aDevice;
     MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
     MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
     MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd));
 }
Пример #8
0
 public VorzeA10Cyclone(IButtplugLogManager aLogManager,
                        IBluetoothDeviceInterface aInterface)
     : base(aLogManager,
            "Vorze A10 Cyclone",
            aInterface)
 {
     MsgFuncs.Add(typeof(VorzeA10CycloneCmd), HandleVorzeA10CycloneCmd);
     MsgFuncs.Add(typeof(StopDeviceCmd), HandleStopDeviceCmd);
 }
Пример #9
0
 public Kiiroo([NotNull] IButtplugLogManager aLogManager,
               [NotNull] IBluetoothDeviceInterface aInterface)
     : base(aLogManager,
            $"Kiiroo {aInterface.Name}",
            aInterface)
 {
     MsgFuncs.Add(typeof(KiirooCmd), HandleKiirooRawCmd);
     MsgFuncs.Add(typeof(StopDeviceCmd), HandleStopDeviceCmd);
 }
Пример #10
0
 public Lovense(IButtplugLogManager aLogManager,
                IBluetoothDeviceInterface aInterface)
     : base(aLogManager,
            $"Lovense Device ({aInterface.Name})",
            aInterface)
 {
     MsgFuncs.Add(typeof(SingleMotorVibrateCmd), HandleSingleMotorVibrateCmd);
     MsgFuncs.Add(typeof(StopDeviceCmd), HandleStopDeviceCmd);
 }
Пример #11
0
 public TestDevice(IButtplugLogManager aLogManager, string aName, string aIdentifier = null)
     : base(aLogManager, aName, aIdentifier ?? aName)
 {
     MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
     MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes()
     {
         FeatureCount = 2
     }));
     MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
 }
Пример #12
0
 public FleshlightLaunch([NotNull] IButtplugLogManager aLogManager,
                         [NotNull] IBluetoothDeviceInterface aInterface)
     : base(aLogManager,
            "Fleshlight Launch",
            aInterface)
 {
     // Setup message function array
     MsgFuncs.Add(typeof(FleshlightLaunchFW12Cmd), HandleFleshlightLaunchRawCmd);
     MsgFuncs.Add(typeof(StopDeviceCmd), HandleStopDeviceCmd);
 }
Пример #13
0
 public Youcups(IButtplugLogManager aLogManager,
                IBluetoothDeviceInterface aInterface,
                IBluetoothDeviceInfo aInfo)
     : base(aLogManager,
            $"Youcups Device ({friendlyNames[aInterface.Name]})",
            aInterface,
            aInfo)
 {
     MsgFuncs.Add(typeof(SingleMotorVibrateCmd), HandleSingleMotorVibrateCmd);
     MsgFuncs.Add(typeof(StopDeviceCmd), HandleStopDeviceCmd);
 }
Пример #14
0
 public CycloneX10(IButtplugLogManager aLogManager, IHidDevice aHid, CycloneX10HidDeviceInfo aDeviceInfo)
     : base(aLogManager, aHid, aDeviceInfo)
 {
     MsgFuncs.Add(typeof(VorzeA10CycloneCmd), new ButtplugDeviceWrapper(HandleVorzeA10CycloneCmd));
     MsgFuncs.Add(typeof(RotateCmd), new ButtplugDeviceWrapper(HandleRotateCmd, new MessageAttributes()
     {
         FeatureCount = 1
     }));
     MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
     aHid.OpenDevice();
 }
 public XInputGamepadDevice(IButtplugLogManager aLogManager, Controller aDevice)
     : base(aLogManager, "XBox Compatible Gamepad (XInput)", aDevice.UserIndex.ToString())
 {
     _device = aDevice;
     MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
     MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes()
     {
         FeatureCount = 2
     }));
     MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
 }
Пример #16
0
 public MagicMotion(IButtplugLogManager aLogManager,
                    IBluetoothDeviceInterface aInterface,
                    IBluetoothDeviceInfo aInfo)
     : base(aLogManager,
            $"MagicMotion Device ({aInterface.Name})",
            aInterface,
            aInfo)
 {
     MsgFuncs.Add(typeof(SingleMotorVibrateCmd), HandleSingleMotorVibrateCmd);
     MsgFuncs.Add(typeof(StopDeviceCmd), HandleStopDeviceCmd);
 }
Пример #17
0
 public Lovense(IButtplugLogManager aLogManager,
                IBluetoothDeviceInterface aInterface,
                IBluetoothDeviceInfo aInfo)
     : base(aLogManager,
            "Lovense Unknown Device",
            aInterface,
            aInfo)
 {
     MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
     MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes()
     {
         FeatureCount = _vibratorCount
     }));
     MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
 }
Пример #18
0
 public VorzeA10Cyclone(IButtplugLogManager aLogManager,
                        IBluetoothDeviceInterface aInterface,
                        IBluetoothDeviceInfo aInfo)
     : base(aLogManager,
            "Vorze A10 Cyclone",
            aInterface,
            aInfo)
 {
     MsgFuncs.Add(typeof(VorzeA10CycloneCmd), new ButtplugDeviceWrapper(HandleVorzeA10CycloneCmd));
     MsgFuncs.Add(typeof(RotateCmd), new ButtplugDeviceWrapper(HandleRotateCmd, new MessageAttributes()
     {
         FeatureCount = 1
     }));
     MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
 }
Пример #19
0
 public WeVibe(IButtplugLogManager aLogManager,
               IBluetoothDeviceInterface aInterface,
               IBluetoothDeviceInfo aInfo)
     : base(aLogManager,
            $"WeVibe Device ({aInterface.Name})",
            aInterface,
            aInfo)
 {
     MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
     MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes()
     {
         FeatureCount = 1
     }));
     MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
 }
Пример #20
0
 public OhMiBodFuse([NotNull] IButtplugLogManager aLogManager,
                    [NotNull] IBluetoothDeviceInterface aInterface,
                    [NotNull] IBluetoothDeviceInfo aInfo)
     : base(aLogManager,
            $"OhMiBod {aInterface.Name}",
            aInterface,
            aInfo)
 {
     MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
     MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes()
     {
         FeatureCount = 2
     }));
     MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
 }
Пример #21
0
 public KiirooGen2Vibe([NotNull] IButtplugLogManager aLogManager,
                       [NotNull] IBluetoothDeviceInterface aInterface,
                       [NotNull] IBluetoothDeviceInfo aInfo)
     : base(aLogManager,
            $"{DevInfos[aInterface.Name].Brand} {aInterface.Name}",
            aInterface,
            aInfo)
 {
     _devInfo = DevInfos[aInterface.Name];
     MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
     MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes {
         FeatureCount = _devInfo.VibeCount
     }));
     MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
 }
Пример #22
0
 public FleshlightLaunch([NotNull] IButtplugLogManager aLogManager,
                         [NotNull] IBluetoothDeviceInterface aInterface,
                         [NotNull] IBluetoothDeviceInfo aInfo)
     : base(aLogManager,
            "Fleshlight Launch",
            aInterface,
            aInfo)
 {
     // Setup message function array
     MsgFuncs.Add(typeof(FleshlightLaunchFW12Cmd), new ButtplugDeviceWrapper(HandleFleshlightLaunchRawCmd));
     MsgFuncs.Add(typeof(LinearCmd), new ButtplugDeviceWrapper(HandleLinearCmd, new MessageAttributes()
     {
         FeatureCount = 1
     }));
     MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
 }
Пример #23
0
        public LiBo(IButtplugLogManager aLogManager,
                    IBluetoothDeviceInterface aInterface,
                    IBluetoothDeviceInfo aInfo)
            : base(aLogManager,
                   $"LiBo ({aInterface.Name})",
                   aInterface,
                   aInfo)
        {
            MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
            MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes()
            {
                FeatureCount = _vibratorCount
            }));

            // TODO Add a handler for Estim shocking, add a battery handler.
            MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
        }
Пример #24
0
 public Youcups(IButtplugLogManager aLogManager,
                IBluetoothDeviceInterface aInterface,
                IBluetoothDeviceInfo aInfo)
     : base(aLogManager,
            $"Youcups Unknown",
            aInterface,
            aInfo)
 {
     if (FriendlyNames.ContainsKey(aInterface.Name))
     {
         Name = $"Youcups {FriendlyNames[aInterface.Name]}";
     }
     MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
     MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes()
     {
         FeatureCount = 1
     }));
     MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
 }
Пример #25
0
        public WeVibe(IButtplugLogManager aLogManager,
                      IBluetoothDeviceInterface aInterface,
                      IBluetoothDeviceInfo aInfo)
            : base(aLogManager,
                   $"WeVibe {aInterface.Name}",
                   aInterface,
                   aInfo)
        {
            if (DualVibes.Contains(aInterface.Name))
            {
                _vibratorCount = 2;
            }

            MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
            MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes()
            {
                FeatureCount = _vibratorCount
            }));
            MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
        }
Пример #26
0
        public Kiiroo([NotNull] IButtplugLogManager aLogManager,
                      [NotNull] IBluetoothDeviceInterface aInterface,
                      [NotNull] IBluetoothDeviceInfo aInfo)
            : base(aLogManager,
                   $"Kiiroo {aInterface.Name}",
                   aInterface,
                   aInfo)
        {
            MsgFuncs.Add(typeof(KiirooCmd), new ButtplugDeviceWrapper(HandleKiirooRawCmd));
            MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));

            if (aInterface.Name == "PEARL")
            {
                MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes()
                {
                    FeatureCount = 1
                }));
                MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
            }
        }
Пример #27
0
        public MysteryVibe(IButtplugLogManager aLogManager,
                           IBluetoothDeviceInterface aInterface,
                           IBluetoothDeviceInfo aInfo)
            : base(aLogManager,
                   $"MysteryVibe Crescendo",
                   aInterface,
                   aInfo)
        {
            // Create a new timer that wont fire any events just yet
            _updateValueTimer.Interval = DelayTimeMS;
            _updateValueTimer.Elapsed += MysteryVibeUpdateHandler;
            _updateValueTimer.Enabled  = false;
            aInterface.DeviceRemoved  += OnDeviceRemoved;

            MsgFuncs.Add(typeof(SingleMotorVibrateCmd), new ButtplugDeviceWrapper(HandleSingleMotorVibrateCmd));
            MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes()
            {
                FeatureCount = 6
            }));
            MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
        }
Пример #28
0
        public FleshlightLaunch([NotNull] IButtplugLogManager aLogManager,
                                [NotNull] IBluetoothDeviceInterface aInterface,
                                [NotNull] IBluetoothDeviceInfo aInfo)
            : base(aLogManager,
                   aInterface.Name,
                   aInterface,
                   aInfo)
        {
            if (_brandNames.ContainsKey(aInterface.Name))
            {
                Name = $"{_brandNames[aInterface.Name]} {aInterface.Name}";
            }

            // Setup message function array
            MsgFuncs.Add(typeof(FleshlightLaunchFW12Cmd), new ButtplugDeviceWrapper(HandleFleshlightLaunchRawCmd));
            MsgFuncs.Add(typeof(LinearCmd), new ButtplugDeviceWrapper(HandleLinearCmd, new MessageAttributes()
            {
                FeatureCount = 1
            }));
            MsgFuncs.Add(typeof(StopDeviceCmd), new ButtplugDeviceWrapper(HandleStopDeviceCmd));
        }
        public SimulatedButtplugDevice(
            SimulatorManager aManager,
            [NotNull] IButtplugLogManager aLogManager,
            [NotNull] DeviceSimulator.PipeMessages.DeviceAdded da)
            : base(aLogManager, da.Name, da.Id)
        {
            _manager = aManager;
            if (da.HasLinear)
            {
                MsgFuncs.Add(typeof(FleshlightLaunchFW12Cmd), HandleFleshlightLaunchFW12Cmd);
            }

            if (da.HasVibrator)
            {
                MsgFuncs.Add(typeof(SingleMotorVibrateCmd), HandleSingleMotorVibrateCmd);
            }

            if (da.HasRotator)
            {
                MsgFuncs.Add(typeof(VorzeA10CycloneCmd), HandleVorzeA10CycloneCmd);
            }

            MsgFuncs.Add(typeof(StopDeviceCmd), HandleStopDeviceCmd);
        }
Пример #30
0
        public override async Task <ButtplugMessage> Initialize()
        {
            BpLogger.Trace($"Initializing {Name}");

            // Subscribing to read updates
            await Interface.SubscribeToUpdates();

            Interface.BluetoothNotifyReceived += NotifyReceived;

            // Retreiving device type info for identification.
            var writeMsg = await Interface.WriteValue(ButtplugConsts.SystemMsgId, Encoding.ASCII.GetBytes($"DeviceType;"), true);

            if (writeMsg is Error)
            {
                BpLogger.Error($"Error requesting device info from Lovense {Name}");
                return(writeMsg);
            }

            var(msg, result) = await Interface.ReadValue(ButtplugConsts.SystemMsgId);

            string deviceInfoString = string.Empty;

            if (msg is Ok)
            {
                deviceInfoString = Encoding.ASCII.GetString(result);
            }
            else
            {
                // The device info notification isn't available immediately.
                // TODO Turn this into a task semaphore with cancellation/timeout, let system handle check timing.
                int timeout = 500;
                while (timeout > 0)
                {
                    if (_lastNotifyReceived != string.Empty)
                    {
                        deviceInfoString = _lastNotifyReceived;
                        break;
                    }

                    timeout -= 5;
                    await Task.Delay(5);
                }
            }

            if (deviceInfoString != string.Empty)
            {
                BpLogger.Debug($"Received device query return for {Interface.Name}");
                // Expected Format X:YY:ZZZZZZZZZZZZ X is device type leter YY is firmware version Z
                // is bluetooth address
                var deviceInfo = deviceInfoString.Split(':');

                // If we don't get back the amount of tokens we expect, identify as unknown, log, bail.
                if (deviceInfo.Length != 3 || deviceInfo[0].Length != 1)
                {
                    return(BpLogger.LogErrorMsg(ButtplugConsts.SystemMsgId, Error.ErrorClass.ERROR_DEVICE,
                                                $"Unknown Lovense DeviceType of {deviceInfoString} found. Please report to B******g Developers by filing an issue at https://github.com/metafetish/b******g/"));
                }

                var deviceTypeLetter = deviceInfo[0][0];
                if (deviceTypeLetter == 'C')
                {
                    deviceTypeLetter = 'A';
                }
                int.TryParse(deviceInfo[1], out var deviceVersion);
                BpLogger.Trace($"Lovense DeviceType Return: {deviceTypeLetter}");
                if (!Enum.IsDefined(typeof(LovenseDeviceType), (uint)deviceTypeLetter))
                {
                    // If we don't know what device this is, just assume it has a single vibrator,
                    // call it unknown, log something.
                    return(BpLogger.LogErrorMsg(ButtplugConsts.SystemMsgId, Error.ErrorClass.ERROR_DEVICE,
                                                $"Unknown Lovense Device of Type {deviceTypeLetter} found. Please report to B******g Developers by filing an issue at https://github.com/metafetish/b******g/"));
                }

                Name = $"Lovense {Enum.GetName(typeof(LovenseDeviceType), (uint)deviceTypeLetter)} v{deviceVersion}";

                _deviceType = (LovenseDeviceType)deviceTypeLetter;
            }
            else
            {
                // If we for some reason don't get a device info query back, use fallback method.
                //
                // TODO Remove this branch at some point? Not sure we'll need it now since device queries seem stable.
                BpLogger.Warn($"Error retreiving device info from Lovense {Name}, using fallback method");

                // Some of the older devices seem to have issues with info lookups? Not sure why, so
                // for now use fallback method.
                switch (Interface.Name.Substring(0, 6))
                {
                case "LVS-B0":
                    _deviceType = LovenseDeviceType.Max;
                    break;

                case "LVS-A0":
                case "LVS-C0":
                    _deviceType = LovenseDeviceType.Nora;
                    break;

                case "LVS-L0":
                    _deviceType = LovenseDeviceType.Ambi;
                    break;

                default:
                    _deviceType = LovenseDeviceType.Unknown;
                    break;
                }

                Name = $"Lovense {Enum.GetName(typeof(LovenseDeviceType), (uint)_deviceType)} v{Interface.Name.Substring(Interface.Name.Length - 2)}";
            }

            if (_deviceType == LovenseDeviceType.Unknown)
            {
                BpLogger.Error("Lovense device type unknown, treating as single vibrator device. Please contact developers for more info.");
            }

            switch (_deviceType)
            {
            case LovenseDeviceType.Edge:

                // Edge has 2 vibrators
                _vibratorCount++;
                MsgFuncs.Remove(typeof(VibrateCmd));
                MsgFuncs.Add(typeof(VibrateCmd), new ButtplugDeviceWrapper(HandleVibrateCmd, new MessageAttributes()
                {
                    FeatureCount = _vibratorCount
                }));
                break;

            case LovenseDeviceType.Nora:

                // Nora has a rotator
                MsgFuncs.Add(typeof(RotateCmd), new ButtplugDeviceWrapper(HandleRotateCmd, new MessageAttributes()
                {
                    FeatureCount = 1
                }));
                break;
            }

            return(new Ok(ButtplugConsts.SystemMsgId));
        }