62 : irSender(irSender_), commandLed(commandLed_), transmitLed(transmitLed_) {
81 digitalWrite(pin, HIGH);
86 digitalWrite(pin, LOW);
91 digitalWrite(pin, HIGH);
92 delay((
unsigned long) ms);
93 digitalWrite(pin, LOW);
98 for (
unsigned int i = 0; i < count; i++) {
110 while (!isalpha(b[0]) && n > 0) {
122 if (strncmp(buf,
"getdevices", 10) == 0)
124 else if (strncmp(buf,
"getversion", 10) == 0)
126 else if (strncmp(buf,
"blink", 5) == 0)
128 else if (strncmp(buf,
"sendir", 6) == 0)
131 stream.println(F(
"ERR 001"));
136 for (
const char *p = buf; *p !=
'\0'; p++) {
143 static void grok(microseconds_t *buf,
size_t length, frequency_t freq) {
144 for (
unsigned int i = 0; i < length; i++) {
145 int duration = atoi(strtok(NULL,
","));
146 buf[i] = (microseconds_t) (1000000UL * duration / freq);
151 unsigned int commas =
noCommas(buf);
154 uint16_t
id = atoi(strtok(NULL,
","));
155 frequency_t freq = atoi(strtok(NULL,
","));
156 uint16_t repeat = atoi(strtok(NULL,
","));
157 uint16_t offset = atoi(strtok(NULL,
","));
158 size_t lengthIntro = offset - 1;
159 microseconds_t intro[lengthIntro];
160 grok(intro, lengthIntro, freq);
161 size_t lengthRepetition = commas - offset - 4;
162 microseconds_t reps[lengthRepetition];
163 grok(reps, lengthRepetition, freq);
165 IrSignal irSignal(intro, lengthIntro, reps, lengthRepetition, freq);
167 irSender->sendIrSignal(irSignal, repeat);
174 stream.println(F(
"device,0,0 ETHERNET"));
175 if (irSender != NULL)
177 stream.println(F(
"endlistdevices"));
static const int invalidPin
static unsigned int noCommas(const char *buf)
#define VERSION
Version of the current library.
void initLed(int pin) const
void getversion(Stream &stream) const
Implements the getversion command.
void turnOnOffLed(int pin, milliseconds_t delay) const
Turns on the pin as the first argument, waits delay milli seconds, then turns off the pin...
void turnOnLed(int pin) const
static const size_t bufSize
Max length on input line.
static void grok(microseconds_t *buf, size_t length, frequency_t freq)
This class emulates the IR sending of a GlobalCache device.
static const char eolChar
GlobalCache uses CR as line terminator.
GlobalCovfefe(IrSender *irSender, int commandLed=invalidPin, int transmitLed=invalidPin)
Main constructor.
void getdevices(Stream &stream) const
Implements the getdevices command.
virtual void processCommand(Stream &stream, char *buf) const
Processes one command from the supplied Stream argument.
void turnOffLed(int pin) const
virtual void blink(unsigned int count=blinkCount, milliseconds_t delay=blinkDelay) const
Implements the blink command (found in GC-100)
void sendir(Stream &stream, char *buf) const
Implements the sendir command.
static const char * version
Version of the present program.
void readProcessCommand(Stream &stream) const
Reads and processes one command from the supplied Stream argument.