Пример #1
0
        private void LoadPicker()
        {
            isPickerActive = true;

            if (oBlueToothCmds_Picker == null)
            {
                oBlueToothCmds_Picker = new BlueToothCmds();
            }

            oBlueToothCmds_Picker.Clear();

            try
            {
                // ToDo: Load from db

                oBlueToothCmds_Picker.CreateTestCommands(oUserSetting.GetUserUnits(), false);
                oBlueToothCmds_Picker.RemoveAll(x => x.isSelected);
                pkrProcess.ItemsSource  = oBlueToothCmds_Picker;
                pkrProcess.IsEnabled    = true;
                pkrProcess.IsVisible    = true;
                pkrProcess.SelectedItem = null;
                pkrProcess.Focus();
            }
            catch (Exception ex)
            {
                DisplayMessage(ex.Message);
                isPickerActive = false;
            }
        }
Пример #2
0
        private void LoadProcessPicker(bool isAdd)
        {
            isPickerProcessActive = true;
            isPickerProcessAdd    = isAdd;

            pkrProcess.Title = (isAdd) ? "Add a Process" : "Delete a Process";

            if (oBlueToothCmds_Picker == null)
            {
                oBlueToothCmds_Picker = new BlueToothCmds();
            }

            oBlueToothCmds_Picker.Clear();

            try
            {
                //oBlueToothCmds_Picker.CreateTestCommands(oUserSetting.GetUserUnits(), false);
                oBlueToothCmds_Picker.RetrieveCommands(oUserSettings.GetUserUnits(), false);
                oBlueToothCmds_Picker.RemoveAll(x => (isPickerProcessAdd) ? x.isSelected : !x.isSelected);
                pkrProcess.ItemsSource  = null;
                pkrProcess.ItemsSource  = oBlueToothCmds_Picker;
                pkrProcess.IsEnabled    = true;
                pkrProcess.IsVisible    = true;
                pkrProcess.SelectedItem = null;
                pkrProcess.Focus();
            }
            catch (Exception ex)
            {
                DisplayMessage(ex.Message);
                isPickerProcessActive = false;
            }
        }
Пример #3
0
        private static void InitListViewItems(BlueToothCmds oBthCmds)
        {
            ProcessItems.Clear();

            foreach (BluetoothCmd bthCmd in oBthCmds)
            {
                AddListViewItem(bthCmd);
            }

            UpdateListViewItems();
        }
Пример #4
0
        private async Task <bool> OpenBluetooth(string name, string address, bool isTest)
        {
            //oBluetooth = null;
            //oBluetooth = new Bluetooth(true, isTest); // Create connection object

            if (!oUserSettings.GetIsTestMode())
            {
                if (!Bluetooth.CheckAdapterPresent()) // Check if bluetooth is available on this device: display message and return on failure
                {
                    ProcessConnectionError(ERROR_TYPE.ADAPTER_ERROR);
                    return(false);
                }

                if (!Bluetooth.CheckAdapterEnabled()) // Check if bluetooth is enabled on this device: display message and return on failure
                {
                    ProcessConnectionError(ERROR_TYPE.ADAPTER_DISABLED);
                    return(false);
                }

                if (!oBluetooth.LoadPairedDevices()) // Attempt to load paired devices: display message and return on failure
                {
                    ProcessConnectionError(ERROR_TYPE.PAIR_ERROR);
                    return(false);
                }

                if (!oBluetooth.CheckPairedDevices()) // Check if there are paired devices available: display message and return on failure
                {
                    ProcessConnectionError(ERROR_TYPE.PAIR_NONE);
                    return(false);
                }

                if (!await oBluetooth.OpenPairedDevice(name, address, true)) // Attempt to open paired device: if failed get list of paired devices
                {
                    ProcessConnectionError(ERROR_TYPE.PAIR_FAILED);
                    return(false);
                }
            }

            // Load commands and run processing loop

            oBlueToothCmds = null;
            oBlueToothCmds = new BlueToothCmds();

            // ToDo: replace with db values
            //oBlueToothCmds.CreateTestCommands(oUserSetting.GetUserUnits(), true);
            oBlueToothCmds.RetrieveCommands(oUserSettings.GetUserUnits(), true);

            InitCommands(oBlueToothCmds);
            InitListViewItems(oBlueToothCmds);
            RunProcesses();
            return(true);
        }
Пример #5
0
 private void UpdateListViewItems()
 {
     try
     {
         oBlueToothCmds = null;
         oBlueToothCmds = new BlueToothCmds();
         oBlueToothCmds.RetrieveCommands(oUserSettings.GetUserUnits(), false);
         InitListViewItems(oBlueToothCmds);
     }
     catch (Exception e)
     {
         Debug.WriteLine("Error updating listview:" + e.Message);
     }
 }
Пример #6
0
        private void InitCommands(BlueToothCmds oBthCmds)
        {
            if (oBthCmds == null)
            {
                return;
            }

            foreach (BluetoothCmd bthCmd in oBthCmds)
            {
                if (bthCmd.isSelected && bthCmd.Selection_Type == BlueToothCmds.SELECTION_TYPE.NONE)
                {
                    bthCmd.Selection_Type = BlueToothCmds.SELECTION_TYPE.USER;
                }

                bthCmd.isProcess = (bthCmd.Selection_Type == BlueToothCmds.SELECTION_TYPE.USER ||
                                    bthCmd.Selection_Type == BlueToothCmds.SELECTION_TYPE.USER_PROCESS);
            }
        }
Пример #7
0
        private static void InitListViewItems(BlueToothCmds oBthCmds)
        {
            ProcessItems.Clear();

            if (oBthCmds == null)
            {
                return;
            }

            foreach (BluetoothCmd bthCmd in oBthCmds)
            {
                if (bthCmd.isSelected && bthCmd.Selection_Type == BlueToothCmds.SELECTION_TYPE.NONE)
                {
                    bthCmd.Selection_Type = BlueToothCmds.SELECTION_TYPE.USER;
                }

                if (bthCmd.Selection_Type == BlueToothCmds.SELECTION_TYPE.USER ||
                    bthCmd.Selection_Type == BlueToothCmds.SELECTION_TYPE.USER_PROCESS)
                {
                    AddListViewItem(bthCmd);
                }
            }
        }
Пример #8
0
        private void SetProcessPickerSelection(int index)
        {
            if (index == -1 || pkrProcess.Items.Count == 0)
            {
                return;
            }

            BluetoothCmd bthCmd = (BluetoothCmd)pkrProcess.SelectedItem;

            if (bthCmd == null)
            {
                throw new Exception("Selection Error Occurred");
            }

            bthCmd.isSelected = isPickerProcessAdd;

            if (!BlueToothCmds.updateRecord(bthCmd))
            {
                throw  new Exception("Failed to update command");
            }

            UpdateListViewItems();

            if (!bthCmd.isSelected)
            {
                bthCmd.Selection_Type = (bthCmd.Selection_Type == BlueToothCmds.SELECTION_TYPE.USER_PROCESS)
                    ? BlueToothCmds.SELECTION_TYPE.PROCESS
                    : BlueToothCmds.SELECTION_TYPE.NONE;
            }
            else
            {
                bthCmd.Selection_Type = (bthCmd.Selection_Type == BlueToothCmds.SELECTION_TYPE.PROCESS)
                    ? BlueToothCmds.SELECTION_TYPE.USER_PROCESS
                    : BlueToothCmds.SELECTION_TYPE.USER;
            }
        }