Esempio n. 1
0
        private async void RefreshConnectionStatus()
        {
            void UpdateConnectionString(string text, Color color) => Device.InvokeOnMainThreadAsync(() => { LblConnectionStatus.Text = text; LblConnectionStatus.TextColor = color; });

            _ = Task.Run(() => ViewExtensions.RelRotateTo(ImgRefreshConnection, 2800, 10000));

            UpdateConnectionString("Připojování...", Color.Gray);

            await Task.Run(() =>
            {
                switch (BluetoothController.ConnectToRPi())
                {
                case ConnectionState.BluetoothOFF:
                    UpdateConnectionString("Bluetooth je vypnuto!", Color.Gray);
                    break;

                case ConnectionState.Failed:
                    UpdateConnectionString("Připojení s RPi selhalo.", Color.Red);
                    break;

                case ConnectionState.Connected:
                    UpdateConnectionString("Připojení s RPi navázano.", Color.Green);
                    break;
                }
            });

            ViewExtensions.CancelAnimations(ImgRefreshConnection);
        }
Esempio n. 2
0
        private void DeviceListItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            BluetoothController.StopDiscovery();
            var configActivity = new Intent(this, typeof(ConfigActivity));

            configActivity.PutExtra("Device", (BluetoothDevice)e.Parent.GetItemAtPosition(e.Position));
            StartActivityForResult(configActivity, 0);
        }
Esempio n. 3
0
 private void PreInit()
 {
     PinController       = new PinController(this);
     EventManager        = new EventManager(this);
     MorseTranslator     = new MorseRelayTranslator(this);
     BluetoothController = new BluetoothController(this);
     SoundController     = new SoundController(this);
     ConfigManager       = new PinConfigManager(this);
 }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var controller = new BluetoothController();

            controller.Start();

            Console.ReadKey();
        }
Esempio n. 5
0
 private void StartDiscoveryDevices()
 {
     if (BluetoothController.IsEnabled)
     {
         BluetoothController.StartDiscovery();
     }
     else
     {
         BluetoothController.Enable();
     }
 }
Esempio n. 6
0
 internal GpioCore(PinsWrapper pins, Core core, bool shouldGracefullyShutdown = true)
 {
     Core = core ?? throw new ArgumentNullException(nameof(core));
     Pins = pins;
     IsGracefullShutdownRequested = shouldGracefullyShutdown;
     PinController       = new PinController(this);
     EventGenerator      = new InternalEventGenerator(Core, PinController.GetDriver());
     MorseTranslator     = new MorseRelayTranslator(this);
     BluetoothController = new BluetoothController(this);
     SoundController     = new SoundController(this);
     PinConfig           = new PinConfig();
 }
Esempio n. 7
0
        public GpioCore(AvailablePins _availablePins, bool _gracefullShutdownRequested = true)
        {
            AvailablePins = _availablePins;
            IsGracefullShutdownRequested = _gracefullShutdownRequested;

            PinController       = new PinController(this);
            EventManager        = new EventManager(this);
            MorseTranslator     = new MorseRelayTranslator(this);
            BluetoothController = new BluetoothController(this);
            SoundController     = new SoundController(this);
            ConfigManager       = new PinConfigManager(this);
        }
Esempio n. 8
0
    public void OnPointerUp(PointerEventData eventData)
    {
        Debug.Log("button unpressed");
        BluetoothController.SetMessage(null);
        isMoving = false;

        Vector3 moveOffset = oldPosition - transform.position;

        if (pressTimer < 0.3 && Mathf.Abs(moveOffset.magnitude) < 0.001F)
        {
            ButtonClickAction();
        }

        pressTimer = 0;
    }
