public FakeDistanceSensorDriver(IGpio gpio, ILogger logger, IEnumerable <DistanceSensorPin> pinMapping)
 {
     MeasurementsChannel = Channel.CreateBounded <double>(new BoundedChannelOptions(21)
     {
         FullMode = BoundedChannelFullMode.DropOldest
     });
 }
示例#2
0
        /// <summary>
        /// Releaseses all resources used this object.
        /// </summary>
        /// <param name="disposing">
        /// Set true if disposing managed resources in addition to unmanaged.
        /// </param>
        protected virtual void Dispose(Boolean disposing)
        {
            if (this._isDisposed)
            {
                return;
            }

            if (disposing)
            {
                this._name = null;
                this._tag  = null;
                if (this._pin != null)
                {
                    this._pin.Dispose();
                    this._pin = null;
                }

                if (this._props != null)
                {
                    this._props.Clear();
                    this._props = null;
                }
            }
            this.StateChanged = null;
            this.PulseStart   = null;
            this.PulseStop    = null;
            this._isDisposed  = true;
        }
示例#3
0
		/// <summary>
		/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
		/// </summary>
		/// <filterpriority>2</filterpriority>
		/// <remarks>Call <see cref="Dispose"/> when you are finished using the
		/// <see cref="CyrusBuilt.MonoPi.Components.Buzzer.BuzzerComponent"/>. The <see cref="Dispose"/> method leaves the
		/// <see cref="CyrusBuilt.MonoPi.Components.Buzzer.BuzzerComponent"/> in an unusable state. After calling
		/// <see cref="Dispose"/>, you must release all references to the
		/// <see cref="CyrusBuilt.MonoPi.Components.Buzzer.BuzzerComponent"/> so the garbage collector can reclaim the memory
		/// that the <see cref="CyrusBuilt.MonoPi.Components.Buzzer.BuzzerComponent"/> was occupying.</remarks>
		public override void Dispose() {
			if (this._pwm != null) {
				this._pwm.Dispose();
				this._pwm = null;
			}
			base.Dispose();
		}
