Пример #1
0
        private void OverCurrentPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            bool state_changed = false;
            GpioPinValue curr_pin_value = _pin.Read();

            // Detect a change in pin state
            if ( (_last_pin_value == INACTIVE &&  curr_pin_value == ACTIVE) ||
                 (_last_pin_value == ACTIVE && curr_pin_value == INACTIVE) )
            {
                state_changed = true;
            }

            _last_pin_value = curr_pin_value;

            if (curr_pin_value == ACTIVE)
            {
                _state = DETECT_STATE;
            }
            else
            {
                _state = NO_DETECT_STATE;
            }

            // Send an alert only on a change
            if (state_changed)
            {                
                foreach (var callback in _alert_callbacks)
                {
                    callback("overcurrent:" + _id + ":" + _state);
                }
            }

        }
        private async void pin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
                if (args.Edge.CompareTo(GpioPinEdge.RisingEdge) == 0)
                {
                    //Motion Detected UI
                    UiAlert();

                    //Create JSON payload
                    var json = string.Format("{{sensor:Motion,  room:MsConfRoom1,  utc:{0}}}", DateTime.UtcNow.ToString("MM/dd/yyyy_HH:mm:ss"));
                    var data = new ASCIIEncoding().GetBytes(json);

                    //POST Data
                    string url = "https://rrpiot.azurewebsites.net/SensorData";
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.Method = "POST";
                    request.ContentType = "application/json";
                    using (Stream myStream = await request.GetRequestStreamAsync())
                    {
                        myStream.Write(data, 0, data.Length);
                    }
                    await request.GetResponseAsync();
                }
                else
                {
                    //Display No Motion Detected UI
                    UiNoMotion();
                }

        }
 private void handleButton(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     Debug.WriteLine("Value Change on pin:" + sender.PinNumber + " : " + args.Edge);
     TelemetryManager.WriteTelemetryEvent("Action_PhysicalButton");
     if (args.Edge == GpioPinEdge.RisingEdge)
     {
         switch (this.buttonPins[sender.PinNumber])
         {
             case InputAction.NextChannel:
                 this.playlistManager.NextTrack();
                 break;
             case InputAction.PreviousChannel:
                 this.playlistManager.PreviousTrack();
                 break;
             case InputAction.VolumeUp:
                 this.playbackManager.Volume += 0.1;
                 break;
             case InputAction.VolumeDown:
                 this.playbackManager.Volume -= 0.1;
                 break;
             case InputAction.Sleep:
                 if (PowerState.Powered == this.powerManager.PowerState)
                 {
                     this.powerManager.PowerState = PowerState.Standby;
                 }
                 else
                 {
                     this.powerManager.PowerState = PowerState.Powered;
                 }
                 break;
         }
     }
 }
Пример #4
0
        private void Pin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
        {
            var edge = e.Edge;
            if ((pressedValue == GpioPinValue.High) && (edge == GpioPinEdge.RisingEdge))
            {
                isPressed = true;
            }
            else if ((pressedValue == GpioPinValue.Low) && (edge == GpioPinEdge.FallingEdge))
            {
                isPressed = true;
            }
            else
            {
                isPressed = false;
            }

            // Notify
            if (isPressed)
            {
                pressedEvent.Raise(owner, EmptyEventArgs.Instance);
                if (ClickMode == ButtonClickMode.Press)
                {
                    clickEvent.Raise(owner, EmptyEventArgs.Instance);
                }
            }
            else
            {
                releasedEvent.Raise(owner, EmptyEventArgs.Instance);
                if (ClickMode == ButtonClickMode.Release)
                {
                    clickEvent.Raise(owner, EmptyEventArgs.Instance);
                }
            }
        }
Пример #5
0
 private void MotionSensorPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     if (OnChanged != null)
     {
         OnChanged(this, args);
     }
 }
Пример #6
0
        private void buttonPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
        {
            // toggle the state of the LED every time the button is pressed
            if (e.Edge == GpioPinEdge.FallingEdge)
            {
                ledPinValue = (ledPinValue == GpioPinValue.Low) ?
                    GpioPinValue.High : GpioPinValue.Low;
                ledPin.Write(ledPinValue);
            }

            // need to invoke UI updates on the UI thread because this event
            // handler gets invoked on a separate thread.
            var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                if (e.Edge == GpioPinEdge.FallingEdge)
                {
                    ledEllipse.Fill = (ledPinValue == GpioPinValue.Low) ? 
                        redBrush : grayBrush;
                    GpioStatus.Text = "Button Pressed";
                }
                else
                {
                    GpioStatus.Text = "Button Released";
                }
            });
        }
