Skip to content

Commit

Permalink
Modernize IrSignal.
Browse files Browse the repository at this point in the history
Resolves #16. Part of #17.
  • Loading branch information
bengtmartensson committed Jan 30, 2021
1 parent 867bea8 commit b27d92f
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 41 deletions.
4 changes: 3 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,14 @@ getDataLength KEYWORD2
getDuration KEYWORD2
IrSignal KEYWORD2
IrSignal KEYWORD2
IrSignal KEYWORD2
~IrSignal KEYWORD2
IrSignal KEYWORD2
IrSignal KEYWORD2
IrSignal KEYWORD2
IrSignal KEYWORD2
clone KEYWORD2
IrSignal KEYWORD2
IrSignal KEYWORD2
getFrequency KEYWORD2
getDutyCycle KEYWORD2
getEnding KEYWORD2
Expand Down
32 changes: 16 additions & 16 deletions src/IrSignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,42 @@ IrSignal::IrSignal(const IrSequence& intro_, const IrSequence& repeat_, const Ir
: frequency(frequency_),dutyCycle(dutyCycle_),intro(intro_),repeat(repeat_),ending(ending_) {
}

IrSignal::IrSignal(IrSequence&& intro_, IrSequence&& repeat_, IrSequence&& ending_,
frequency_t frequency_, dutycycle_t dutyCycle_)
: frequency(frequency_),dutyCycle(dutyCycle_),intro(intro_),repeat(repeat_),ending(ending_) {
}

IrSignal::IrSignal(const IrSequence& intro_, const IrSequence& repeat_,
frequency_t frequency_, dutycycle_t dutyCycle_)
: frequency(frequency_), dutyCycle(dutyCycle_), intro(intro_), repeat(repeat_), ending() {
}

IrSignal::IrSignal(const IrSignal& orig)
: frequency(orig.frequency),dutyCycle(orig.dutyCycle),intro(orig.intro),repeat(orig.repeat),ending(orig.ending) {
IrSignal::IrSignal(IrSequence&& intro_, IrSequence&& repeat_,
frequency_t frequency_, dutycycle_t dutyCycle_)
: frequency(frequency_), dutyCycle(dutyCycle_), intro(intro_), repeat(repeat_), ending() {
}

IrSignal::IrSignal(const microseconds_t *intro_, size_t introLength,
const microseconds_t *repeat_, size_t repeatLength,
const microseconds_t *ending_, size_t endingLength,
frequency_t frequency_, dutycycle_t dutyCycle_)
const microseconds_t *repeat_, size_t repeatLength,
const microseconds_t *ending_, size_t endingLength,
frequency_t frequency_, dutycycle_t dutyCycle_)
: frequency(frequency_),
dutyCycle(dutyCycle_),
intro(intro_, introLength),
repeat(repeat_, repeatLength),
ending(ending_, endingLength) {
dutyCycle(dutyCycle_),
intro(intro_, introLength),
repeat(repeat_, repeatLength),
ending(ending_, endingLength) {
}

IrSignal::IrSignal(const microseconds_t *intro_, size_t introLength,
const microseconds_t *repeat_, size_t repeatLength,
frequency_t frequency_, dutycycle_t dutyCycle_)
: frequency(frequency_),
dutyCycle(dutyCycle_),
dutyCycle(dutyCycle_),
intro(intro_, introLength),
repeat(repeat_, repeatLength),
ending() {
}

IrSignal::~IrSignal() {
//delete intro;
//delete repeat;
//delete ending;
}

#if HAS_FLASH_READ

IrSignal* IrSignal::readFlash(const microseconds_t *intro, size_t lengthIntro,
Expand Down
116 changes: 92 additions & 24 deletions src/IrSignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,117 @@
class IrSignal {
public:
static const frequency_t defaultFrequency = 38000U;
static const frequency_t invalidFrequency = (frequency_t) -1;
static const dutycycle_t noDutyCycle = -1;
private:
static const frequency_t invalidFrequency = static_cast<frequency_t>(-1);
static const dutycycle_t noDutyCycle = static_cast<dutycycle_t>(-1);
static const dutycycle_t defaultDutyCycle = noDutyCycle;

private:
// Maintainer note: the members being const prohibits assignment operators.
// Alternatively, the members can be made non-const and assignments allowed.
const frequency_t frequency = defaultFrequency;
const dutycycle_t dutyCycle = defaultDutyCycle;
const IrSequence intro;
const IrSequence repeat;
const IrSequence ending;

public:
IrSignal();
IrSignal(const IrSignal& orig);
/**
* Constructs an empty IrSignal.
*/
IrSignal() {};
IrSignal(const IrSignal& orig) = default;
IrSignal(IrSignal&& orig) = default;

#ifndef DOXYGEN
IrSignal& operator=(const IrSignal& rhs) = delete;
IrSignal& operator=(IrSignal&& rhs) = delete;
#endif // ! DOXYGEN

virtual ~IrSignal();
virtual ~IrSignal() {};

/**
* Constructor that "moves" the data pointers.
* This is essentially a convenience function that combines IrSequence and IrSignal constructors.
*
* @param intro
* @param lengthIntro
* @param repeat
* @param lengthRepeat
* @param ending
* @param lengthEnding
* @param frequency
* @param dutyCycle
*/
IrSignal(const microseconds_t *intro, size_t lengthIntro,
const microseconds_t *repeat, size_t lengthRepeat,
const microseconds_t *ending, size_t lengthEnding,
frequency_t frequency = defaultFrequency,
dutycycle_t dutyCycle = defaultDutyCycle);

/**
* Constructor that "moves" the data pointers. No ending sequence.
* This is essentially a convenience function that combines IrSequence and IrSignal constructors.
*
* @param intro
* @param lengthIntro
* @param repeat
* @param lengthRepeat
* @param frequency
* @param dutyCycle
*/
IrSignal(const microseconds_t *intro, size_t lengthIntro,
const microseconds_t *repeat, size_t lengthRepeat,
frequency_t frequency = defaultFrequency,
dutycycle_t dutyCycle = defaultDutyCycle);

/**
* Copy constructor.
* @param intro
* @param repeat
* @param ending
* @param frequency
* @param dutyCycle
* @return
*/
IrSignal(const IrSequence& intro, const IrSequence& repeat, const IrSequence& ending,
frequency_t frequency = defaultFrequency, dutycycle_t dutyCycle = defaultDutyCycle);

/**
* Move constructor.
*
* @param intro
* @param repeat
* @param ending
* @param frequency
* @param dutyCycle
* @return
*/
IrSignal(IrSequence&& intro, IrSequence&& repeat, IrSequence&& ending,
frequency_t frequency = defaultFrequency, dutycycle_t dutyCycle = defaultDutyCycle);

/**
* Copy constructors for IrSignals without ending sequence.
*
* @param intro
* @param repeat
* @param frequency
* @param dutyCycle
* @return
*/
IrSignal(const IrSequence& intro, const IrSequence& repeat,
frequency_t frequency = defaultFrequency, dutycycle_t dutyCycle = defaultDutyCycle);

/**
* Move constructor for IrSignals without ending sequence.
* @param intro
* @param repeat
* @param frequency
* @param dutyCycle
* @return
*/
IrSignal(IrSequence&& intro, IrSequence&& repeat,
frequency_t frequency = defaultFrequency, dutycycle_t dutyCycle = defaultDutyCycle);

static IrSignal* readFlash(const microseconds_t *intro, size_t lengthIntro,
const microseconds_t *repeat, size_t lengthRepeat,
const microseconds_t *ending, size_t lengthEnding,
Expand All @@ -47,22 +132,6 @@ class IrSignal {
frequency_t frequency = defaultFrequency,
dutycycle_t dutyCycle = defaultDutyCycle);

private:
const frequency_t frequency;
const dutycycle_t dutyCycle;
const IrSequence intro;
const IrSequence repeat;
const IrSequence ending;

public:

/**
* Creates a (deep) copy of the current object.
* The user must delete it manually.
* @return Pointer to the cloned object.
*/
IrSignal *clone() const;

frequency_t getFrequency() const {
return frequency;
}
Expand Down Expand Up @@ -119,7 +188,6 @@ class IrSignal {
* Otherwise do nothing and return false.
* No extra spaces or line feeds are generated.
* @param stream Stream onto the output is printed.
* @param frequency modulation frequency
*/
bool dumpDutyCycle(Stream& stream) const {
return dumpDutyCycle(stream, dutyCycle);
Expand All @@ -128,7 +196,7 @@ class IrSignal {
/**
* Static version of dumpDutyCycle.
* @param stream Stream onto the output is printed.
* @param frequency modulation frequency
* @param dutyCycle
*/
static bool dumpDutyCycle(Stream& stream, dutycycle_t dutyCycle);

Expand Down

0 comments on commit b27d92f

Please sign in to comment.