Пример #1
0
        public MicrocontrollerViewModel(MicrocontrollerModel MicrocontrollerModel, GPIOPinListsViewModel GPIOPinListsViewModel)
        {
            _microcontrollerModel  = MicrocontrollerModel;
            _gPIOPinListsViewModel = GPIOPinListsViewModel;

            //Populates the GPIOPinViewModelList based on its model counterpart.
            foreach (GPIOPinModel gPIOPinModel in _microcontrollerModel.GPIOPinModelList)
            {
                GPIOPinViewModel pinViewModel = null;

                if (gPIOPinModel.GetType() == typeof(PWMPinModel))
                {
                    pinViewModel = new PWMPinViewModel((PWMPinModel)gPIOPinModel);
                }
                else if (gPIOPinModel.GetType() == typeof(CommunicationPinModel))
                {
                    pinViewModel = new CommunicationPinViewModel((CommunicationPinModel)gPIOPinModel);
                }
                else if (gPIOPinModel.GetType() == typeof(AnalogInPinModel))
                {
                    pinViewModel = new AnalogInPinViewModel((AnalogInPinModel)gPIOPinModel);
                }
                else if (gPIOPinModel.GetType() == typeof(DigitalPinModel))
                {
                    pinViewModel = new DigitalPinViewModel((DigitalPinModel)gPIOPinModel);
                }

                if (pinViewModel != null)
                {
                    _gPIOPinViewModelList.Add(pinViewModel);
                    //Populates the lists in GPIOPinListsViewModel.
                    _gPIOPinListsViewModel.AppendPinSettingList(pinViewModel);
                }
            }
        }
 /// <summary>
 /// Adds a PinViewModel into the PinSettingsList.
 /// </summary>
 /// <param name="pinName"></param>
 /// <param name="pinSetting"></param>
 public void AppendPinSettingList(GPIOPinViewModel pinViewModel)
 {
     foreach (PinSetting pinSetting in pinViewModel.GPIOPinModel.PossiblePinSettingList)
     {
         int categoryIndex;
         for (categoryIndex = 0; categoryIndex < _gPIOPinSettingCategories.Count; categoryIndex++)
         {
             if (_gPIOPinSettingCategories[categoryIndex] == pinSetting)
             {
                 break;
             }
         }
         //Creates a new PinSetting category if applicable.
         if (categoryIndex == _gPIOPinSettingCategories.Count)
         {
             _gPIOPinSettingCategories.Add(pinSetting);
             _gPIOPinBySettingList.Add(new ObservableCollection <GPIOPinViewModel>());
         }
         _gPIOPinBySettingList[categoryIndex].Add(pinViewModel);
     }
     OnPropertyChanged("GPIOPinSettingCategoryList");
     OnPropertyChanged("GPIOPinSettingList");
 }
 /// <summary>
 /// Called by this class' GPIOPinViewModelList property setters.
 /// </summary>
 /// <param name="pinViewModelField"></param>
 /// <param name="possiblePinViewModelListField"></param>
 /// <param name="pinSetting"></param>
 public void RefreshGPIOPinViewModelList(ref GPIOPinViewModel pinViewModelField, ref ObservableCollection <GPIOPinViewModel> possiblePinViewModelListField, PinSetting pinSetting)
 {
     possiblePinViewModelListField = GetUnattachedPinsByPinSetting(pinSetting);
     possiblePinViewModelListField.Insert(0, pinViewModelField); //The first option of the list is to keep the same GPIO Pin.
     //The rest of the list is populated by unattached GPIO Pins.
 }