GlobalCovfefe
GlobalCovfefeLearner.cpp
Go to the documentation of this file.
1 /*
2 Copyright (C) 2018 Bengt Martensson.
3 
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at
7 your option) any later version.
8 
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see http://www.gnu.org/licenses/.
16 */
17 
18 #include "GlobalCovfefeLearner.h"
19 
20 GlobalCovfefeLearner::GlobalCovfefeLearner(IrSender *irSender_, IrReader *irReader_,
21  int commandLed_, int learnLed_, int transmitLed_)
22 : GlobalCovfefe(irSender_, commandLed_, transmitLed_),irReader(irReader_),learnLed(learnLed_) {
23  irReader->reset();
24  initLed(learnLed);
25 }
26 
28 }
29 
31 }
32 
33 void GlobalCovfefeLearner::blink(unsigned int count, milliseconds_t ms) const {
34  for (unsigned int i = 0; i < count; i++) {
35  turnOnOffLed(learnLed, ms);
36  GlobalCovfefe::blink(1, ms);
37  }
38 }
39 
40 void GlobalCovfefeLearner::processCommand(Stream &stream, char* buf) const {
41  if (strncmp(buf, "get_IRL", 7) == 0)
42  getIRL(stream);
43  else
44  GlobalCovfefe::processCommand(stream, buf);
45 }
46 
47 void GlobalCovfefeLearner::getIRL(Stream &stream) const {
48  stream.println(F("IR Learner Enabled"));
49  turnOnLed(learnLed);
50 
51  irReader->receive();
52  turnOffLed(learnLed);
53  if (!irReader->isEmpty()) {
54  stream.print(F("sendir,1:1,1,"));
55  frequency_t freq = irReader->getFrequency();
56  stream.print(freq);
57  stream.print(",1,1");
58  for (unsigned int i = 0; i < irReader->getDataLength(); i++) {
59  stream.print(",");
60  stream.print(((uint32_t) irReader->getDuration(i) * freq)/1000000UL);
61  }
62  stream.println();
63  }
64 }
void initLed(int pin) const
void getIRL(Stream &stream) const
Invoke the configured learner, and deliver the result in sendir format.
virtual void processCommand(Stream &stream, char *buf) const
Processes one command from the supplied Stream argument.
virtual void blink(unsigned int count=blinkCount, milliseconds_t delay=blinkDelay) const
Implements the blink command (found in GC-100)
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
This class emulates the IR sending of a GlobalCache device.
Definition: GlobalCovfefe.h:27
This class is derived from GlobalCovfefe, and adds the get_IRL command, invoking a learner...
GlobalCovfefeLearner(IrSender *irSender, IrReader *irReader, int commandLed=invalidPin, int learnLed=invalidPin, int transmitLed=invalidPin)
Main constructor.
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)