/// <summary> /// Encode a word, along with it repeats, into a sequence of segments /// </summary> /// <remarks> /// Because the IguanaWorks client has a built-in timeout that /// can't deal with sequences that are too long, every repeat /// will have its own sequence. /// </remarks> public IEnumerable<IEnumerable<Segment>> EncodeWord(RC5Word word) { var result = Enumerable.Range(0, word.Count) .SelectMany(_ => new IEnumerable<Segment>[] { EncodeWithoutRepeat(word), // Have a word sleep after every word, so we can arbitrarily append // encoded words new Segment[] { new Segment(false, RepeatPauseUsec) } }); state.ToggleBit = !state.ToggleBit; return result; }
/// <summary> /// Encode a word, along with it repeats, into a sequence of segments /// </summary> /// <remarks> /// Because the IguanaWorks client has a built-in timeout that /// can't deal with sequences that are too long, every repeat /// will have its own sequence. /// </remarks> public IEnumerable <IEnumerable <Segment> > EncodeWord(RC5Word word) { var result = Enumerable.Range(0, word.Count) .SelectMany(_ => new IEnumerable <Segment>[] { EncodeWithoutRepeat(word), // Have a word sleep after every word, so we can arbitrarily append // encoded words new Segment[] { new Segment(false, RepeatPauseUsec) } }); state.ToggleBit = !state.ToggleBit; return(result); }
/// <summary> /// Return the bits that need to be encoded for a word /// </summary> private IEnumerable<bool> WordBits(RC5Word word) { return new bool[] { true, (word.Command & 0x40) == 0, // Note: bit inverted state.ToggleBit, // System (word.System & 0x10) != 0, (word.System & 0x08) != 0, (word.System & 0x04) != 0, (word.System & 0x02) != 0, (word.System & 0x01) != 0, // Command (word.Command & 0x20) != 0, (word.Command & 0x10) != 0, (word.Command & 0x08) != 0, (word.Command & 0x04) != 0, (word.Command & 0x02) != 0, (word.Command & 0x01) != 0 }; }
/// <summary> /// Return the bits that need to be encoded for a word /// </summary> private IEnumerable <bool> WordBits(RC5Word word) { return(new bool[] { true, (word.Command & 0x40) == 0, // Note: bit inverted state.ToggleBit, // System (word.System & 0x10) != 0, (word.System & 0x08) != 0, (word.System & 0x04) != 0, (word.System & 0x02) != 0, (word.System & 0x01) != 0, // Command (word.Command & 0x20) != 0, (word.Command & 0x10) != 0, (word.Command & 0x08) != 0, (word.Command & 0x04) != 0, (word.Command & 0x02) != 0, (word.Command & 0x01) != 0 }); }
/// <summary> /// Encode a single RC5 Word into a sequence of segments, ignoring repeats /// </summary> private IEnumerable<Segment> EncodeWithoutRepeat(RC5Word word) { return WordBits(word).SelectMany(BitToTransition); }
/// <summary> /// Transmit an RC5 word according to the repeat count inside /// </summary> public void Transmit(RC5Word word) { encoder.EncodeWord(word).Each(client.TransmitSequence); }
/// <summary> /// Encode a single RC5 Word into a sequence of segments, ignoring repeats /// </summary> private IEnumerable <Segment> EncodeWithoutRepeat(RC5Word word) { return(WordBits(word).SelectMany(BitToTransition)); }