protected async override void OnNavigatedTo(NavigationEventArgs args)
        {
            SetStatusActive(true);
            var di = args.Parameter as DeviceInformationWrapper;

            if (di.SerialPortPreferences == null)
            {
                // Make sure we set up good defaults.
                const string DefaultShortcutId = "CraftyRobot-Smartibot";
                di.SerialPortPreferences = new UserSerialPortPreferences()
                {
                    LineEnd    = UserSerialPortPreferences.TerminalLineEnd.CR,
                    SavePrefix = "CraftyRobot_Smartibot_",
                    ShortcutId = DefaultShortcutId, // must match the Id value in CraftyRobot_Smartibot_Commands.json
                };
                di.SerialPortPreferences.ReadFromLocalSettings();
                if (di.SerialPortPreferences.ShortcutId == "(name)")
                {
                    di.SerialPortPreferences.ShortcutId = DefaultShortcutId;
                }
            }
            var ble = await BluetoothLEDevice.FromIdAsync(di.di.Id);

            SetStatusActive(false);

            // // // bleDevice.ble = ble;
            // // // bleDevice.Status.OnBluetoothStatus += bleDevice_OnBluetoothStatus;

            Uart = new Nordic_Uart(ble);
            await Uart.EnsureCharacteristicAsync();

            Uart.Status.OnBluetoothStatus += bleDevice_OnBluetoothStatus;
            // NOTE: check for status?

            // Set up the terminal adapter, connecting the terminal control and the bluetooth device.
            TerminalAdapter = new nRFUartTerminalAdapter(uiTerminalControl, Uart);
            uiTerminalControl.ParentTerminal = this;
            uiTerminalControl.UserCanSetSerialLineEndings = false;
            // the adapter tells the terminal control to display the status.
            // The terminal control would rather we display the status.

            await TerminalAdapter.InitAsync();

            uiTerminalControl.DI = di;

            // Get the buttons to show!
            uiTerminalControl.UpdateShortcutButtons();
        }
コード例 #2
0
 /// <summary>
 /// Don't forget to call InitAsync() to start reading from device+terminal and passing data from one to the other.
 /// </summary>
 /// <param name="terminal"></param>
 /// <param name="input_nrf"></param>
 public nRFUartTerminalAdapter(ITerminal terminal, Nordic_Uart input_nrf)
 {
     Terminal = terminal;
     nrf      = input_nrf;
 }