http://mbed.org/users/shintamainjp/notebook/starboard_expbrd-one_ex1_en/
Dependencies: mbed RemoteIR SuperTweet ConfigFile EthernetNetIf
Diff: mylib/MyHomeLight/MyHomeLight.cpp
- Revision:
- 0:db299c5a18ba
- Child:
- 1:c4cfd136f9c7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mylib/MyHomeLight/MyHomeLight.cpp Fri Oct 29 23:17:01 2010 +0000 @@ -0,0 +1,64 @@ +#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; +}