예제 #1
0
        /*******************************************************************************************
        * PUBLIC METHODS
        *******************************************************************************************/
        public async Task Initialize()
        {
            webcam = new UsbCamera();
            try
            {
                await webcam.InitializeAsync();

                this.isEnabled = true;
            }
            catch (Exception ex)
            {
                var events = new Dictionary <string, string> {
                    { "UsbCamera", ex.Message }
                };
                TelemetryHelper.TrackEvent("FailedToInitializeMediaCapture", events);
            }

            //Initialize PIR Sensor
            pirSensor = new PirSensor(App.Controller.XmlSettings.GpioMotionPin, PirSensor.SensorType.ActiveLow);
            pirSensor.motionDetected += PirSensor_MotionDetected;

            Interlocked.Exchange(ref isCapturing, 0);

            PhotoTaken = delegate { };
        }
        public RaspberryPiCameraTrap(string location, RaspberryPiCameraTrapSettings settings)
        {
            Location = location;
            Settings = settings;

            HueLights = new HueLights(settings.HueBridgeIp, settings.HueKey);

            // Connect to Azure IoT Hub
            DeviceClient             = DeviceClient.Create(settings.IotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey(settings.IotHubDeviceId, settings.IotHubDeviceKey), TransportType.Mqtt);
            DeviceClient.ProductInfo = "MorrisCounter"; // I have no idea what this is

            // Turn on the IR spotlight
            Spotlight = new IrSpotlight(settings.SpotlightPin);
            Spotlight.SwitchOn();

            // Start the video stream
            Console.WriteLine("Opening video stream");
            Camera = new PiCamera(settings.CameraSettings, settings.VideoChunkDuration);
            Camera.StartVideoStream();

            // Enable the PIR Sensor and subscribe to the callback
            PirSensor sensor = new PirSensor(settings.SensorPin);

            sensor.MotionDetected += MotionDetected;
        }
예제 #3
0
        /// <summary>
        /// Attempts to initialize Gpio for application. This includes doorbell interaction and locking/unlccking of door.
        /// Returns true if initialization is successful and Gpio can be utilized. Returns false otherwise.
        /// </summary>
        public bool Initialize()
        {
            // Gets the GpioController
            gpioController = GpioController.GetDefault();
            if (gpioController == null)
            {
                // There is no Gpio Controller on this device, return false.
                return(false);
            }

            // Opens the GPIO pin that interacts with the doorbel button
            doorbellPin = gpioController.OpenPin(GpioConstants.ButtonPinID);

            if (doorbellPin == null)
            {
                // Pin wasn't opened properly, return false
                return(false);
            }

            // Set a debounce timeout to filter out switch bounce noise from a button press
            doorbellPin.DebounceTimeout = TimeSpan.FromMilliseconds(75);

            if (doorbellPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                // Take advantage of built in pull-up resistors of Raspberry Pi 2 and DragonBoard 410c
                doorbellPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                // MBM does not support PullUp as it does not have built in pull-up resistors
                doorbellPin.SetDriveMode(GpioPinDriveMode.Input);
            }

            //Initialize PIR Sensor
            pirSensor = new PirSensor(GpioConstants.PirSensorPinID, PirSensor.SensorType.ActiveHigh);
            pirSensor.motionDetected += PirSensor_motionDetected;

            /*       // Opens the GPIO pin that interacts with the door lock system
             *     doorLockPin = gpioController.OpenPin(GpioConstants.DoorLockPinID);
             *     if(doorLockPin == null)
             *     {
             *         // Pin wasn't opened properly, return false
             *         return false;
             *     }
             *     // Sets doorbell pin drive mode to output as pin will be used to output information to lock
             *     doorLockPin.SetDriveMode(GpioPinDriveMode.Output);
             *     // Initializes pin to high voltage. This locks the door.
             *     doorLockPin.Write(GpioPinValue.High);*/

            //Initialization was successfull, return true
            return(true);
        }
예제 #4
0
파일: PiTest.cs 프로젝트: amithsaddi/rpibot
        public static void TestPirSensor()
        {
            PirSensor pirSensor = new PirSensor();

            while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
            {
                var detected = pirSensor.CheckSensor();
                Console.WriteLine("Motion Detected : " + detected);
                Thread.Sleep(1000);
            }

            pirSensor.Dispose();
        }
예제 #5
0
        /*******************************************************************************************
        * PUBLIC METHODS
        *******************************************************************************************/
        public bool Initialize()
        {
            var gpioController = GpioController.GetDefault();

            if (gpioController == null)
            {
                return(false);
            }

            //Initialize PIR Sensor
            pirSensor = new PirSensor(GpioConstants.PirSensorPinID, PirSensor.SensorType.ActiveHigh);
            pirSensor.motionDetected += PirSensor_motionDetected;
            return(true);
        }
예제 #6
0
        /*******************************************************************************************
        * PUBLIC METHODS
        *******************************************************************************************/
        public async Task Initialize()
        {
            webcam = new UsbCamera();
            try
            {
                await webcam.InitializeAsync();
                this.isEnabled = true;
            }
            catch (Exception ex)
            {
                var events = new Dictionary<string, string> { { "UsbCamera", ex.Message } };
                TelemetryHelper.TrackEvent("FailedToInitializeMediaCapture", events);
            }

            //Initialize PIR Sensor
            pirSensor = new PirSensor(App.Controller.XmlSettings.GpioMotionPin, PirSensor.SensorType.ActiveLow);
            pirSensor.motionDetected += PirSensor_MotionDetected;

            Interlocked.Exchange(ref isCapturing, 0);
        }