Restructuration du projet entier
This commit is contained in:
parent
a070cc44eb
commit
f70cd29467
32 changed files with 439 additions and 216 deletions
|
@ -0,0 +1,5 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../../../include/AnalogDevices/AnalogActuators/AnalogActuatorMotor.h"
|
19
OtherDevices/AnalogDevices/AnalogDevice.cpp
Normal file
19
OtherDevices/AnalogDevices/AnalogDevice.cpp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
#include "../../include/AnalogDevices/AnalogDevice.h"
|
||||||
|
//AnalogDevice ///////////////////
|
||||||
|
|
||||||
|
AnalogDevice::AnalogDevice(int val, int temps) : Device(), val(val), temps(temps) {}
|
||||||
|
|
||||||
|
int AnalogDevice::getVal() const {
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AnalogDevice::getTemps() const {
|
||||||
|
return temps;
|
||||||
|
}
|
||||||
|
|
||||||
|
AnalogSensor::AnalogSensor(int val, int temps) : AnalogDevice(val, temps) {}
|
||||||
|
|
||||||
|
AnalogActuator::AnalogActuator(int val, int temps) : AnalogDevice(val, temps) {}
|
|
@ -0,0 +1,5 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../../../include/AnalogDevices/AnalogSensors/AnalogSensorHumidity.h"
|
|
@ -0,0 +1,18 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../../../include/AnalogDevices/AnalogSensors/AnalogSensorLuminosity.h"
|
||||||
|
|
||||||
|
//AnalogSensorLuminosity ///////////////////////////
|
||||||
|
AnalogSensorLuminosity::AnalogSensorLuminosity(int temps):AnalogDevice(200, temps){}
|
||||||
|
|
||||||
|
void AnalogSensorLuminosity::run(){
|
||||||
|
while(1){
|
||||||
|
val = luminosite_environnement;
|
||||||
|
if(ptrmem!=NULL){
|
||||||
|
*ptrmem = val;
|
||||||
|
}
|
||||||
|
sleep(temps);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../../../include/AnalogDevices/AnalogSensors/AnalogSensorManometre.h"
|
|
@ -0,0 +1,5 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../../../include/AnalogDevices/AnalogSensors/AnalogSensorPHmetre.h"
|
|
@ -0,0 +1,19 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../../../include/AnalogDevices/AnalogSensors/AnalogSensorTemperature.h"
|
||||||
|
|
||||||
|
//classe AnalogSensorTemperature
|
||||||
|
AnalogSensorTemperature::AnalogSensorTemperature(int val,int temps):AnalogDevice(val,temps){
|
||||||
|
alea=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnalogSensorTemperature::run(){
|
||||||
|
while(1){
|
||||||
|
alea=1-alea;
|
||||||
|
if(ptrmem!=NULL)
|
||||||
|
*ptrmem=val+alea;
|
||||||
|
sleep(temps);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../../../include/DigitalDevices/DigitalActuators/DigitalActuatorElectrovanne.h"
|
|
@ -0,0 +1,5 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../../../include/DigitalDevices/DigitalActuators/DigitalActuatorRadiator.h"
|
|
@ -0,0 +1,33 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../../../include/DigitalDevices/DigitalActuators/IntelligentDigitalActuatorLED.h"
|
||||||
|
|
||||||
|
// IntelligentDigitalActuatorLED //////////////////
|
||||||
|
IntelligentDigitalActuatorLED::IntelligentDigitalActuatorLED(int t):DigitalDevice(t){}
|
||||||
|
|
||||||
|
void IntelligentDigitalActuatorLED::run(){
|
||||||
|
int previousState = LOW; //initialisee a eteint
|
||||||
|
while(1){
|
||||||
|
if(ptrmem!=NULL) {
|
||||||
|
state = *ptrmem;
|
||||||
|
if (state == LOW) {
|
||||||
|
cout << "((((eteint))))\n";
|
||||||
|
if (state != previousState) {
|
||||||
|
luminosite_environnement -= 50;
|
||||||
|
}
|
||||||
|
previousState = state;
|
||||||
|
} else { //state == HIGH
|
||||||
|
cout << "((((allume))))\n";
|
||||||
|
if (state != previousState) {
|
||||||
|
luminosite_environnement += 50;
|
||||||
|
}
|
||||||
|
previousState = state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sleep(temps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
21
OtherDevices/DigitalDevices/DigitalDevice.cpp
Normal file
21
OtherDevices/DigitalDevices/DigitalDevice.cpp
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../../include/DigitalDevices/DigitalDevice.h"
|
||||||
|
//DigitalDevice ///////////////////
|
||||||
|
DigitalDevice::DigitalDevice(int temps) : Device(), state(LOW), temps(temps) {}
|
||||||
|
|
||||||
|
int DigitalDevice::getState() const {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DigitalDevice::getTemps() const {
|
||||||
|
return temps;
|
||||||
|
}
|
||||||
|
|
||||||
|
//DigitalSensors
|
||||||
|
|
||||||
|
DigitalSensor::DigitalSensor(int temps) : DigitalDevice(temps) {}
|
||||||
|
|
||||||
|
DigitalActuator::DigitalActuator(int temps) : DigitalDevice(temps) {}
|
|
@ -0,0 +1,30 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../../../include/DigitalDevices/DigitalSensors/ExternalDigitalSensorButton.h"
|
||||||
|
|
||||||
|
//ExternalDigDevice/////////////////////////
|
||||||
|
|
||||||
|
ExternalDigitalSensorButton::ExternalDigitalSensorButton(int temps):DigitalSensor(temps) {}
|
||||||
|
|
||||||
|
int ExternalDigitalSensorButton::getState(){
|
||||||
|
setState(); //determine if on.txt exists before getting state
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExternalDigitalSensorButton::setState() {
|
||||||
|
if (ifstream("D:\\Documents\\Etudes\\INSA\\4A\\C++\\Projet_VictorAvecUnK\\src\\on.txt")){
|
||||||
|
state = HIGH;
|
||||||
|
} else {
|
||||||
|
state = LOW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ExternalDigitalSensorButton::run() {
|
||||||
|
while (1) {
|
||||||
|
*ptrmem = this->getState();
|
||||||
|
sleep(temps);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,9 @@
|
||||||
#include "core_simulation.h"
|
#include "core_simulation.h"
|
||||||
#include "mydevices.h"
|
#include "mydevices.h"
|
||||||
|
#include "include/AnalogDevices/AnalogSensors/AnalogSensorTemperature.h"
|
||||||
|
#include "include/DigitalDevices/DigitalActuators/IntelligentDigitalActuatorLED.h"
|
||||||
|
#include "include/AnalogDevices/AnalogSensors/AnalogSensorLuminosity.h"
|
||||||
|
#include "include/DigitalDevices/DigitalSensors/ExternalDigitalSensorButton.h"
|
||||||
|
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
#!/usr/bin/bash
|
|
||||||
echo "g++ -Wall -std=c++11 board.cpp core_simulation.cpp mydevices.cpp sketch_ino.cpp -o arduino"
|
|
||||||
g++ -Wall -std=c++11 board.cpp core_simulation.cpp mydevices.cpp sketch_ino.cpp -o arduino
|
|
|
@ -2,7 +2,6 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "core_simulation.h"
|
#include "core_simulation.h"
|
||||||
|
|
||||||
// class BoardException
|
// class BoardException
|
||||||
|
|
|
@ -91,24 +91,24 @@ public:
|
||||||
class Board{
|
class Board{
|
||||||
public:
|
public:
|
||||||
// valeur sur les pin
|
// valeur sur les pin
|
||||||
unsigned short io[MAX_IO_PIN];
|
unsigned short io[MAX_IO_PIN];
|
||||||
// pin d'entree ou de sortie
|
// pin d'entree ou de sortie
|
||||||
enum typeio stateio[MAX_IO_PIN];
|
enum typeio stateio[MAX_IO_PIN];
|
||||||
// threads representant chaque senseur/actionneur sur le pins analogique et digitale
|
// threads representant chaque senseur/actionneur sur le pins analogique et digitale
|
||||||
thread *tabthreadpin[MAX_IO_PIN];
|
thread *tabthreadpin[MAX_IO_PIN];
|
||||||
// representation du bus I2C
|
// representation du bus I2C
|
||||||
I2C bus;
|
I2C bus;
|
||||||
// representation de la liaison terminal
|
// representation de la liaison terminal
|
||||||
Terminal Serial;
|
Terminal Serial;
|
||||||
// threads representant chaque senseur/actionneur sur le bus I2C
|
// threads representant chaque senseur/actionneur sur le bus I2C
|
||||||
thread *tabthreadbus[MAX_I2C_DEVICES];
|
thread *tabthreadbus[MAX_I2C_DEVICES];
|
||||||
|
|
||||||
// simulation de la boucle de controle arduino
|
// simulation de la boucle de controle arduino
|
||||||
void run();
|
void run();
|
||||||
// accroachage d'un senseur/actionneur à une pin
|
// accroachage d'un senseur/actionneur à une pin
|
||||||
void pin(int p, Device& s);
|
void pin(int p, Device& s);
|
||||||
// accroachage d'un senseur/actionneur à une adresse du bus I2C
|
// accroachage d'un senseur/actionneur à une adresse du bus I2C
|
||||||
void i2c(int addr,Device& dev);
|
void i2c(int addr,Device& dev);
|
||||||
// fonction arduino : configuration d'une pin en entree ou en sortie
|
// fonction arduino : configuration d'une pin en entree ou en sortie
|
||||||
void pinMode(int p,enum typeio t);
|
void pinMode(int p,enum typeio t);
|
||||||
// fonction arduino : ecriture HIGH ou LOW sur une pin
|
// fonction arduino : ecriture HIGH ou LOW sur une pin
|
||||||
|
@ -120,9 +120,9 @@ public:
|
||||||
// fonction arduino : ecriture analogique sur une pin
|
// fonction arduino : ecriture analogique sur une pin
|
||||||
int analogRead(int i);
|
int analogRead(int i);
|
||||||
// fonction arduino : initialisation de la carte arduino
|
// fonction arduino : initialisation de la carte arduino
|
||||||
void setup();
|
void setup();
|
||||||
// fonction arduino : boucle de controle de la carte arduino
|
// fonction arduino : boucle de controle de la carte arduino
|
||||||
void loop();
|
void loop();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
14
include/AnalogDevices/AnalogActuators/AnalogActuatorMotor.h
Normal file
14
include/AnalogDevices/AnalogActuators/AnalogActuatorMotor.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef PROJET_VICTORAVECUNK_ANALOGACTUATORMOTOR_H
|
||||||
|
#define PROJET_VICTORAVECUNK_ANALOGACTUATORMOTOR_H
|
||||||
|
|
||||||
|
|
||||||
|
class AnalogActuatorMotor {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PROJET_VICTORAVECUNK_ANALOGACTUATORMOTOR_H
|
34
include/AnalogDevices/AnalogDevice.h
Normal file
34
include/AnalogDevices/AnalogDevice.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
#include "../../core_simulation.h"
|
||||||
|
#include "../../mydevices.h"
|
||||||
|
|
||||||
|
#ifndef PROJET_VICTORAVECUNK_ANALOGDEVICE_H
|
||||||
|
#define PROJET_VICTORAVECUNK_ANALOGDEVICE_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class AnalogDevice : public Device{
|
||||||
|
protected:
|
||||||
|
int val;
|
||||||
|
// temps entre 2 prises de valeurs
|
||||||
|
int temps;
|
||||||
|
// valeur de temperature mesuree
|
||||||
|
public:
|
||||||
|
AnalogDevice(int val, int temps);
|
||||||
|
|
||||||
|
int getVal() const;
|
||||||
|
int getTemps() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AnalogSensor : public AnalogDevice{
|
||||||
|
public:
|
||||||
|
AnalogSensor(int val, int temps);
|
||||||
|
};
|
||||||
|
|
||||||
|
class AnalogActuator : public AnalogDevice{
|
||||||
|
public:
|
||||||
|
AnalogActuator(int val, int temps);
|
||||||
|
};
|
||||||
|
#endif //PROJET_VICTORAVECUNK_ANALOGDEVICE_H
|
14
include/AnalogDevices/AnalogSensors/AnalogSensorHumidity.h
Normal file
14
include/AnalogDevices/AnalogSensors/AnalogSensorHumidity.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef PROJET_VICTORAVECUNK_ANALOGSENSORHUMIDITY_H
|
||||||
|
#define PROJET_VICTORAVECUNK_ANALOGSENSORHUMIDITY_H
|
||||||
|
|
||||||
|
|
||||||
|
class AnalogSensorHumidity {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PROJET_VICTORAVECUNK_ANALOGSENSORHUMIDITY_H
|
23
include/AnalogDevices/AnalogSensors/AnalogSensorLuminosity.h
Normal file
23
include/AnalogDevices/AnalogSensors/AnalogSensorLuminosity.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef PROJET_VICTORAVECUNK_ANALOGSENSORLUMINOSITY_H
|
||||||
|
#define PROJET_VICTORAVECUNK_ANALOGSENSORLUMINOSITY_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include "../AnalogDevice.h"
|
||||||
|
|
||||||
|
class AnalogSensorLuminosity: public AnalogDevice{
|
||||||
|
|
||||||
|
public:
|
||||||
|
AnalogSensorLuminosity(int t);
|
||||||
|
virtual void run();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PROJET_VICTORAVECUNK_ANALOGSENSORLUMINOSITY_H
|
14
include/AnalogDevices/AnalogSensors/AnalogSensorManometre.h
Normal file
14
include/AnalogDevices/AnalogSensors/AnalogSensorManometre.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef PROJET_VICTORAVECUNK_ANALOGSENSORMANOMETRE_H
|
||||||
|
#define PROJET_VICTORAVECUNK_ANALOGSENSORMANOMETRE_H
|
||||||
|
|
||||||
|
|
||||||
|
class AnalogSensorManometre {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PROJET_VICTORAVECUNK_ANALOGSENSORMANOMETRE_H
|
14
include/AnalogDevices/AnalogSensors/AnalogSensorPHmetre.h
Normal file
14
include/AnalogDevices/AnalogSensors/AnalogSensorPHmetre.h
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef PROJET_VICTORAVECUNK_ANALOGSENSORPHMETRE_H
|
||||||
|
#define PROJET_VICTORAVECUNK_ANALOGSENSORPHMETRE_H
|
||||||
|
|
||||||
|
|
||||||
|
class AnalogSensorPHmetre {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PROJET_VICTORAVECUNK_ANALOGSENSORPHMETRE_H
|
|
@ -0,0 +1,29 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef PROJET_VICTORAVECUNK_ANALOGSENSORTEMPERATURE_H
|
||||||
|
#define PROJET_VICTORAVECUNK_ANALOGSENSORTEMPERATURE_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include "../AnalogDevice.h"
|
||||||
|
|
||||||
|
// exemple de capteur analogique de temperature, ne pas oublier d'heriter de Device
|
||||||
|
class AnalogSensorTemperature: public AnalogDevice {
|
||||||
|
private:
|
||||||
|
// fait osciller la valeur du cpateur de 1
|
||||||
|
int alea;
|
||||||
|
|
||||||
|
public:
|
||||||
|
//constructeur ne pas oublier d'initialiser la classe mere
|
||||||
|
AnalogSensorTemperature(int d,int t);
|
||||||
|
// thread representant le capteur et permettant de fonctionner independamment de la board
|
||||||
|
virtual void run();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PROJET_VICTORAVECUNK_ANALOGSENSORTEMPERATURE_H
|
|
@ -0,0 +1,14 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef PROJET_VICTORAVECUNK_DIGITALACTUATORELECTROVANNE_H
|
||||||
|
#define PROJET_VICTORAVECUNK_DIGITALACTUATORELECTROVANNE_H
|
||||||
|
|
||||||
|
|
||||||
|
class DigitalActuatorElectrovanne {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PROJET_VICTORAVECUNK_DIGITALACTUATORELECTROVANNE_H
|
|
@ -0,0 +1,14 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef PROJET_VICTORAVECUNK_DIGITALACTUATORRADIATOR_H
|
||||||
|
#define PROJET_VICTORAVECUNK_DIGITALACTUATORRADIATOR_H
|
||||||
|
|
||||||
|
|
||||||
|
class DigitalActuatorRadiator {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PROJET_VICTORAVECUNK_DIGITALACTUATORRADIATOR_H
|
|
@ -0,0 +1,26 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef PROJET_VICTORAVECUNK_INTELLIGENTDIGITALACTUATORLED_H
|
||||||
|
#define PROJET_VICTORAVECUNK_INTELLIGENTDIGITALACTUATORLED_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
|
||||||
|
#include "../DigitalDevice.h"
|
||||||
|
|
||||||
|
class IntelligentDigitalActuatorLED: public DigitalDevice{
|
||||||
|
|
||||||
|
public:
|
||||||
|
// initialisation du temps de rafraichiisement
|
||||||
|
IntelligentDigitalActuatorLED(int t);
|
||||||
|
// thread representant l'actionneur et permettant de fonctionner independamment de la board
|
||||||
|
virtual void run();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //PROJET_VICTORAVECUNK_INTELLIGENTDIGITALACTUATORLED_H
|
33
include/DigitalDevices/DigitalDevice.h
Normal file
33
include/DigitalDevices/DigitalDevice.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef PROJET_VICTORAVECUNK_DIGITALDEVICE_H
|
||||||
|
#define PROJET_VICTORAVECUNK_DIGITALDEVICE_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "../../core_simulation.h"
|
||||||
|
#include "../../mydevices.h"
|
||||||
|
|
||||||
|
class DigitalDevice : public Device {
|
||||||
|
protected:
|
||||||
|
int state;
|
||||||
|
int temps;
|
||||||
|
public:
|
||||||
|
DigitalDevice(int temps);
|
||||||
|
|
||||||
|
|
||||||
|
int getState() const;
|
||||||
|
int getTemps() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DigitalSensor : public DigitalDevice{
|
||||||
|
public:
|
||||||
|
DigitalSensor(int temps);
|
||||||
|
};
|
||||||
|
|
||||||
|
class DigitalActuator : public DigitalDevice{
|
||||||
|
public:
|
||||||
|
DigitalActuator(int temps);
|
||||||
|
};
|
||||||
|
#endif //PROJET_VICTORAVECUNK_DIGITALDEVICE_H
|
|
@ -0,0 +1,22 @@
|
||||||
|
//
|
||||||
|
// Created by camer on 16/05/2020.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef PROJET_VICTORAVECUNK_EXTERNALDIGITALSENSORBUTTON_H
|
||||||
|
#define PROJET_VICTORAVECUNK_EXTERNALDIGITALSENSORBUTTON_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "../DigitalDevice.h"
|
||||||
|
|
||||||
|
class ExternalDigitalSensorButton : public DigitalSensor{
|
||||||
|
public:
|
||||||
|
ExternalDigitalSensorButton(int temps);
|
||||||
|
|
||||||
|
int getState();
|
||||||
|
void setState();
|
||||||
|
|
||||||
|
virtual void run();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //PROJET_VICTORAVECUNK_EXTERNALDIGITALSENSORBUTTON_H
|
108
mydevices.cpp
108
mydevices.cpp
|
@ -3,90 +3,8 @@
|
||||||
//int luminosite_environnement = 200;
|
//int luminosite_environnement = 200;
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
//DigitalDevice ///////////////////
|
|
||||||
DigitalDevice::DigitalDevice(int temps) : Device(), state(0), temps(temps) {}
|
|
||||||
|
|
||||||
int DigitalDevice::getState() const {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DigitalDevice::getTemps() const {
|
|
||||||
return temps;
|
|
||||||
}
|
|
||||||
|
|
||||||
//AnalogDevice ///////////////////
|
|
||||||
|
|
||||||
AnalogDevice::AnalogDevice(int val, int temps) : Device(), val(val), temps(temps) {}
|
|
||||||
|
|
||||||
int AnalogDevice::getVal() const {
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
int AnalogDevice::getTemps() const {
|
|
||||||
return temps;
|
|
||||||
}
|
|
||||||
|
|
||||||
//classe AnalogSensorTemperature
|
|
||||||
AnalogSensorTemperature::AnalogSensorTemperature(int val,int temps):AnalogDevice(val,temps){
|
|
||||||
alea=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AnalogSensorTemperature::run(){
|
|
||||||
while(1){
|
|
||||||
alea=1-alea;
|
|
||||||
if(ptrmem!=NULL)
|
|
||||||
*ptrmem=val+alea;
|
|
||||||
sleep(temps);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//AnalogSensorLuminosity ///////////////////////////
|
|
||||||
AnalogSensorLuminosity::AnalogSensorLuminosity(int temps):AnalogDevice(200, temps){}
|
|
||||||
|
|
||||||
void AnalogSensorLuminosity::run(){
|
|
||||||
while(1){
|
|
||||||
val = luminosite_environnement;
|
|
||||||
if(ptrmem!=NULL){
|
|
||||||
*ptrmem = val;
|
|
||||||
}
|
|
||||||
sleep(temps);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// IntelligentDigitalActuatorLED //////////////////
|
|
||||||
IntelligentDigitalActuatorLED::IntelligentDigitalActuatorLED(int t):DigitalDevice(t){
|
|
||||||
}
|
|
||||||
|
|
||||||
void IntelligentDigitalActuatorLED::run(){
|
|
||||||
int previousState = LOW; //initialisee a eteint
|
|
||||||
while(1){
|
|
||||||
if(ptrmem!=NULL) {
|
|
||||||
state = *ptrmem;
|
|
||||||
if (state == LOW) {
|
|
||||||
cout << "((((eteint))))\n";
|
|
||||||
if (state != previousState) {
|
|
||||||
luminosite_environnement -= 50;
|
|
||||||
}
|
|
||||||
previousState = state;
|
|
||||||
} else { //state == HIGH
|
|
||||||
cout << "((((allume))))\n";
|
|
||||||
if (state != previousState) {
|
|
||||||
luminosite_environnement += 50;
|
|
||||||
}
|
|
||||||
previousState = state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sleep(temps);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// classe I2CActuatorScreen
|
// classe I2CActuatorScreen
|
||||||
I2CActuatorScreen::I2CActuatorScreen ():Device(){
|
I2CActuatorScreen::I2CActuatorScreen ():Device(){}
|
||||||
}
|
|
||||||
|
|
||||||
void I2CActuatorScreen::run(){
|
void I2CActuatorScreen::run(){
|
||||||
while(1){
|
while(1){
|
||||||
|
@ -99,30 +17,6 @@ void I2CActuatorScreen::run(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//ExternalDigDevice/////////////////////////
|
|
||||||
|
|
||||||
ExternalDigitalSensorButton::ExternalDigitalSensorButton(int temps):DigitalDevice(temps) {}
|
|
||||||
|
|
||||||
int ExternalDigitalSensorButton::getState(){
|
|
||||||
setState(); //determine if on.txt exists before getting state
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExternalDigitalSensorButton::setState() {
|
|
||||||
if (ifstream("on.txt")){
|
|
||||||
state = 1;
|
|
||||||
} else {
|
|
||||||
state = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ExternalDigitalSensorButton::run() {
|
|
||||||
while (1) {
|
|
||||||
*ptrmem = this->getState();
|
|
||||||
sleep(temps);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//TODO Capteur de temperature a revoir avec conditions
|
//TODO Capteur de temperature a revoir avec conditions
|
||||||
//TODO Electrovanne / moteur (a voir food)
|
//TODO Electrovanne / moteur (a voir food)
|
||||||
//TODO Radiateur rechauffer terrarium
|
//TODO Radiateur rechauffer terrarium
|
||||||
|
|
94
mydevices.h
94
mydevices.h
|
@ -9,87 +9,11 @@
|
||||||
#include "core_simulation.h"
|
#include "core_simulation.h"
|
||||||
|
|
||||||
static int luminosite_environnement = 200;
|
static int luminosite_environnement = 200;
|
||||||
|
|
||||||
class DigitalDevice : public Device {
|
|
||||||
protected:
|
|
||||||
int state;
|
|
||||||
int temps;
|
|
||||||
public:
|
|
||||||
DigitalDevice(int temps);
|
|
||||||
|
|
||||||
|
|
||||||
int getState() const;
|
|
||||||
int getTemps() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
class AnalogDevice : public Device{
|
|
||||||
protected:
|
|
||||||
int val;
|
|
||||||
// temps entre 2 prises de valeurs
|
|
||||||
int temps;
|
|
||||||
// valeur de temperature mesuree
|
|
||||||
public:
|
|
||||||
AnalogDevice(int val, int temps);
|
|
||||||
|
|
||||||
int getVal() const;
|
|
||||||
int getTemps() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
// exemple de capteur analogique de temperature, ne pas oublier d'heriter de Device
|
|
||||||
class AnalogSensorTemperature: public AnalogDevice {
|
|
||||||
private:
|
|
||||||
// fait osciller la valeur du cpateur de 1
|
|
||||||
int alea;
|
|
||||||
|
|
||||||
public:
|
|
||||||
//constructeur ne pas oublier d'initialiser la classe mere
|
|
||||||
AnalogSensorTemperature(int d,int t);
|
|
||||||
// thread representant le capteur et permettant de fonctionner independamment de la board
|
|
||||||
virtual void run();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class AnalogSensorLuminosity: public AnalogDevice{
|
|
||||||
|
|
||||||
public:
|
|
||||||
AnalogSensorLuminosity(int t);
|
|
||||||
virtual void run();
|
|
||||||
};
|
|
||||||
|
|
||||||
// exemple d'actionneur digital : une led, ne pas oublier d'heriter de Device
|
|
||||||
class DigitalActuatorLED: public Device {
|
|
||||||
private:
|
|
||||||
// etat de la LED
|
|
||||||
int state;
|
|
||||||
// temps entre 2 affichage de l etat de la led
|
|
||||||
int temps;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// initialisation du temps de rafraichiisement
|
|
||||||
DigitalActuatorLED(int t);
|
|
||||||
// thread representant l'actionneur et permettant de fonctionner independamment de la board
|
|
||||||
virtual void run();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IntelligentDigitalActuatorLED: public DigitalDevice{
|
|
||||||
|
|
||||||
public:
|
|
||||||
// initialisation du temps de rafraichiisement
|
|
||||||
IntelligentDigitalActuatorLED(int t);
|
|
||||||
// thread representant l'actionneur et permettant de fonctionner independamment de la board
|
|
||||||
virtual void run();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// exemple d'actionneur sur le bus I2C permettant d'echanger des tableaux de caracteres : un ecran, ne pas oublier d'heriter de Device
|
// exemple d'actionneur sur le bus I2C permettant d'echanger des tableaux de caracteres : un ecran, ne pas oublier d'heriter de Device
|
||||||
class I2CActuatorScreen : public Device{
|
class I2CActuatorScreen : public Device{
|
||||||
protected:
|
protected:
|
||||||
// memorise l'affichage de l'ecran
|
// memorise l'affichage de l'ecran
|
||||||
char buf[I2C_BUFFER_SIZE];
|
char buf[I2C_BUFFER_SIZE];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// constructeur
|
// constructeur
|
||||||
|
@ -97,21 +21,5 @@ public:
|
||||||
// thread representant le capteur et permettant de fonctionner independamment de la board
|
// thread representant le capteur et permettant de fonctionner independamment de la board
|
||||||
virtual void run();
|
virtual void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExternalDigitalSensorButton : public DigitalDevice{
|
|
||||||
public:
|
|
||||||
ExternalDigitalSensorButton(int temps);
|
|
||||||
|
|
||||||
int getState();
|
|
||||||
void setState();
|
|
||||||
|
|
||||||
virtual void run();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//class ExternalDigitalSensorButton: public Device
|
//class ExternalDigitalSensorButton: public Device
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
0
on.txt
Normal file
0
on.txt
Normal file
|
@ -16,7 +16,7 @@ void Board::setup(){
|
||||||
void Board::loop(){
|
void Board::loop(){
|
||||||
char buf[100];
|
char buf[100];
|
||||||
int val;
|
int val;
|
||||||
int val1;
|
int val1;
|
||||||
static int cpt=0;
|
static int cpt=0;
|
||||||
static int bascule=0;
|
static int bascule=0;
|
||||||
int i=0;
|
int i=0;
|
||||||
|
@ -44,9 +44,9 @@ void Board::loop(){
|
||||||
}
|
}
|
||||||
// on eteint et on allume la LED
|
// on eteint et on allume la LED
|
||||||
if(analogRead(4))
|
if(analogRead(4))
|
||||||
digitalWrite(0,HIGH);
|
digitalWrite(0,HIGH);
|
||||||
else
|
else
|
||||||
digitalWrite(0,LOW);
|
digitalWrite(0,LOW);
|
||||||
bascule=1-bascule;
|
bascule=1-bascule;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue