Esempio n. 1
0
        public async Task Setup()
        {
            await ExecuteOnMainThread(() => _checkConnectiontimer.Stop());

            IsReady = false;

            await Task.Delay(2000);

            ConnectionNotify?.Invoke(this, "Tentando se Conectar");
            await Task.Delay(2000);

            if (_bluetoothSerial != null)
            {
                Arduino?.Dispose();
                Arduino = new RemoteDevice(_bluetoothSerial);
                await Task.Delay(1000);
                await ExecuteOnMainThread(() => _bluetoothSerial.begin(57600, SerialConfig.SERIAL_8N1));
            }
            else
            {
                Arduino?.Dispose();
                Arduino = new RemoteDevice(_usbSerial);
                await Task.Delay(1000);
                await ExecuteOnMainThread(() => _usbSerial.begin(57600, SerialConfig.SERIAL_8N1));
            }

            SerialOut = new SerialOutController(Arduino, 12, 8, 7);

            Arduino.DeviceConnectionLost += message =>
            {
                ConnectionNotify?.Invoke(this, "Conexão Arduino Perdida: " + message);
            };

            Arduino.DeviceConnectionFailed += async message =>
            {
                ConnectionNotify?.Invoke(this, "Conexão Arduino Falhou: " + message);
                await Task.Delay(5000);
            };

            Arduino.DeviceReady += async() => await ArduinoOnDeviceReady();

            Servos = new Dictionary <ETinBotServo, ServoController>()
            {
                [ETinBotServo.ServoHand]     = new ServoController(Arduino, 09),
                [ETinBotServo.ServoHeadX]    = new ServoController(Arduino, 05),
                [ETinBotServo.ServoHeadY]    = new ServoController(Arduino, 06),
                [ETinBotServo.ServoLeftArm]  = new ServoController(Arduino, 03, true),
                [ETinBotServo.ServoRightArm] = new ServoController(Arduino, 11),
                [ETinBotServo.ServoTorso]    = new ServoController(Arduino, 10)
            };

            await ExecuteOnMainThread(() => _checkConnectiontimer.Start());
        }
Esempio n. 2
0
        private async Task ArduinoOnDeviceReady()
        {
            ConnectionNotify?.Invoke(this, "Arduino Ready");

            await SerialOut.Reset(false);

            await Task.Delay(300);

            await AttachServos();

            Arduino.SafePinMode(_phoneChargePin, PinMode.OUTPUT);

            IsReady = true;
        }
Esempio n. 3
0
        public Body(UsbSerial usbSerial)
        {
            _usbSerial = usbSerial;
            _usbSerial.ConnectionEstablished += () => ConnectionNotify?.Invoke(this, "USB estabelecido");
            _usbSerial.ConnectionFailed      += message =>
            {
                ConnectionNotify?.Invoke(this, "USB falhou: " + message);
                Setup();
            };
            _usbSerial.ConnectionLost += message =>
            {
                ConnectionNotify?.Invoke(this, "USB perdido: " + message);
            };

            _checkConnectiontimer.Interval = TimeSpan.FromSeconds(90);
            _checkConnectiontimer.Tick    += CheckConnectiontimerOnTick;
        }
Esempio n. 4
0
        public Body(BluetoothSerial bluetoothSerial)
        {
            _bluetoothSerial = bluetoothSerial;
            _bluetoothSerial.ConnectionEstablished += () => ConnectionNotify?.Invoke(this, "Bluetooth estabelecido");
            _bluetoothSerial.ConnectionFailed      += async message =>
            {
                ConnectionNotify?.Invoke(this, "Bluetooth falhou: " + message);
                await Task.Delay(5000);

                Setup();
            };
            _bluetoothSerial.ConnectionLost += message =>
            {
                ConnectionNotify?.Invoke(this, "Bluetooth perdido: " + message);
                Setup();
            };

            _checkConnectiontimer.Interval = TimeSpan.FromSeconds(30);
            _checkConnectiontimer.Tick    += CheckConnectiontimerOnTick;
        }