This library is a very low level interface to a transmit IR codes. Other libraries could be built on top of it to transmit different manufactures codes, or a specific code. I use the library to remotely trigger a Nikon DSLR camera the same way an ML3 Nikon remote does.

Committer:
ASaidi
Date:
Sun Dec 12 05:40:01 2010 +0000
Revision:
1:208b4f080b2f
Parent:
0:7d2088337345

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ASaidi 0:7d2088337345 1
ASaidi 1:208b4f080b2f 2 /**
ASaidi 0:7d2088337345 3 * Low level infrared transmission
ASaidi 0:7d2088337345 4 * This library provides a low level interface to send IR commands. in principle
ASaidi 0:7d2088337345 5 * other higher level IR type remotes could be build on top of this. I wrote
ASaidi 0:7d2088337345 6 * this code to send IR commands to a Nikon camera, which it works rather well
ASaidi 0:7d2088337345 7 * for.
ASaidi 0:7d2088337345 8 *
ASaidi 0:7d2088337345 9 * Copyright (C) 2010 Ali Saidi
ASaidi 0:7d2088337345 10 *
ASaidi 0:7d2088337345 11 * Permission is hereby granted, free of charge, to any person obtaining a copy
ASaidi 0:7d2088337345 12 * of this software and associated documentation files (the "Software"), to deal
ASaidi 0:7d2088337345 13 * in the Software without restriction, including without limitation the rights
ASaidi 0:7d2088337345 14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ASaidi 0:7d2088337345 15 * copies of the Software, and to permit persons to whom the Software is
ASaidi 0:7d2088337345 16 * furnished to do so, subject to the following conditions:
ASaidi 0:7d2088337345 17 *
ASaidi 0:7d2088337345 18 * The above copyright notice and this permission notice shall be included in
ASaidi 0:7d2088337345 19 * all copies or substantial portions of the Software.
ASaidi 0:7d2088337345 20 *
ASaidi 0:7d2088337345 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ASaidi 0:7d2088337345 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ASaidi 0:7d2088337345 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ASaidi 0:7d2088337345 24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ASaidi 0:7d2088337345 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ASaidi 0:7d2088337345 26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ASaidi 0:7d2088337345 27 * THE SOFTWARE.
ASaidi 0:7d2088337345 28 */
ASaidi 0:7d2088337345 29
ASaidi 0:7d2088337345 30 #ifndef __TXIR_HPP__
ASaidi 0:7d2088337345 31 #define __TXIR_HPP__
ASaidi 0:7d2088337345 32
ASaidi 0:7d2088337345 33 #include <mbed.h>
ASaidi 0:7d2088337345 34
ASaidi 1:208b4f080b2f 35 /** A low-level ifrared transmit library */
ASaidi 0:7d2088337345 36 class TxIR {
ASaidi 0:7d2088337345 37 private:
ASaidi 0:7d2088337345 38 /** Function that does the work */
ASaidi 0:7d2088337345 39 void doAction();
ASaidi 0:7d2088337345 40
ASaidi 0:7d2088337345 41 /** A timeout that is used to do the next action, so we don't spin
ASaidi 0:7d2088337345 42 * for the entire IR sequence
ASaidi 0:7d2088337345 43 */
ASaidi 0:7d2088337345 44 Timeout delay;
ASaidi 0:7d2088337345 45
ASaidi 0:7d2088337345 46 /** If the stack is currently busy transmitting something */
ASaidi 0:7d2088337345 47 bool _inUse;
ASaidi 0:7d2088337345 48
ASaidi 0:7d2088337345 49 /** A local copy of the data so the caller can muck with their own */
ASaidi 0:7d2088337345 50 unsigned *data;
ASaidi 0:7d2088337345 51
ASaidi 0:7d2088337345 52 /** length of the array */
ASaidi 0:7d2088337345 53 unsigned len;
ASaidi 0:7d2088337345 54
ASaidi 0:7d2088337345 55 /** Current location in the array */
ASaidi 0:7d2088337345 56 unsigned pos;
ASaidi 0:7d2088337345 57
ASaidi 0:7d2088337345 58 /** The pin used to send the IR commands */
ASaidi 0:7d2088337345 59 PwmOut txPin;
ASaidi 0:7d2088337345 60
ASaidi 0:7d2088337345 61 /** If we're currenting sending data or waiting */
ASaidi 0:7d2088337345 62 bool high;
ASaidi 0:7d2088337345 63
ASaidi 0:7d2088337345 64 public:
ASaidi 0:7d2088337345 65 /** Initialize the TxIR library
ASaidi 0:7d2088337345 66 * @param pin a pin on the mbed that is PWM capable
ASaidi 0:7d2088337345 67 */
ASaidi 0:7d2088337345 68 TxIR(PinName pin)
ASaidi 0:7d2088337345 69 : _inUse(false), txPin(pin)
ASaidi 0:7d2088337345 70 {}
ASaidi 0:7d2088337345 71
ASaidi 0:7d2088337345 72 /** If something is currently being sent
ASaidi 0:7d2088337345 73 * @return is something being tranmitted currently
ASaidi 0:7d2088337345 74 * @todo is there a lock library available, this certainly isn't safe
ASaidi 0:7d2088337345 75 */
ASaidi 0:7d2088337345 76 bool inUse() { return _inUse; }
ASaidi 0:7d2088337345 77
ASaidi 0:7d2088337345 78 /** Transmit an IR sequence
ASaidi 0:7d2088337345 79 * @param freq the modulation frequency in us normally ~40kHz -> 26us
ASaidi 0:7d2088337345 80 * @param len the number of modulation changes to send (length of data)
ASaidi 0:7d2088337345 81 * @param data an array of on/off times in us that will be transmitted
ASaidi 0:7d2088337345 82 * @return transmission has begun
ASaidi 0:7d2088337345 83 */
ASaidi 0:7d2088337345 84 bool txSeq(unsigned freq, unsigned len, const unsigned *data);
ASaidi 0:7d2088337345 85 };
ASaidi 0:7d2088337345 86
ASaidi 0:7d2088337345 87 #endif // __TXIR_HPP__
ASaidi 0:7d2088337345 88