Esempio n. 9
0
    public void OnPointerDown(PointerEventData eventData)
    {
        ButtonData button = this.transform.GetComponent <ButtonData>();

        Debug.Log("button " + button.GetButtonName() + " pressed, message = " + button.GetButtonMessage());
        byte[] message = StringToByteArray(button.GetButtonMessage());
        //for (int i = 0; i < message.Length; i++)
        //     Debug.Log(message[i]);
        BluetoothController.SetMessage(message);
        isMoving = true;

        oldPosition = transform.position;

        clickOffset = Input.mousePosition - transform.position;
    }
Esempio n. 10
0
        /// <summary>
        /// Initialize the page, create task for listening of data from RPi
        /// </summary>
        public SatDataPage()
        {
            InitializeComponent();

            if (GUIAnimations.CheckConnection(this))
            {
                return;
            }

            Disappearing += SatDataPage_Disappearing;

            _token = new CancellationTokenSource();



            //Sends query for listening satellite data.
            _ = BluetoothController.SendQueryToRPiAsync(Query.DataSatellite);

            Task.Run(async() =>
            {
                while (true)
                {
                    string data = await BluetoothController.ReadDataFromRPiAsync();
                    Dispatcher.BeginInvokeOnMainThread(() => GUIAnimations.UpdateData(data, new Dictionary <string, Label>()
                    {
                        { "MessageID", LblMessage },
                        { "Temperature", LblTemp },
                        { "Humidity", LblHum },
                        { "Pressure", LblPress },
                        { "Altitude", LblAlt },
                        { "Longitude", LblLong },
                        { "Latitude", LblLat }
                    }, LblUpdateTime));

                    //Cancellation operation
                    if (_token.Token.IsCancellationRequested)
                    {
                        await BluetoothController.ClearIncomeBuffer();
                        return;
                    }
                }
            });
        }
Esempio n. 11
0
    void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        Screen.sleepTimeout         = SleepTimeout.NeverSleep;
        Application.targetFrameRate = 30;

        c_AchievementCtrl = AchievementController.Instance;
        c_FightCtrl       = FightController.Instance;
        c_FontCtrl        = FontController.Instance;
        c_LayoutCtrl      = LayoutController.Instance;
        c_LanguageCtrl    = LanguageController.Instance;
        c_SkinCtrl        = SkinController.Instance;
        c_TextColorCtrl   = TextColorController.Instance;
        c_RecordCtrl      = RecordController.Instance;
        c_RankCtrl        = RankController.Instance;
        c_GuiCtrl         = GuiController.Instance;
        c_BluetoothCtrl   = BluetoothController.Instance;
    }
Esempio n. 12
0
    public MainViewModel(BluetoothController bluetoothController, IAlertMessage message)
    {
        _bluetoothController = bluetoothController;

        _message = message;

        _selectDeviceInteraction = new Interaction <IDevice[], IDevice>();

        IncreaseSpeedCommand = ReactiveCommand.Create(() =>
        {
            if (Speed == 100)
            {
                return(100);
            }

            return(Speed += 10f);
        });

        DecreaseSpeedCommand = ReactiveCommand.Create(() =>
        {
            if (Speed == 0)
            {
                return(0);
            }

            return(Speed -= 10f);
        });

        _bluetoothController.IsEnabled.ToPropertyEx(this, x => x.IsEnabled);

        _bluetoothController.IsConnected.ToPropertyEx(this, x => x.IsConnected);

        _bluetoothController.SensorValue.ToPropertyEx(this, x => x.SensorValue);



        ScanCommand = ReactiveCommand.CreateFromTask <bool>(OnScanAsync);

        DigitalMoveCommand = ReactiveCommand.CreateFromTask <JoystickDirection>(OnDigitalMoveAsync);
    }
