void TestCapacitiveUpdating()
        {
            Console.WriteLine("TestCapacitiveUpdating...");

            capacitive.Subscribe(new FilterableChangeObserver <FloatChangeResult, float>(
                                     h => {
                Console.WriteLine($"Moisture values: {Math.Truncate(h.New)}, old: {Math.Truncate(h.Old)}, delta: {h.DeltaPercent}");
            },
                                     e => {
                return(true);
            }
                                     ));

            capacitive.Updated += (object sender, FloatChangeResult e) =>
            {
                Console.WriteLine($"Moisture Updated: {e.New}");
            };

            capacitive.StartUpdating();
        }
Beispiel #2
0
        void Initialize()
        {
            Console.WriteLine("Initialize hardware...");

            onboardLed = new RgbPwmLed(device: Device,
                                       redPwmPin: Device.Pins.OnboardLedRed,
                                       greenPwmPin: Device.Pins.OnboardLedGreen,
                                       bluePwmPin: Device.Pins.OnboardLedBlue,
                                       3.3f, 3.3f, 3.3f,
                                       Meadow.Peripherals.Leds.IRgbLed.CommonType.CommonAnode);
            onboardLed.SetColor(Color.Red);

            button          = new PushButton(Device, Device.Pins.D04, ResistorMode.InternalPullUp);
            button.Clicked += ButtonClicked;

            var config = new SpiClockConfiguration
                         (
                speedKHz: 6000,
                mode: SpiClockConfiguration.Mode.Mode3
                         );
            var display = new St7789
                          (
                device: Device,
                spiBus: Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config),
                chipSelectPin: Device.Pins.D02,
                dcPin: Device.Pins.D01,
                resetPin: Device.Pins.D00,
                width: 240, height: 240
                          );

            displayController = new DisplayController(display);

            capacitive = new Capacitive(
                device: Device,
                analogPin: Device.Pins.A01,
                minimumVoltageCalibration: MINIMUM_VOLTAGE_CALIBRATION,
                maximumVoltageCalibration: MAXIMUM_VOLTAGE_CALIBRATION);
            capacitive.Subscribe(new FilterableChangeObserver <FloatChangeResult, float>(
                                     handler =>
            {
                onboardLed.SetColor(Color.Purple);

                displayController.UpdateMoistureImage(handler);
                displayController.UpdateMoisturePercentage(handler.New, handler.Old);

                onboardLed.SetColor(Color.Green);
            },
                                     filter =>
            {
                return(Math.Abs(filter.Delta) > 0.05);
            }
                                     ));
            capacitive.StartUpdating(
                sampleCount: 10,
                sampleIntervalDuration: 40,
                standbyDuration: (int)TimeSpan.FromHours(1).TotalMilliseconds);

            analogTemperature = new AnalogTemperature(Device, Device.Pins.A00, AnalogTemperature.KnownSensorType.LM35);
            analogTemperature.Subscribe(new FilterableChangeObserver <AtmosphericConditionChangeResult, AtmosphericConditions>(
                                            handler =>
            {
                onboardLed.SetColor(Color.Purple);

                displayController.UpdateTemperatureValue(handler.New.Temperature.Value, handler.Old.Temperature.Value);

                onboardLed.SetColor(Color.Green);
            },
                                            filter =>
            {
                return(Math.Abs(filter.Delta.Temperature.Value) > 1f);
            }
                                            ));
            analogTemperature.StartUpdating(
                sampleCount: 10,
                sampleIntervalDuration: 40,
                standbyDuration: (int)TimeSpan.FromHours(1).TotalMilliseconds);

            onboardLed.SetColor(Color.Green);
        }
Beispiel #3
0
        void Initialize()
        {
            onboardLed = new RgbPwmLed(
                device: Device,
                redPwmPin: Device.Pins.OnboardLedRed,
                greenPwmPin: Device.Pins.OnboardLedGreen,
                bluePwmPin: Device.Pins.OnboardLedBlue);
            onboardLed.SetColor(Color.Red);

            button          = new PushButton(Device, Device.Pins.D04, ResistorMode.InternalPullUp);
            button.Clicked += ButtonClicked;

            var config = new SpiClockConfiguration(
                speed: new Frequency(48000, Frequency.UnitType.Kilohertz),
                mode: SpiClockConfiguration.Mode.Mode3);
            var spiBus = Device.CreateSpiBus(
                clock: Device.Pins.SCK,
                copi: Device.Pins.MOSI,
                cipo: Device.Pins.MISO,
                config: config);
            var display = new St7789
                          (
                device: Device,
                spiBus: spiBus,
                chipSelectPin: Device.Pins.D02,
                dcPin: Device.Pins.D01,
                resetPin: Device.Pins.D00,
                width: 240, height: 240
                          );

            displayController = new DisplayController(display);

            capacitive = new Capacitive(
                device: Device,
                analogPin: Device.Pins.A01,
                minimumVoltageCalibration: MINIMUM_VOLTAGE_CALIBRATION,
                maximumVoltageCalibration: MAXIMUM_VOLTAGE_CALIBRATION);

            var capacitiveObserver = Capacitive.CreateObserver(
                handler: result =>
            {
                onboardLed.SetColor(Color.Purple);

                displayController.UpdateMoistureImage(result.New);
                displayController.UpdateMoisturePercentage(result.New, result.Old.Value);

                onboardLed.SetColor(Color.Green);
            },
                filter: null
                );

            capacitive.Subscribe(capacitiveObserver);

            capacitive.StartUpdating(TimeSpan.FromHours(1));

            analogTemperature = new AnalogTemperature(Device, Device.Pins.A00, AnalogTemperature.KnownSensorType.LM35);
            var analogTemperatureObserver = AnalogTemperature.CreateObserver(
                handler =>
            {
                onboardLed.SetColor(Color.Purple);

                displayController.UpdateTemperatureValue(handler.New, handler.Old.Value);

                onboardLed.SetColor(Color.Green);
            },
                filter: null
                );

            analogTemperature.Subscribe(analogTemperatureObserver);
            analogTemperature.StartUpdating(TimeSpan.FromHours(1));

            onboardLed.SetColor(Color.Green);
        }