private void Run(string[] args) { // Creating this from static causes an exception in Raspian. Not in ubunti though? Log = LogManager.GetCurrentClassLogger(); var options = new ConsoleOptions(args); if (options.ShowHelp) { Console.WriteLine("Options:"); options.OptionSet.WriteOptionDescriptions(Console.Out); return; } var deviceFactory = new Pca9685DeviceFactory(); var device = deviceFactory.GetDevice(options.UseFakeDevice); var motorController = new PwmController(device); motorController.Init(); Log.InfoFormat("RPi.Console running with {0}", options); switch (options.Mode) { case Mode.DcMotor: RunDcMotor(motorController); break; case Mode.Servo: RunServo(motorController); break; case Mode.Stepper: motorController.Stepper.Rotate(600); break; case Mode.Led: RunLed(motorController); break; case Mode.RawPwm: RunRawPwm(device); break; case Mode.AlarmClock: var alarmClock = new AlarmClock(motorController); alarmClock.Set(options.AlarmDate); alarmClock.WaitForAlarm(); break; case Mode.SignalRTest: var signalRConnection = new SignalRConnection(motorController); signalRConnection.Run(); break; } motorController.AllStop(); deviceFactory.Dispose(); //http://nlog-project.org/2011/10/30/using-nlog-with-mono.html // NLog.LogManager.Configuration = null; }
private static PwmController GetPwmController(ConsoleOptions options) { var deviceFactory = new Pca9685DeviceFactory(); var device = deviceFactory.GetDevice(options.UseFakeDevice); var motorController = new PwmController(device); motorController.Init(); return motorController; }
private void FrmMain_Load(object sender, EventArgs e) { _deviceFactory = new Pca9685DeviceFactory(); var device = _deviceFactory.GetDevice(); _motorController = new PwmController(device); _motorController.Init(); //LogBus.Instance.LogReceived += Instance_LogReceived; }
public SignalRConnection(PwmController pwmController) { _pwmController = pwmController; }
private static void RunServo(PwmController motorController) { motorController.Servo.MoveTo(0); Thread.Sleep(1000); motorController.Servo.MoveTo(100); Thread.Sleep(1000); motorController.Servo.MoveTo(50); Thread.Sleep(1000); }
private static void RunDcMotor(PwmController motorController) { for (int i = 10; i <= 100; i += 10) { motorController.DcMotor.Go(i); Thread.Sleep(1000); } motorController.DcMotor.Stop(); Thread.Sleep(1000); for (int i = 10; i <= 100; i += 10) { motorController.DcMotor.Go(i, MotorDirection.Reverse); Thread.Sleep(1000); } motorController.DcMotor.Stop(); }
private static void RunLed(PwmController motorController) { for (int i = 0; i < 20; i++) { motorController.Led0.On(); Thread.Sleep(100); motorController.Led0.Off(); Thread.Sleep(100); } for (int i = 0; i <= 100; i++) { motorController.Led0.On(i); Thread.Sleep(10); } for (int i = 100; i >= 0; i--) { motorController.Led0.On(i); Thread.Sleep(10); } motorController.Led0.Off(); }
public AlarmClock(PwmController pwmController) { _pwmController = pwmController; }