Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed RemoteIR SuperTweet ConfigFile EthernetNetIf
mylib/MyHomeLight/MyHomeLight.cpp
- Committer:
- shintamainjp
- Date:
- 2010-10-29
- Revision:
- 0:db299c5a18ba
- Child:
- 1:c4cfd136f9c7
File content as of revision 0:db299c5a18ba:
#include "MyHomeLight.h"
#include "RemoteIR.h"
const MyHomeLight::light_signal_t MyHomeLight::lights[8] = {
{0, "\x2C\x52\x09\x02\x08\x82"},
{1, "\x2C\x52\x09\x02\x0A\xA2"},
{2, "\x2C\x52\x09\x02\x0C\xC2"},
{3, "\x2C\x52\x09\x02\x0E\xE2"},
{4, "\x2C\x52\x09\x42\x08\xC2"},
{5, "\x2C\x52\x09\x42\x0A\xE2"},
{6, "\x2C\x52\x09\x42\x0C\x82"},
{7, "\x2C\x52\x09\x42\x0E\xA2"},
};
/**
* Create.
*
* @param tx_pin Pin of IR transmitter.
*/
MyHomeLight::MyHomeLight(PinName tx_pin) : tx(tx_pin) {
}
/**
* Dispose.
*/
MyHomeLight::~MyHomeLight() {
}
/**
* Toggle state.
*
* @param channel Target channel number.
* @return true if it succeed.
*/
bool MyHomeLight::toggle(const int channel) {
RemoteIR::Format fmt = RemoteIR::AEHA;
uint8_t *sig = getLightSignal(channel);
if (sig != NULL) {
for (int i = 0; i < 2; i++) {
while (tx.getState() != TransmitterIR::Idle) {
wait_us(100);
}
tx.setData(fmt, sig, 48);
wait_ms(120);
}
return true;
}
return false;
}
/**
* Get a signal for a light.
*
* @param channel Channel of a light.
*
* @return A pointer to a signal.
*/
uint8_t *MyHomeLight::getLightSignal(int channel) {
const int n = sizeof(lights) / sizeof(lights[0]);
if ((0 <= channel) && (channel <= n - 1)) {
return (uint8_t *)lights[channel].signal;
}
return NULL;
}