Exemple #1
0
 /// <summary>
 /// Reset the onboard oled screen by switching off/on the reset pin.
 /// </summary>
 public void Reset()
 {
     oledReset?.Write(PinValue.Low);
     Thread.Sleep(100);
     oledReset?.Write(PinValue.High);
     Thread.Sleep(100);
 }
Exemple #2
0
 private void On()
 {
     if (!CurrentState.IsFiring)
     {
         //Logger.LogInformation($"SSR: {Id} - ON {_millisOn}");
         _pin?.Write(GpioPinValue.High);
         PriorState            = CurrentState;
         CurrentState          = CurrentState.Fire(true);
         CurrentState.IsFiring = true;
         SendNotification();
     }
 }
Exemple #3
0
        public void Switch(SSRState state)
        {
            switch (state)
            {
            case SSRState.On:
                _gpioPin?.Write(GpioPinValue.High);
                break;

            case SSRState.Off:
                _gpioPin?.Write(GpioPinValue.Low);
                break;
            }
            State = state;
        }
Exemple #4
0
        private async void Timer_Tick(object sender, object e)
        {
            // Switch off status LEDs
            redStatus?.Write(GpioPinValue.Low);
            greenStatus?.Write(GpioPinValue.Low);

            // Collect temperature and humidity
            var temp  = shield.GetTemperature();
            var humid = shield.GetHumidity();

            tempMeasurements.Add(temp);
            humidMeasurements.Add(humid);

            // Update UI
            TempValue.Text     = Math.Round(temp, 2) + " \u00B0C";
            HumidityValue.Text = Math.Round(humid, 2) + "%";
            UpdateValue.Text   = DateTime.Now.ToString();

            // Send average of collected humid and temp once every full 30 minutes
            var minute = DateTime.Now.Minute;

            if (minute == 00 || minute == 30)
            {
                // Ensures, that only one message is sent per minute
                if (!thisMinutesMessageSent)
                {
                    thisMinutesMessageSent = true;
                    await SendAvgTempAndHumidAsync();
                }
            }
            else
            {
                thisMinutesMessageSent = false;
            }
        }
        public async Task <bool> Initialiser(uint largeur, uint hauteur, string sousTypeVideo)
        {
            bool res = false;

            _ledOccupe?.Write(GpioPinValue.High);
            _mediaCapture = new MediaCapture();
            await _mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings()
            {
                SharingMode          = MediaCaptureSharingMode.ExclusiveControl,
                MemoryPreference     = MediaCaptureMemoryPreference.Cpu,
                StreamingCaptureMode = StreamingCaptureMode.Video
            });

            res = await InitialiserSourceImages(largeur, hauteur, sousTypeVideo);

            _ledOccupe?.Write(GpioPinValue.Low);
            return(res);
        }
Exemple #6
0
        private async void ProcessTimerTick(object sender, object e)
        {
            _secondsUntilLaunch--;

            if (_secondsUntilLaunch > 0)
            {
                await ProvideStatusUpdate(_secondsUntilLaunch.ToString());
            }
            else if (_secondsUntilLaunch == 0)
            {
                Status.Text = "Lift off";
                _pin?.Write(GpioPinValue.Low);
            }
            else if (_secondsUntilLaunch < 0)
            {
                _pin?.Write(GpioPinValue.High);
                _controlTimer.Stop();
                RecordLaunch();
            }
        }
        private async void _lecteurMedia_FrameArrived(MediaFrameReader sender, MediaFrameArrivedEventArgs args)
        {
            lock (_photoAPrendreLOCK)
            {
                if (_photoAPrendre != 1)
                {
                    return;
                }
                _photoAPrendre++;
            }

            _ledOccupe?.Write(GpioPinValue.High);
            MediaFrameReference imageCourante = sender.TryAcquireLatestFrame();

            if (!(imageCourante == null || imageCourante.VideoMediaFrame == null || imageCourante.VideoMediaFrame.SoftwareBitmap == null))
            {
                await EnregistrerImage(imageCourante);

                lock (_photoAPrendreLOCK) { _photoAPrendre = 0; }
            }
            _ledOccupe?.Write(GpioPinValue.Low);
        }
