Skip to content

Commit

Permalink
Misc fixes and modernizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengtmartensson committed Feb 6, 2021
1 parent 9479d8e commit a8b6f13
Show file tree
Hide file tree
Showing 37 changed files with 301 additions and 180 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ version: $(VERSION_H)
$(VERSION_H): library.properties Makefile
echo "Creating $(VERSION_H)"
@echo "// This file was automatically generated from $<; do not edit." > $@
@echo "#pragma once" >> $@
@echo "/**" >> $@
@echo " * Version of the current library." >> $@
@echo " * Taken from the version in $<." >> $@
Expand Down
28 changes: 7 additions & 21 deletions examples/IrReceiverSampler/IrReceiverSampler.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
#endif

#define BUFFERSIZE 200U
#define BAUD 115200

//#define DEBUG
#define BAUD 115200UL

#ifdef ARDUINO_AVR_NANO
#define IRRECEIVER_1_GND 6U
Expand All @@ -26,7 +24,7 @@
#define IRRECEIVER_1_VCC 14
#endif

IrReceiver *receiver;
static IrReceiver *receiver;

void setup() {
#ifdef IRRECEIVER_1_GND
Expand All @@ -45,24 +43,12 @@ void setup() {
receiver = IrReceiverSampler::newIrReceiverSampler(BUFFERSIZE, RECEIVE_PIN);
Serial.print("Listening on pin ");
Serial.println(receiver->getPin(), DEC);
receiver->enable();
#ifdef DEBUG_PIN
Serial.print(F("Debug pin = "));
Serial.println(DEBUG_PIN, DEC);
#endif
}

void loop() {
if (receiver->isReady()) {
if (receiver->isEmpty())
Serial.println("timeout");
else
receiver->dump(Serial);
receiver->reset();
} else {
#ifdef DEBUG
Serial.println("listening");
delay(2000);
#endif
}
receiver->receive(); // combines enable, loop, disable
if (receiver->isEmpty())
Serial.println("timeout");
else
receiver->dump(Serial);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// This sketch combines sending and receiving.

#include <Arduino.h>
#include <IrReceiverSampler.h>
#include <IrSenderPwm.h>

#ifdef ESP32
#define RECEIVE_PIN 4U
#elif defined(ESP8266)
#define RECEIVE_PIN 2U
#elif defined(ARDUINO_AVR_MICRO)
#define RECEIVE_PIN 10
#elif defined (ARDUINO_TEENSY32) // Teenex 3.1-3.2
#define RECEIVE_PIN 7U
#else
#define RECEIVE_PIN 5U
#endif

#define BUFFERSIZE 200U
#define BAUD 115200

#ifdef ARDUINO_AVR_NANO
#define IRRECEIVER_1_GND 6U
#define IRRECEIVER_1_VCC 7U
#endif

#ifdef ARDUINO_AVR_MICRO
#define IRRECEIVER_1_GND 16U
#define IRRECEIVER_1_VCC 14U
#endif

static constexpr frequency_t necFrequency = 38400U;

// NEC(1) 122 29 with no repetition; powers on many Yamaha receivers
static const microseconds_t array[]
#if HAS_FLASH_READ
PROGMEM
#endif
= {
9024, 4512, 564, 564, 564, 1692, 564, 564, 564, 1692, 564, 1692,
564, 1692, 564, 1692, 564, 564, 564, 1692, 564, 564, 564, 1692,
564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564,
564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564,
564, 564, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 1692, 564,
1692, 564, 1692, 564, 39756
};

static const IrSequence* irSequence =
#if HAS_FLASH_READ
IrSequence::readFlash(array, sizeof (array) / sizeof (microseconds_t));
#else
new IrSequence(array, sizeof (array) / sizeof (microseconds_t));
#endif
static IrReceiver *receiver;

void setup() {
#ifdef IRRECEIVER_1_GND
pinMode(IRRECEIVER_1_GND, OUTPUT);
digitalWrite(IRRECEIVER_1_GND, LOW);
#endif

#ifdef IRRECEIVER_1_VCC
pinMode(IRRECEIVER_1_VCC, OUTPUT);
digitalWrite(IRRECEIVER_1_VCC, HIGH);
#endif

Serial.begin(BAUD);
while(!Serial)
;
#if HAS_FLASH_READ
Serial.println(F("Sending a signal from PROGMEM!"));
#else
Serial.println(F("Sending a signal!"));
#endif
IrSender *sender = IrSenderPwm::getInstance(true);
sender->send(*irSequence, necFrequency);

receiver = IrReceiverSampler::newIrReceiverSampler(BUFFERSIZE, RECEIVE_PIN);
Serial.println(F("Listening!"));
receiver->enable();
}

void loop() {
receiver->receive(); // combines enable, loop, disable
if (receiver->isEmpty()) {
Serial.println("timeout");
} else
receiver->dump(Serial);
}
8 changes: 3 additions & 5 deletions examples/IrSenderNonMod/IrSenderNonMod.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <IrSenderNonMod.h>

#define NON_MOD_PIN 10U
static constexpr pin_t NON_MOD_PIN = 10U;

// Arctech D=13, S=8, F=0 (Generated by IrScrutinizer)
static const microseconds_t offData[] = {
Expand Down Expand Up @@ -33,10 +33,8 @@ void setup() {
void loop() {
// send it twice, since Intertechno devices seems to need that
// for reliability
sender.sendNonModulated(on);
sender.sendNonModulated(on);
sender.sendNonModulated(on, 2);
delay(2000);
sender.sendNonModulated(off);
sender.sendNonModulated(off);
sender.sendNonModulated(off, 2);
delay(2000);
}
11 changes: 5 additions & 6 deletions examples/IrSenderPwm/IrSenderPwm.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

#include <IrSenderPwm.h>

static const frequency_t necFrequency = 38400U;
static const unsigned long BAUD = 115200U;
static const pin_t PIN = 3U;
static constexpr frequency_t necFrequency = 38400U;
static constexpr unsigned long BAUD = 115200UL;
static constexpr pin_t PIN = 3U;

// NEC(1) 122 29 with no repetition; powers on many Yamaha receivers
static const microseconds_t array[] = {
Expand All @@ -20,8 +20,7 @@ static const microseconds_t array[] = {
};

static const IrSequence irSequence(array, sizeof(array) / sizeof(microseconds_t));
static dutycycle_t dutyCycle;
IrSender* irSender;
static IrSender* irSender;

void setup() {
Serial.begin(BAUD);
Expand All @@ -32,11 +31,11 @@ void setup() {
else
Serial.println(F("Hardware PWM NOT available, will be emulated in software."));
randomSeed(analogRead(A0));
dutyCycle = (dutycycle_t) random(20,80);
irSender = IrSenderPwm::getInstance(true, PIN);
}

void loop() {
dutycycle_t dutyCycle;dutyCycle = static_cast<dutycycle_t>(random(20,80));
Serial.print(F("Shooting @ pin "));
Serial.print(irSender->getPin(), DEC);
Serial.print(F(" with duty cycle "));
Expand Down
13 changes: 9 additions & 4 deletions examples/IrSenderPwmSoftDelay/IrSenderPwmSoftDelay.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

#include <IrSenderPwmSoftDelay.h>

static const frequency_t necFrequency = 38400U;
static const pin_t pin = 4U; // D2 on ESP8266
static const uint32_t BAUD = 115200UL;
static constexpr frequency_t necFrequency = 38400U;
static constexpr pin_t pin =
#ifdef ESP8266
4U; // D2 on ESP8266
#else
3U;
#endif
static constexpr uint32_t BAUD = 115200UL;

// NEC(1) 122 29 with no repetition; powers on many Yamaha receivers
static const microseconds_t array[] = {
Expand All @@ -18,7 +23,7 @@ static const microseconds_t array[] = {
};

static const IrSequence irSequence(array, sizeof(array) / sizeof(microseconds_t));
IrSender* irSender;
static IrSender* irSender;

void setup() {
Serial.begin(BAUD);
Expand Down
19 changes: 13 additions & 6 deletions examples/IrSenderPwmSpinWait/IrSenderPwmSpinWait.ino
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
// This sketch sends a raw signal using the soft PWM sender every 5 seconds.
// It requires an IR-Led connected to the sending pin
// On slow processors, it may produce erroneous result,
// in particular modulation frequency.

#include <IrSenderPwmSpinWait.h>

static const frequency_t necFrequency = 38400U;
static const pin_t pin = 4U; // D2 on ESP8266
static const unsigned long BAUD = 115200UL;
static constexpr frequency_t necFrequency = 38400U;
static constexpr pin_t pin =
#ifdef ESP8266
4U; // D2 on ESP8266
#else
3U;
#endif
static constexpr uint32_t BAUD = 115200UL;

// NEC(1) 122 29 with no repetition; powers on many Yamaha receivers
static const microseconds_t array[] = {
Expand All @@ -18,7 +25,7 @@ static const microseconds_t array[] = {
};

static const IrSequence irSequence(array, sizeof(array) / sizeof(microseconds_t));
IrSender* irSender;
static IrSender* irSender;

void setup() {
Serial.begin(BAUD);
Expand All @@ -28,8 +35,8 @@ void setup() {
}

void loop() {
Serial.print("sending on pin ");
Serial.print(F(" sending @ pin "));
Serial.println(pin, DEC);
irSender->send(irSequence, necFrequency, 33U);
irSender->send(irSequence, necFrequency);
delay(5000);
}
17 changes: 8 additions & 9 deletions examples/LearningHashDecoder/LearningHashDecoder.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <IrReceiverSampler.h>
#include <HashDecoder.h>

#define RECEIVE_PIN 5U
#define BUFFERSIZE 200U
#define BAUD 115200
static constexpr pin_t RECEIVE_PIN = 5U;
static constexpr size_t BUFFERSIZE = 200U;
static constexpr uint32_t BAUD = 115200UL;
static constexpr uint32_t NecRepeatHash = 84696351UL;

//#define DEBUG

Expand All @@ -24,11 +25,9 @@ public :
Command(const char* n, uint32_t c) : name(n),code(c) {}
};

unsigned numberCommands = sizeof (names) / sizeof (const char*);

static constexpr unsigned numberCommands = sizeof(names) / sizeof(const char*);
static Command *learnedCommands;

IrReceiver *receiver;
static IrReceiver *receiver;

void setup() {
Serial.begin(BAUD);
Expand Down Expand Up @@ -80,14 +79,14 @@ void setup() {

void loop() {
do
receiver->receive();
receiver->receive();
while (receiver->isEmpty());

uint32_t hash = HashDecoder::decodeHash(*receiver);
#ifdef DEBUG
Serial.println(hash);
#endif
if (hash == 84696351) // NEC1 repeat, discard
if (hash == NecRepeatHash) // NEC1 repeat, discard
return;

for (unsigned i = 0; i < numberCommands; i++) {
Expand Down
6 changes: 3 additions & 3 deletions examples/MicroGirs/MicroGirs.ino
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ static bool processCommand(const String& line, Stream& stream) {
uint16_t introLength = (uint16_t) tokenizer.getInt();
uint16_t repeatLength = (uint16_t) tokenizer.getInt();
uint16_t endingLength = (uint16_t) tokenizer.getInt();
microseconds_t intro[introLength];
microseconds_t repeat[repeatLength];
microseconds_t ending[endingLength];
microseconds_t *intro = new microseconds_t[introLength];
microseconds_t *repeat = new microseconds_t[repeatLength];
microseconds_t *ending = new microseconds_t[endingLength];
for (uint16_t i = 0; i < introLength; i++)
intro[i] = tokenizer.getMicroseconds();
for (uint16_t i = 0; i < repeatLength; i++)
Expand Down
4 changes: 2 additions & 2 deletions examples/MultiDecoder/MultiDecoder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define RECEIVE_PIN 5U
#define BUFFERSIZE 200U
#define BAUD 115200
#define BAUD 115200UL

IrReceiver *receiver;

Expand All @@ -22,7 +22,7 @@ void loop() {
Serial.println(F("timeout"));
else {
MultiDecoder decoder(*receiver);
if (decoder.isValid())
if (decoder)
decoder.printDecode(Serial);
else
Serial.println(F("No decode"));
Expand Down
12 changes: 7 additions & 5 deletions examples/Nec1Decoder/Nec1Decoder.ino
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// This sketch uses the IrReceiveSampler to receive a signal, and tries to
// decode it as a NEC1 signal
// decode it as a NEC signal

#include <IrReceiverSampler.h>
#include <Nec1Decoder.h>

#define RECEIVE_PIN 5U
#define BUFFERSIZE 200U
#define BAUD 115200
#define BAUD 115200UL

IrReceiver *receiver;
static IrReceiver *receiver;

void setup() {
Serial.begin(BAUD);
while (!Serial)
;
receiver = IrReceiverSampler::newIrReceiverSampler(BUFFERSIZE, RECEIVE_PIN);
}

Expand All @@ -22,9 +24,9 @@ void loop() {
Serial.println(F("timeout"));
else {
Nec1Decoder decoder(*receiver);
if (decoder.isValid())
if (decoder)
decoder.printDecode(Serial);
else
Serial.println(F("No decode"));
Serial.println(F("No decode as NEC"));
}
}
Loading

0 comments on commit a8b6f13

Please sign in to comment.