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.
TxIR.hpp
00001 00002 /** 00003 * Low level infrared transmission 00004 * This library provides a low level interface to send IR commands. in principle 00005 * other higher level IR type remotes could be build on top of this. I wrote 00006 * this code to send IR commands to a Nikon camera, which it works rather well 00007 * for. 00008 * 00009 * Copyright (C) 2010 Ali Saidi 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining a copy 00012 * of this software and associated documentation files (the "Software"), to deal 00013 * in the Software without restriction, including without limitation the rights 00014 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00015 * copies of the Software, and to permit persons to whom the Software is 00016 * furnished to do so, subject to the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be included in 00019 * all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00022 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00023 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00024 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00025 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00026 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00027 * THE SOFTWARE. 00028 */ 00029 00030 #ifndef __TXIR_HPP__ 00031 #define __TXIR_HPP__ 00032 00033 #include <mbed.h> 00034 00035 /** A low-level ifrared transmit library */ 00036 class TxIR { 00037 private: 00038 /** Function that does the work */ 00039 void doAction(); 00040 00041 /** A timeout that is used to do the next action, so we don't spin 00042 * for the entire IR sequence 00043 */ 00044 Timeout delay; 00045 00046 /** If the stack is currently busy transmitting something */ 00047 bool _inUse; 00048 00049 /** A local copy of the data so the caller can muck with their own */ 00050 unsigned *data; 00051 00052 /** length of the array */ 00053 unsigned len; 00054 00055 /** Current location in the array */ 00056 unsigned pos; 00057 00058 /** The pin used to send the IR commands */ 00059 PwmOut txPin; 00060 00061 /** If we're currenting sending data or waiting */ 00062 bool high; 00063 00064 public: 00065 /** Initialize the TxIR library 00066 * @param pin a pin on the mbed that is PWM capable 00067 */ 00068 TxIR(PinName pin) 00069 : _inUse(false), txPin(pin) 00070 {} 00071 00072 /** If something is currently being sent 00073 * @return is something being tranmitted currently 00074 * @todo is there a lock library available, this certainly isn't safe 00075 */ 00076 bool inUse() { return _inUse; } 00077 00078 /** Transmit an IR sequence 00079 * @param freq the modulation frequency in us normally ~40kHz -> 26us 00080 * @param len the number of modulation changes to send (length of data) 00081 * @param data an array of on/off times in us that will be transmitted 00082 * @return transmission has begun 00083 */ 00084 bool txSeq(unsigned freq, unsigned len, const unsigned *data); 00085 }; 00086 00087 #endif // __TXIR_HPP__ 00088
Generated on Wed Jul 13 2022 00:19:24 by 1.7.2