Infrared4Arduino 1.2.3
Loading...
Searching...
No Matches
IrSenderPwm.cpp
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#include "IrSenderPwm.h"
19
20#ifdef HAS_HARDWARE_PWM
21#include "IrSenderPwmHard.h"
22#else
24#endif
25
26IrSenderPwm *IrSenderPwm::instance = nullptr;
27
28IrSenderPwm::IrSenderPwm(pin_t outputPin) : IrSender(outputPin) {
29}
30
32 if (instance != nullptr)
33 return nullptr;
34 instance =
35#ifdef HAS_HARDWARE_PWM
37#else
38 new IrSenderPwmSoftDelay(outputPin);
39#endif
40 return instance;
41}
42
43IrSenderPwm *IrSenderPwm::getInstance(bool create, pin_t outputPin) {
44 if (instance == nullptr && create)
45 instance = newInstance(outputPin);
46 return instance;
47}
48
50 if (instance != nullptr)
51#ifdef HAS_HARDWARE_PWM
53#else
54 delete instance;
55#endif
56 instance = nullptr;
57}
uint8_t pin_t
Type for GPIO pin, compatible with Arduino libs.
Definition: InfraredTypes.h:41
static void deleteInstance()
static IrSenderPwmHard * newInstance(pin_t ouputPin=Board::getInstance() ->defaultPwmPin())
Creates a new instance (if not existing) and returns it.
Sending function using timer PWM.
Sending function using timer PWM.
Definition: IrSenderPwm.h:29
static void deleteInstance()
Definition: IrSenderPwm.cpp:49
IrSenderPwm(pin_t sendPin)
Definition: IrSenderPwm.cpp:28
static IrSenderPwm * getInstance(bool create=false, pin_t outputPin=Board::getInstance() ->defaultPwmPin())
Returns a pointer to the instance, or nullptr if not initialized.
Definition: IrSenderPwm.cpp:43
static IrSenderPwm * newInstance(pin_t outputPin)
Creates a new instance (if not existing) and returns it.
Definition: IrSenderPwm.cpp:31
Abstract base class for all sending classes.
Definition: IrSender.h:27