Пример #7
0
        private void M_cadence_sensor_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            if (args.Edge == GpioPinEdge.RisingEdge)
            {
                Debug.WriteLine("{0} Pedal Sensor", DateTime.Now);

                //TimeSpan cadence_interval = DateTime.Now - m_last_cadence;

                //m_last_cadence = DateTime.Now;

                m_cadence_blips.Enqueue(DateTime.Now);

                if (m_cadence_blips.Count > 5)
                {
                    m_cadence_blips.Dequeue();
                }

                if (m_cadence_blips.Count > 2)
                {

                    double cadence_interval = (m_cadence_blips.Last() - m_cadence_blips.First()).TotalSeconds / m_cadence_blips.Count;

                    Debug.WriteLine("Interval = {0} (count = {1})", cadence_interval, m_cadence_blips.Count);

                    RPM = (int)Math.Floor(30 / cadence_interval); //its 60 divided by 2 due to the 2 magnets
                }

            }
        }
Пример #8
0
        private async void PirSensorService_MotionDetected(object sender, Windows.Devices.Gpio.GpioPinValueChangedEventArgs e)
        {
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                          () =>
            {
                Ellipse_pir.Fill = redBrush;
            });


            StorageFile photo = await usbCameraService.CapturePhoto();

            pinUploadingPhoto.Write(GpioPinValue.High);
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                          () =>
            {
                Ellipse_upload.Fill = yellowBrush;
            });

            await deviceClientService.UploadBlob(photo);


            pinUploadingPhoto.Write(GpioPinValue.Low);
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                          () =>
            {
                Ellipse_upload.Fill = grayBrush;
                Ellipse_pir.Fill    = grayBrush;
            });
        }
 private void InputPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     if(args.Edge == GpioPinEdge.FallingEdge)
     {
         AccumulatedTotal = AccumulatedTotal + LitersPerPulse;
     }
 }
Пример #10
0
        /// <summary>
        /// Event called when GPIO PIN 16 changes (PIR signal)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void PinPIR_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            //simple guard to prevent it from triggering this function again before it's compelted the first time - one sound at a time please
            if (IsPlaying)
                return;
            else
                IsPlaying = true;
            try
            {
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                async () =>
                {
                  PIRStatus.Text = "New PIR pin value: " + args.Edge.ToString();
                 //SoundPlayer mantra = new SoundPlayer(@"C:\WINDOWS\Media\mantra.wav");
                 SoundPlayer mantra = new SoundPlayer(Resource1.mantra);

                  mantra.Play();
                    
                   });
            }
            catch (Exception ex)
            {
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                () =>
                {
                    PIRStatus.Text = "PIR Error: " + ex.Message;
                });
            }
            finally
            {
                isPlaying = false;
            }

            return;
        }
 private void Pin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     if (pin.Read() == GpioPinValue.High)
     {
         int bla;
     }
 }
Пример #12
0
        private void ValueChangedHandler(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            var pinNumber = sender.PinNumber;
            var gpioPinValue = sender.Read();
            Debug.WriteLine("Pin {0} changed to {1}", pinNumber, gpioPinValue);

            if (pinNumber == TiltSensorPin)
            {
                _halper.DishwasherTilt(gpioPinValue == GpioPinValue.High);
                var currentStatus = _halper.Get().CurrentStatus;
                if (currentStatus == DishwasherStatus.Clean && gpioPinValue == GpioPinValue.High)
                {
                    ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(10000));
                }
                return;
            }

            var tiltSensorValue = _gpioSensors[TiltSensorPin].Read();
            if (gpioPinValue == GpioPinValue.High)
            {
                if (pinNumber == CleanLightPin)
                {
                    _halper.EndDishwasherRun();
                }
                else if (tiltSensorValue == GpioPinValue.Low && _pinToCycleTypeMap.ContainsKey(pinNumber))
                {
                    _halper.StartDishwasherRun(_pinToCycleTypeMap[pinNumber]);
                }
            }
        }