Esempio n. 13
0
        private async void ImgShutdown_Tapped(object sender, EventArgs e)
        {
            if (GUIAnimations.CheckConnection(this))
            {
                return;
            }

            string result = await DisplayActionSheet("Vyberte akci", "Zrušit", "", "Vypnout RPi", "Resetovat RPi", "Resetovat data monitoring");

            switch (result)
            {
            case "Vypnout RPi":
                await BluetoothController.SendQueryToRPiAsync("shutdown");

                await Task.Delay(1_000);

                RefreshConnectionStatus();
                break;

            case "Resetovat RPi":
                await BluetoothController.SendQueryToRPiAsync("reboot");

                await Task.Delay(1_000);

                RefreshConnectionStatus();
                await Task.Delay(15_000);

                RefreshConnectionStatus();
                break;

            case "Resetovat data monitoring":
                await BluetoothController.SendQueryToRPiAsync("restartOG");

                await Task.Delay(1_000);

                break;
            }
        }
        public static void Main()
        {
            Debug.Print("Program started.");

            var ioController = new IOController();
            var btController = new BluetoothController(ioController);
            //var btController = new DummyBluetoothController();

            var gameController = new GameController(btController, ioController);

            btController.GameController = gameController;
            ioController.GameController = gameController;

            gameController.Respawn();

            Debug.Print("Init complete, looping...");

            while (true)
            {
                ioController.Process();
                btController.Process();
            }
        }
Esempio n. 15
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Config);

            _device = (BluetoothDevice)Intent.GetParcelableExtra("Device");
            _socket = BluetoothController.GetBluetoothSocket(_device);

            try
            {
                ConnectToSocket(_socket);
            }
            catch (Exception e)
            {
                var intent = new Intent(this, typeof(MainActivity));
                intent.PutExtra("Message", "Unable connect to device");
                SetResult(Result.Canceled, intent);
                Finish();
                return;
            }
            InitializeGui();
        }
Esempio n. 16
0
        private async void BttnGetBPEJ_Clicked(object sender, EventArgs e)
        {
            if (GUIAnimations.CheckConnection(this))
            {
                return;
            }

            BttnGetBPEJ.IsEnabled = false;

            var token = GUIAnimations.DotLoadingAnimation(LblBPEJFinding, "Vyhodnocování", 7, 300);

            Location location = null;

            try
            {
                location = await Geolocation.GetLocationAsync();

                EntrBPEJcode.Text = await BluetoothController.GetDataFromRPiAsync($"get_bpej {location.Longitude} {location.Latitude}", 1000, 1000);

                EntrBPEJcode_Completed(null, null);
            }
            catch (FeatureNotEnabledException)
            {
                _ = DisplayAlert("Lokace není povolená", "Pro použití funkce si povolte lokaci v telefonu.", "OK");
            }
            catch (Exception ex)
            {
                _ = DisplayAlert("Debug - Exception", ex.Message, "OK");
            }

            token.Cancel();
            await Task.Delay(500);

            LblBPEJFinding.Text = location != null ? $"Vaše pozice | z. délka: {location.Longitude}, z. šířka: {location.Latitude}" : "Vaši pozici se nepodařilo lokalizovat.";

            BttnGetBPEJ.IsEnabled = true;
        }
Esempio n. 17
0
 private void Start()
 {
     bluetoothController = GameServices.GetService <BluetoothController>();
     bluetoothController.BondedDeviceDiscovered += OnBondedDeviceDiscovered;
 }
Esempio n. 18
0
        /// <summary>
        /// Sends cancellation query to the RPi, cancel the listening task
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void BaseDataPage_Disappearing(object sender, EventArgs e)
        {
            await BluetoothController.SendQueryToRPiAsync(Query.DataOFF);

            _token.Cancel();
        }
Esempio n. 19
0
 private void background_DoWork(object sender, DoWorkEventArgs e)
 {
     bluetoothController = new BluetoothController();
     bluetoothController.findBluetoothTolist();
 }
