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 0:7d2088337345 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 #include "TxIR.hpp"
ASaidi 0:7d2088337345 31
ASaidi 0:7d2088337345 32
ASaidi 0:7d2088337345 33 void
ASaidi 0:7d2088337345 34 TxIR::doAction()
ASaidi 0:7d2088337345 35 {
ASaidi 0:7d2088337345 36 if (pos >= len) {
ASaidi 0:7d2088337345 37 delete [] data;
ASaidi 0:7d2088337345 38 _inUse = false;
ASaidi 0:7d2088337345 39 txPin.write(0);
ASaidi 0:7d2088337345 40 return;
ASaidi 0:7d2088337345 41 }
ASaidi 0:7d2088337345 42
ASaidi 0:7d2088337345 43 delay.attach_us(this, &TxIR::doAction, data[pos++]);
ASaidi 0:7d2088337345 44 if (high)
ASaidi 0:7d2088337345 45 txPin.write(0);
ASaidi 0:7d2088337345 46 else
ASaidi 0:7d2088337345 47 txPin.write(0.5);
ASaidi 0:7d2088337345 48 high = !high;
ASaidi 0:7d2088337345 49 }
ASaidi 0:7d2088337345 50
ASaidi 0:7d2088337345 51 bool
ASaidi 0:7d2088337345 52 TxIR::txSeq(unsigned freq, unsigned _len, const unsigned *_data)
ASaidi 0:7d2088337345 53 {
ASaidi 0:7d2088337345 54 // @todo a lock or semaphore should be used here
ASaidi 0:7d2088337345 55 if (inUse())
ASaidi 0:7d2088337345 56 return false;
ASaidi 0:7d2088337345 57 _inUse = true;
ASaidi 0:7d2088337345 58
ASaidi 0:7d2088337345 59 // keep a copy of the data, so it can't change
ASaidi 0:7d2088337345 60 len = _len;
ASaidi 0:7d2088337345 61 data = new unsigned[len];
ASaidi 0:7d2088337345 62 memcpy(data, _data, len * sizeof(unsigned));
ASaidi 0:7d2088337345 63 pos = 0;
ASaidi 0:7d2088337345 64
ASaidi 0:7d2088337345 65 // setup the PWM
ASaidi 0:7d2088337345 66 txPin.write(0.0);
ASaidi 0:7d2088337345 67 txPin.period_us(freq);
ASaidi 0:7d2088337345 68
ASaidi 0:7d2088337345 69 // Get the interrupt ready
ASaidi 0:7d2088337345 70 delay.detach();
ASaidi 0:7d2088337345 71 high = true;
ASaidi 0:7d2088337345 72 delay.attach_us(this, &TxIR::doAction, data[pos++]);
ASaidi 0:7d2088337345 73
ASaidi 0:7d2088337345 74 // Begin
ASaidi 0:7d2088337345 75 txPin.write(0.5);
ASaidi 0:7d2088337345 76
ASaidi 0:7d2088337345 77 return true;
ASaidi 0:7d2088337345 78 }