Exemple #8
0
        private void PumpStateRequestOccured(ComponentStateRequest <PumpRequestState> pumpRequestState)
        {
            bool correctPump = pumpRequestState.Id == CurrentState.Id;

            if (pumpRequestState.Id == CurrentState.Id && CurrentState.IsDifferent(pumpRequestState.RequestState))
            {
                CurrentState = CurrentState.Update(pumpRequestState.RequestState);

                if (CurrentState.IsEngaged)
                {
                    _pin?.Write(GpioPinValue.High);
                }
                else
                {
                    _pin?.Write(GpioPinValue.Low);
                }

                Logger.LogInformation($"Pump: {CurrentState.Id} - {CurrentState.IsEngaged}");

                _eventHandler.ComponentStateChangeFiring(new ComponentStateChange <PumpState> {
                    CurrentState = CurrentState.Clone()
                });
            }
        }
Exemple #9
0
        private async void Twitter_Tick(ThreadPoolTimer timer)
        {
            var lastTweet = await _twitter.GetTweet();

            if (lastTweet.user == null)
            {
                return;
            }

            var onOffstr = lastTweet.on ? "ligar" : "desligar";

            _pinLed?.Write(lastTweet.on ? GpioPinValue.High : GpioPinValue.Low);

            await _dispacher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                this.txbMessage1.Text  = $"{lastTweet.user} \nmandou {onOffstr}!";
                this.imgProfile.Source = new BitmapImage(new Uri(lastTweet.image));
            });
        }
Exemple #10
0
        /// <summary>
        /// Write either command or data, with automatic 4/8-bit selection
        /// </summary>
        /// <param name="value">value to write</param>
        /// <param name="mode">Mode for RS (register select) pin.</param>
        /// <param name="backlight">Backlight state.</param>
        public void Send(byte value, bool mode, bool backlight)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException();
            }

            _rsPort.Write(mode ? GpioPinValue.High : GpioPinValue.Low);

            // if there is a RW pin indicated, set it low to Write
            _rwPort?.Write(GpioPinValue.Low);

            if (!FourBitMode)
            {
                Write8Bits(value);
            }
            else
            {
                Write4Bits((byte)(value >> 4));
                Write4Bits(value);
            }
        }
Exemple #11
0
 private void TurnLedOn()
 {
     pinValue = GpioPinValue.Low;
     pin.Write(pinValue);
 }
Exemple #12
0
 public void PowerON()
 {
     oledVext?.Write(PinValue.Low); // based on Heltec.cpp:Heltec_ESP32::VextON()
     Thread.Sleep(100);
 }
Exemple #13
0
 private void setPinStatus(GpioPin pin, GpioPinValue value)
 {
     pin.Write(value);
 }
Exemple #14
0
 // Set the red led state
 private void redLedState(GpioPinValue val)
 {
     redLed?.Write(val);
 }
Exemple #15
0
        public Byte RegisterReadByte(byte address)
        {
            byte[] writeBuffer = new byte[] { address &= RegisterAddressReadMask };
            byte[] readBuffer  = new byte[1];
            Debug.Assert(Rfm9XLoraModem != null);

            ChipSelectGpioPin.Write(GpioPinValue.Low);
            Rfm9XLoraModem.Write(writeBuffer);
            Rfm9XLoraModem.Read(readBuffer);
            ChipSelectGpioPin.Write(GpioPinValue.High);

            return(readBuffer[0]);
        }
 public void On()
 {
     pin.Write(GpioPinValue.High);
 }
Exemple #17
0
 public void SwitchOn()
 {
     gpiPin.Write(GpioPinValue.High);
     Sequence.Add(new Tuple <Color, string>(this.color, gpiPin.Read().ToString()));
 }
Exemple #18
0
 void Pulse(GpioPin pin)
 {
     pin.Write(GpioPinValue.Low);
     pin.Write(GpioPinValue.High);
 }
 /// <summary>
 /// Disables the module (power off).
 /// </summary>
 public void Disable()
 {
     //serialPort.Close(); TODO: No support in UWP does anything need to happen instead?
     resetControl.Write(ResetState.NotRunning);
 }
