Beispiel #1
0
 public async Task ConnectAsync(ButtplugEmbeddedConnectorOptions aConnector)
 {
     if (aConnector == null)
     {
         aConnector = new ButtplugEmbeddedConnectorOptions();
     }
     await ButtplugFFI.SendConnectLocal(
         _messageSorter,
         _clientHandle,
         aConnector.ServerName,
         aConnector.MaxPingTime,
         aConnector.AllowRawMessages,
         aConnector.DeviceConfigJSON,
         aConnector.UserDeviceConfigJSON,
         aConnector.DeviceCommunicationManagerTypes);
 }
        public async Task ConnectAsync(ButtplugEmbeddedConnectorOptions aConnector)
        {
            if (aConnector == null)
            {
                aConnector = new ButtplugEmbeddedConnectorOptions();
            }

            await ButtplugFFI.SendConnectLocal(
                _messageSorter,
                _clientHandle,
                aConnector.ServerName,
                aConnector.MaxPingTime,
                aConnector.AllowRawMessages,
                aConnector.DeviceConfigJSON,
                aConnector.UserDeviceConfigJSON,
                aConnector.DeviceCommunicationManagerTypes,
                SorterCallbackDelegate, GCHandle.ToIntPtr(_indexHandle));

            Connected = true;
        }
Beispiel #3
0
        private static async Task RunExample()
        {
            ButtplugFFILog.LogMessage += (aObj, aMsg) => { Console.WriteLine($"LOG: {aMsg}"); };
            ButtplugFFILog.SetLogOptions(ButtplugLogLevel.Info, true);
            var client = new ButtplugClient("Test Client");

            client.DeviceAdded += (obj, args) =>
            {
                var device = args.Device;
                Console.WriteLine($"Device Added: {device.Name}");
                foreach (var msg in args.Device.AllowedMessages)
                {
                    Console.WriteLine($"{msg.Key} {msg.Value}");
                    foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(msg.Value))
                    {
                        string name  = descriptor.Name;
                        object value = descriptor.GetValue(obj);
                        Console.WriteLine("{0}={1}", name, value);
                    }
                }
                //await device.SendVibrateCmd(1.0);
            };
            client.DeviceRemoved += (obj, args) =>
            {
                Console.WriteLine($"Device removed: {args.Device.Name}");
            };
            client.ScanningFinished += (obj, args) =>
            {
                Console.WriteLine("Scanning finished.");
            };
            client.ServerDisconnect += (obj, args) =>
            {
                Console.WriteLine("Server disconnected.");
            };
            var options = new B******g.ButtplugEmbeddedConnectorOptions();
            //options.AllowRawMessages = true;
            await client.ConnectAsync(options).ConfigureAwait(false);

            /*
             * await client.ConnectAsync(new B******g.ButtplugWebsocketConnectorOptions(new Uri("ws://localhost:12345")));
             * await client.StartScanningAsync();
             * await WaitForKey();
             * Console.WriteLine("Disconnecting");
             * await client.DisconnectAsync();
             * await WaitForKey();
             * await client.ConnectAsync(new B******g.ButtplugWebsocketConnectorOptions(new Uri("ws://localhost:12345")));
             * await client.StartScanningAsync();
             * await WaitForKey();
             * Console.WriteLine("Disconnecting");
             * await client.DisconnectAsync();
             * await WaitForKey();
             * await client.ConnectAsync(new B******g.ButtplugWebsocketConnectorOptions(new Uri("ws://localhost:12345")));
             */
            await client.StartScanningAsync().ConfigureAwait(false);

            Console.WriteLine($"Is Scanning: {client.IsScanning}");
            await WaitForKey().ConfigureAwait(false);

//            ButtplugFFILog.SetLogOptions(ButtplugLogLevel.Debug, true);
            await client.StopScanningAsync().ConfigureAwait(false);

            /*
             * while (true) {
             *  foreach (var device in client.Devices) {
             *      if (device.AllowedMessages.ContainsKey(ServerMessage.Types.MessageAttributeType.BatteryLevelCmd))
             *      {
             *          Console.WriteLine("Fetching Battery");
             *          Console.WriteLine($"Battery: {await device.SendBatteryLevelCmd()}");
             *          //await device.SendRawWriteCmd(Endpoint.Tx, Encoding.ASCII.GetBytes("Vibrate:10;"), false);
             *          //await device.SendVibrateCmd(0.5);
             *          await Task.Delay(500);
             *          //await device.SendStopDeviceCmd();
             *          //await device.SendRawWriteCmd(Endpoint.Tx, System.Text.Encoding.ASCII.GetBytes("Air:Level:3;"), false);
             *      }
             *  }
             * }
             */
            await WaitForKey().ConfigureAwait(false);

            Console.WriteLine("killing log?");
            ButtplugFFILog.SetLogOptions(ButtplugLogLevel.Off, true);
            await WaitForKey().ConfigureAwait(false);

            client.Dispose();
            client = null;
            await WaitForKey().ConfigureAwait(false);
        }