Lib for sending IR signals from mbed.
Dependents: ir-puck ir-puck2 ir-puck
IRSender.h@2:4576fcd93ffd, 2014-08-05 (annotated)
- Committer:
- cristea
- Date:
- Tue Aug 05 08:31:41 2014 +0000
- Revision:
- 2:4576fcd93ffd
- Parent:
- 1:402625e9170f
Add license to the project
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cristea | 2:4576fcd93ffd | 1 | /** |
cristea | 2:4576fcd93ffd | 2 | * Low level infrared transmission |
cristea | 2:4576fcd93ffd | 3 | * This library provides a low level interface to send IR commands. in principle |
cristea | 2:4576fcd93ffd | 4 | * other higher level IR type remotes could be build on top of this. I wrote |
cristea | 2:4576fcd93ffd | 5 | * this code to send IR commands to a Nikon camera, which it works rather well |
cristea | 2:4576fcd93ffd | 6 | * for. |
cristea | 2:4576fcd93ffd | 7 | * |
cristea | 2:4576fcd93ffd | 8 | * Copyright (C) 2010 Ali Saidi |
cristea | 2:4576fcd93ffd | 9 | * |
cristea | 2:4576fcd93ffd | 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
cristea | 2:4576fcd93ffd | 11 | * of this software and associated documentation files (the "Software"), to deal |
cristea | 2:4576fcd93ffd | 12 | * in the Software without restriction, including without limitation the rights |
cristea | 2:4576fcd93ffd | 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
cristea | 2:4576fcd93ffd | 14 | * copies of the Software, and to permit persons to whom the Software is |
cristea | 2:4576fcd93ffd | 15 | * furnished to do so, subject to the following conditions: |
cristea | 2:4576fcd93ffd | 16 | * |
cristea | 2:4576fcd93ffd | 17 | * The above copyright notice and this permission notice shall be included in |
cristea | 2:4576fcd93ffd | 18 | * all copies or substantial portions of the Software. |
cristea | 2:4576fcd93ffd | 19 | * |
cristea | 2:4576fcd93ffd | 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
cristea | 2:4576fcd93ffd | 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
cristea | 2:4576fcd93ffd | 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
cristea | 2:4576fcd93ffd | 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
cristea | 2:4576fcd93ffd | 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
cristea | 2:4576fcd93ffd | 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
cristea | 2:4576fcd93ffd | 26 | * THE SOFTWARE. |
cristea | 2:4576fcd93ffd | 27 | */ |
cristea | 2:4576fcd93ffd | 28 | |
cristea | 2:4576fcd93ffd | 29 | /** |
cristea | 2:4576fcd93ffd | 30 | * Copyright 2014 Nordic Semiconductor |
cristea | 2:4576fcd93ffd | 31 | * |
cristea | 2:4576fcd93ffd | 32 | * Licensed under the Apache License, Version 2.0 (the "License"); |
cristea | 2:4576fcd93ffd | 33 | * you may not use this file except in compliance with the License. |
cristea | 2:4576fcd93ffd | 34 | * You may obtain a copy of the License at |
cristea | 2:4576fcd93ffd | 35 | * |
cristea | 2:4576fcd93ffd | 36 | * http://www.apache.org/licenses/LICENSE-2.0 |
cristea | 2:4576fcd93ffd | 37 | * |
cristea | 2:4576fcd93ffd | 38 | * Unless required by applicable law or agreed to in writing, software |
cristea | 2:4576fcd93ffd | 39 | * distributed under the License is distributed on an "AS IS" BASIS, |
cristea | 2:4576fcd93ffd | 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
cristea | 2:4576fcd93ffd | 41 | * See the License for the specific language governing permissions and |
cristea | 2:4576fcd93ffd | 42 | * limitations under the License |
cristea | 2:4576fcd93ffd | 43 | */ |
cristea | 0:741de6c95ae9 | 44 | |
cristea | 0:741de6c95ae9 | 45 | #ifndef __IRSENDER__H__ |
cristea | 0:741de6c95ae9 | 46 | #define __IRSENDER__H__ |
cristea | 0:741de6c95ae9 | 47 | |
cristea | 0:741de6c95ae9 | 48 | #define DEBUG 0 |
cristea | 0:741de6c95ae9 | 49 | |
cristea | 0:741de6c95ae9 | 50 | #if DEBUG |
cristea | 0:741de6c95ae9 | 51 | #define LOG(fmt, ...) do { __IRSENDER__irLogger.printf("[IRSender] "); __IRSENDER__irLogger.printf(fmt, ##__VA_ARGS__); } while(0) |
cristea | 0:741de6c95ae9 | 52 | #define APPEND(fmt, ...) do { __IRSENDER__irLogger.printf(fmt, ##__VA_ARGS__); } while(0) |
cristea | 0:741de6c95ae9 | 53 | static Serial __IRSENDER__irLogger(USBTX, USBRX); |
cristea | 0:741de6c95ae9 | 54 | #else |
cristea | 0:741de6c95ae9 | 55 | #define LOG(fmt, ...) |
cristea | 1:402625e9170f | 56 | #define APPEND(fmt, ...) |
cristea | 0:741de6c95ae9 | 57 | #endif |
cristea | 0:741de6c95ae9 | 58 | |
cristea | 0:741de6c95ae9 | 59 | /** Small library to drive the pin of an IR LED. |
cristea | 0:741de6c95ae9 | 60 | * Send the frequency of the signal, the length |
cristea | 0:741de6c95ae9 | 61 | * of the data and the duration of on and off |
cristea | 0:741de6c95ae9 | 62 | * in ms. |
cristea | 0:741de6c95ae9 | 63 | */ |
cristea | 0:741de6c95ae9 | 64 | |
cristea | 0:741de6c95ae9 | 65 | class IRSender { |
cristea | 0:741de6c95ae9 | 66 | private: |
cristea | 0:741de6c95ae9 | 67 | bool _inUse; |
cristea | 0:741de6c95ae9 | 68 | PwmOut senderPin; |
cristea | 0:741de6c95ae9 | 69 | Timer timer; |
cristea | 0:741de6c95ae9 | 70 | |
cristea | 0:741de6c95ae9 | 71 | public: |
cristea | 0:741de6c95ae9 | 72 | IRSender(PinName pin) : _inUse(false), senderPin(pin) {} |
cristea | 0:741de6c95ae9 | 73 | bool irSeq(unsigned freq, unsigned len, const unsigned *data); |
cristea | 0:741de6c95ae9 | 74 | }; |
cristea | 0:741de6c95ae9 | 75 | |
cristea | 0:741de6c95ae9 | 76 | #endif // __IRSENDER__H__ |