Exemple #20
0
        private bool Read()
        {
            var now = DateTime.UtcNow;

            if (!_firstReading && ((now - _prevReading).TotalMilliseconds < 2000))
            {
                return(false);
            }

            _firstReading = false;
            _prevReading  = now;;

            _data[0] = _data[1] = _data[2] = _data[3] = _data[4] = 0;

            _dataPin.PinMode = GpioPinDriveMode.Output;

            _dataPin.Write(GpioPinValue.High);

            Thread.Sleep(250);

            _dataPin.Write(GpioPinValue.Low);

            Thread.Sleep(20);

            //TIME CRITICAL ###############
            _dataPin.Write(GpioPinValue.High);
            //=> DELAY OF 40 microseconds needed here
            WaitMicroseconds(40);

            _dataPin.PinMode = GpioPinDriveMode.Input;
            //Delay of 10 microseconds needed here
            WaitMicroseconds(10);

            if (ExpectPulse(GpioPinValue.Low) == 0)
            {
                return(false);
            }
            if (ExpectPulse(GpioPinValue.High) == 0)
            {
                return(false);
            }

            // Now read the 40 bits sent by the sensor.  Each bit is sent as a 50
            // microsecond low pulse followed by a variable length high pulse.  If the
            // high pulse is ~28 microseconds then it's a 0 and if it's ~70 microseconds
            // then it's a 1.  We measure the cycle count of the initial 50us low pulse
            // and use that to compare to the cycle count of the high pulse to determine
            // if the bit is a 0 (high state cycle count < low state cycle count), or a
            // 1 (high state cycle count > low state cycle count).
            for (int i = 0; i < 40; ++i)
            {
                UInt32 lowCycles = ExpectPulse(GpioPinValue.Low);
                if (lowCycles == 0)
                {
                    return(false);
                }
                UInt32 highCycles = ExpectPulse(GpioPinValue.High);
                if (highCycles == 0)
                {
                    return(false);
                }
                _data[i / 8] <<= 1;
                // Now compare the low and high cycle times to see if the bit is a 0 or 1.
                if (highCycles > lowCycles)
                {
                    // High cycles are greater than 50us low cycle count, must be a 1.
                    _data[i / 8] |= 1;
                }
                // Else high cycles are less than (or equal to, a weird case) the 50us low
                // cycle count so this must be a zero.  Nothing needs to be changed in the
                // stored data.
            }
            //TIME CRITICAL_END #############

            // Check we read 40 bits and that the checksum matches.
            if (_data[4] == ((_data[0] + _data[1] + _data[2] + _data[3]) & 0xFF))
            {
                return(true);
            }
            else
            {
                //Checksum failure!
                return(false);
            }
        }
Exemple #21
0
        /// <summary>
        /// Initializes the RainbowHAT. It will setup all required
        /// GPIO pins.
        ///
        /// Caution:
        ///     This is required before accessing other
        ///     methods in this class.
        /// </summary>
        private async void InitializeAsync()
        {
            Logger.Log(this, "Starting InitializeAsync");

            // Check if drivers are enabled
            Logger.Log(this, "Checking for LightningProvider");
            if (!LightningProvider.IsLightningEnabled)
            {
                Logger.Log(this, "LightningProvider not enabled. Returning.");
                return;
            }

            // Aggregate provider.
            LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();

            // Get default controllers.
            Logger.Log(this, "Getting default controller.");
            pwmController  = (await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider()))[1];
            gpioController = await GpioController.GetDefaultAsync();

            i2cController = await I2cController.GetDefaultAsync();

            // Ensure requiored controllers are available.
            if (gpioController == null || i2cController == null || pwmController == null)
            {
                Logger.Log(this, "One or more controller missing.");
                return;
            }

            // Setup controllers.
            pwmController.SetDesiredFrequency(50);

            // Setup LEDs.
            Logger.Log(this, "Setup LEDs");
            redPin = gpioController.OpenPin(GPIO_NUMBER_RED);
            redPin.Write(GpioPinValue.Low);
            redPin.SetDriveMode(GpioPinDriveMode.Output);
            greenPin = gpioController.OpenPin(GPIO_NUMBER_GREEN);
            greenPin.Write(GpioPinValue.Low);
            greenPin.SetDriveMode(GpioPinDriveMode.Output);
            bluePin = gpioController.OpenPin(GPIO_NUMBER_BLUE);
            bluePin.Write(GpioPinValue.Low);
            bluePin.SetDriveMode(GpioPinDriveMode.Output);

            // Setup buttons
            Logger.Log(this, "Setup buttons");
            buttonAPin = gpioController.OpenPin(21);
            buttonAPin.SetDriveMode(GpioPinDriveMode.Input);
            buttonBPin = gpioController.OpenPin(20);
            buttonBPin.SetDriveMode(GpioPinDriveMode.Input);
            buttonCPin = gpioController.OpenPin(16);
            buttonCPin.SetDriveMode(GpioPinDriveMode.Input);

            // Setup buzzer
            Logger.Log(this, "Setup buzzers / servos / motors");
            buzzerPin = pwmController.OpenPin(GPIO_NUMBER_BUZZER);
            buzzerPin.SetActiveDutyCyclePercentage(0.05);

            // Setup timer.
            Logger.Log(this, "Setup timers");
            captiveButtonsValueReadTimer = ThreadPoolTimer.CreatePeriodicTimer(CaptiveButtonsValueReadTimer_Tick, BUTTON_READ_INTERVAL);
            temperatureValueReadTimer    = ThreadPoolTimer.CreatePeriodicTimer(TemperatureValueReadTimer_Tick, SENSOR_READ_INTERVAL);
            pressureValueReadTimer       = ThreadPoolTimer.CreatePeriodicTimer(PreassureValueReadTimer_Tick, SENSOR_READ_INTERVAL);

            // Initialze child devices
            Logger.Log(this, "Setup APA102");
            apa102.Initialize(gpioController);

            Logger.Log(this, "Setup BMP280");
            await bmp280.InitializeAsync(i2cController);

            Logger.Log(this, "Setup HT16K33");
            ht16k33.Initialize(i2cController);

            // Set device as intialized.
            Logger.Log(this, "Finished InitializeAsync");
            isInitialized = true;
        }
