示例#1
0
        // Check configuration is valid
        private void saveForm()
        {
            bool configurationIsValid = true;

            // Create configuration
            Configuration configuration = new Configuration();
            configuration.HaptiQName = configurationName.Text;

            configuration.idServoBoard = _currentAdvancedServoBoard.SerialNumber;
            configuration.nameServoBoard = _currentAdvancedServoBoard.Name;
            configuration.interfaceKitBoardAttached = (int)InterfaceKitsComboBox.SelectedItem == 0 ? false : true;
            if (configuration.interfaceKitBoardAttached)
            {
                configuration.idInterfaceKit = _currentInterfaceKitBoard.SerialNumber;
                configuration.nameInterfaceKit = _currentInterfaceKitBoard.Name;
            }

            configuration.numberActuators = checkedServos(configuration);
            configuration.numberPressureSensors = checkedPressureSensors(configuration);

            if (configuration.numberActuators == 0) // there must be a positive number of actuators
            {
                configurationIsValid = false;
            }

            if (_currentInputIdentifier != null)
            {
                configuration.inputIdentifier = _currentInputIdentifier;
            }
            else
            {
                configurationIsValid = false;
            }

            // Remove chosen boards from devicesToBeConfigured
            // XXX - code duplication
            // XXX - remove from comboBox too
            for (int i = _devicesToBeConfigured.Count - 1; i >= 0; i--)
            {
                if (_devicesToBeConfigured[i].GetType() == typeof(AdvancedServo) && 
                    _devicesToBeConfigured[i].SerialNumber == _currentAdvancedServoBoard.SerialNumber)
                {
                    _devicesToBeConfigured.Remove(_devicesToBeConfigured[i]);
                }
                else if (configuration.interfaceKitBoardAttached &&
                    _devicesToBeConfigured[i].GetType() == typeof(InterfaceKit) &&
                    _devicesToBeConfigured[i].SerialNumber == _currentInterfaceKitBoard.SerialNumber)
                {
                    _devicesToBeConfigured.Remove(_devicesToBeConfigured[i]);
                }
            }

            // Update color of save button 
            changeButtonColor(button1, configurationIsValid);

            ConfigurationManager.addConfiguration(configuration);
        }
示例#2
0
 /// <summary>
 /// Add a given configuration to the ConfigurationManager
 /// </summary>
 /// <param name="configuration"></param>
 public static void addConfiguration(Configuration configuration)
 {
     configuration.serializableInputIdentifier = configuration.inputIdentifier.getSerializableInputIdentifier();
     configurations.Add(configuration);
     String configurationFile = Configuration.CONFIGURATION_FILENAME_PREFIX + 
         configuration.HaptiQName.Replace(" ", string.Empty) + 
         Configuration.CONFIGURATION_FILENAME_EXT;
     Helper.SerializeToXML(configuration, configurationFile);
 }
示例#3
0
文件: Helper.cs 项目: sic2/HaptiQ
 /// <summary>
 /// Serialize given configuration to specified file (XML)
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="fileName"></param>
 public static void SerializeToXML(Configuration configuration, String fileName)
 {
     XmlSerializer serializer = new XmlSerializer(typeof(Configuration));
     TextWriter textWriter = new StreamWriter(@fileName);
     serializer.Serialize(textWriter, configuration);
     textWriter.Close();
 }
示例#4
0
 private int checkedPressureSensors(Configuration configuration)
 {
     if (Pressure1.Checked) { configuration.pressureSensors.Add(0); }
     if (Pressure2.Checked) { configuration.pressureSensors.Add(1); }
     if (Pressure3.Checked) { configuration.pressureSensors.Add(2); }
     if (Pressure4.Checked) { configuration.pressureSensors.Add(3); }
     if (Pressure5.Checked) { configuration.pressureSensors.Add(4); }
     if (Pressure6.Checked) { configuration.pressureSensors.Add(5); }
     if (Pressure7.Checked) { configuration.pressureSensors.Add(6); }
     if (Pressure8.Checked) { configuration.pressureSensors.Add(7); }
     return configuration.pressureSensors.Count;
 }
示例#5
0
 private int checkedServos(Configuration configuration)
 {
     if (Actuator1.Checked) 
     { configuration.actuators[0] = new SerializableTuple<int,int>(Actuator1MIN.Value, Actuator1MAX.Value); }
     if (Actuator2.Checked)
     { configuration.actuators[1] = new SerializableTuple<int, int>(Actuator2MIN.Value, Actuator2MAX.Value); }
     if (Actuator3.Checked)
     { configuration.actuators[2] = new SerializableTuple<int, int>(Actuator3MIN.Value, Actuator3MAX.Value); }
     if (Actuator4.Checked)
     { configuration.actuators[3] = new SerializableTuple<int, int>(Actuator4MIN.Value, Actuator4MAX.Value); }
     if (Actuator5.Checked)
     { configuration.actuators[4] = new SerializableTuple<int, int>(Actuator5MIN.Value, Actuator5MAX.Value); }
     if (Actuator6.Checked)
     { configuration.actuators[5] = new SerializableTuple<int, int>(Actuator6MIN.Value, Actuator6MAX.Value); }
     if (Actuator7.Checked)
     { configuration.actuators[6] = new SerializableTuple<int, int>(Actuator7MIN.Value, Actuator7MAX.Value); }
     if (Actuator8.Checked)
     { configuration.actuators[7] = new SerializableTuple<int, int>(Actuator8MIN.Value, Actuator8MAX.Value); }
     return configuration.actuators.Count;
 }
示例#6
0
文件: HaptiQ.cs 项目: sic2/HaptiQ
        /// <summary>
        /// Initialise the HaptiQ given a configuration
        /// </summary>
        /// <param name="id">id for this HaptiQ. 
        /// The HaptiQs manager or whoever is creating the HaptiQ should use an 
        /// id which is unique.</param>
        /// <param name="configuration">Configuration used by this HaptiQ to setup 
        /// servo and interfacekit boards.</param>
        public HaptiQ(uint id, Configuration configuration)
        {
            if (configuration == null)
            {
                Helper.Logger("HaptiQ_API.HaptiQ.HaptiQ:: id: " + id + "; configuration is null");
                throw new ArgumentNullException("HaptiQ_API.HaptiQ.HaptiQ:: configuration");
            }

            this._id = id;
            this._configuration = configuration;

            // Initialise data structures
            _inputData = new Dictionary<int, Tuple<DateTime, PRESSURE_STATE>>();
            _currentPressureData = new Dictionary<int, double>();
            _actuators = new List<Actuator>();
            _behaviours = new HashSet<IBehaviour>();

            // Initialise boards
            initialiseServoBoard();
            initialiseInterfaceKitBoard();
           
            // Let this HaptiQ be an independent thread.
            // Another approach would be to have the HaptiQsManager to handle all the HaptiQs sequentially,
            // but then the users may lose the feeling of concurrency.
            Thread thread = new Thread(loop);
            thread.Start();
        }