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

Committer:
sigveseb
Date:
2014-08-01
Revision:
13:f016a0bc4a7d
Parent:
5:3642c0af497e
Child:
14:b00d0c5ba8e3

File content as of revision 13:f016a0bc4a7d:

#include "mbed.h"
#include "TxIR.hpp"

#define LOG_LEVEL_VERBOSE
#include "Puck.h"

Puck* puck = &Puck::getPuck();

TxIR txir(p14);

const UUID IR_SERVICE_UUID = stringToUUID("bftj ir         ");
const UUID COMMAND_UUID    = stringToUUID("bftj ir command ");
const UUID DATA_UUID       = stringToUUID("bftj ir data    ");
const UUID PERIOD_UUID     = stringToUUID("bftj ir period  ");

unsigned int dataBuffer[100];
uint8_t period = 26;
int receiveIndex;

#define COMMAND_BEGIN_CODE_TRANSMISSION 0
#define COMMAND_END_CODE_TRANSMISSION 1


void onCommandWrite(uint8_t* value) {
    LOG_VERBOSE("Got command: %i\n", value[0]);
    switch(value[0]) {
        case COMMAND_BEGIN_CODE_TRANSMISSION:
            receiveIndex = 0;
            break;
        case COMMAND_END_CODE_TRANSMISSION:
            LOG_INFO("Going to fire IR code...\n");
            txir.txSeq(period, 200, dataBuffer);
            LOG_INFO("Fire complete!\n");
            break;
    }
}


void onDataWrite(uint8_t* value) {
    LOG_VERBOSE("Got data, index: %i\n", receiveIndex);
    for(int i = 0; i < 20 && receiveIndex < 100; i += 2) {
        dataBuffer[receiveIndex++] = (value[i] << 8) | value[i + 1];
    }
}


void onPeriodWrite(uint8_t* value) {
    period = value[0];    
    LOG_VERBOSE("Period is now: %i\n", period);
}


int main() {
    puck->addCharacteristic(IR_SERVICE_UUID, COMMAND_UUID, 1);
    puck->addCharacteristic(IR_SERVICE_UUID, DATA_UUID, 20);
    puck->addCharacteristic(IR_SERVICE_UUID, PERIOD_UUID, 1);
    puck->init(0xABBA);
    puck->onCharacteristicWrite(COMMAND_UUID, onCommandWrite);
    puck->onCharacteristicWrite(DATA_UUID, onDataWrite);
    puck->onCharacteristicWrite(PERIOD_UUID, onPeriodWrite);
    while (puck->drive());
}