Esempio n. 1
0
        public Pwm(
            ObjectEnvironment environment,
            string id,
            string name,
            PwmController controller,
            string description = null,
            Object parent = null
            )
            : base(environment, id, name,
                new ObjectType("PWM", "PWM", "Pulse width modulation"),
                description, parent)
        {
            controller.ValidateNonNull(nameof(controller));
            Controller = controller;

            PinCount = new Property<int>(this, nameof(PinCount), "Pin count", Controller.PinCount);
            Items.Add(PinCount);

            DelegateCommand command;
            command = new DelegateCommand<int>(this,
                nameof(OpenPin), "Open pin",
                p => OpenPin(p),
                p => CanOpenPin(p),
                parameters: new CommandParameterInfo<int>("Number", "Number", "Pin number")
                );
            Items.Add(command);

            Frequency = new PhysicalProperty<double>(this,
                nameof(Frequency), "Frequency", Controller.ActualFrequency, Units.Hertz);
            Items.Add(Frequency);

            MinFrequency = new PhysicalProperty<double>(this,
                nameof(MinFrequency), "Minimum frequency", Controller.MinFrequency, Units.Hertz);
            Items.Add(MinFrequency);

            MaxFrequency = new PhysicalProperty<double>(this,
                nameof(MaxFrequency), "Maximum frequency", Controller.MaxFrequency, Units.Hertz);
            Items.Add(MaxFrequency);

            command = new DelegateCommand<double>(this,
                nameof(SetFrequency), "Set frequency",
                p => SetFrequency(p),
                p => CanSetFrequency(p),
                parameters: new CommandPhysicalParameterInfo<double>(Frequency)
                );
            Items.Add(command);
        }
Esempio n. 2
0
        internal PwmPin(
            Pwm pwm,
            string id,
            int number,
            Windows.Devices.Pwm.PwmPin pin
            )
            : base(pwm.Environment,
                id,
                string.Format($"Pin {number + 1}"),
                new ObjectType("PWM pin", "PWM pin", "Pulse width modulation pin"),
                parent: pwm)
        {
            pwm.ValidateNonNull(nameof(pwm));
            number.ValidateIn(0, pwm.PinCount.Value);
            pin.ValidateNonNull(nameof(pin));
            Pwm = pwm;
            Pin = pin;

            Number = new Property<int>(this,
                nameof(Number), "Number", number);
            Items.Add(Number);

            DelegateCommand command;
            command = new DelegateCommand(this,
                nameof(Close), "Close",
                () => Close()
                );
            Items.Add(command);

            IsStarted = new Property<bool>(this,
                nameof(IsStarted), "Is started", false);
            Items.Add(IsStarted);
            command = new DelegateCommand(this,
                nameof(Start), "Start",
                () => Start(),
                () => CanStart
                );
            Items.Add(command);
            command = new DelegateCommand(this,
                nameof(Stop), "Stop",
                () => Stop(),
                () => CanStop
                );
            Items.Add(command);

            DutyCyclePercentage = new PhysicalProperty<double>(this,
                nameof(DutyCyclePercentage), "Duty cycle", pin.GetActiveDutyCyclePercentage(), Units.Percentage
                );
            Items.Add(DutyCyclePercentage);
            command = new DelegateCommand<double>(this,
                nameof(SetDutyCyclePercentage), "Set duty cycle",
                p => SetDutyCyclePercentage(p),
                p => CanSetDutyCyclePercentage(p),
                parameters: new CommandPhysicalParameterInfo<double>(DutyCyclePercentage)
                );
            Items.Add(command);

            Polarity = new Property<PwmPulsePolarity>(this, nameof(Polarity), "Polarity", pin.Polarity);
            Items.Add(Polarity);
            command = new DelegateCommand<PwmPulsePolarity>(this,
                nameof(SetPolarity), "Set polarity",
                p => SetPolarity(p),
                parameters: new CommandParameterInfo<PwmPulsePolarity>(Polarity)
                );
            Items.Add(command);
        }