http://mbed.org/users/shintamainjp/notebook/starboard_expbrd-one_ex1_en/

Dependencies:   mbed RemoteIR SuperTweet ConfigFile EthernetNetIf

Committer:
shintamainjp
Date:
Fri Oct 29 23:17:01 2010 +0000
Revision:
0:db299c5a18ba
Child:
1:c4cfd136f9c7
Initial version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shintamainjp 0:db299c5a18ba 1 #include "MyHomeLight.h"
shintamainjp 0:db299c5a18ba 2 #include "RemoteIR.h"
shintamainjp 0:db299c5a18ba 3
shintamainjp 0:db299c5a18ba 4 const MyHomeLight::light_signal_t MyHomeLight::lights[8] = {
shintamainjp 0:db299c5a18ba 5 {0, "\x2C\x52\x09\x02\x08\x82"},
shintamainjp 0:db299c5a18ba 6 {1, "\x2C\x52\x09\x02\x0A\xA2"},
shintamainjp 0:db299c5a18ba 7 {2, "\x2C\x52\x09\x02\x0C\xC2"},
shintamainjp 0:db299c5a18ba 8 {3, "\x2C\x52\x09\x02\x0E\xE2"},
shintamainjp 0:db299c5a18ba 9 {4, "\x2C\x52\x09\x42\x08\xC2"},
shintamainjp 0:db299c5a18ba 10 {5, "\x2C\x52\x09\x42\x0A\xE2"},
shintamainjp 0:db299c5a18ba 11 {6, "\x2C\x52\x09\x42\x0C\x82"},
shintamainjp 0:db299c5a18ba 12 {7, "\x2C\x52\x09\x42\x0E\xA2"},
shintamainjp 0:db299c5a18ba 13 };
shintamainjp 0:db299c5a18ba 14
shintamainjp 0:db299c5a18ba 15 /**
shintamainjp 0:db299c5a18ba 16 * Create.
shintamainjp 0:db299c5a18ba 17 *
shintamainjp 0:db299c5a18ba 18 * @param tx_pin Pin of IR transmitter.
shintamainjp 0:db299c5a18ba 19 */
shintamainjp 0:db299c5a18ba 20 MyHomeLight::MyHomeLight(PinName tx_pin) : tx(tx_pin) {
shintamainjp 0:db299c5a18ba 21 }
shintamainjp 0:db299c5a18ba 22
shintamainjp 0:db299c5a18ba 23 /**
shintamainjp 0:db299c5a18ba 24 * Dispose.
shintamainjp 0:db299c5a18ba 25 */
shintamainjp 0:db299c5a18ba 26 MyHomeLight::~MyHomeLight() {
shintamainjp 0:db299c5a18ba 27 }
shintamainjp 0:db299c5a18ba 28
shintamainjp 0:db299c5a18ba 29 /**
shintamainjp 0:db299c5a18ba 30 * Toggle state.
shintamainjp 0:db299c5a18ba 31 *
shintamainjp 0:db299c5a18ba 32 * @param channel Target channel number.
shintamainjp 0:db299c5a18ba 33 * @return true if it succeed.
shintamainjp 0:db299c5a18ba 34 */
shintamainjp 0:db299c5a18ba 35 bool MyHomeLight::toggle(const int channel) {
shintamainjp 0:db299c5a18ba 36 RemoteIR::Format fmt = RemoteIR::AEHA;
shintamainjp 0:db299c5a18ba 37 uint8_t *sig = getLightSignal(channel);
shintamainjp 0:db299c5a18ba 38 if (sig != NULL) {
shintamainjp 0:db299c5a18ba 39 for (int i = 0; i < 2; i++) {
shintamainjp 0:db299c5a18ba 40 while (tx.getState() != TransmitterIR::Idle) {
shintamainjp 0:db299c5a18ba 41 wait_us(100);
shintamainjp 0:db299c5a18ba 42 }
shintamainjp 0:db299c5a18ba 43 tx.setData(fmt, sig, 48);
shintamainjp 0:db299c5a18ba 44 wait_ms(120);
shintamainjp 0:db299c5a18ba 45 }
shintamainjp 0:db299c5a18ba 46 return true;
shintamainjp 0:db299c5a18ba 47 }
shintamainjp 0:db299c5a18ba 48 return false;
shintamainjp 0:db299c5a18ba 49 }
shintamainjp 0:db299c5a18ba 50
shintamainjp 0:db299c5a18ba 51 /**
shintamainjp 0:db299c5a18ba 52 * Get a signal for a light.
shintamainjp 0:db299c5a18ba 53 *
shintamainjp 0:db299c5a18ba 54 * @param channel Channel of a light.
shintamainjp 0:db299c5a18ba 55 *
shintamainjp 0:db299c5a18ba 56 * @return A pointer to a signal.
shintamainjp 0:db299c5a18ba 57 */
shintamainjp 0:db299c5a18ba 58 uint8_t *MyHomeLight::getLightSignal(int channel) {
shintamainjp 0:db299c5a18ba 59 const int n = sizeof(lights) / sizeof(lights[0]);
shintamainjp 0:db299c5a18ba 60 if ((0 <= channel) && (channel <= n - 1)) {
shintamainjp 0:db299c5a18ba 61 return (uint8_t *)lights[channel].signal;
shintamainjp 0:db299c5a18ba 62 }
shintamainjp 0:db299c5a18ba 63 return NULL;
shintamainjp 0:db299c5a18ba 64 }