RemoteControl/InfraredProxy/infrared_proxy.cpp
void InfraredProxy::read_line(
EthernetClient& client, char* buffer, const int buffer_length)
{
int buffer_pos = 0;
while (client.available() && (buffer_pos < buffer_length - 1)) {
const char c = client.read();
if (c == '\n')
break;
if (c != '\r')
buffer[buffer_pos++] = c;
}
buffer[buffer_pos] = '\0';
}
read_line
reads one line of data sent by a client. A line ends either with a newline
character (\n) or with a carriage return character followed by a newline
character (\r\n).
read_line
expects the
EthernetClient
object to read data from, a
character buffer to store the data in (
buffer
), and the maximum length of the
character buffer (
buffer_length
). The method ignores all newline and carriage
return characters, and it sets the line’s last character to \0 so the buffer to
be filled will always be a null-terminated string.
send_ir_data
is responsible for sending infrared commands:
RemoteControl/InfraredProxy/infrared_proxy.cpp
bool InfraredProxy::send_ir_data(
const char* protocol, const int bits, const long value)
{
bool result = true;
if (!strcasecmp(protocol, "NEC"))
_infrared_sender.sendNEC(value, bits);
else if (!strcasecmp(protocol, "SONY"))
_infrared_sender.sendSony(value, bits);
else if (!strcasecmp(protocol, "RC5"))
_infrared_sender.sendRC5(value, bits);
else if (!strcasecmp(protocol, "RC6"))
_infrared_sender.sendRC6(value, bits);
else if (!strcasecmp(protocol, "DISH"))
_infrared_sender.sendDISH(value, bits);
else if (!strcasecmp(protocol, "SHARP"))
_infrared_sender.sendSharp(value, bits);
else if (!strcasecmp(protocol, "JVC"))
_infrared_sender.sendJVC(value, bits, 0);
else if (!strcasecmp(protocol, "SAMSUNG"))
_infrared_sender.sendSAMSUNG(value, bits);
else
result = false;
return result;
}
Chapter 12. Creating Your Own Universal Remote Control • 218
report erratum • discuss
www.it-ebooks.info