Пример #13
0
        private void buttonPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
        {
            //// toggle the state of the LED every time the button is pressed
            //if (e.Edge == GpioPinEdge.FallingEdge)
            //{
            //    ledPinValue = (ledPinValue == GpioPinValue.Low) ?
            //        GpioPinValue.High : GpioPinValue.Low;
            //    ledPin.Write(ledPinValue);
            //} 

            // need to invoke UI updates on the UI thread because this event
            // handler gets invoked on a separate thread.
            var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                if (buttonPin.Read() == GpioPinValue.High)
                {
                    ledPinValue = GpioPinValue.High;
                    ledEllipse.Fill = grayBrush;
                    ledPin.Write(ledPinValue);
                    GpioStatus.Text = "No Mouse...";
                    SendMessageToIoTHubAsync(1);
                }
                if (buttonPin.Read() == GpioPinValue.Low)
                {
                    ledPinValue = GpioPinValue.Low;
                    ledEllipse.Fill = redBrush;
                    ledPin.Write(ledPinValue);
                    GpioStatus.Text = "Dead Mouse...";
                    SendMessageToIoTHubAsync(2);
                }
            });
        }
Пример #14
0
 /*******************************************************************************************
 * PRIVATE METHODS
 ********************************************************************************************/
 private async void PirSensor_OnChanged(object sender, GpioPinValueChangedEventArgs e)
 {
     //Start the timer for the duration of motion
     if (e.Edge == GpioPinEdge.FallingEdge)
     {
         await TakePhotoAsync();
     }
 }
 private void irqPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     if (args.Edge != GpioPinEdge.FallingEdge) return;
     _logger.Trace("IRQ Event Received!");
     RegisterContainer.StatusRegister.Load();
     Interrupted?.Invoke(this, new InterruptedEventArgs { StatusRegister = RegisterContainer.StatusRegister });
     _irqPin.Write(GpioPinValue.High);
 }
Пример #16
0
 private void ButtonpinValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     // Just shutdown on one edge
     if (args.Edge == GpioPinEdge.RisingEdge)
     {
         ShutdownManager.BeginShutdown(ShutdownKind.Shutdown, TimeSpan.FromSeconds(0.5));
     }
 }
Пример #17
0
        private void Interrupt(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            if (device == null)
                return;

            int interruptStatus = readWriteHelper.ReadByte(Constants.IntStatus);
            if ((interruptStatus & 0x10) != 0)
                readWriteHelper.WriteByte(Constants.UserCtrl, 0x44); // reset and enable fifo

            if ((interruptStatus & 0x1) == 0)
                return;

            var ea = new MpuSensorEventArgs
            {
                Status = (byte)interruptStatus,
                SamplePeriod = 0.02f
            };

            var l = new List<MpuSensorValue>();

            int count = readWriteHelper.ReadWord(Constants.FifoCount);

            while (count >= Constants.SensorBytes)
            {
                var data = readWriteHelper.ReadBytes(Constants.FifoRW, Constants.SensorBytes);
                count -= Constants.SensorBytes;

                var xa = (short)(data[0] << 8 | data[1]);
                var ya = (short)(data[2] << 8 | data[3]);
                var za = (short)(data[4] << 8 | data[5]);

                var xg = (short)(data[6] << 8 | data[7]);
                var yg = (short)(data[8] << 8 | data[9]);
                var zg = (short)(data[10] << 8 | data[11]);

                var sv = new MpuSensorValue
                {
                    AccelerationX = xa / (float)16384,
                    AccelerationY = ya / (float)16384,
                    AccelerationZ = za / (float)16384,
                    GyroX = xg / (float)131,
                    GyroY = yg / (float)131,
                    GyroZ = zg / (float)131
                };

                l.Add(sv);
            }

            ea.Values = l.ToArray();

            if (SensorInterruptEvent == null)
                return;

            if (ea.Values.Length > 0)
                SensorInterruptEvent(this, ea);
        }
Пример #18
0
        private void FlowPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            GpioPinValue state = _pin.Read();

            if (_last_flow_state == GpioPinValue.Low && state == GpioPinValue.High)
            {
                _low_to_high_count++;
            }
            _last_flow_state = state;
        }
Пример #19
0
 private void ButtonPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     if (sender.Read() == GpioPinValue.High)
     {
         sendEvents = !sendEvents;
         if (sendEvents)
         {
             Task.Run(() => SendEvents());
         }
     }
 }
