示例#1
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            // Connect the Button to digital port 2
            IButtonSensor button = DeviceFactory.Build.ButtonSensor(Pin.DigitalPin2);

            // Connect the Buzzer to digital port 5
            IBuzzer buzzer = DeviceFactory.Build.Buzzer(Pin.DigitalPin5);

            // Loop endlessly
            while (true)
            {
                try
                {
                    // Check the value of the button.

                    string buttonon   = button.CurrentState.ToString();
                    bool   buttonison = buttonon.Equals("On", StringComparison.OrdinalIgnoreCase);

                    // Check the state of the buzzer.  This is just to output to debug!
                    SensorStatus status   = buzzer.CurrentState;
                    bool         buzzeron = status.ToString().Equals("On", StringComparison.OrdinalIgnoreCase);

                    // Print out Diagnostics.
                    System.Diagnostics.Debug.WriteLine("Button is " + buttonon);
                    System.Diagnostics.Debug.WriteLine("Buzzer is " + status.ToString());

                    // If the Button is on . . . .
                    if (buttonison)
                    {
                        buzzer.ChangeState(GrovePi.Sensors.SensorStatus.On);
                    }
                    else
                    {
                        buzzer.ChangeState(GrovePi.Sensors.SensorStatus.Off);
                    }
                }
                catch (Exception ex)
                {
                    // NOTE: There are frequent exceptions of the following:
                    // WinRT information: Unexpected number of bytes was transferred. Expected: '. Actual: '.
                    // This appears to be caused by the rapid frequency of writes to the GPIO
                    // These are being swallowed here/

                    // If you want to see the exceptions uncomment the following:
                    // System.Diagnostics.Debug.WriteLine(ex.ToString());
                }
            }
        }
示例#2
0
 public void OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy)
 {
     if (sensor.Type == SensorType.Accelerometer)
     {
         Reading.AccelerationAccuracy = accuracy.ToString();
     }
 }
示例#3
0
        //TODO: store sensor accuracy in a global variable(one for each sensor(array?)), and then just update the variable in OnAccuracyChanged, and include it with The datapoints
        /// <summary>
        /// if a sensors accuracy changes then this gets called
        /// </summary>
        /// <param name="sensor"></param>
        /// <param name="accuracy"></param>
        public void OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy)
        {
            if (sensor != null)
            {
                debugLog("Sensor Accuracy changed, Sensor: " + sensor.Type);
                Log.Debug("HH_TEST", "Accuracy changed for: " + sensor.Type);
                //textView.Text = "Accuracy changed, sensor was: " + sensor.Type.ToString();

                if (stepCounter != null && sensor.Type == stepCounter.Type)
                {
                    debugLog("Accuracy changed for stepcounter");
                    accuracies[0] = accuracy.ToString("G");
                }
                else if (heartBeatsensor != null && sensor.Type == heartBeatsensor.Type)
                {
                    debugLog("Accuracy changed for heartbeat sensor");
                    accuracies[1] = accuracy.ToString("G");
                }
                else if (heartRatesensor != null && sensor.Type == heartRatesensor.Type)
                {
                    debugLog("Accuracy changed for heart rate sensor");
                    accuracies[2] = accuracy.ToString("G");
                }
            }

            if (sensor != null)
            {
                string type = sensor.Type.ToString("G");
                string acc  = accuracy.ToString();
                sensorStatusHandler.updateStatus(type + "accuracy changed(" + acc + ")");
            }
            else
            {
                sensorStatusHandler.updateStatus("Sensor accuracy changed");
            }
        }
