提交 f9d9682b 编写于 作者: A Andrew Phelps

address feedback to change sample to pwm-pin-output

上级 263072f3
......@@ -13,13 +13,23 @@ namespace DeviceApiTester.Commands.Pwm
[Option('d', "driver", HelpText = "The PwmDriver to use: { Windows | Unix }", Required = false, Default = PwmDriverType.Windows)]
public PwmDriverType Driver { get; set; }
[Option("pwm-chip", HelpText = "The PWM chip (controller) to use", Required = false, Default = 0)]
public int PwmChip { get; set; }
[Option("pwm-channel", HelpText = "The PWM channel (pin) to use", Required = false, Default = 0)]
public int PwmChannel { get; set; }
[Option('c', "dutycycle", HelpText = "The duty cycle for PWM output from 1-100", Required = false, Default = 50)]
public int DutyCycle { get; set; }
[Option('f', "frequency", HelpText = "The frequency in hertz", Required = false, Default = 400.0)]
public double Frequency { get; set; }
protected PwmController CreatePwmController()
{
PwmDriver pwmDriver = DriverFactory.CreateFromEnum<PwmDriver, PwmDriverType>(this.Driver);
return pwmDriver != null
? new PwmController(pwmDriver)
: new PwmController(pwmDriver);
return new PwmController(pwmDriver);
}
}
}
\ No newline at end of file
......@@ -10,8 +10,8 @@ using DeviceApiTester.Infrastructure;
namespace DeviceApiTester.Commands.Pwm
{
[Verb("pwm-dim-led", HelpText = "Dims an LED connected to a specified PWM pin for 3 seconds")]
public class DimLed : PwmCommand, ICommandVerbAsync
[Verb("pwm-pin-output", HelpText = "Starts PWM output on the given chip/channel for desired amount of seconds")]
public class PwmPinOutput : PwmCommand, ICommandVerbAsync
{
/// <summary>Executes the command asynchronously.</summary>
/// <returns>The command's exit code.</returns>
......@@ -22,32 +22,20 @@ namespace DeviceApiTester.Commands.Pwm
/// </remarks>
public async Task<int> ExecuteAsync()
{
Console.WriteLine($"LedPin={LedPin}, DutyCycle={DutyCycle}, Frequency={Frequency}, Driver={Driver}");
using (var pwm = CreatePwmController())
{
int pwmChip = 0;
int pwmChannel = LedPin;
double pwmFreq = (double)Frequency;
Console.WriteLine("Opening the pin {0}, chip {1}, at duty cycle {2} and frequency {3}", LedPin, pwmChip, DutyCycle, pwmFreq );
Console.WriteLine("Enabling PWM output with chip {0} / channel {1}, {2}% duty cycle @ {3}hz for {4} seconds ", PwmChip, PwmChip, DutyCycle, Frequency, Seconds);
pwm.OpenChannel(pwmChip, pwmChannel);
pwm.StartWriting(pwmChip, pwmChannel, pwmFreq, DutyCycle);
await Task.Delay(3000);
pwm.StopWriting(pwmChip, pwmChannel);
pwm.OpenChannel(PwmChip, PwmChannel);
pwm.StartWriting(PwmChip, PwmChannel, Frequency, DutyCycle);
await Task.Delay(Seconds * 1000);
pwm.StopWriting(PwmChip, PwmChannel);
}
return 0;
}
[Option('l', "led-pin", HelpText = "The PWM pin which the LED is connected to, numbered based on the --scheme argument", Required = true)]
public int LedPin { get; set; }
[Option('c', "dutycycle", HelpText = "The duty cycle for PWM output from 1-100", Required = false, Default = 50)]
public int DutyCycle { get; set; }
[Option('f', "frequency", HelpText = "The frequency in herz", Required = false, Default = 400)]
public int Frequency { get; set; }
[Option('s', "seconds", HelpText = "The number of seconds to output the PWM signal", Required = false, Default = 3)]
public int Seconds { get; set; }
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册