Пример #20
0
 //This method will be called everytime there is a change in the GPIO pin value
 private async void buttonPin_ValueChanged(object sender, GpioPinValueChangedEventArgs e)
 {
     //Only read the sensor value when the button is released
     if (e.Edge == GpioPinEdge.RisingEdge)
     {
         //Read the approximate color from the sensor
        
         //Output the colr name to the speaker
        
     }
 }
Пример #21
0
 //This method will be called everytime there is a change in the GPIO pin value
 private async void buttonPin_ValueChanged(object sender, GpioPinValueChangedEventArgs e)
 {
     //Only read the sensor value when the button is released
     if (e.Edge == GpioPinEdge.RisingEdge)
     {
         //Read the approximate color from the sensor
         string colorRead = await colorSensor.getClosestColor();
         //Output the colr name to the speaker
         await SpeakColor(colorRead);
     }
 }
Пример #22
0
        private void OnValueChanged( GpioPin sender, GpioPinValueChangedEventArgs args )
        {
            EventHandler eventToFire = args.Edge == GpioPinEdge.FallingEdge
                ? this.Pushed
                : this.Released;

            if( eventToFire != null )
            {
                eventToFire( this, new EventArgs() );
            }
        }
Пример #23
0
 private void CheckParking(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     if (switch_right.Read() == GpioPinValue.High && switch_left.Read() == GpioPinValue.High) //When both switches are pressed
     {
         led_blue.Write(GpioPinValue.Low); //Turn on blue LED
     }
     else
     {
         led_blue.Write(GpioPinValue.High); //Turn off blue LED
     }
 }
Пример #24
0
 private void _forwardButton_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     if (forwardButton.Read() == GpioPinValue.Low)
     {
         currentPulseWidth = ForwardPulseWidth;
     }
     else
     {
         currentPulseWidth = 0;
     }
 }
Пример #25
0
 private void CheckContainer(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     if (switch_container.Read() == GpioPinValue.Low) //When the container switches is pressed
     {
         containerBlink.Stop();
         led_green.Write(GpioPinValue.Low); //Turn on green LED
     }
     else
     {
         containerBlink.Start();
     }
 }
Пример #26
0
 private void AbortPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
         if (args.Edge == GpioPinEdge.RisingEdge)
             missonAborted = missonAborted ? false : true;
         AbortText.Text = (missonAborted ? "ABORT MISSION!" : "");
         if (missonAborted)
             ledAbortPin.Write(GpioPinValue.Low);
         else
             ledAbortPin.Write(GpioPinValue.High);
     });
 }
Пример #27
0
		private async void buttonPin_ValueChanged(object sender, GpioPinValueChangedEventArgs e)
		{
			if (e.Edge == GpioPinEdge.RisingEdge)
			{
				ColorfulRestProperty color = await colorSensor.getColorfulRestData();
				await SpeakColor(color.Name.Value);

				Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
				{
					updateUI(color, updText: true);
				}).AsTask().Wait();
			}
		}
        private void _pinMotion_ValueChanged(GpioPin sender,
           GpioPinValueChangedEventArgs args)
        {
            var isOn = args.Edge == GpioPinEdge.FallingEdge;
            if (isOn)
            {
                //takePicture and call oxford service;
                Debug.WriteLine("Movement Detected");
                
            }


        }
 private async void _startSensor_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     if (!_timer.IsRunning)
     {
         
         _timer.Start();
         await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() => {
             txtStatus.Text = "Timer Started....";
             txtResults.Text = "";
         });
        
     }
 
 }
 private async void PinPIR_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
 {
     await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         if (args.Edge == GpioPinEdge.RisingEdge)
         {
             burglar.Visibility = Visibility.Visible;
         }
         else
         {
             burglar.Visibility = Visibility.Collapsed;
         }
     });
 }
Пример #31
0
 private void buttonPressAction(GpioPin mycallerPin, GpioPinValueChangedEventArgs myevent)
 {
     //Debug.WriteLine("Event handler detected ButtonPin Change : " + myevent.Edge);
     if (myevent.Edge == GpioPinEdge.RisingEdge) //RisingEdge)
     {
         //Debug.WriteLine("Event handler detected RISING Edge");
         ledPinVal = (ledPinVal == GpioPinValue.Low) ?
             GpioPinValue.High : GpioPinValue.Low;
         ledPin.Write(ledPinVal);
     }
     else
     {
         //Debug.WriteLine("Event handler detected FALLING Edge");
     }
 }