Esempio n. 20
0
        private async void EntrBPEJcode_Completed(object sender, EventArgs e)
        {
            // _ = ViewExtensions.RelRotateTo(ImgLoadingInfoBPEJ, 2800, 10000);

            if (GUIAnimations.CheckConnection(this))
            {
                return;
            }

            PrgrssBrBPEJ.IsVisible = true;
            PrgrssBrBPEJ.Progress  = 0;
            TblSctnPlants.Clear();
            TblSctnClimate.Clear();
            TblSctnInclination.Clear();
            TblSctnSoilDepth.Clear();
            TblSctnSoilUnit.Clear();
            BttnGetBPEJ.IsEnabled = false;

            _ = PrgrssBrBPEJ.ProgressTo(0.5, 23000, Easing.Linear);

            var data = await BluetoothController.GetDataFromRPiAsync("getBPEJ " + EntrBPEJcode.Text + " plants", 5000);

            GUIAnimations.FillTableSection(TblSctnPlants, data.Split('\n')[0].Split(';'), data.Split('\n')[1].Split(';'), async(s, a) =>
            {
                var plant = (((s as ViewCell).View as StackLayout).Children[0] as Label).Text;
                await Navigation.PushModalAsync(new PlantsPage(plant));
            });

            _ = PrgrssBrBPEJ.ProgressTo(0.6, 1250, Easing.Linear);

            data = await BluetoothController.GetDataFromRPiAsync("getBPEJ " + EntrBPEJcode.Text + " climate", 5000);

            GUIAnimations.FillTableSection(TblSctnClimate, data.Split('\n')[0].Split(';'), data.Split('\n')[1].Split(';'));

            _ = PrgrssBrBPEJ.ProgressTo(0.7, 1250, Easing.Linear);

            data = await BluetoothController.GetDataFromRPiAsync("getBPEJ " + EntrBPEJcode.Text + " inclination", 5000);

            GUIAnimations.FillTableSection(TblSctnInclination, data.Split('\n')[0].Split(';'), data.Split('\n')[1].Split(';'));

            _ = PrgrssBrBPEJ.ProgressTo(0.8, 1250, Easing.Linear);

            data = await BluetoothController.GetDataFromRPiAsync("getBPEJ " + EntrBPEJcode.Text + " soilDepth", 5000);

            GUIAnimations.FillTableSection(TblSctnSoilDepth, data.Split('\n')[0].Split(';'), data.Split('\n')[1].Split(';'));

            _ = PrgrssBrBPEJ.ProgressTo(0.9, 1250, Easing.Linear);

            data = await BluetoothController.GetDataFromRPiAsync("getBPEJ " + EntrBPEJcode.Text + " soilUnit", 5000);

            GUIAnimations.FillTableSection(TblSctnSoilUnit, data.Split('\n')[0].Split(';'), new string[] { String.Join("\n", data.Split('\n').Skip(1).ToArray()) });

            _ = PrgrssBrBPEJ.ProgressTo(1, 1250, Easing.Linear);

            PrgrssBrBPEJ.IsVisible = false;
            BttnGetBPEJ.IsEnabled  = true;


            /*GUIAnimations.FillTableSection(TblSctnPlants, data.Split('\n')[0].Split(';'), data.Split('\n')[1].Split(';'));
             * GUIAnimations.FillTableSection(TblSctnClimate, data.Split('\n')[2].Split(';'), data.Split('\n')[3].Split(';'));
             * GUIAnimations.FillTableSection(TblSctnInclination, data.Split('\n')[4].Split(';'), data.Split('\n')[5].Split(';'));
             * GUIAnimations.FillTableSection(TblSctnSoilDepth, data.Split('\n')[6].Split(';'), data.Split('\n')[7].Split(';'));
             * GUIAnimations.FillTableSection(TblSctnSoilUnit, data.Split('\n')[8].Split(';'), data.Split('\n')[9].Split(';'));*/


            //ViewExtensions.CancelAnimations(ImgLoadingInfoBPEJ);


            //data = await BPEJController.LoadBPEJDetailsAsync(CodeBPEJ.SoilUnit, int.Parse(EntrBPEJcode.Text.Substring(5, 2)), false);
            //FillTableSection(TblSctnSoilUnit, new string[] { "Kód", "Popis" }, new string[] { data.Item2[0], string.Join(Environment.NewLine, data.Item2.Skip(1)) });
        }