示例#1
0
 public void Dispose()
 {
     _servoMotor?.Dispose();
     _servoChannel?.Dispose();
     _pca9685?.Dispose();
     _i2cDevice?.Dispose();
 }
        static void Main(string[] args)
        {
            var root = new ConfigurationBuilder()
                       .SetBasePath(Directory.GetCurrentDirectory())
                       .AddJsonFile("settings.json")
                       .Build();

            int interval = root.GetSection("Interval").Get <int>();

            _pin   = root.GetSection("Pin").Get <int>();
            _gates = root.GetSection("Gates").Get <List <Gate> >();

            _cpuTemperature = new CpuTemperature();
            _fan            = new SoftwarePwmChannel(pinNumber: _pin, frequency: 400, dutyCycle: 0);
            _fan.Start();

            using Timer timer = new Timer(interval);
            timer.Elapsed    += Timer_Elapsed;
            timer.Start();

            Console.CancelKeyPress += (sender, eArgs) => {
                _quitEvent.Set();
                eArgs.Cancel = true;
            };
            _quitEvent.WaitOne();

            _fan.Dispose();
            _cpuTemperature.Dispose();
            timer.Dispose();
        }
示例#3
0
 public override void Dispose()
 {
     _speed = 0.0;
     _pwm?.Dispose();
     _pwm = null !;
     base.Dispose();
 }
示例#4
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _pwm?.Dispose();
                _pwm = null;
            }

            base.Dispose(disposing);
        }
示例#5
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _pwma.Stop();
         _pwmb.Stop();
         _pwma?.Dispose();
         _pwmb?.Dispose();
     }
 }
示例#6
0
 /// <summary>
 /// Dispose Buzzer.
 /// </summary>
 public void Dispose()
 {
     _pwmChannel?.Dispose();
     _pwmChannel = null;
 }
示例#7
0
        static void RunEncoder()
        {
            WriteLine($"Pulse Width Modulation Test on GPIO 18");
            WriteLine($"Using rotary encoder");
            var running = true;
            var pwm     = new PwmChannel(0, 0);
            var period  = 0.1d;

            WriteLine($"Running PWM with period of {period}ms.");
            pwm.Period    = (ulong)(period * 1_000_000d);
            pwm.DutyCycle = 0.5d;
            pwm.Enable();

            var button = Pi.Gpio.Pin(25, PinKind.InputPullUp);

            button.OnRisingEdge += (sender, args) =>
            {
                if (args.Bounced)
                {
                    return;
                }
                running = false;
            };

            var left  = Pi.Gpio.Pin(23, PinKind.InputPullUp);
            var right = Pi.Gpio.Pin(24, PinKind.InputPullUp);

            left.OnRisingEdge += (sender, args) =>
            {
                if (args.Bounced)
                {
                    return;
                }
                if (left.Value == right.Value)
                {
                    period *= 0.9d;
                }
                else
                {
                    period *= 1d / 0.9d;
                }
                pwm.Period = (ulong)(period * 1_000_000d);
                WriteLine($"Changed PWM period to {period}ms.");
            };

            try
            {
                while (running)
                {
                    Pi.Wait(50);
                }
            }
            finally
            {
                button.RemoveEvents();
                button.Dispose();
                left.RemoveEvents();
                left.Dispose();
                pwm.Disable();
                pwm.Dispose();
            }
        }
示例#8
0
 public void Stop()
 {
     pwmChannel.Dispose();
     cts?.Cancel();
 }