Infrared4Arduino
IrSender.cpp
Go to the documentation of this file.
1 /*
2 Copyright (C) 2015 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 3 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 "IrSender.h"
19 #include "IrSignal.h"
20 
21 // From IRLib.cpp, renamed from My_delay_uSecs.
22 
23 //The Arduino built in function delayMicroseconds has limits we wish to exceed
24 //Therefore we have created this alternative
26  if (T) {
27  if (T > 16000) {
28  delayMicroseconds(T % 1000);
29  delay(T / 1000);
30  } else
31  delayMicroseconds(T);
32  };
33 }
34 
36  outputPin = invalidPin;
37 }
38 
40  outputPin = pin;
41  pinMode(pin, OUTPUT);
42  digitalWrite(pin, LOW);
43 }
44 
46  mute();
47 }
48 
50  digitalWrite(outputPin, LOW);
51 }
52 
53 void IrSender::sendIrSignal(const IrSignal& irSignal, unsigned int noSends) {
54  if (!irSignal.getIntro().isEmpty())
55  send(irSignal.getIntro(), irSignal.getFrequency());
56  for (unsigned int i = 0; i < irSignal.noRepetitions(noSends); i++)
57  send(irSignal.getRepeat(), irSignal.getFrequency());
58  if (!irSignal.getEnding().isEmpty())
59  send(irSignal.getEnding(), irSignal.getFrequency());
60 }
boolean isEmpty() const
Definition: IrSequence.h:53
uint16_t microseconds_t
Type for durations in micro seconds.
Definition: InfraredTypes.h:16
uint8_t pin_t
Type for GPIO pin, compatible with Arduino libs.
Definition: InfraredTypes.h:40
unsigned int noRepetitions(unsigned int noSends) const
Implementation of the count semantics, i.e., how many repetitions should be sent if the signal is sen...
Definition: IrSignal.h:104
This class models an IR signal with intro-, repeat-, and ending sequences.
Definition: IrSignal.h:11
const IrSequence & getIntro() const
Definition: IrSignal.h:64
void delayUSecs(microseconds_t T)
Definition: IrSender.cpp:25
const IrSequence & getRepeat() const
Definition: IrSignal.h:60
virtual void send(const IrSequence &irSequence, frequency_t frequency=IrSignal::defaultFrequency)=0
Sends an IrSequence with the prescribed frequency.
const pin_t invalidPin
Symbolic name for an invalid pin number.
Definition: InfraredTypes.h:42
frequency_t getFrequency() const
Definition: IrSignal.h:52
const IrSequence & getEnding() const
Definition: IrSignal.h:56
virtual void mute()
Force output pin inactive.
Definition: IrSender.cpp:49
virtual ~IrSender()
Definition: IrSender.cpp:45
IrSender()
Definition: IrSender.cpp:35
void sendIrSignal(const IrSignal &irSignal, unsigned int noSends=1)
Sends the IrSignal given as argument the prescribed number of times.
Definition: IrSender.cpp:53