diff --git a/AgroBase/.vs/AgroBase/FileContentIndex/8fad4bfb-f14e-4f77-8a05-c012a6a590ca.vsidx b/AgroBase/.vs/AgroBase/FileContentIndex/57ddc087-206b-4a8b-8a18-7c1c31afa7c2.vsidx similarity index 80% rename from AgroBase/.vs/AgroBase/FileContentIndex/8fad4bfb-f14e-4f77-8a05-c012a6a590ca.vsidx rename to AgroBase/.vs/AgroBase/FileContentIndex/57ddc087-206b-4a8b-8a18-7c1c31afa7c2.vsidx index 8e7b9c3f4..c682b222b 100644 Binary files a/AgroBase/.vs/AgroBase/FileContentIndex/8fad4bfb-f14e-4f77-8a05-c012a6a590ca.vsidx and b/AgroBase/.vs/AgroBase/FileContentIndex/57ddc087-206b-4a8b-8a18-7c1c31afa7c2.vsidx differ diff --git a/AgroBase/.vs/AgroBase/v17/.suo b/AgroBase/.vs/AgroBase/v17/.suo index a0a0dd71c..a1b69020d 100644 Binary files a/AgroBase/.vs/AgroBase/v17/.suo and b/AgroBase/.vs/AgroBase/v17/.suo differ diff --git a/AgroBase/AgroBase/Models/Modules/SensoriamentoModel.cs b/AgroBase/AgroBase/Models/Modules/SensoriamentoModel.cs index 2620585e8..256feecac 100644 --- a/AgroBase/AgroBase/Models/Modules/SensoriamentoModel.cs +++ b/AgroBase/AgroBase/Models/Modules/SensoriamentoModel.cs @@ -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() { busVoltage, current, power }); break; diff --git a/Firmware/Modulos/SensorCorrenteModel.h b/Firmware/Modulos/SensorCorrenteModel.h index c6be9d820..012e42c5a 100644 --- a/Firmware/Modulos/SensorCorrenteModel.h +++ b/Firmware/Modulos/SensorCorrenteModel.h @@ -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);