RegulationIntensite/mesure.cpp

123 lines
2.6 KiB
C++
Raw Normal View History

2017-02-15 19:48:31 +01:00
#include <stdarg.h>
#include "arduino.h"
#include "mesure.h"
2017-02-15 21:27:17 +01:00
courant::courant(uint8_t pinU1, uint8_t pinU2, int r)
2017-02-15 19:48:31 +01:00
{
this->pinU1 = pinU1;
this->pinU2 = pinU2;
this->r = r;
pinMode(pinU1, 0);
pinMode(pinU2, 0);
bridgeU1Enable = 0;
bridgeU2Enable = 0;
2017-02-15 22:08:17 +01:00
bridgeU1RapportR = 1;
bridgeU2RapportR = 1;
2017-02-15 19:48:31 +01:00
}
2017-02-15 21:27:17 +01:00
courant::courant(uint8_t pinU1, uint8_t pinU2, int r, uint8_t bridgeU1Enable, uint8_t bridgeU2Enable,...)
2017-02-15 19:48:31 +01:00
{
2017-02-15 21:27:17 +01:00
2017-02-15 19:48:31 +01:00
this->pinU1 = pinU1;
this->pinU2 = pinU2;
this->r = r;
pinMode(pinU1, 0);
pinMode(pinU2, 0);
this->bridgeU1Enable = bridgeU1Enable;
this->bridgeU2Enable = bridgeU2Enable;
va_list ap;
va_start(ap, bridgeU2Enable);
if(bridgeU1Enable)
{
this->bridgeU1Enable = bridgeU1Enable;
this->bridgeU2Enable = bridgeU2Enable;
2017-02-15 21:27:17 +01:00
bridgeU1RapportR = va_arg(ap, double);
2017-02-15 19:48:31 +01:00
if(bridgeU2Enable)
2017-02-15 21:27:17 +01:00
bridgeU2RapportR = va_arg(ap, double);
2017-02-15 19:48:31 +01:00
else
2017-02-15 22:08:17 +01:00
bridgeU2RapportR = 1;
2017-02-15 19:48:31 +01:00
}
else
{
2017-02-15 22:08:17 +01:00
this->bridgeU1Enable = 1;
2017-02-15 19:48:31 +01:00
this->bridgeU2Enable = bridgeU2Enable;
2017-02-15 22:08:17 +01:00
bridgeU1RapportR = 1;
2017-02-15 19:48:31 +01:00
if(bridgeU2Enable)
2017-02-15 21:27:17 +01:00
bridgeU2RapportR = va_arg(ap, double);
2017-02-15 19:48:31 +01:00
else
2017-02-15 22:08:17 +01:00
bridgeU2RapportR = 1;
2017-02-15 19:48:31 +01:00
}
va_end(ap);
}
2017-02-15 21:27:17 +01:00
void courant::config(uint8_t pinU1, uint8_t pinU2, int r)
2017-02-15 19:48:31 +01:00
{
this->pinU1 = pinU1;
this->pinU2 = pinU2;
this->r = r;
pinMode(pinU1, 0);
pinMode(pinU2, 0);
bridgeU1Enable = 0;
bridgeU2Enable = 0;
2017-02-15 22:08:17 +01:00
bridgeU1RapportR = 1;
bridgeU2RapportR = 1;
2017-02-15 19:48:31 +01:00
}
2017-02-15 21:27:17 +01:00
void courant::config(uint8_t pinU1, uint8_t pinU2, int r, uint8_t bridgeU1Enable, uint8_t bridgeU2Enable, ...)
2017-02-15 19:48:31 +01:00
{
this->pinU1 = pinU1;
this->pinU2 = pinU2;
this->r = r;
pinMode(pinU1, 0);
pinMode(pinU2, 0);
this->bridgeU1Enable = bridgeU1Enable;
this->bridgeU2Enable = bridgeU2Enable;
va_list ap;
va_start(ap, bridgeU2Enable);
if(bridgeU1Enable)
{
this->bridgeU1Enable = bridgeU1Enable;
this->bridgeU2Enable = bridgeU2Enable;
2017-02-15 21:27:17 +01:00
bridgeU1RapportR = va_arg(ap, double);
2017-02-15 19:48:31 +01:00
if(bridgeU2Enable)
2017-02-15 21:27:17 +01:00
bridgeU2RapportR = va_arg(ap, double);
2017-02-15 19:48:31 +01:00
else
2017-02-15 22:08:17 +01:00
bridgeU2RapportR = 1;
2017-02-15 19:48:31 +01:00
}
else
{
2017-02-15 22:08:17 +01:00
this->bridgeU1Enable = 1;
2017-02-15 19:48:31 +01:00
this->bridgeU2Enable = bridgeU2Enable;
2017-02-15 22:08:17 +01:00
bridgeU1RapportR = 1;
2017-02-15 19:48:31 +01:00
if(bridgeU2Enable)
2017-02-15 21:27:17 +01:00
bridgeU2RapportR = va_arg(ap, double);
2017-02-15 19:48:31 +01:00
else
2017-02-15 22:08:17 +01:00
bridgeU2RapportR = 1;
2017-02-15 19:48:31 +01:00
}
va_end(ap);
}
void courant::lireTension()
{
u1RAW = analogRead(pinU1);
u2RAW = analogRead(pinU2);
2017-02-15 22:08:17 +01:00
u1 = (u1RAW*(5.0/1024.0))*(1/bridgeU1RapportR);
u2 = (u2RAW*(5.0/1024.0))*(1/bridgeU2RapportR);
2017-02-15 19:48:31 +01:00
}
2017-02-15 21:27:17 +01:00
double courant::lireCourant()
2017-02-15 19:48:31 +01:00
{
lireTension();
2017-02-15 21:41:51 +01:00
double i = ((u1-u2)/(double)r)*1000;
2017-02-15 19:48:31 +01:00
return i;
}
2017-02-15 21:27:17 +01:00
double courant::lireTensionU1()
2017-02-15 19:48:31 +01:00
{
return u1;
}
2017-02-15 21:27:17 +01:00
double courant::lireTensionU2()
2017-02-15 19:48:31 +01:00
{
return u2;
}