Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
IrSender.h
Go to the documentation of this file.
1/*
2Copyright (C) 2015 Bengt Martensson.
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2 of the License, or (at
7your option) any later version.
8
9This program is distributed in the hope that it will be useful, but
10WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12General Public License for more details.
13
14You should have received a copy of the GNU General Public License along with
15this program. If not, see http://www.gnu.org/licenses/.
16*/
17
18#pragma once
19
20#include <Arduino.h>
21#include "IrSignal.h"
22#include "Board.h"
23
27class IrSender {
28private:
29 pin_t sendPin;
30
31public:
32 inline pin_t getPin() const {
33 return sendPin;
34 }
35
36protected:
37 // TODO: Rewrite for efficiency
38 inline void writeHigh() { Board::getInstance()->writeHigh(sendPin); };
39 inline void writeLow() { Board::getInstance()->writeLow(sendPin); };
40
41 IrSender(pin_t pin);
42
43 // TODO: something sensible...
44 /*virtual*/ static void barfForInvalidPin(pin_t sendPin __attribute__((unused))) {};
45
46 virtual void enable(frequency_t frequency, dutycycle_t dutyCycle = Board::defaultDutyCycle) = 0;
47 virtual void sendSpace(microseconds_t time) { Board::delayMicroseconds(time); };
48 virtual void sendMark(microseconds_t time) = 0;
49
50public:
51#ifndef DOXYGEN
52 IrSender() = delete;
53 IrSender(const IrSender&) = delete;
54 IrSender(IrSender&&) = delete;
55 IrSender& operator=(const IrSender&) = delete;
56 IrSender& operator=(IrSender&&) = delete;
57#endif // ! DOXYGEN
58
59 virtual ~IrSender();
60
67 virtual void send(const IrSequence& irSequence, frequency_t frequency = IrSignal::defaultFrequency, dutycycle_t dutyCycle = Board::defaultDutyCycle);
68
77 void sendIrSignal(const IrSignal& irSignal, unsigned int noSends = 1);
78
84 void sendWhile(const IrSignal& irSignal, bool(*trigger)());
85
87 void mute() { writeLow(); };
88};
int8_t dutycycle_t
Type for duty cycle in percent.
Definition: InfraredTypes.h:36
uint16_t microseconds_t
Type for durations in micro seconds.
Definition: InfraredTypes.h:15
uint32_t frequency_t
Type for modulation frequency in Hz.
Definition: InfraredTypes.h:31
uint8_t pin_t
Type for GPIO pin, compatible with Arduino libs.
Definition: InfraredTypes.h:41
static Board * getInstance()
Definition: Board.h:53
virtual void writeHigh()
Definition: Board.h:299
static void delayMicroseconds(microseconds_t)
Version of delayMicroseconds able to grok more than 16383 micros.
Definition: Board.cpp:25
virtual void writeLow()
Definition: Board.h:298
static constexpr dutycycle_t defaultDutyCycle
Default duty cycle to use.
Definition: Board.h:69
Abstract base class for all sending classes.
Definition: IrSender.h:27
void writeLow()
Definition: IrSender.h:39
virtual void sendMark(microseconds_t time)=0
void writeHigh()
Definition: IrSender.h:38
static void barfForInvalidPin(pin_t sendPin __attribute__((unused)))
Definition: IrSender.h:44
pin_t getPin() const
Definition: IrSender.h:32
virtual void send(const IrSequence &irSequence, frequency_t frequency=IrSignal::defaultFrequency, dutycycle_t dutyCycle=Board::defaultDutyCycle)
Sends an IrSequence with the prescribed frequency.
Definition: IrSender.cpp:57
virtual ~IrSender()
Definition: IrSender.cpp:26
virtual void enable(frequency_t frequency, dutycycle_t dutyCycle=Board::defaultDutyCycle)=0
virtual void sendSpace(microseconds_t time)
Definition: IrSender.h:47
void sendIrSignal(const IrSignal &irSignal, unsigned int noSends=1)
Sends the IrSignal given as argument the prescribed number of times.
Definition: IrSender.cpp:30
void mute()
Force output pin inactive.
Definition: IrSender.h:87
void sendWhile(const IrSignal &irSignal, bool(*trigger)())
Send an IrSignal, when and as long as trigger() returns true.
Definition: IrSender.cpp:37
This class consists of a vector of durations.
Definition: IrSequence.h:11
This class models an IR signal with intro-, repeat-, and ending sequences.
Definition: IrSignal.h:11
static constexpr frequency_t defaultFrequency
Definition: IrSignal.h:13