ultimas alteracoes

This commit is contained in:
Diego Freitas 2025-05-08 12:12:13 -03:00
parent 2965e26df1
commit 44ef7aaf4e
4 changed files with 27 additions and 14 deletions

Binary file not shown.

View File

@ -2009,7 +2009,8 @@ namespace AgroBase.Models.Modules
}
case CanMessagePosicaoDados.Dados1:
{
_sensor.Temperatura = Parametros.Count > 0 ? Parametros[0] : -1;
double.TryParse(sensor.Parametros.FirstOrDefault(x => x.Descricao == "Offset")?.Valor ?? "0", out double offset);
_sensor.Temperatura = Parametros.Count > 0 ? (Parametros[0] + offset) : -1;
break;
}
}
@ -2048,7 +2049,7 @@ namespace AgroBase.Models.Modules
{
_sensor.BusVoltage = Parametros.Count > 0 ? Parametros[0] : -1;
_sensor.Current = Parametros.Count > 1 ? Parametros[1] : -1;
_sensor.Power = Parametros.Count > 2 ? Parametros[2] : -1;
_sensor.Power = Parametros.Count > 2 ? (Parametros[2] / 100.0) : -1;
break;
}
case CanMessagePosicaoDados.Dados2:
@ -2324,7 +2325,7 @@ namespace AgroBase.Models.Modules
case S_Code.sCOR:
{
double busVoltage = ConverterByteParaDouble(data, 2);
double current = ConverterByteParaDouble(data, 4) * 10;
double current = ConverterByteParaDouble(data, 4);
double power = ConverterByteParaDouble(data, 6);
DefinirOuCriar(ID_Num, posicao, componente, new List<dynamic>() { busVoltage, current, power });
break;

View File

@ -32,7 +32,7 @@ class SensorCorrente {
void Inicializar() {
if (Iniciado) {
PrintTela(_ID + " ja inicializado");
MostrarLog("Sensor ja inicializado");
return;
}
@ -47,10 +47,10 @@ class SensorCorrente {
Iniciado = sINA219.begin();
if (Iniciado) {
sINA219.setCalibration_32V_2A();
PrintTela(_ID + " (INA219) iniciado no canal " + String(_CanalMUX));
MostrarLog("Sensor (INA219) iniciado no canal " + String(_CanalMUX));
}
else {
PrintTela(_ID + " nao iniciado!");
PrintTela("Sensor nao iniciado!");
}
}
else {
@ -69,11 +69,11 @@ class SensorCorrente {
EscreverRegistradorINA(0x00, 0x8000); // Bit 15 = 1 → RESET
uint16_t cal = (uint16_t)(0.00512 / (currentLSB * shuntLSB));
//EscreverRegistradorINA(0xD4, cal);
PrintTela(_ID + " (INA228) iniciado no canal " + String(_CanalMUX));
MostrarLog("Sensor (INA228) iniciado no canal " + String(_CanalMUX));
}
} else {
Iniciado = false;
PrintTela(_ID + " nao iniciado, endereco " + _Endereco + " nao encontrado!");
MostrarLog("Sensor nao iniciado, endereco " + String(_Endereco) + " nao encontrado!");
}
I2CService::LiberarAcessoI2C(ID_Num);
@ -81,7 +81,7 @@ class SensorCorrente {
void Desligar() {
if (!Iniciado) {
PrintTela(_ID + " nao esta inicializado");
MostrarLog("Sensor nao esta inicializado");
return;
}
@ -93,7 +93,7 @@ class SensorCorrente {
}
}
PrintTela(_ID + " Desligado");
MostrarLog("Sensor Desligado");
}
void RequisitarDados() {
@ -163,7 +163,7 @@ class SensorCorrente {
sensor->Inicializar();
if (!jaExiste) {
lista.push_back(sensor);
PrintTela("Sensor de corrente adicionado via CAN: sCOR_" + String(idNum));
sensor->MostrarLog("Sensor de corrente adicionado via CAN: sCOR_" + String(idNum));
}
}
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
@ -174,7 +174,7 @@ class SensorCorrente {
status = sensor->MontarMensagemCAN(CanMessagePosicaoDados::Status);
delete sensor;
lista.erase(it);
PrintTela("Sensor de corrente removido via CAN: sCOR_" + String(idNum));
sensor->MostrarLog("Sensor de corrente removido via CAN: sCOR_" + String(idNum));
}
}
break;
@ -184,6 +184,14 @@ class SensorCorrente {
}
private:
bool DebugMode = true;
void MostrarLog(String mensagem) {
if (DebugMode) {
PrintTela("[COR " + _ID + "] " + mensagem);
}
}
Adafruit_INA219 sINA219;
static constexpr float currentLSB_10A = 0.0001;
static constexpr float currentLSB_50A = 0.00119;
@ -229,8 +237,10 @@ class SensorCorrente {
if (isINA219) {
busVoltage = sINA219.getBusVoltage_V();
current = sINA219.getCurrent_mA() / 10000.0;
power = sINA219.getPower_mW() / 100.0;
current = sINA219.getCurrent_mA();
power = sINA219.getPower_mW();
MostrarLog("BusVoltage: " + String(busVoltage) + ", Current: " + String(current) + ", Power: " + String(power));
}
else {
uint32_t rawBus = LerRegistradorINA(0x05, 3);
@ -244,6 +254,8 @@ class SensorCorrente {
current = rawCurrent * currentLSB;
energy = rawEnergy * currentLSB * 3.125 * 16 / 3600.0;
temperature = ((int16_t)rawTemp) * 0.0078125;
MostrarLog("BusVoltage: " + String(busVoltage) + ", Current: " + String(current) + ", Power: " + String(power) + ", Energy: " + String(energy) + ", Temperature: " + String(temperature));
}
I2CService::LiberarAcessoI2C(ID_Num);