This library implements RC6 (protocol used by some philips remotes). It has a receiver class and a transmitter class. Currently, only mode 0 is supported. It is tested with my DVD/HDD recorder.
Rc6.h@0:f8e2ed766064, 2011-02-27 (annotated)
- Committer:
- hilgo
- Date:
- Sun Feb 27 20:28:35 2011 +0000
- Revision:
- 0:f8e2ed766064
Initial revision: Receiver does not check framing yet (thus other remotes cause junk!)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hilgo | 0:f8e2ed766064 | 1 | /* mbed RC6 (Philips remote control protocol) library |
hilgo | 0:f8e2ed766064 | 2 | * Copyright (c) 2011 Jeroen Hilgers |
hilgo | 0:f8e2ed766064 | 3 | * |
hilgo | 0:f8e2ed766064 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
hilgo | 0:f8e2ed766064 | 5 | * of this software and associated documentation files (the "Software"), to deal |
hilgo | 0:f8e2ed766064 | 6 | * in the Software without restriction, including without limitation the rights |
hilgo | 0:f8e2ed766064 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
hilgo | 0:f8e2ed766064 | 8 | * copies of the Software, and to permit persons to whom the Software is |
hilgo | 0:f8e2ed766064 | 9 | * furnished to do so, subject to the following conditions: |
hilgo | 0:f8e2ed766064 | 10 | * |
hilgo | 0:f8e2ed766064 | 11 | * The above copyright notice and this permission notice shall be included in |
hilgo | 0:f8e2ed766064 | 12 | * all copies or substantial portions of the Software. |
hilgo | 0:f8e2ed766064 | 13 | * |
hilgo | 0:f8e2ed766064 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
hilgo | 0:f8e2ed766064 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
hilgo | 0:f8e2ed766064 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
hilgo | 0:f8e2ed766064 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
hilgo | 0:f8e2ed766064 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
hilgo | 0:f8e2ed766064 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
hilgo | 0:f8e2ed766064 | 20 | * THE SOFTWARE. |
hilgo | 0:f8e2ed766064 | 21 | */ |
hilgo | 0:f8e2ed766064 | 22 | |
hilgo | 0:f8e2ed766064 | 23 | #ifndef __RC6_H__ |
hilgo | 0:f8e2ed766064 | 24 | #define __RC6_H__ |
hilgo | 0:f8e2ed766064 | 25 | |
hilgo | 0:f8e2ed766064 | 26 | #include "mbed.h" |
hilgo | 0:f8e2ed766064 | 27 | |
hilgo | 0:f8e2ed766064 | 28 | /** RC6 (Philips remote control) receiver / transmitter library. |
hilgo | 0:f8e2ed766064 | 29 | * |
hilgo | 0:f8e2ed766064 | 30 | * Example: Code receiver for 'play/pause' on remote for Philips HDD&DVD recorder. |
hilgo | 0:f8e2ed766064 | 31 | * |
hilgo | 0:f8e2ed766064 | 32 | * Leader |S3|S2|S1|S0|Togl|A7|A6|A5|A4|A3|A2|A1|A0|D7|D6|D5|D4|D3|D2|D1|D0| |
hilgo | 0:f8e2ed766064 | 33 | * |1 |0 |0 |0 |1 |0 |0 |1 |1 |0 |0 |1 |0 |0 |0 |1 |0 |1 |1 |0 |0 | |
hilgo | 0:f8e2ed766064 | 34 | * | | | | | | | | | | | | | | | | | | | | | | |
hilgo | 0:f8e2ed766064 | 35 | * ------ |- | -| -| -|-- | -| -|- |- | -| -|- | -| -| -|- | -|- |- | -| -| |
hilgo | 0:f8e2ed766064 | 36 | * --| -|- |- |- | --|- |- | -| -|- |- | -|- |- |- | -|- | -| -|- |- | |
hilgo | 0:f8e2ed766064 | 37 | * | | | | | | | | | | | | | | | | | | | | | | |
hilgo | 0:f8e2ed766064 | 38 | * |
hilgo | 0:f8e2ed766064 | 39 | * The toggle bit is in bit 16, A7-A0 in bits 15-8, D7-D0 in bits 7-0. |
hilgo | 0:f8e2ed766064 | 40 | * Thus for the example, 0x1322C is returned. S3..S0 are not implemented |
hilgo | 0:f8e2ed766064 | 41 | * and received / transmitted as shown in the example. |
hilgo | 0:f8e2ed766064 | 42 | */ |
hilgo | 0:f8e2ed766064 | 43 | |
hilgo | 0:f8e2ed766064 | 44 | class Rc6Transmitter |
hilgo | 0:f8e2ed766064 | 45 | { |
hilgo | 0:f8e2ed766064 | 46 | public: |
hilgo | 0:f8e2ed766064 | 47 | /** Create a Rc6Transmitter and initizalize it. |
hilgo | 0:f8e2ed766064 | 48 | * |
hilgo | 0:f8e2ed766064 | 49 | * @param pin irPin pin connected IR Led (led on on high level). |
hilgo | 0:f8e2ed766064 | 50 | */ |
hilgo | 0:f8e2ed766064 | 51 | Rc6Transmitter(PinName irPin); |
hilgo | 0:f8e2ed766064 | 52 | |
hilgo | 0:f8e2ed766064 | 53 | /** Send a code once. |
hilgo | 0:f8e2ed766064 | 54 | * The function will return synchronously and send the code once. |
hilgo | 0:f8e2ed766064 | 55 | * |
hilgo | 0:f8e2ed766064 | 56 | * @param code Code to send. |
hilgo | 0:f8e2ed766064 | 57 | */ |
hilgo | 0:f8e2ed766064 | 58 | void Send(uint32_t code); |
hilgo | 0:f8e2ed766064 | 59 | |
hilgo | 0:f8e2ed766064 | 60 | /** Check if the transmitter is idle. |
hilgo | 0:f8e2ed766064 | 61 | * |
hilgo | 0:f8e2ed766064 | 62 | * @return True if transmitter still busy. |
hilgo | 0:f8e2ed766064 | 63 | */ |
hilgo | 0:f8e2ed766064 | 64 | bool IsBusy(); |
hilgo | 0:f8e2ed766064 | 65 | |
hilgo | 0:f8e2ed766064 | 66 | private: |
hilgo | 0:f8e2ed766064 | 67 | void Tick(); |
hilgo | 0:f8e2ed766064 | 68 | |
hilgo | 0:f8e2ed766064 | 69 | bool mBusy; |
hilgo | 0:f8e2ed766064 | 70 | uint16_t mPattern[50]; // 1 leader, 4 startbits, 1 toggle bit, 16 data bits ==> |
hilgo | 0:f8e2ed766064 | 71 | // at most 24 mark / pause durations + 0,0 terminator = 50 entries. |
hilgo | 0:f8e2ed766064 | 72 | Ticker mTicker; |
hilgo | 0:f8e2ed766064 | 73 | uint16_t mMark; // Tick: Remaining half-cycles of mark. |
hilgo | 0:f8e2ed766064 | 74 | uint16_t mPause; // Tick: Remaining half-cycles of pause. |
hilgo | 0:f8e2ed766064 | 75 | uint16_t *mPatPtr; // Transitter pointer. |
hilgo | 0:f8e2ed766064 | 76 | DigitalOut mOut; // Pin connected to IR. |
hilgo | 0:f8e2ed766064 | 77 | }; |
hilgo | 0:f8e2ed766064 | 78 | |
hilgo | 0:f8e2ed766064 | 79 | class Rc6Receiver |
hilgo | 0:f8e2ed766064 | 80 | { |
hilgo | 0:f8e2ed766064 | 81 | public: |
hilgo | 0:f8e2ed766064 | 82 | /** Create a Rc6Receiver and initizalize it. |
hilgo | 0:f8e2ed766064 | 83 | * |
hilgo | 0:f8e2ed766064 | 84 | * @param pin irPin pin connected to IR sensor (low level when IR is received, e.g. TSOP1736). |
hilgo | 0:f8e2ed766064 | 85 | */ |
hilgo | 0:f8e2ed766064 | 86 | Rc6Receiver(PinName irPin); |
hilgo | 0:f8e2ed766064 | 87 | |
hilgo | 0:f8e2ed766064 | 88 | /** Check if anything was received since last poll. Returns 0xFFFFFFFF if not. |
hilgo | 0:f8e2ed766064 | 89 | * |
hilgo | 0:f8e2ed766064 | 90 | * @return Last code received or 0xFFFFFFFF if nothing was received since last poll. |
hilgo | 0:f8e2ed766064 | 91 | */ |
hilgo | 0:f8e2ed766064 | 92 | uint32_t Receive(); |
hilgo | 0:f8e2ed766064 | 93 | |
hilgo | 0:f8e2ed766064 | 94 | private: |
hilgo | 0:f8e2ed766064 | 95 | InterruptIn irq; |
hilgo | 0:f8e2ed766064 | 96 | void OnRise(); |
hilgo | 0:f8e2ed766064 | 97 | void OnFall(); |
hilgo | 0:f8e2ed766064 | 98 | void OnTimeout(); |
hilgo | 0:f8e2ed766064 | 99 | Timeout mTimeout; |
hilgo | 0:f8e2ed766064 | 100 | Timer mTimer; |
hilgo | 0:f8e2ed766064 | 101 | bool mBusy; |
hilgo | 0:f8e2ed766064 | 102 | uint32_t mCode; |
hilgo | 0:f8e2ed766064 | 103 | uint32_t mLastCode; |
hilgo | 0:f8e2ed766064 | 104 | }; |
hilgo | 0:f8e2ed766064 | 105 | |
hilgo | 0:f8e2ed766064 | 106 | #endif // __RC6_H__ |