private static void ConsumePulse(TimeSpan width, bool state) { DateTime now = DateTime.Now; if (now < _nextCommand) return; long usWidth = width.TotalMicroseconds(); //czekamy na 1 if (state) { if (usWidth > MinWidth && usWidth < MaxWidth) _okImpulses++; } else { if (_okImpulses == 1) { if (usWidth > MinWidth && usWidth < MaxWidth) Debug.Print("RC5!"); _okImpulses = 0; _nextCommand = now.AddMilliseconds(500); } } }
public static float ToInches(TimeSpan pulse) { if (pulse.Equals(TimeSpan.MaxValue)) return Single.MaxValue; float result = pulse.TotalMicroseconds()/148f; return result; }
private void ConsumePulse(TimeSpan width, bool state) { long usWidth = width.TotalMicroseconds(); //poczatek ramki if (usWidth > NextFrame || _cnt == 0) { _cnt = 1; _prevBit = false; //zawsze zaczyna sie od 0 _frame = 0; return; } if (_cnt == 0) return; //jesli szerokosc impulsu szersza niz 1 bit to dwa bity int bitCnt = usWidth > MaxOneBitTime ? 2 : 1; for (int i = 1; i <= bitCnt; i++) { _cnt++; if (_cnt%2 == 0) DecodeMenchester(_prevBit, state); //co dwa bity dekodujemy bit ramki else { //jesli juz mamy przedostatni bit to nie czekamy na ostatni mamy ca³¹ ramkê if (_cnt == 27) { _cnt++; //ostatni bit jest przeciwienstwem przedostatniego //tutaj b³¹d w dekodowaniu menchester nie moze siê pojawiæ DecodeMenchester(state, !state); //mamy ramke OnFrame(_frame); //zaczynamy od nowa _cnt = 0; } else _prevBit = state; //to tylko kolejny bit } } }