/// <summary> /// Writes a value to the pin. /// </summary> /// <param name="value">Write Value (0/1) <see cref="GpioPinValue"/>.</param> public void Write(ProviderGpioPinValue value) { this.pin.Write(GpioPinValue.High); var val = (GpioPinValue)value; this.pin.Write(val); }
/// <summary> /// Create native reader for values (read bytes vaules) /// </summary> public void ReadValues() { int MAX_TIMINGS = 85; int[] dht11_dat = new int[5] { 0, 0, 0, 0, 0 }; dht11_dat[0] = dht11_dat[1] = dht11_dat[2] = dht11_dat[3] = dht11_dat[4] = 0; byte counter = 0; byte j = 0, i; ProviderGpioPinValue laststate = ProviderGpioPinValue.High; SetUpNativeSensor(); for (int k = 0; k < 20; k++) { for (i = 0; i < MAX_TIMINGS; i++) { counter = 0; while (this.nativePin.Read() == (ProviderGpioPinValue)laststate) { counter++; Task.Delay(1); if (counter == 255) { break; } } laststate = (ProviderGpioPinValue)this.nativePin.Read(); if (counter == 255) { break; } // Skip first 3 samples if ((i >= 4) && (i % 2 == 0)) { dht11_dat[j / 8] <<= 1; if (counter > 16) { dht11_dat[j / 8] |= 1; } j++; } } if ((j >= 40) && (dht11_dat[4] == ((dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]) & 0xFF))) { if (!(dht11_dat[0] == 0) && (dht11_dat[2] == 0)) { this.Message += "\n\n" + string.Format("Humidity = {0}.{1} | Temperature = {2}.{3} * C", dht11_dat[0], dht11_dat[1], dht11_dat[2], dht11_dat[3]); } } this.Message += "\n\n" + string.Format("Humidity = {0}.{1} | Temperature = {2}.{3} * C", 0, 0, 0, 0); } }