Hey guys,
I'm having trouble using IrRecv inside a class. I get some redefinition errors. Is there something I'm missing?
// Classe Climatisation
// gère un moteur DC branché un pin PWM et une DEL
// possède un DHT11 pour le contrôle de la température
// Tâche : Le moteur et la DEL s'active lorsque la température est supérieure à 23°C
// Tâche : Le moteur et la DEL s'arrête lorsque la température est inférieure à 22°C
// Tâche : Le moteur est sur Pause si la valeur de l'attribue onPause est à true
#pragma once
#include <Arduino.h>
#include <DHT.h>
#include <IRremote.hpp>
#define TEMP_INTERVAL 5000
#define DHTTYPE DHT11
// Énumération pour les états du moteur soit ON, OFF et PAUSE
enum MotorState { ON, OFF, PAUSE };
class Climatisation {
public:
// Constructeur
Climatisation(int pinMotor, int pinLed, int pinDht, int pinIR);
// Méthodes
void update();
void setOnPause(bool value) { _onPause = value; };
bool getOnPause() { return _onPause; };
float getTemperature() { return _temperature; };
float getHumidity() { return _humidity; };
void setLowTemp(int value) { _lowTemp = value; };
void setHighTemp(int value) { _highTemp = value; };
// Méthode pour ajouter un callback
void setCallback(void (*callback)(bool, String)) {
this->callback = callback;
}
private:
int _pinMotor;
int _pinLed;
int _pinDht;
int _pinIR = -1;
DHT _dht;
IRrecv _irRecv;
bool _onPause;
float _temperature;
float _humidity;
unsigned long _currentTime;
int _lowTemp = 22;
int _highTemp = 23;
MotorState _motorState = OFF;
void onState();
void offState();
void pauseState();
void readDht();
// Callback, état et nom de l'événement
void (*callback)(bool, String);
void sendEvent(bool);
};
#include "Climatisation.h"
// Constructeur
Climatisation::Climatisation(int pinMotor, int pinLed, int pinDht, int pinIR)
: _pinMotor(pinMotor), _pinLed(pinLed), _pinDht(pinDht), _pinIR(pinIR), _dht(_pinDht, DHTTYPE), _irRecv(pinIR){
_dht.begin();
if (_pinIR != -1) {
//IrReceiver.begin(_pinIR, false); // Assurez-vous que _pinIR est initialisé correctement
}
_onPause = false;
_temperature = 0;
_humidity = 0;
_currentTime = 0;
}
// Lecture du DHT à l'intervalle TEMP_INTERVAL
void Climatisation::readDht() {
static unsigned long _dhtPrevious = 0;
if (_currentTime - _dhtPrevious < TEMP_INTERVAL) return;
_dhtPrevious = _currentTime;
_humidity = _dht.readHumidity();
_temperature = _dht.readTemperature();
}
// Méthode update
void Climatisation::update() {
_currentTime = millis();
readDht();
switch (_motorState) {
case ON:
onState();
break;
case OFF:
offState();
break;
case PAUSE:
pauseState();
break;
default:
break;
}
}
// Méthode onState
void Climatisation::onState() {
if (_onPause) {
_motorState = PAUSE;
sendEvent(false);
return;
}
if (_temperature <= _lowTemp) {
_motorState = OFF;
sendEvent(false);
return;
}
digitalWrite(_pinMotor, 255);
digitalWrite(_pinLed, HIGH);
}
// Méthode offState
void Climatisation::offState() {
if (_temperature >= _highTemp) {
_motorState = ON;
sendEvent(true);
return;
}
digitalWrite(_pinMotor, 0);
digitalWrite(_pinLed, LOW);
}
// Méthode pauseState
void Climatisation::pauseState() {
if (!_onPause) {
_motorState = ON;
sendEvent(true);
return;
}
digitalWrite(_pinMotor, 0);
}
void Climatisation::sendEvent(bool state) {
if (callback == NULL) return;
callback(state, "Climatisation");
}
Errors
private/var/folders/lb/hq1157px7h73_45gyzmw2kch0000gn/T/arduino/sketches/16E98FAD8F09B8B800C32B1CCB7D490F/sketch/prj_maison_pair.ino.cpp.o (symbol from plugin): In function `evenemement(bool, String)':
(.text+0x0): multiple definition of `irparams'
/private/var/folders/lb/hq1157px7h73_45gyzmw2kch0000gn/T/arduino/sketches/16E98FAD8F09B8B800C32B1CCB7D490F/sketch/Climatisation.cpp.o (symbol from plugin):(.text+0x0): first defined here
/private/var/folders/lb/hq1157px7h73_45gyzmw2kch0000gn/T/arduino/sketches/16E98FAD8F09B8B800C32B1CCB7D490F/sketch/prj_maison_pair.ino.cpp.o (symbol from plugin): In function `evenemement(bool, String)':
(.text+0x0): multiple definition of `timerEnableReceiveInterrupt()'
and so on...
Thanks in advance