示例#4
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Sensors.MotionSensorBase"/>
		/// class.
		/// </summary>
		/// <param name="pin">
		/// The pin being used to read the sensor input.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="pin"/> cannot be null.
		/// </exception>
		protected MotionSensorBase(IGpio pin) {
			if (pin == null) {
				throw new ArgumentNullException("pin");
			}
			this._pin = pin;
			this._props = new Dictionary<String, String>();
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Motors.StepperMotorComponent"/>
		/// class with the output pins for each controller in the stepper motor.
		/// </summary>
		/// <param name="pins">
		/// The output pins for each controller in the stepper motor.
		/// </param>
		public StepperMotorComponent(IGpio[] pins)
			: base() {
			this._pins = pins;
			foreach (IGpio p in pins) {
				p.Provision();
			}
		}
示例#6
0
        /// <summary>
        /// Releases all resource used by the <see cref="CyrusBuilt.MonoPi.Components.Switches.SwitchComponent"/>
        /// object.
        /// </summary>
        /// <remarks>
        /// Call <see cref="Dispose"/> when you are finished using the
        /// <see cref="CyrusBuilt.MonoPi.Components.Switches.SwitchComponent"/>. The
        /// <see cref="Dispose"/> method leaves the
        /// <see cref="CyrusBuilt.MonoPi.Components.Switches.SwitchComponent"/> in an
        /// unusable state. After calling
        /// <see cref="Dispose"/>, you must release all references to the
        /// <see cref="CyrusBuilt.MonoPi.Components.Switches.SwitchComponent"/> so the
        /// garbage collector can reclaim the
        /// memory that the <see cref="CyrusBuilt.MonoPi.Components.Switches.SwitchComponent"/>
        /// was occupying.
        /// </remarks>
        public override void Dispose()
        {
            lock (_syncLock) {
                _isPolling = false;
            }

            if ((this._pollThread != null) && (this._pollThread.IsAlive))
            {
                try {
                    Thread.Sleep(50);
                    this._pollThread.Abort();
                }
                catch (ThreadAbortException) {
                    Thread.ResetAbort();
                }
                finally {
                    this._pollThread = null;
                }
            }

            if (this._pin != null)
            {
                this._pin.Dispose();
                this._pin = null;
            }
            base.Dispose();
        }
示例#7
0
        /// <summary>
        /// Releases all resource used by the <see cref="CyrusBuilt.MonoPi.Sensors.DS1620"/> object.
        /// </summary>
        /// <remarks>
        /// Call <see cref="Dispose"/> when you are finished using the <see cref="CyrusBuilt.MonoPi.Sensors.DS1620"/>. The
        /// <see cref="Dispose"/> method leaves the <see cref="CyrusBuilt.MonoPi.Sensors.DS1620"/> in an unusable state. After calling
        /// <see cref="Dispose"/>, you must release all references to the <see cref="CyrusBuilt.MonoPi.Sensors.DS1620"/> so the
        /// garbage collector can reclaim the memory that the <see cref="CyrusBuilt.MonoPi.Sensors.DS1620"/> was occupying.
        /// </remarks>
        public void Dispose()
        {
            if (this._isDisposed)
            {
                return;
            }

            if (this._clock != null)
            {
                this._clock.Dispose();
                this._clock = null;
            }

            if (this._data != null)
            {
                this._data.Dispose();
                this._data = null;
            }

            if (this._reset != null)
            {
                this._reset.Dispose();
                this._reset = null;
            }
            this._isDisposed = true;
        }
示例#8
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Buzzer.BuzzerComponent"/>
		/// class with the pin the buzzer is attached to.
		/// </summary>
		/// <param name="pwmPin">
		/// The pin the buzzer is attached to.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// The pin cannot be null.
		/// </exception>
		public BuzzerComponent(IGpio pwmPin)
			: base() {
			if (pwmPin == null) {
				throw new ArgumentNullException("pwmPin");
			}
			this._pwm = pwmPin;
			this._pwm.Provision();
		}
示例#9
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Lights.LightComponent"/>
		/// class with the pin controlling the light.
		/// </summary>
		/// <param name="pin">
		/// The output pin the light is wired to.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// The pin cannot be null.
		/// </exception>
		public LightComponent(IGpio pin)
			: base() {
			if (pin == null) {
				throw new ArgumentNullException("pin");
			}
			this._pin = pin;
			this._pin.Provision();
		}
示例#10
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Relays.RelayBase"/>
		/// class with the pin being used to control the relay.
		/// </summary>
		/// <param name="pin">
		/// The output pin being used to control the relay.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="pin"/> cannot null.
		/// </exception>
		protected RelayBase(IGpio pin) {
			if (pin == null) {
				throw new ArgumentNullException("pin");
			}
			this._pin = pin;
			this._pin.Provision();
			this._props = new Dictionary<String, String>();
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Switches.MomentarySwitchComponent"/>
		/// class with the pin the switch is wired to.
		/// </summary>
		/// <param name="pin">
		/// The input pin to check switch state on.
		/// </param>
		public MomentarySwitchComponent(IGpio pin)
			: base() {
			if (pin == null) {
				throw new ArgumentNullException("pin");
			}
			this._pin = pin;
			this._pin.Provision();
			this._pin.StateChanged += this.OnStateChanged;
		}
示例#12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Sensors.MotionSensorBase"/>
 /// class.
 /// </summary>
 /// <param name="pin">
 /// The pin being used to read the sensor input.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="pin"/> cannot be null.
 /// </exception>
 protected MotionSensorBase(IGpio pin)
 {
     if (pin == null)
     {
         throw new ArgumentNullException("pin");
     }
     this._pin   = pin;
     this._props = new Dictionary <String, String>();
 }
示例#13
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 /// <filterpriority>2</filterpriority>
 /// <remarks>Call <see cref="Dispose"/> when you are finished using the
 /// <see cref="CyrusBuilt.MonoPi.Components.Buzzer.BuzzerComponent"/>. The <see cref="Dispose"/> method leaves the
 /// <see cref="CyrusBuilt.MonoPi.Components.Buzzer.BuzzerComponent"/> in an unusable state. After calling
 /// <see cref="Dispose"/>, you must release all references to the
 /// <see cref="CyrusBuilt.MonoPi.Components.Buzzer.BuzzerComponent"/> so the garbage collector can reclaim the memory
 /// that the <see cref="CyrusBuilt.MonoPi.Components.Buzzer.BuzzerComponent"/> was occupying.</remarks>
 public override void Dispose()
 {
     if (this._pwm != null)
     {
         this._pwm.Dispose();
         this._pwm = null;
     }
     base.Dispose();
 }
示例#14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Lights.LEDComponent"/>
 /// class with the pin controlling the LED.
 /// </summary>
 /// <param name="pin">
 /// The output pin the LED is wired to.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// The pin cannot be null.
 /// </exception>
 public LEDComponent(IGpio pin)
     : base()
 {
     if (pin == null)
     {
         throw new ArgumentNullException("pin");
     }
     this._pin = pin;
     this._pin.Provision();
 }
示例#15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Buzzer.BuzzerComponent"/>
 /// class with the pin the buzzer is attached to.
 /// </summary>
 /// <param name="pwmPin">
 /// The pin the buzzer is attached to.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// The pin cannot be null.
 /// </exception>
 public BuzzerComponent(IGpio pwmPin)
     : base()
 {
     if (pwmPin == null)
     {
         throw new ArgumentNullException("pwmPin");
     }
     this._pwm = pwmPin;
     this._pwm.Provision();
 }
示例#16
0
        public Motor(IGpio gpio, ILogger <Motor> logger)
        {
            if (gpio is null)
            {
                throw new ArgumentNullException("GPIO controller can not be null.");
            }

            this.logger         = logger;
            this.gpioController = gpio;
        }
示例#17
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Sensors.DS1620"/>
		/// class with the clock, data, and reset GPIO pins.
		/// </summary>
		/// <param name="clock">
		/// The clock pin.
		/// </param>
		/// <param name="data">
		/// The data pin.
		/// </param>
		/// <param name="reset">
		/// The reset pin.
		/// </param>
		public DS1620(IGpio clock, IGpio data, IGpio reset) {
			this._clock = clock;
			this._clock.Provision();

			this._data = data;
			this._data.Provision();

			this._reset = reset;
			this._reset.Provision();
		}
示例#18
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Lights.DimmableLightComponent"/>
		/// class with the pin controlling the light and the minimum and
		/// maximum light level.
		/// </summary>
		/// <param name="pin">
		/// The pin used to control the dimmable light.
		/// </param>
		/// <param name="min">
		/// The minimum brightness level.
		/// </param>
		/// <param name="max">
		/// The maximum brightness level.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// The pin cannot be null.
		/// </exception>
		public DimmableLightComponent(IGpio pin, Int32 min, Int32 max)
			: base() {
			if (pin == null) {
				throw new ArgumentNullException("pin");
			}
			this._pin = pin;
			this._pin.Provision();
			this._min = min;
			this._max = max;
		}
示例#19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Relays.RelayBase"/>
 /// class with the pin being used to control the relay.
 /// </summary>
 /// <param name="pin">
 /// The output pin being used to control the relay.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="pin"/> cannot null.
 /// </exception>
 protected RelayBase(IGpio pin)
 {
     if (pin == null)
     {
         throw new ArgumentNullException("pin");
     }
     this._pin = pin;
     this._pin.Provision();
     this._props = new Dictionary <String, String>();
 }
示例#20
0
        public DistanceSensorDriver(IGpio gpio, ILogger logger, IEnumerable <DistanceSensorPin> pinMapping)
        {
            this.gpio       = gpio;
            this.logger     = logger;
            this.pinMapping = pinMapping.ToDictionary(pin => pin.PinName);

            MeasurementsChannel = Channel.CreateBounded <double>(new BoundedChannelOptions(21)
            {
                FullMode = BoundedChannelFullMode.DropOldest
            });
        }
示例#21
0
文件: Gpio.cs 项目: Ereadian/PiLib
 /// <summary>
 /// Initializes a new instance of the <see cref="Ereadian.RaspberryPi.Library.Hardware.Gpio"/> class.
 /// </summary>
 /// <param name="pinNaming">Pin naming.</param>
 /// <param name="useLocal">If set to <c>true</c> use local GPIO operation.</param>
 public Gpio(PinNaming pinNaming, bool useLocal = UseLocal)
 {
     if (useLocal)
     {
         this.implementation = new LocalGpio(pinNaming);
     }
     else
     {
         this.implementation = new RemoteGpio(pinNaming);
     }
 }
示例#22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Sensors.DS1620"/>
        /// class with the clock, data, and reset GPIO pins.
        /// </summary>
        /// <param name="clock">
        /// The clock pin.
        /// </param>
        /// <param name="data">
        /// The data pin.
        /// </param>
        /// <param name="reset">
        /// The reset pin.
        /// </param>
        public DS1620(IGpio clock, IGpio data, IGpio reset)
        {
            this._clock = clock;
            this._clock.Provision();

            this._data = data;
            this._data.Provision();

            this._reset = reset;
            this._reset.Provision();
        }
示例#23
0
		/// <summary>
		/// Releases all resource used by the <see cref="CyrusBuilt.MonoPi.Components.Lights.LightComponent"/>
		/// object.
		/// </summary>
		/// <remarks>
		/// Call <see cref="Dispose"/> when you are finished using the
		/// <see cref="CyrusBuilt.MonoPi.Components.Lights.LightComponent"/>. The
		/// <see cref="Dispose"/> method leaves the
		/// <see cref="CyrusBuilt.MonoPi.Components.Lights.LightComponent"/> in an
		/// unusable state. After calling <see cref="Dispose"/>, you must release
		/// all references to the <see cref="CyrusBuilt.MonoPi.Components.Lights.LightComponent"/>
		/// so the garbage collector can reclaim the memory that the
		/// <see cref="CyrusBuilt.MonoPi.Components.Lights.LightComponent"/> was occupying.
		/// </remarks>
		public override void Dispose() {
			if (base.IsDisposed) {
				return;
			}

			if (this._pin != null) {
				this._pin.Dispose();
				this._pin = null;
			}
			base.Dispose();
		}
示例#24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Switches.SwitchComponent"/>
 /// class with the pin the switch is wired to.
 /// </summary>
 /// <param name="pin">
 /// The input pin to check switch state on.
 /// </param>
 public SwitchComponent(IGpio pin)
     : base()
 {
     if (pin == null)
     {
         throw new ArgumentNullException("pin");
     }
     this._pin = pin;
     this._pin.Provision();
     this._pin.StateChanged += this.OnStateChanged;
 }
示例#25
0
        public async override Task SetUp()
        {
            await base.SetUp();

            gpio = metawear.GetModule <IGpio>();

            mwTask = await metawear.ScheduleAsync(3141, 59, true, () => {
                gpio.Pins[0].AbsoluteReference.Read();
                gpio.Pins[0].Adc.Read();
            });
        }
示例#26
0
        public async override Task SetUp()
        {
            await base.SetUp();

            Action commands = () => {
                gpio.Pins[0].AbsoluteReference.Read();
                gpio.Pins[0].Adc.Read();
            };

            gpio   = metawear.GetModule <IGpio>();
            mwTask = await(indefinite ? metawear.ScheduleAsync(3141, true, commands) : metawear.ScheduleAsync(3141, 59, true, commands));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Lights.DimmableLightComponent"/>
 /// class with the pin controlling the light and the minimum and
 /// maximum light level.
 /// </summary>
 /// <param name="pin">
 /// The pin used to control the dimmable light.
 /// </param>
 /// <param name="min">
 /// The minimum brightness level.
 /// </param>
 /// <param name="max">
 /// The maximum brightness level.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// The pin cannot be null.
 /// </exception>
 public DimmableLightComponent(IGpio pin, Int32 min, Int32 max)
     : base()
 {
     if (pin == null)
     {
         throw new ArgumentNullException("pin");
     }
     this._pin = pin;
     this._pin.Provision();
     this._min = min;
     this._max = max;
 }
        /// <summary>
        /// Write the given value to the given pin.
        /// </summary>
        /// <param name="pin">The pin to set.</param>
        /// <param name="state">The new state of the pin.</param>
        public void WriteDigital(DigitalPin pin, bool state)
        {
            IGpio gpioPin = pin == DigitalPin.DIO16 ? this.dio16 : this.dio26;

            //if (gpioPin. != GpioPinDriveMode.Output)
            //gpioPin.SetDriveMode(GpioPinDriveMode.Output);
            // Initialize the pin as a high output
            gpioPin.SetDirection(Gpio.DirectionOutInitiallyHigh);
            // Low voltage is considered active
            gpioPin.SetActiveType(Gpio.ActiveHigh);

            gpioPin.Value = (state ? true : false);
        }
        public override void SetUp()
        {
            base.SetUp();

            gpio = metawear.GetModule <IGpio>();

            Task <IScheduledTask> task = metawear.ScheduleAsync(3141, 59, true, () => {
                gpio.Pins[0].AbsoluteReference.Read();
                gpio.Pins[0].Adc.Read();
            });

            task.Wait();
            mwTask = task.Result;
        }
示例#30
0
        /// <summary>
        /// Releases all resource used by the <see cref="CyrusBuilt.MonoPi.Components.Lights.LEDComponent"/>
        /// object.
        /// </summary>
        /// <remarks>
        /// Call <see cref="Dispose"/> when you are finished using the
        /// <see cref="CyrusBuilt.MonoPi.Components.Lights.LEDComponent"/>. The
        /// <see cref="Dispose"/> method leaves the
        /// <see cref="CyrusBuilt.MonoPi.Components.Lights.LEDComponent"/> in an
        /// unusable state. After calling <see cref="Dispose"/>, you must release
        /// all references to the <see cref="CyrusBuilt.MonoPi.Components.Lights.LEDComponent"/>
        /// so the garbage collector can reclaim the memory that the
        /// <see cref="CyrusBuilt.MonoPi.Components.Lights.LEDComponent"/> was occupying.
        /// </remarks>
        public override void Dispose()
        {
            if (base.IsDisposed)
            {
                return;
            }

            if (this._pin != null)
            {
                this._pin.Dispose();
                this._pin = null;
            }
            base.Dispose();
        }
        public RaspberryPi(ILogger <RaspberryPi> logger, IGpio gpio, ICamera camera)
        {
            _logger       = logger;
            _woopsaServer = new WoopsaServer(this);
            _woopsaServer.Authenticator = new SimpleAuthenticator("Raspberry",
                                                                  (sender, e) => e.IsAuthenticated = e.Username == "admin" && e.Password == "admin");

            _gpio   = gpio;
            _camera = camera;
            _logger.LogDebug("Raspberry pi created");


            //TODO : to that more dynamically
            _woopsaServer.WebServer.Routes.Add("camera", HTTPMethod.GET, new RouteHandlerFileSystem(Camera.SharedFolder));
        }
示例#32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Ereadian.RaspberryPi.Library.Hardware.GPIO.SN74HC595"/> class.
        /// </summary>
        /// <param name="gpio">gpio instance</param>
        /// <param name="dsPinNumber">pin number which connected to DS (SDI serial data input)</param>
        /// <param name="shPinNumber">pin number which connected to SH CP (shift register clock input).</param>
        /// <param name="stPinNumber">pin number which connected to ST CP (RCLK memory clock input).</param>
        public SN74HC595(IGpio gpio, int dsPinNumber, int shPinNumber, int stPinNumber)
        {
            this.gpio        = gpio;
            this.dsPinNumber = dsPinNumber;
            this.stPinNumber = stPinNumber;
            this.shPinNumber = shPinNumber;

            gpio.SetPinDirection(dsPinNumber, GpioPinDirection.Output);
            gpio.SetPinDirection(stPinNumber, GpioPinDirection.Output);
            gpio.SetPinDirection(shPinNumber, GpioPinDirection.Output);

            this.gpio[dsPinNumber] = GpioPinValue.Low;
            this.gpio[stPinNumber] = GpioPinValue.Low;
            this.gpio[shPinNumber] = GpioPinValue.Low;
        }
        /// <summary>
        /// Reads the current state of the given pin.
        /// </summary>
        /// <param name="pin">The pin to read.</param>
        /// <returns>True if high, false is low.</returns>
        public bool ReadDigital(DigitalPin pin)
        {
            //if (!Enum.IsDefined(typeof(DigitalPin), pin)) throw new ArgumentException(nameof(pin));

            IGpio gpioPin = pin == DigitalPin.DIO16 ? this.dio16 : this.dio26;

            //if (gpioPin.GetDriveMode() != GpioPinDriveMode.Input)
            //  gpioPin.SetDriveMode(GpioPinDriveMode.Input);

            // Initialize the pin as an input
            gpioPin.SetDirection(Gpio.DirectionIn);
            // High voltage is considered active
            gpioPin.SetActiveType(Gpio.ActiveHigh);

            return(gpioPin.Value == true);
        }
示例#34
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Temperature.TemperatureSensorBase"/>
		/// class with the clock, data, and reset pins needed for the sensor.
		/// </summary>
		/// <param name="clock">
		/// The GPIO pin used for the clock.
		/// </param>
		/// <param name="data">
		/// The GPIO pin used for data.
		/// </param>
		/// <param name="reset">
		/// The GPIO pin used to trigger reset.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// Pins cannot be null.
		/// </exception>
		protected TemperatureSensorBase(IGpio clock, IGpio data, IGpio reset)
			: base() {
			if (clock == null) {
				throw new ArgumentNullException("clock");
			}

			if (data == null) {
				throw new ArgumentNullException("data");
			}

			if (reset == null) {
				throw new ArgumentNullException("reset");
			}

			this._tempSensor = new DS1620(clock, data, reset);
		}
        private void SetupDemo1()
        {
            try
            {
                var LED_PIN_NAME = "GPIO2_IO02";

                // Red LED
                //Raspberry Pi 3 - BCM6
                //i.MX7D - GPIO2_IO02

                _redLED = _manager.OpenGpio(LED_PIN_NAME);
                //redLED = RainbowHat.OpenLedRed();
                // Configure as an output.
                _redLED.SetDirection(Gpio.DirectionOutInitiallyLow);
            }
            catch (IOException ex)
            {
                Log.Error(TAG, "Error during onCreate!", ex);
            }

            _ledToggleView = FindViewById <ToggleButton>(Resource.Id.ledToggle);

            try
            {
                _ledToggleView.Checked = _redLED.Value;
            }
            catch (IOException ex)
            {
                Log.Error(TAG, "Error during setChecked!", ex);
            }


            _ledToggleView.CheckedChange += (sender, e) => {
                try
                {
                    _redLED.Value = e.IsChecked;
                }
                catch (IOException ex)
                {
                    Log.Error(TAG, "Error during onCheckedChanged!", ex);
                }
            };
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Temperature.TemperatureSensorBase"/>
        /// class with the clock, data, and reset pins needed for the sensor.
        /// </summary>
        /// <param name="clock">
        /// The GPIO pin used for the clock.
        /// </param>
        /// <param name="data">
        /// The GPIO pin used for data.
        /// </param>
        /// <param name="reset">
        /// The GPIO pin used to trigger reset.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Pins cannot be null.
        /// </exception>
        protected TemperatureSensorBase(IGpio clock, IGpio data, IGpio reset)
            : base()
        {
            if (clock == null)
            {
                throw new ArgumentNullException("clock");
            }

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (reset == null)
            {
                throw new ArgumentNullException("reset");
            }

            this._tempSensor = new DS1620(clock, data, reset);
        }
            public Motor(PCA9685 pwm, int pwmChannel, String direction1Pin, String direction2Pin)
            {
                PeripheralManager manager = PeripheralManager.Instance;

                this.direction1 = manager.OpenGpio(direction1Pin);
                this.direction2 = manager.OpenGpio(direction2Pin);
                this.speed      = 0.0;
                this.pwm        = pwm;
                this.disposed   = false;

                this.pwmChannel = pwmChannel;
                // Initialize the pin as a high output
                this.direction1.SetDirection(Gpio.DirectionOutInitiallyHigh);
                // Low voltage is considered active
                this.direction1.SetActiveType(Gpio.ActiveHigh);

                // Initialize the pin as a high output
                this.direction2.SetDirection(Gpio.DirectionOutInitiallyHigh);
                // Low voltage is considered active
                this.direction2.SetActiveType(Gpio.ActiveHigh);
            }
示例#38
0
		/// <summary>
		/// Releaseses all resources used this object.
		/// </summary>
		/// <param name="disposing">
		/// Set true if disposing managed resources in addition to unmanaged.
		/// </param>
		protected virtual void Dispose(Boolean disposing) {
			if (this._isDisposed) {
				return;
			}

			if (disposing) {
				this._name = null;
				this._tag = null;
				if (this._pin != null) {
					this._pin.Dispose();
					this._pin = null;
				}

				if (this._props != null) {
					this._props.Clear();
					this._props = null;
				}
			}

			this.StateChanged = null;
			this._isDisposed = true;
		}
        public PCA9685(String I2CBus, String GPIO_NAME)
        {
            PeripheralManager pioService = PeripheralManager.Instance;
            II2cDevice        _device    = pioService.OpenI2cDevice(I2CBus, I2C_ADDRESS);

            this.write5   = new byte[5];
            this.write2   = new byte[2];
            this.write1   = new byte[1];
            this.read1    = new byte[1];
            this.disposed = false;

            this.device = _device;
            try
            {
                PeripheralManager manager = PeripheralManager.Instance;
                this.outputEnable = manager.OpenGpio(GPIO_NAME);
            }
            catch (Exception e)
            {
                Log.WriteLine(LogPriority.Info, TAG, "Unable to access GPIO", e);
            }


            if (this.outputEnable != null)
            {
                // Initialize the pin as a high output
                this.outputEnable.SetDirection(Gpio.DirectionOutInitiallyHigh);
                // Low voltage is considered active
                this.outputEnable.SetActiveType(Gpio.ActiveLow);
                // Toggle the value to be LOW
                this.outputEnable.Value = (false);
                //this.outputEnable.SetDriveMode(GpioPinDriveMode.Output);
                //this.outputEnable.Write(GpioPinValue.Low);
            }

            this.WriteRegister(Register.Mode1, (byte)0x20);
            this.WriteRegister(Register.Mode2, (byte)0x06);
        }
        private void SetupDemo2()
        {
            try
            {
                var pinName = "GPIO6_IO14"; //A button for i.MX7D, BCM21 for Rpi3
                _buttonA = _manager.OpenGpio(pinName);
                // Configure as an input, trigger events on every change.
                _buttonA.SetDirection(Gpio.DirectionIn);
                // Value is true when the pin is HIGH
                _buttonA.SetActiveType(Gpio.ActiveHigh);
                _buttonA.SetEdgeTriggerType(Gpio.EdgeFalling);
                _buttonA.RegisterGpioCallback(new Handler(), this);


                var buttonB        = RainbowHat.OpenButtonB();
                var ledToggleViewB = FindViewById <ToggleButton>(Resource.Id.ledToggleB);
                buttonB.ButtonEvent += (sender, e) => {
                    ledToggleViewB.Checked = !ledToggleViewB.Checked;
                };
            } catch (IOException ex) {
                Log.Error(TAG, "Error during onCreate!", ex);
            }
        }
 public bool OnGpioEdge(IGpio gpio)
 {
     _ledToggleView.Checked = !_ledToggleView.Checked;
     return(true);
 }
示例#42
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Sensors.SensorComponent"/>
		/// class with the <see cref="CyrusBuilt.MonoPi.IO.GpioMem"/> I/O pin to use.
		/// </summary>
		/// <param name="pin">
		/// The <see cref="CyrusBuilt.MonoPi.IO.GpioMem"/> I/O pin to use.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="pin"/> cannot null.
		/// </exception>
		public SensorComponent(IGpio pin)
			: base(pin) {
		}
		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="CyrusBuilt.MonoPi.Components.Temperature.TemperatureSensorComponent"/>
		/// class with the clock, data, and reset pins needed for the sensor,
		/// as well as the scale to get the temperature readings in.
		/// </summary>
		/// <param name="scale">
		/// The scale to get the temperature readings in.
		/// </param>
		/// <param name="clock">
		/// The GPIO pin used for the clock.
		/// </param>
		/// <param name="data">
		/// The GPIO pin used for data.
		/// </param>
		/// <param name="reset">
		/// The GPIO pin used to trigger reset.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// Pins cannot be null.
		/// </exception>
		public TemperatureSensorComponent(TemperatureScale scale, IGpio clock, IGpio data, IGpio reset)
			: base(clock, data, reset) {
			this._scale = scale;
		}
		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="CyrusBuilt.MonoPi.Components.Temperature.TemperatureSensorComponent"/>
		/// class with the clock, data, and reset pins needed for the sensor.
		/// </summary>
		/// <param name="clock">
		/// The GPIO pin used for the clock.
		/// </param>
		/// <param name="data">
		/// The GPIO pin used for data.
		/// </param>
		/// <param name="reset">
		/// The GPIO pin used to trigger reset.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// Pins cannot be null.
		/// </exception>
		public TemperatureSensorComponent(IGpio clock, IGpio data, IGpio reset)
			: base(clock, data, reset) {
		}
		/// <summary>
		/// Releases all resource used by the <see cref="CyrusBuilt.MonoPi.Components.Switches.MomentarySwitchComponent"/>
		/// object.
		/// </summary>
		/// <remarks>
		/// Call <see cref="Dispose"/> when you are finished using the
		/// <see cref="CyrusBuilt.MonoPi.Components.Switches.MomentarySwitchComponent"/>. The
		/// <see cref="Dispose"/> method leaves the 
		/// <see cref="CyrusBuilt.MonoPi.Components.Switches.MomentarySwitchComponent"/> in an
		/// unusable state. After calling <see cref="Dispose"/>, you must release all references
		/// to the <see cref="CyrusBuilt.MonoPi.Components.Switches.MomentarySwitchComponent"/>
		/// so the garbage collector can reclaim the memory that the
		/// <see cref="CyrusBuilt.MonoPi.Components.Switches.MomentarySwitchComponent"/> was occupying.
		/// </remarks>
		public override void Dispose() {
			lock (_syncLock) {
				_isPolling = false;
			}

			if ((this._pollThread != null) && (this._pollThread.IsAlive)) {
				try {
					Thread.Sleep(50);
					this._pollThread.Abort();
				}
				catch (ThreadAbortException) {
					Thread.ResetAbort();
				}
				finally {
					this._pollThread = null;
				}
			}

			if (this._pin != null) {
				this._pin.Dispose();
				this._pin = null;
			}
			base.Dispose();
		}
示例#46
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Sensors.MotionSensorComponent"/>
		/// class with the <see cref="CyrusBuilt.MonoPi.IO.GpioMem"/> I/O pin to use.
		/// </summary>
		/// <param name="pin">
		/// The <see cref="CyrusBuilt.MonoPi.IO.GpioMem"/> I/O pin to use.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="pin"/> cannot null.
		/// </exception>
		public MotionSensorComponent(IGpio pin)
			: base(pin) {
		}
示例#47
0
        public Eater(IGpio gpio)
        {
            this.gpio = gpio;

            SetPins();
        }
示例#48
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.Components.Relays.RelayComponent"/>
		/// class with the <see cref="CyrusBuilt.MonoPi.IO.GpioMem"/> I/O pin to use.
		/// </summary>
		/// <param name="pin">
		/// The <see cref="CyrusBuilt.MonoPi.IO.IGpio"/> I/O pin to use.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="pin"/> cannot null.
		/// </exception>
		public RelayComponent(IGpio pin)
			: base(pin) {
		}
示例#49
0
		/// <summary>
		/// Releases all resource used by the <see cref="CyrusBuilt.MonoPi.Sensors.DS1620"/> object.
		/// </summary>
		/// <remarks>
		/// Call <see cref="Dispose"/> when you are finished using the <see cref="CyrusBuilt.MonoPi.Sensors.DS1620"/>. The
		/// <see cref="Dispose"/> method leaves the <see cref="CyrusBuilt.MonoPi.Sensors.DS1620"/> in an unusable state. After calling
		/// <see cref="Dispose"/>, you must release all references to the <see cref="CyrusBuilt.MonoPi.Sensors.DS1620"/> so the
		/// garbage collector can reclaim the memory that the <see cref="CyrusBuilt.MonoPi.Sensors.DS1620"/> was occupying.
		/// </remarks>
		public void Dispose() {
			if (this._isDisposed) {
				return;
			}

			if (this._clock != null) {
				this._clock.Dispose();
				this._clock = null;
			}

			if (this._data != null) {
				this._data.Dispose();
				this._data = null;
			}

			if (this._reset != null) {
				this._reset.Dispose();
				this._reset = null;
			}
			this._isDisposed = true;
		}