Exemple #22
0
        /// <summary>
        /// Performs the given action on the RainbowHAT
        /// </summary>
        /// <param name="action">Action to perform.</param>
        public void PerformAction(RainbowHATAction action)
        {
            // Ensure device has been initialized.
            if (!isInitialized)
            {
                Logger.Log(this, "Device is not initialized, yet. Retrying `PerformAction(...)` soon again.");
                ThreadPoolTimer.CreateTimer((ThreadPoolTimer threadPoolTimer) => { PerformAction(action); }, TimeSpan.FromSeconds(PERFORM_ACTION_COOLDOWN_SECONDS));
                return;
            }

            // Try perform action.
            Logger.Log(this, $"PerformAction called with '{action}' action.");
            switch (action)
            {
            case RainbowHATAction.TurnOnRed:
                redPin.Write(GpioPinValue.High);
                break;

            case RainbowHATAction.TurnOffRed:
                redPin.Write(GpioPinValue.Low);
                break;

            case RainbowHATAction.TurnOnGreen:
                greenPin.Write(GpioPinValue.High);
                break;

            case RainbowHATAction.TurnOffGreen:
                greenPin.Write(GpioPinValue.Low);
                break;

            case RainbowHATAction.TurnOnBlue:
                bluePin.Write(GpioPinValue.High);
                break;

            case RainbowHATAction.TurnOffBlue:
                bluePin.Write(GpioPinValue.Low);
                break;

            case RainbowHATAction.LEDsOn:
                apa102.TurnOn();
                break;

            case RainbowHATAction.LEDsOff:
                apa102.TurnOff();
                break;

            case RainbowHATAction.Buzz:
                buzzerPin.Start();
                ThreadPoolTimer.CreateTimer((ThreadPoolTimer threadPoolTimer) => { buzzerPin.Stop(); }, TimeSpan.FromMilliseconds(500));
                break;

            case RainbowHATAction.ShowRainbow:
                apa102.ShowColors();
                break;

            case RainbowHATAction.ShowDemo:
                redPin.Write(GpioPinValue.High);
                greenPin.Write(GpioPinValue.High);
                bluePin.Write(GpioPinValue.High);
                apa102.ShowColors();
                ht16k33.Show("Demo");
                break;

            default:
                Logger.Log(this, $"Unknown action should be performed: {action}");
                break;
            }
        }
Exemple #23
0
 private void OnBTN_Click(object sender, RoutedEventArgs e)
 {
     _pin21.Write(GpioPinValue.High);
 }
Exemple #24
0
 public bool turnON()
 {
     // Drive the pin to low to have current flow into the LED
     pin.Write(GpioPinValue.Low);
     return(State());
 }
Exemple #25
0
 private void btnGPIONo_Click(object sender, RoutedEventArgs e)
 {
     ledPin.Write(GpioPinValue.Low);
     ledPin.SetDriveMode(GpioPinDriveMode.Output);
 }
Exemple #26
0
 public void MoveForward()
 {
     _motorGpioPinA.Write(GpioPinValue.Low);
     _motorGpioPinB.Write(GpioPinValue.High);
 }
 private static void ToggleLED()
 {
     LEDOn = !LEDOn;
     LED?.Write(LEDOn ? GpioPinValue.High : GpioPinValue.Low);
 }
Exemple #28
0
 // Set the orange led state
 private void orangeLedState(GpioPinValue val)
 {
     orangeLed?.Write(val);
 }
 /// <summary>
 /// Sets the sleep control pin to active state (sleep request).
 /// </summary>
 public void Sleep()
 {
     sleepControl.Write(SleepState.Sleeping);
 }
Exemple #30
0
 public void StopBuzz(GpioPin pin)
 {
     pin.Write(GpioPinValue.Low);
 }