22 #include <avr/pgmspace.h> 28 #if defined(ETHERNET) & !defined(ARDUINO) 34 #include <IPAddress.h> 38 #include <LiquidCrystal_I2C.h> 42 #include <IrReceiverSampler.h> 46 #include <IrSenderPwm.h> 49 #include <IrReceiverSampler.h> 53 #include <IrWidgetAggregating.h> 57 #include <IrSenderNonMod.h> 62 #error DECODER without RECEIVE is nonsensical, aborting. 64 #include <MultiDecoder.h> 69 #error RENDER without TRANSMIT is nonsensical, aborting. 72 #include <Nec1Renderer.h> 73 #include <Rc5Renderer.h> 77 #error NAMED_COMMANDS is presently not supported 93 #if defined(CONFIGURABLE_LEDS) & (! defined(PARAMETERS) | !defined(LED)) 94 #error CONFIGURABLE_LEDS defined but not PARAMETERS and LED, aborting. 97 #ifdef CONFIGURABLE_LEDS 98 #define LED_PARAMETER_CONST 100 #define LED_PARAMETER_CONST const 104 #define PARAMETERS_NAME Parameters 105 #define PARAMETER_CONST 107 #define PARAMETERS_NAME 108 #define PARAMETER_CONST const 136 #if defined(RECEIVE) | defined(CAPTURE) 142 #ifdef IRRECEIVER_2_PIN 157 #define modulesSupported EXPAND_AND_QUOTE(Base TRANSMIT_NAME CAPTURE_NAME RENDERER_NAME RECEIVE_NAME DECODER_NAME LED_NAME LCD_NAME PARAMETERS_NAME NAMED_COMMANDS_NAME PRONTO_NAME) 159 #define PROGNAME "AGirs" 164 #define okString "OK" 165 #define errorString "ERROR" 166 #define timeoutString "." 170 static bool sendIrSignal(
const IrSignal &irSignal,
unsigned int noSends=1) {
178 (irSignal.getFrequency() == 0) ? (IrSender*)
new IrSenderNonMod(
NON_MOD_PIN) :
180 (IrSender*) IrSenderPwm::getInstance(
true);
182 irSender->sendIrSignal(irSignal, noSends);
185 if (irSignal.getFrequency() == 0)
189 IrSenderPwm::deleteInstance();
199 # if defined(RECEIVE) | defined(CAPTURE) 202 while (stream.available())
212 MultiDecoder multiDecoder(*irReader);
214 if (multiDecoder.getType() > MultiDecoder::noise) {
216 ?
"." : multiDecoder.getDecode(),
217 multiDecoder.getType() != MultiDecoder::nec_ditto);
218 if (multiDecoder.getType() == MultiDecoder::nec)
228 #if defined(DECODER) & ! defined(DONT_REPORT_DECODES) // lircd does its own decoding 229 switch (multiDecoder.getType()) {
230 case MultiDecoder::noise:
233 case MultiDecoder::undecoded:
234 irReader->dump(stream);
237 stream.println(multiDecoder.getDecode());
240 #else // ! (defined(DECODER) & ! defined(DONT_REPORT_DECODES)) 241 if (irReader->isEmpty())
244 irReader->dump(stream);
249 IrReceiverSampler *
irReceiver = IrReceiverSampler::getInstance();
264 while (!
irReceiver->isReady() && stream.available() == 0)
266 std::cout <<
"** Simulating timeout **" << std::endl;
277 IrReceiverSampler::deleteInstance();
285 IrWidget *irWidget = IrWidgetAggregating::newIrWidgetAggregating(
captureSize,
287 if (irWidget == NULL)
288 stream.println(F(
"This cannot happen"));
300 std::cout <<
"** Simulating timeout **" << std::endl;
307 if (!irWidget->isEmpty()) {
310 irWidget->dump(stream);
313 IrWidgetAggregating::deleteInstance();
318 #ifdef NAMED_COMMANDS 321 extern const IrNamedRemoteSet remoteSet;
323 static bool sendNamedCommand(Stream& stream, String& remoteName, String& commandName,
unsigned int noSends) {
324 const IrNamedRemote* remote = remoteSet.getIrNamedRemote(remoteName.c_str());
325 if (remote == NULL) {
326 stream.println(F(
"No such remote"));
330 const IrNamedCommand* command = remote->getIrNamedCommand(commandName.c_str());
331 if (command == NULL) {
332 stream.println(F(
"No such command"));
335 const IrSignal *irSignal = command->getIrSignal();
336 bool status = sendIrSignal(*irSignal, noSends);
341 static void dumpRemote(Stream& stream, String& name) {
342 if (name.length() == 0) {
343 for (
unsigned int i = 0; i < remoteSet.getNoIrNamedRemotes(); i++) {
344 stream.print(remoteSet.getIrNamedRemotes()[i]->getName());
349 const IrNamedRemote* remote = remoteSet.getIrNamedRemote(name.c_str());
351 stream.println(F(
"No such remote"));
353 for (
unsigned int i = 0; i < remote->getNoCommands(); i++) {
354 stream.print(remote->getAllCommands()[i]->getName());
367 #if defined(TRANSMIT) 369 IrSenderPwm::getInstance(
true)->mute();
393 #ifdef SDCARD_ON_ETHERSHIELD_PIN 402 Ethernet.begin(mac, IPAddress(IPADDRESS), IPAddress(DNSSERVER), IPAddress(GATEWAY), IPAddress(SUBNETMASK));
410 "",
"",
"",
"http://arduino/nosuchfile.html");
417 #if defined(ARDUINO) & !defined(ETHERNET) | defined(SERIAL_DEBUG) 420 #if defined(ARDUINO_AVR_LEONARDO) | defined(ARDUINO_AVR_MICRO) 428 Serial.println(Ethernet.localIP());
430 #endif // defined(ARDUINO) & !defined(ETHERNET) | defined(SERIAL_DEBUG) 434 void info(Stream& stream) {
435 stream.print(
"Board: ");
436 #ifdef ARDUINO_AVR_MEGA2560 437 stream.print(F(
"Arduino Mega2560"));
438 #elif defined(ARDUINO_AVR_NANO) 439 stream.print(F(
"Arduino Nano"));
440 #elif defined(ARDUINO_AVR_LEONARDO) 441 stream.print(F(
"Arduino Leonardo"));
442 #elif defined(ARDUINO_AVR_MINI) 443 stream.print(F(
"Arduino Leonardo"));
444 #elif defined(ARDUINO_AVR_UNO) 445 stream.print(F(
"Arduino Uno"));
447 stream.print(F(
"Unknown"));
456 static inline bool isPrefix(
const String& cmd,
const char *
string) {
457 return strncmp(cmd.c_str(), string, cmd.length()) == 0;
460 static inline bool isPrefix(
const char *
string,
const String& cmd) {
461 return strncmp(cmd.c_str(), string, strlen(
string)) == 0;
465 bool isPrefix(
const String& cmd,
const __FlashStringHelper *pstring) {
466 return strncmp_PF(cmd.c_str(), (uint_farptr_t) pstring, cmd.length()) == 0;
469 bool isPrefix(
const __FlashStringHelper *pstring,
const String& cmd) {
470 return strncmp_PF(cmd.c_str(), (uint_farptr_t) pstring, strlen_PF((uint_farptr_t) pstring)) == 0;
475 #if defined(COMMANDLED) & defined(LED) 481 while (stream.available() == 0) {
485 String line = stream.readStringUntil(
EOLCHAR);
490 static char str[1000];
491 std::cin.getline(str, 1000);
492 if (std::cin.eof()) {
493 std::cout <<
"Bye!" << std::endl;
499 while (isspace(s[strlen(s)-1]))
500 s[strlen(s)-1] =
'\0';
504 #if defined(DEBUG_CMD) 507 #if defined(COMMANDLED) & defined(LED) 521 if (cmd.length() == 0) {
527 if (cmd[0] ==
'a' || cmd[0] ==
'c') {
534 String rest = tokenizer.
getRest();
542 pin_t no = (pin_t) tokenizer.
getInt();
543 String value = tokenizer.
getToken();
567 String variableName = tokenizer.
getToken();
568 long value = tokenizer.
getInt();
569 unsigned long *variable32 = NULL;
570 uint16_t *variable16 = NULL;
571 uint8_t *variable8 = NULL;
572 #if defined(RECEIVE) || defined(CAPTURE) 573 if (
isPrefix(F(
"beg"), variableName))
578 if (
isPrefix(F(
"capturee"), variableName))
582 if (
isPrefix(F(
"receivee"), variableName))
586 #if defined(RECEIVE) & defined(IRRECEIVER_2_PIN) 587 if (
isPrefix(variableName, F(
"receiver")))
592 if (
isPrefix(F(
"captures"), variableName)) {
598 #ifdef CONFIGURABLE_LEDS 600 if (
isPrefix(F(
"transmitl"), variableName))
605 if (
isPrefix(F(
"capturel"), variableName))
610 if (
isPrefix(F(
"receivel"), variableName))
615 if (
isPrefix(F(
"commandl"), variableName))
626 if (variable32 != NULL) {
631 }
else if (variable16 != NULL) {
633 *variable16 = (uint16_t) value;
636 }
else if (variable8 != NULL) {
638 *variable8 = (uint8_t) value;
642 stream.println(F(
"No such variable"));
661 #ifdef NAMED_COMMANDS 663 uint16_t noSends = (uint16_t) tokenizer.
getInt();
664 String remoteName = tokenizer.
getToken();
665 String commandName = tokenizer.
getToken();
666 bool success = sendNamedCommand(stream, remoteName, commandName, noSends);
673 dumpRemote(stream, name);
686 uint16_t noSends = (uint16_t) tokenizer.
getInt();
688 uint16_t introLength = (uint16_t) tokenizer.
getInt();
689 uint16_t repeatLength = (uint16_t) tokenizer.
getInt();
690 uint16_t endingLength = (uint16_t) tokenizer.
getInt();
691 microseconds_t intro[introLength];
692 microseconds_t repeat[repeatLength];
693 microseconds_t ending[endingLength];
694 for (uint16_t i = 0; i < introLength; i++)
696 for (uint16_t i = 0; i < repeatLength; i++)
698 for (uint16_t i = 0; i < endingLength; i++)
700 IrSignal irSignal(intro, introLength, repeat, repeatLength, ending, endingLength, frequency);
701 bool status = sendIrSignal(irSignal, noSends);
708 uint16_t noSends = (uint16_t) tokenizer.
getInt();
709 String rest = tokenizer.
getRest();
710 IrSignal *irSignal = Pronto::parse(rest.c_str());
712 if (irSignal != NULL) {
713 status = sendIrSignal(*irSignal, noSends);
723 uint16_t noSends = (uint16_t) tokenizer.
getInt();
724 String protocol = tokenizer.
getToken();
725 const IrSignal *irSignal = NULL;
726 if (
isPrefix(protocol, F(
"nec1"))) {
727 unsigned int D = (unsigned) tokenizer.
getInt();
728 unsigned int S = (unsigned) tokenizer.
getInt();
729 unsigned int F = (unsigned) tokenizer.
getInt();
731 ? Nec1Renderer::newIrSignal(D, S)
732 : Nec1Renderer::newIrSignal(D, S, F);
733 }
else if (
isPrefix(protocol, F(
"rc5"))) {
734 unsigned int D = (unsigned) tokenizer.
getInt();
735 unsigned int F = (unsigned) tokenizer.
getInt();
736 unsigned int T = (unsigned) tokenizer.
getInt();
738 ? Rc5Renderer::newIrSignal(D, F)
739 : Rc5Renderer::newIrSignal(D, F, T);
741 stream.print(F(
"no such protocol: "));
742 stream.println(protocol);
745 if (irSignal != NULL) {
746 status = sendIrSignal(*irSignal, noSends);
776 Serial.println(
"Command: " + line);
781 #if defined(ETHERNET) 783 while (client.available() == 0) {
788 if (!client.connected())
802 EthernetClient client =
server.available();
805 client.setTimeout(10000);
812 Serial.print(F(
"Connection from "));
815 #if defined(COMMANDLED) & defined(LED) 820 #if defined(COMMANDLED) & defined(LED) 828 Serial.println(F(
"Connection closed!"));
830 client.println(F(
"Bye"));
832 #if defined(COMMANDLED) & defined(LED) 836 if (client.connected())
843 Stream& stream = Serial;
845 Stream stream(std::cout);
microseconds_t getMicroseconds()
static const unsigned sensorNo
static bool receive(Stream &stream)
#define IRRECEIVER_MARK_EXCESS
This quantity is added to all gaps and subtracted from all marks when receiving.
#define VERSION
Version of the current library.
EthernetServer server(PORT)
static void setupReceivers()
static pin_t receiverPin(uint8_t receiverNo UNUSED)
static void setupSensors()
#define SERIALBAUD
Configured speed of the serial port.
static bool readProcessOneCommand(Stream &stream)
#define COMMANDLED
Number of logical LED to light when waiting for command.
#define DEFAULT_CAPTURESIZE
Size of capture and receive arrays.
#define PORT
TCP port to use.
static void lcdSetCursor(uint8_t x=0, uint8_t y=0)
#define DEFAULT_CAPTURE_ENDINGTIMEOUT
By capture, time to wait before signal is considered ended.
static void setup(int8_t i2cAddress=-1, uint8_t columns=defaultLcdColumns, uint8_t rows=defaultLcdRows, const pin_t physicalLeds[maxLeds]=NULL, const led_t logicalLeds[maxLeds]=NULL, const bool shouldTimeOut[maxLeds]=NULL)
Sets up the instance, to be called before using the instance.
bool readProcessOneTcpCommand(EthernetClient &client)
static String ip2string(IPAddress ip)
#define TRANSMITLED
Number of logical LED to light when transmission takings place.
#define RECEIVELED
Number of logical LED to light when waiting for reception.
#define EXPAND_AND_QUOTE(str)
static PARAMETER_CONST unsigned long receiveEndingTimeout
static const uint8_t receiverNo
static bool setLogicLed(led_t logicLed, LedState state)
static PARAMETER_CONST uint16_t captureSize
#define DEFAULT_RECEIVE_ENDINGTIMEOUT
By receive, time to wait before signal is considered ended.
static void setupLedGroundPins()
#define LED_PARAMETER_CONST
static void flushIn(Stream &stream UNUSED)
static PARAMETER_CONST unsigned long captureEndingTimeout
static void setupShouldTimeout(led_t logicLed, bool state)
static IrReceiver * irReceiver
frequency_t getFrequency()
static void decodeOrDump(IrReader *irReader, Stream &stream)
#define EOLCHAR
Character that ends the command lines.
static bool processCommand(const String &line, Stream &stream)
#define MACADDRESS
Must define MAC-Address to use here (!!).
static bool isPrefix(const String &cmd, const char *string)
static void lcdPrint(String &string, bool clear=true, int x=0, int y=-1)
static void printVariable(Stream &stream, const char *variableName, unsigned long value)
#define CAPTURELED
Number of logical LED to light when waiting for capture.
static bool sensorPullup(uint8_t sensorNo UNUSED)
static void selfTest(const char *text)
#define SERIALTIMEOUT
Timeout for serial line.
#define IRSENSOR_MARK_EXCESS
This quantity is added to all gaps and subtracted from all marks when capturing.
#define SDCARD_ON_ETHERSHIELD_PIN
Pin to disable (put low) on Ethernet shield.
static void checkTurnoff()
Turn off if it is due.
static String readCommand(Stream &stream)
#define DECODELED
Define to support blinking with LED according to decoding outcome.
#define DEFAULT_BEGINTIMEOUT
Time to wait for signal to start.
static bool capture(Stream &stream)
static PARAMETER_CONST unsigned long beginTimeout
static unsigned long freeRam()
static bool receiverPullup(uint8_t receiverNo UNUSED)