示例#1
0
        public void saveGloveConfiguration(string fileName, Glove selectedGlove)
        {
            XElement rootXML   = new XElement("hand");
            XElement boardPins = new XElement("boardPins");

            rootXML.Add(boardPins);
            foreach (int pin in selectedGlove.GloveConfiguration.PositivePins)
            {
                XElement positivePinXML = new XElement("positivePin");
                positivePinXML.SetAttributeValue("pin", pin);
                boardPins.Add(positivePinXML);
            }

            foreach (int pin in selectedGlove.GloveConfiguration.NegativePins)
            {
                XElement negativePinXML = new XElement("negativePin");
                negativePinXML.SetAttributeValue("pin", pin);
                boardPins.Add(negativePinXML);
            }

            selectedGlove.GloveConfiguration.GloveHash = selectedGlove.GloveConfiguration.PositivePins.GetHashCode().ToString();
            rootXML.SetAttributeValue("baudRate", selectedGlove.GloveConfiguration.BaudRate);
            rootXML.SetAttributeValue("gloveHash", selectedGlove.GloveConfiguration.GloveHash);
            rootXML.SetAttributeValue("gloveName", fileName);
            selectedGlove.GloveConfiguration.GloveName = fileName;

            rootXML.Save(fileName);

            serviceClient.SaveGlove(selectedGlove);
        }
        /// <summary>
        /// Handles the event of selectors (combobox in this case) changing their selection.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void selectorsSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (((ComboBox)sender).SelectedItem != null)
            {
                String selection = ((ComboBox)sender).SelectedItem.ToString();
                //String region = (String)((ComboBox)sender).AccessibleName;

                //Si el selector usado poseia otro actuador con anterioridad, este debe ser liberado y añadido a los otros selectores, en general, a todos.

                // Si se selecciona un actuador, la idea es que no se pueda volver a seleccionar en otro punto de la mano.

                int owner = ((ComboBox)sender).TabIndex;
                if (selection != null)
                {
                    if (!selection.Equals(""))
                    {
                        int selectionFlexor = Int32.Parse(selection);
                        removeFlexor(selectionFlexor, sender);
                        try
                        {
                            this.selectedGlove.GloveConfiguration.GloveProfile.FlexorsMappings.Add(owner, selectionFlexor);
                            gloves.addFlexor(this.selectedGlove, selectionFlexor, owner);
                        }
                        catch (Exception)
                        {
                            /*   int liberatedFlexor = this.selectedGlove.GloveConfiguration.GloveProfile.FlexorsMappings[owner];
                             * liberateFlexor(liberatedFlexor, sender);
                             * this.selectedGlove.GloveConfiguration.GloveProfile.FlexorsMappings[owner] = selectionFlexor;
                             * gloves.addFlexor(this.selectedGlove, selectionFlexor, owner);
                             */
                        }
                    }
                    else
                    {
                        int liberatedFlexorC;
                        this.selectedGlove.GloveConfiguration.GloveProfile.FlexorsMappings.TryGetValue(owner, out liberatedFlexorC);
                        int?liberatedFlexor = liberatedFlexorC;
                        if (liberatedFlexor != null)
                        {
                            liberatedFlexorC = liberatedFlexor == null ? default(int) : liberatedFlexor.GetValueOrDefault();
                            liberateFlexor(liberatedFlexorC, sender);
                            this.selectedGlove.GloveConfiguration.GloveProfile.FlexorsMappings.Remove(owner);
                            gloves.removeFlexor(this.selectedGlove, owner);
                            changeBarValue(owner, 0);
                        }
                    }
                }
                refreshMappingsList(this.selectedGlove.GloveConfiguration.GloveProfile.FlexorsMappings);
                serviceClient.SaveGlove(this.selectedGlove);
                ((ComboBox)sender).Visibility = Visibility.Hidden;
            }
        }
        /// <summary>
        /// Handles the event of selectors (combobox in this case) changing their selection.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void selectorsSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (((ComboBox)sender).SelectedItem != null)
            {
                String selection = ((ComboBox)sender).SelectedItem.ToString();
                //String region = (String)((ComboBox)sender).AccessibleName;

                //Si el selector usado poseia otro actuador con anterioridad, este debe ser liberado y añadido a los otros selectores, en general, a todos.

                // Si se selecciona un actuador, la idea es que no se pueda volver a seleccionar en otro punto de la mano.

                String owner = ((ComboBox)sender).TabIndex.ToString();
                if (selection != null)
                {
                    if (!selection.Equals(""))
                    {
                        removeActuator(selection, sender);
                        try
                        {
                            this.selectedGlove.GloveConfiguration.GloveProfile.Mappings.Add(owner, selection);
                        }
                        catch (Exception)
                        {
                            String liberatedActuator = this.selectedGlove.GloveConfiguration.GloveProfile.Mappings[owner];
                            liberateActuator(liberatedActuator, sender);
                            this.selectedGlove.GloveConfiguration.GloveProfile.Mappings[owner] = selection;
                        }
                    }
                    else
                    {
                        String liberatedActuator;
                        this.selectedGlove.GloveConfiguration.GloveProfile.Mappings.TryGetValue(owner, out liberatedActuator);
                        if (liberatedActuator != null)
                        {
                            liberateActuator(liberatedActuator, sender);
                            this.selectedGlove.GloveConfiguration.GloveProfile.Mappings.Remove(owner);
                        }
                    }
                }
                refreshMappingsList(this.selectedGlove.GloveConfiguration.GloveProfile.Mappings);
                serviceClient.SaveGlove(this.selectedGlove);
                ((ComboBox)sender).Visibility = Visibility.Hidden;
            }
        }
        private void updateView()
        {
            if (this.selectedGlove.GloveConfiguration.GloveProfile.imuStatus == true)
            {
                button.Content         = "Deactivate data";
                labelIMUStatus.Content = "On";
            }
            else
            {
                button.Content         = "Activate data";
                labelIMUStatus.Content = "Off";
            }

            if (this.selectedGlove.GloveConfiguration.GloveProfile.rawData == true)
            {
                buttonSetRawData.Content = "Processed data";
            }
            else
            {
                buttonSetRawData.Content = "Raw Data";
            }
            serviceClient.SaveGlove(this.selectedGlove);
        }