Exemplo n.º 1
0
        private void StartMonitoring()
        {
            this.txtOutput.Text = string.Empty;

            this.txtOutput.Text = DateTime.Now.Ticks.ToString() + "\n";

            var gpio = GpioController.GetDefault();

            //setPin = gpio.OpenPin(SET_PIN);
            _clockPin = gpio.OpenPin(CLOCK_PIN);
            _dataPin = gpio.OpenPin(DATA_PIN);

            //_clockPin.SetDriveMode(GpioPinDriveMode.Output);
            //_dataPin.SetDriveMode(GpioPinDriveMode.Input);

            //byte data[3];

            //// pulse the clock pin 24 times to read the data
            //for (byte j = 3; j--;)
            //{
            //    for (char i = 8; i--;)
            //    {
            //        digitalWrite(PD_SCK, HIGH);
            //        bitWrite(data[j], i, digitalRead(DOUT));
            //        digitalWrite(PD_SCK, LOW);
            //}

            //for (byte j = 3; j <= 0; j--)            {
            //    this.txtOutput.Text += "j " + j.ToString() + "\n";

            //}

            var c = 0;

            for (int j = 2; j >= 0; j--)
            {
                this.txtOutput.Text += "Byte:" + j + "\n";

                for (int i = 7; i >= 0; i--)
                {
                    _clockPin.Write(GpioPinValue.High);
                    var dataPinValue = _dataPin.Read();
                    _clockPin.Write(GpioPinValue.Low);

                    if (dataPinValue == GpioPinValue.Low)
                    {
                        var yay = true;
                    }

                    this.txtOutput.Text += dataPinValue + "\n";

                    c++;

                }
            }

            // Release the GPIO pins.
            if (_dataPin != null)
            {
                _dataPin.Dispose();
                _dataPin = null;
            }

            if (_clockPin != null)
            {
                _clockPin.Dispose();
                _clockPin = null;
            }
        }