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

Committer:
aleksanb
Date:
Mon Mar 09 14:01:52 2015 +0000
Revision:
21:b65729957b9e
Parent:
19:727d9124e11f
Update puck lib, add power warning;

Who changed what in which revision?

UserRevisionLine numberNew 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"
cristea 18:e96a99547f54 18 #include "IRSender.h"
sigveseb 0:c94311378ec1 19
aleksanb 21:b65729957b9e 20 // Remove the log level define in production. It will prevent your mbed from entering low power modes.
aleksanb 21:b65729957b9e 21 #define LOG_LEVEL_INFO
cristea 10:35d78d589580 22 #include "Log.h"
sigveseb 5:3642c0af497e 23 #include "Puck.h"
sigveseb 0:c94311378ec1 24
sigveseb 5:3642c0af497e 25 Puck* puck = &Puck::getPuck();
sigveseb 0:c94311378ec1 26
cristea 18:e96a99547f54 27 IRSender irpin(p14);
sigveseb 13:f016a0bc4a7d 28
sigveseb 5:3642c0af497e 29 const UUID IR_SERVICE_UUID = stringToUUID("bftj ir ");
sigveseb 13:f016a0bc4a7d 30 const UUID COMMAND_UUID = stringToUUID("bftj ir command ");
sigveseb 13:f016a0bc4a7d 31 const UUID DATA_UUID = stringToUUID("bftj ir data ");
sigveseb 13:f016a0bc4a7d 32 const UUID PERIOD_UUID = stringToUUID("bftj ir period ");
sigveseb 13:f016a0bc4a7d 33
sigveseb 16:0891823672f4 34 #define DATA_BUFFER_SIZE 200
sigveseb 14:b00d0c5ba8e3 35 unsigned int dataBuffer[DATA_BUFFER_SIZE];
sigveseb 13:f016a0bc4a7d 36 uint8_t period = 26;
sigveseb 13:f016a0bc4a7d 37 int receiveIndex;
sigveseb 13:f016a0bc4a7d 38
sigveseb 13:f016a0bc4a7d 39 #define COMMAND_BEGIN_CODE_TRANSMISSION 0
sigveseb 13:f016a0bc4a7d 40 #define COMMAND_END_CODE_TRANSMISSION 1
sigveseb 0:c94311378ec1 41
stiaje 19:727d9124e11f 42 void onCommandWrite(const uint8_t* value, uint8_t length) {
sigveseb 13:f016a0bc4a7d 43 switch(value[0]) {
sigveseb 13:f016a0bc4a7d 44 case COMMAND_BEGIN_CODE_TRANSMISSION:
sigveseb 13:f016a0bc4a7d 45 receiveIndex = 0;
sigveseb 13:f016a0bc4a7d 46 break;
sigveseb 13:f016a0bc4a7d 47 case COMMAND_END_CODE_TRANSMISSION:
stiaje 19:727d9124e11f 48 puck->disconnect();
sigveseb 13:f016a0bc4a7d 49 LOG_INFO("Going to fire IR code...\n");
cristea 18:e96a99547f54 50 irpin.irSeq(period, receiveIndex, dataBuffer);
sigveseb 13:f016a0bc4a7d 51 LOG_INFO("Fire complete!\n");
sigveseb 13:f016a0bc4a7d 52 break;
sigveseb 13:f016a0bc4a7d 53 }
sigveseb 13:f016a0bc4a7d 54 }
sigveseb 0:c94311378ec1 55
stiaje 4:24d9873936e6 56
stiaje 19:727d9124e11f 57 void onDataWrite(const uint8_t* value, uint8_t length) {
stiaje 19:727d9124e11f 58 for(int i = 0; i < 20 && receiveIndex < length; i += 2) {
sigveseb 13:f016a0bc4a7d 59 dataBuffer[receiveIndex++] = (value[i] << 8) | value[i + 1];
sigveseb 13:f016a0bc4a7d 60 }
sigveseb 13:f016a0bc4a7d 61 }
sigveseb 13:f016a0bc4a7d 62
sigveseb 13:f016a0bc4a7d 63
stiaje 19:727d9124e11f 64 void onPeriodWrite(const uint8_t* value, uint8_t length) {
cristea 18:e96a99547f54 65 period = value[0];
sigveseb 0:c94311378ec1 66 }
sigveseb 0:c94311378ec1 67
sigveseb 0:c94311378ec1 68
sigveseb 5:3642c0af497e 69 int main() {
sigveseb 13:f016a0bc4a7d 70 puck->addCharacteristic(IR_SERVICE_UUID, COMMAND_UUID, 1);
sigveseb 13:f016a0bc4a7d 71 puck->addCharacteristic(IR_SERVICE_UUID, DATA_UUID, 20);
sigveseb 13:f016a0bc4a7d 72 puck->addCharacteristic(IR_SERVICE_UUID, PERIOD_UUID, 1);
sigveseb 5:3642c0af497e 73 puck->init(0xABBA);
stiaje 15:cf6c517f31ad 74
sigveseb 14:b00d0c5ba8e3 75 puck->onCharacteristicWrite(&COMMAND_UUID, onCommandWrite);
sigveseb 14:b00d0c5ba8e3 76 puck->onCharacteristicWrite(&DATA_UUID, onDataWrite);
sigveseb 14:b00d0c5ba8e3 77 puck->onCharacteristicWrite(&PERIOD_UUID, onPeriodWrite);
stiaje 15:cf6c517f31ad 78
sigveseb 5:3642c0af497e 79 while (puck->drive());
sigveseb 0:c94311378ec1 80 }