示例#4
0
        private void OnTick(object sender, object e)
        {
            try
            {
                // Check the value of the button.

                string buttonon = button.CurrentState.ToString();
                // bool buttonison = buttonon.Equals("On", StringComparison.OrdinalIgnoreCase);
                System.Diagnostics.Debug.WriteLine("Button is " + buttonon);
            }
            catch (Exception ex)
            {
                // NOTE: There are frequent exceptions of the following:
                // WinRT information: Unexpected number of bytes was transferred. Expected: '. Actual: '.
                // This appears to be caused by the rapid frequency of writes to the GPIO
                // These are being swallowed here/

                // If you want to see the exceptions uncomment the following:
                // System.Diagnostics.Debug.WriteLine(ex.ToString());
            }

            try
            {
                System.Diagnostics.Debug.WriteLine("Brightness: " + brightness.ToString());

                // Check the brightness, if it's going to overflow, reset it.
                if (brightness > 250)
                {
                    brightness = 0;
                }

                // Increase the brightness by 5 points.
                brightness = brightness + 5;
                // Write the values to the three LEDs.
                // USA!  Red, White, and Blue!
                Led1.AnalogWrite(Convert.ToByte(brightness));
            }

            catch (Exception ex)
            {
                // NOTE: There are frequent exceptions of the following:
                // WinRT information: Unexpected number of bytes was transferred. Expected: '. Actual: '.
                // This appears to be caused by the rapid frequency of writes to the GPIO
                // These are being swallowed here/

                // If you want to see the exceptions uncomment the following:
                // System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            try
            {
                // Check the value of the button.

                string buttonon   = button.CurrentState.ToString();
                bool   buttonison = buttonon.Equals("On", StringComparison.OrdinalIgnoreCase);

                // Check the state of the buzzer.  This is just to output to debug!
                SensorStatus status   = buzzer.CurrentState;
                bool         buzzeron = status.ToString().Equals("On", StringComparison.OrdinalIgnoreCase);

                // Print out Diagnostics.
                System.Diagnostics.Debug.WriteLine("Button is " + buttonon);
                System.Diagnostics.Debug.WriteLine("Buzzer is " + status.ToString());

                // If the Button is on . . . .
                if (buttonison)
                {
                    buzzer.ChangeState(GrovePi.Sensors.SensorStatus.On);
                }
                else
                {
                    buzzer.ChangeState(GrovePi.Sensors.SensorStatus.Off);
                }
                try
                {
                    // Check the value of the button, turn it into a string.
                    string sensorvalue = light1.SensorValue().ToString();
                    System.Diagnostics.Debug.WriteLine("light is " + sensorvalue);
                }
                catch (Exception ex)
                {
                    // NOTE: There are frequent exceptions of the following:
                    // WinRT information: Unexpected number of bytes was transferred. Expected: '. Actual: '.
                    // This appears to be caused by the rapid frequency of writes to the GPIO
                    // These are being swallowed here/

                    // If you want to see the exceptions uncomment the following:
                    // System.Diagnostics.Debug.WriteLine(ex.ToString());
                }
            }
            catch (Exception ex)
            {
                // NOTE: There are frequent exceptions of the following:
                // WinRT information: Unexpected number of bytes was transferred. Expected: '. Actual: '.
                // This appears to be caused by the rapid frequency of writes to the GPIO
                // These are being swallowed here/

                // If you want to see the exceptions uncomment the following:
                // System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            //Task.Delay(100).Wait();     // Delay 0.1 second
            // We need to make sure we delay here.  If we don't, we won't be able to read
            // the LCD Screen.
            try
            {
                // First, output to the LCD Display.
                display.SetText("Light:" + light1.SensorValue()).SetBacklightRgb(255, 50, 255);
                // Then output to the debug window.
                System.Diagnostics.Debug.WriteLine("Hello from Dexter Industries!");
            }
            catch (Exception ex)
            {
                // NOTE: There are frequent exceptions of the following:
                // WinRT information: Unexpected number of bytes was transferred. Expected: '. Actual: '.
                // This appears to be caused by the rapid frequency of writes to the GPIO
                // These are being swallowed here/

                // If you want to see the exceptions uncomment the following:
                // System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            try
            {
                // Check the value of the Ultrasonic Sensor
                string sensorvalue = distance1.MeasureInCentimeters().ToString();
                System.Diagnostics.Debug.WriteLine("Ultrasonic reads " + sensorvalue);
            }
            catch (Exception ex)
            {
                // NOTE: There are frequent exceptions of the following:
                // WinRT information: Unexpected number of bytes was transferred. Expected: '. Actual: '.
                // This appears to be caused by the rapid frequency of writes to the GPIO
                // These are being swallowed here/

                // If you want to see the exceptions uncomment the following:
                // System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }