The IR Puck can mimic arbitrary infrared remote controls. Built on the Puck IOT platform.
Dependencies: Puck IRSender mbed
The IR Puck is a puck that can mimic arbitrary infrared remote controls. This is useful for controlling things like TVs, radios, airconditioners, window blinds, and just about anything and everything that can be otherwise be controlled by a regular remote control.
A tutorial for the IR Puck is available on GitHub.
Tutorials and in-depth documentation for the Puck platform is available at the project's GitHub page
main.cpp@17:6375c75a88a5, 2014-08-05 (annotated)
- Committer:
- cristea
- Date:
- Tue Aug 05 08:54:25 2014 +0000
- Revision:
- 17:6375c75a88a5
- Parent:
- 16:0891823672f4
- Child:
- 18:e96a99547f54
Add license
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cristea | 17:6375c75a88a5 | 1 | /** |
cristea | 17:6375c75a88a5 | 2 | * Copyright 2014 Nordic Semiconductor |
cristea | 17:6375c75a88a5 | 3 | * |
cristea | 17:6375c75a88a5 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
cristea | 17:6375c75a88a5 | 5 | * you may not use this file except in compliance with the License. |
cristea | 17:6375c75a88a5 | 6 | * You may obtain a copy of the License at |
cristea | 17:6375c75a88a5 | 7 | * |
cristea | 17:6375c75a88a5 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
cristea | 17:6375c75a88a5 | 9 | * |
cristea | 17:6375c75a88a5 | 10 | * Unless required by applicable law or agreed to in writing, software |
cristea | 17:6375c75a88a5 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
cristea | 17:6375c75a88a5 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
cristea | 17:6375c75a88a5 | 13 | * See the License for the specific language governing permissions and |
cristea | 17:6375c75a88a5 | 14 | * limitations under the License |
cristea | 17:6375c75a88a5 | 15 | */ |
cristea | 17:6375c75a88a5 | 16 | |
sigveseb | 0:c94311378ec1 | 17 | #include "mbed.h" |
sigveseb | 13:f016a0bc4a7d | 18 | #include "TxIR.hpp" |
sigveseb | 0:c94311378ec1 | 19 | |
cristea | 10:35d78d589580 | 20 | #define LOG_LEVEL_ERROR |
cristea | 10:35d78d589580 | 21 | #include "Log.h" |
sigveseb | 5:3642c0af497e | 22 | #include "Puck.h" |
sigveseb | 0:c94311378ec1 | 23 | |
sigveseb | 5:3642c0af497e | 24 | Puck* puck = &Puck::getPuck(); |
sigveseb | 0:c94311378ec1 | 25 | |
sigveseb | 13:f016a0bc4a7d | 26 | TxIR txir(p14); |
sigveseb | 13:f016a0bc4a7d | 27 | |
sigveseb | 5:3642c0af497e | 28 | const UUID IR_SERVICE_UUID = stringToUUID("bftj ir "); |
sigveseb | 13:f016a0bc4a7d | 29 | const UUID COMMAND_UUID = stringToUUID("bftj ir command "); |
sigveseb | 13:f016a0bc4a7d | 30 | const UUID DATA_UUID = stringToUUID("bftj ir data "); |
sigveseb | 13:f016a0bc4a7d | 31 | const UUID PERIOD_UUID = stringToUUID("bftj ir period "); |
sigveseb | 13:f016a0bc4a7d | 32 | |
sigveseb | 16:0891823672f4 | 33 | #define DATA_BUFFER_SIZE 200 |
sigveseb | 14:b00d0c5ba8e3 | 34 | unsigned int dataBuffer[DATA_BUFFER_SIZE]; |
sigveseb | 13:f016a0bc4a7d | 35 | uint8_t period = 26; |
sigveseb | 13:f016a0bc4a7d | 36 | int receiveIndex; |
sigveseb | 13:f016a0bc4a7d | 37 | |
sigveseb | 13:f016a0bc4a7d | 38 | #define COMMAND_BEGIN_CODE_TRANSMISSION 0 |
sigveseb | 13:f016a0bc4a7d | 39 | #define COMMAND_END_CODE_TRANSMISSION 1 |
sigveseb | 0:c94311378ec1 | 40 | |
sigveseb | 13:f016a0bc4a7d | 41 | void onCommandWrite(uint8_t* value) { |
sigveseb | 13:f016a0bc4a7d | 42 | switch(value[0]) { |
sigveseb | 13:f016a0bc4a7d | 43 | case COMMAND_BEGIN_CODE_TRANSMISSION: |
sigveseb | 13:f016a0bc4a7d | 44 | receiveIndex = 0; |
sigveseb | 13:f016a0bc4a7d | 45 | break; |
sigveseb | 13:f016a0bc4a7d | 46 | case COMMAND_END_CODE_TRANSMISSION: |
stiaje | 15:cf6c517f31ad | 47 | puck->getBle().disconnect(); |
sigveseb | 13:f016a0bc4a7d | 48 | LOG_INFO("Going to fire IR code...\n"); |
sigveseb | 16:0891823672f4 | 49 | txir.txSeq(period, receiveIndex, dataBuffer); |
sigveseb | 13:f016a0bc4a7d | 50 | LOG_INFO("Fire complete!\n"); |
sigveseb | 13:f016a0bc4a7d | 51 | break; |
sigveseb | 13:f016a0bc4a7d | 52 | } |
sigveseb | 13:f016a0bc4a7d | 53 | } |
sigveseb | 0:c94311378ec1 | 54 | |
stiaje | 4:24d9873936e6 | 55 | |
sigveseb | 13:f016a0bc4a7d | 56 | void onDataWrite(uint8_t* value) { |
sigveseb | 14:b00d0c5ba8e3 | 57 | for(int i = 0; i < 20 && receiveIndex < DATA_BUFFER_SIZE; i += 2) { |
sigveseb | 13:f016a0bc4a7d | 58 | dataBuffer[receiveIndex++] = (value[i] << 8) | value[i + 1]; |
sigveseb | 13:f016a0bc4a7d | 59 | } |
sigveseb | 13:f016a0bc4a7d | 60 | } |
sigveseb | 13:f016a0bc4a7d | 61 | |
sigveseb | 13:f016a0bc4a7d | 62 | |
sigveseb | 13:f016a0bc4a7d | 63 | void onPeriodWrite(uint8_t* value) { |
sigveseb | 13:f016a0bc4a7d | 64 | period = value[0]; |
sigveseb | 0:c94311378ec1 | 65 | } |
sigveseb | 0:c94311378ec1 | 66 | |
sigveseb | 0:c94311378ec1 | 67 | |
sigveseb | 5:3642c0af497e | 68 | int main() { |
sigveseb | 13:f016a0bc4a7d | 69 | puck->addCharacteristic(IR_SERVICE_UUID, COMMAND_UUID, 1); |
sigveseb | 13:f016a0bc4a7d | 70 | puck->addCharacteristic(IR_SERVICE_UUID, DATA_UUID, 20); |
sigveseb | 13:f016a0bc4a7d | 71 | puck->addCharacteristic(IR_SERVICE_UUID, PERIOD_UUID, 1); |
sigveseb | 5:3642c0af497e | 72 | puck->init(0xABBA); |
stiaje | 15:cf6c517f31ad | 73 | |
sigveseb | 14:b00d0c5ba8e3 | 74 | puck->onCharacteristicWrite(&COMMAND_UUID, onCommandWrite); |
sigveseb | 14:b00d0c5ba8e3 | 75 | puck->onCharacteristicWrite(&DATA_UUID, onDataWrite); |
sigveseb | 14:b00d0c5ba8e3 | 76 | puck->onCharacteristicWrite(&PERIOD_UUID, onPeriodWrite); |
stiaje | 15:cf6c517f31ad | 77 | |
sigveseb | 5:3642c0af497e | 78 | while (puck->drive()); |
sigveseb | 0:c94311378ec1 | 79 | } |