407 lines
22 KiB
C#
407 lines
22 KiB
C#
using AgroBase.Models;
|
|
using AgroBase.Models.Modules;
|
|
using AgroBase.Services;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Forms.DataVisualization.Charting;
|
|
using static AgroBase.Models.Enums;
|
|
|
|
namespace AgroBase.Forms
|
|
{
|
|
public partial class frmAcompanhamento : Form
|
|
{
|
|
AsyncTaskTimerModel tmrAtualizacao;
|
|
|
|
public frmAcompanhamento()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void frmAcompanhamento_Load(object sender, EventArgs e)
|
|
{
|
|
picEF.Paint += pic_Paint;
|
|
picET.Paint += pic_Paint;
|
|
picDF.Paint += pic_Paint;
|
|
picDT.Paint += pic_Paint;
|
|
|
|
tmrAtualizacao = new AsyncTaskTimerModel("tmrAtualizacao", tmrAtualizacao_Tick, 500, this);
|
|
tmrAtualizacao.Start();
|
|
}
|
|
|
|
private void frmAcompanhamento_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
tmrAtualizacao.Dispose();
|
|
}
|
|
|
|
public async Task tmrAtualizacao_Tick()
|
|
{
|
|
picET.Invalidate();
|
|
picEF.Invalidate();
|
|
picDT.Invalidate();
|
|
picDF.Invalidate();
|
|
|
|
pnlOrientacaoGPS.Invalidate();
|
|
pnlOrientacaoMagnetometro.Invalidate();
|
|
|
|
AtualzarDadosMovimentacao();
|
|
|
|
if (UltrasonicA05Service.Iniciado)
|
|
{
|
|
//lblUL_A05.Text = "Ultima Leitura A05: " + UltrasonicA05Service.DadosLeitura.Momento.ToString("HH:mm:ss");
|
|
lblU1.Text = "U1: " + UltrasonicA05Service.DadosLeitura.Configuracao.Sensores[0].LeituraCm.ToString("") + " cm";
|
|
lblU2.Text = "U2: " + UltrasonicA05Service.DadosLeitura.Configuracao.Sensores[1].LeituraCm.ToString("") + " cm";
|
|
lblU3.Text = "U3: " + UltrasonicA05Service.DadosLeitura.Configuracao.Sensores[2].LeituraCm.ToString("") + " cm";
|
|
lblU4.Text = "U4: " + UltrasonicA05Service.DadosLeitura.Configuracao.Sensores[3].LeituraCm.ToString("") + " cm";
|
|
}
|
|
if (Variaveis.OperacaoEmAndamento.DispSen.Dados.ConexaoAtiva)
|
|
{
|
|
AtualizarDadosSensorCorrente("AB3V", lblB3V);
|
|
AtualizarDadosSensorCorrente("AB5V", lblB5V);
|
|
AtualizarDadosSensorCorrente("AB7V2", lblB7V2);
|
|
AtualizarDadosSensorCorrente("AB12V", lblB12V);
|
|
AtualizarDadosSensorCorrente("AB19V", lblB19V);
|
|
AtualizarDadosSensorCorrente("AB24V", lblB24V);
|
|
AtualizarDadosSensorCorrente("AB36V", lblB36V);
|
|
}
|
|
|
|
lblMagnetometro.ForeColor = Variaveis.OperacaoEmAndamento.Sensoriamento.IMU.Iniciado ? Color.Green : Color.Red;
|
|
|
|
var Gps = Variaveis.OperacaoEmAndamento.Sensoriamento.Gps;
|
|
lblGPS.ForeColor = Gps.Inicializado ? Color.Green : Color.Red;
|
|
if (Gps.Inicializado)
|
|
{
|
|
lblGPSDetalhes.Text = Gps.QualidadeFix.ToString() + " - " + Gps.PrecisaoCm.ToString("0.00") + " cm";
|
|
}
|
|
|
|
lblPerformance.Text = Variaveis.OperacaoEmAndamento.DadosPerformance.PerformanceStr;
|
|
|
|
lblSen_Latencia.Text = $"Latencia de Loop: {Variaveis.OperacaoEmAndamento.DispSen.Dados?.DadosLeitura?.LatenciaLoop ?? 0} ms";
|
|
|
|
tmrAtualizacao.SetInterval(500);
|
|
}
|
|
|
|
private void AtualizarDadosSensorCorrente(string id, Label lbl)
|
|
{
|
|
var sensor = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == id);
|
|
if (sensor != null)
|
|
{
|
|
var tensao = sensor.ValoresLeituras.FirstOrDefault(x => x.funcao == FuncoesPinout.Tensao);
|
|
var corrente = sensor.ValoresLeituras.FirstOrDefault(x => x.funcao == FuncoesPinout.Corrente);
|
|
var potencia = sensor.ValoresLeituras.FirstOrDefault(x => x.funcao == FuncoesPinout.Potencia);
|
|
var temperatura = sensor.ValoresLeituras.FirstOrDefault(x => x.funcao == FuncoesPinout.Temperatura);
|
|
var energia = sensor.ValoresLeituras.FirstOrDefault(x => x.funcao == FuncoesPinout.Energia);
|
|
lbl.Text = $"{id.Replace("AB", "Barramento ")}: {tensao.atual.valor.ToString("0.00")} {tensao.unidade_medida}, {corrente.atual.valor.ToString("0.00")} {corrente.unidade_medida}, {potencia.atual.valor.ToString("0.00")} {potencia.unidade_medida}, {temperatura.atual.valor.ToString("0.00")} {temperatura.unidade_medida}, {energia.atual.valor.ToString("0.00")} {energia.unidade_medida}";
|
|
lbl.ForeColor = sensor.Inicializado ? Color.Green : Color.Red;
|
|
}
|
|
}
|
|
|
|
private void AtualzarDadosMovimentacao()
|
|
{
|
|
var DispMvd = Variaveis.OperacaoEmAndamento.DispMvd;
|
|
|
|
//lblTempoConectado.Text = "Tempo conectado: " + (DateTime.Now - DispMvd.CriadoEm).ToString("HH:mm:ss") + " hrs";
|
|
lblTempoEmMovimento.Text = "Tempo em movimento: " + TimeSpan.FromSeconds(DispMvd.Dados.TempoEmAtividade).ToString(@"hh\:mm\:ss") + " hrs";
|
|
lblDistanciaTotal.Text = "Distancia percorrida total: " + DispMvd.Dados.DistanciaPercorridaTotal.ToString("0.00") + " m";
|
|
lblDistanciaParcial.Text = "Distancia percorrida parcial: " + DispMvd.Dados.DistanciaPercorridaParcial.ToString("0.00") + " m";
|
|
|
|
foreach (var Modulo in DispMvd.Dados.Modulos)
|
|
{
|
|
var sTMP = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.Sensores?.FirstOrDefault(x => x.ID.Contains(Modulo.Modulo_ID));
|
|
|
|
Label lblTitulo = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lblM_" + Modulo.Modulo_ID);
|
|
lblTitulo.ForeColor = Modulo.MovMotor.Comandar ? Modulo.MovMotor.Inicializado ? Color.Green : Color.Red : Color.Black;
|
|
lblTitulo.Text = lblTitulo.Text.Split(' ')[0] + " (" + Modulo.Modulo_ID + ") - " + Modulo.MovMotor.CodigoAlarme;
|
|
Label lblM_RPMSP = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_RPMSP");
|
|
lblM_RPMSP.Text = "RPM SP: " + Modulo.MovMotor.RPM_SP_Leitura.ToString("0.00");
|
|
Label lblM_RPM = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_RPM");
|
|
lblM_RPM.Text = "RPM Roda: " + Modulo.MovMotor.RPM_Roda.ToString("0.00");
|
|
Label lblM_Velocidade = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Velocidade");
|
|
lblM_Velocidade.Text = "Velocidade: " + Modulo.MovMotor.VelocidadeInstantanea.ToString("0.00") + " Km/h";
|
|
Label lblM_SentidoSP = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_SentidoSP");
|
|
lblM_SentidoSP.Text = "Sentido SP: " + Enum.GetName(typeof(Sentido), Modulo.MovMotor.Sentido_SP);
|
|
Label lblM_Sentido = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Sentido");
|
|
lblM_Sentido.Text = "Sentido: " + Enum.GetName(typeof(Sentido), Modulo.MovMotor.Sentido);
|
|
Label lblM_Temperatura = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Temperatura");
|
|
lblM_Temperatura.Text = "Temperatura: " + Modulo.MovMotor.Temperatura.ToString("0.00") + "ºC";
|
|
lblM_Temperatura.ForeColor = sTMP?.Inicializado ?? false ? Color.Green : Color.Red;
|
|
Label lblM_Corrente = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Corrente");
|
|
lblM_Corrente.Text = "Corrente: " + Modulo.MovMotor.Corrente_Motor.ToString("0.00") + "A";
|
|
Label lblM_Tensao = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Tensao");
|
|
lblM_Tensao.Text = "Tensão: " + Modulo.MovMotor.Tensao.ToString("0.00") + "V";
|
|
|
|
MvdMotorMOVSensorimanetoGrafico Log = null;
|
|
if (Modulo.MovMotor.LogGrafico.Count > 0)
|
|
{
|
|
Log = Modulo.MovMotor.LogGrafico[Modulo.MovMotor.LogGrafico.Count - 1];
|
|
}
|
|
|
|
double Minimo = 0;
|
|
double Maximo = 0;
|
|
|
|
|
|
try
|
|
{
|
|
Chart chart = (Chart)(pnlFundo.Controls.Find("chart" + Modulo.Modulo_ID, false).First());
|
|
chart.Titles.Clear();
|
|
chart.Titles.Add(Modulo.Modulo_ID);
|
|
var Logs = (Modulo.MovMotor.LogGrafico.Count > MovimentacaoUnificadaModel.LogsManter ? Modulo.MovMotor.LogGrafico.Skip(Math.Max(0, Modulo.MovMotor.LogGrafico.Count - MovimentacaoUnificadaModel.LogsManter)).Take(MovimentacaoUnificadaModel.LogsManter).ToList() : Modulo.MovMotor.LogGrafico).Where(log => log.Modulo_ID == Modulo.Modulo_ID).ToList();
|
|
chart.Series.Clear();
|
|
List<string> Momentos = Logs.Select(x => x.Momento.ToString("mm:ss:fff")).ToList();
|
|
|
|
var serieRPMsp = new Series("RPM SP: " + (Log != null ? Log.RPM_SP : 0));
|
|
serieRPMsp.Points.DataBindXY(Momentos, Logs.Select(x => x.RPM_SP).ToList());
|
|
serieRPMsp.ChartType = SeriesChartType.Line;
|
|
chart.Series.Add(serieRPMsp);
|
|
Minimo = Logs.Any() && Logs.Min(x => x.RPM_SP) < Minimo ? Logs.Min(x => x.RPM_SP) : Minimo;
|
|
Maximo = Logs.Any() && Logs.Min(x => x.RPM_SP) > Maximo ? Logs.Min(x => x.RPM_SP) : Maximo;
|
|
|
|
var serieRPMRoda = new Series("RPM Roda: " + (Log != null ? Log.RPM_Roda : 0));
|
|
serieRPMRoda.Points.DataBindXY(Momentos, Logs.Select(x => x.RPM_Roda).ToList());
|
|
serieRPMRoda.ChartType = SeriesChartType.Spline;
|
|
chart.Series.Add(serieRPMRoda);
|
|
Minimo = Logs.Any() && Logs.Min(x => x.RPM_Roda) < Minimo ? Logs.Min(x => x.RPM_Roda) : Minimo;
|
|
Maximo = Logs.Any() && Logs.Max(x => x.RPM_Roda) > Maximo ? Logs.Max(x => x.RPM_Roda) : Maximo;
|
|
|
|
var serieTemperatura = new Series("Motor ºC: " + (Log != null ? Log.Temperatura : 0));
|
|
serieTemperatura.Points.DataBindXY(Momentos, Logs.Select(x => x.Temperatura).ToList());
|
|
serieTemperatura.ChartType = SeriesChartType.Line;
|
|
chart.Series.Add(serieTemperatura);
|
|
Minimo = Logs.Any() && Logs.Min(x => x.Temperatura) < Minimo ? Logs.Min(x => x.Temperatura) : Minimo;
|
|
Maximo = Logs.Any() && Logs.Max(x => x.Temperatura) > Maximo ? Logs.Max(x => x.Temperatura) : Maximo;
|
|
|
|
var serieTempDriver = new Series("Driver ºC: " + (Log != null ? Log.TemperaturaDriver : 0));
|
|
serieTempDriver.Points.DataBindXY(Momentos, Logs.Select(x => x.TemperaturaDriver).ToList());
|
|
serieTempDriver.ChartType = SeriesChartType.Line;
|
|
chart.Series.Add(serieTempDriver);
|
|
Minimo = Logs.Any() && Logs.Min(x => x.TemperaturaDriver) < Minimo ? Logs.Min(x => x.TemperaturaDriver) : Minimo;
|
|
Maximo = Logs.Any() && Logs.Max(x => x.TemperaturaDriver) > Maximo ? Logs.Max(x => x.TemperaturaDriver) : Maximo;
|
|
|
|
var serieTensao = new Series("Tensão: " + (Log != null ? Log.Tensao : 0));
|
|
serieTensao.Points.DataBindXY(Momentos, Logs.Select(x => x.Tensao).ToList());
|
|
serieTensao.ChartType = SeriesChartType.Line;
|
|
chart.Series.Add(serieTensao);
|
|
Minimo = Logs.Any() && Logs.Min(x => x.Tensao) < Minimo ? Logs.Min(x => x.Tensao) : Minimo;
|
|
Maximo = Logs.Any() && Logs.Max(x => x.Tensao) > Maximo ? Logs.Max(x => x.Tensao) : Maximo;
|
|
|
|
var serieCorrente = new Series("Corrente: " + (Log != null ? Log.Corrente : 0));
|
|
serieCorrente.Points.DataBindXY(Momentos, Logs.Select(x => x.Corrente).ToList());
|
|
serieCorrente.ChartType = SeriesChartType.Line;
|
|
chart.Series.Add(serieCorrente);
|
|
Minimo = Logs.Any() && Logs.Min(x => x.Corrente) < Minimo ? Logs.Min(x => x.Corrente) : Minimo;
|
|
Maximo = Logs.Any() && Logs.Max(x => x.Corrente) > Maximo ? Logs.Max(x => x.Corrente) : Maximo;
|
|
|
|
var seriePotencia = new Series("Potencia: " + (Log != null ? Log.Potencia : 0));
|
|
seriePotencia.Points.DataBindXY(Momentos, Logs.Select(x => x.Potencia).ToList());
|
|
seriePotencia.ChartType = SeriesChartType.Line;
|
|
chart.Series.Add(seriePotencia);
|
|
Minimo = Logs.Any() && Logs.Min(x => x.Potencia) < Minimo ? Logs.Min(x => x.Potencia) : Minimo;
|
|
Maximo = Logs.Any() && Logs.Max(x => x.Potencia) > Maximo ? Logs.Max(x => x.Potencia) : Maximo;
|
|
|
|
var serieCicloTrabalho = new Series("Ciclo Trabalho %: " + (Log != null ? Log.CicloTrabalho : 0));
|
|
serieCicloTrabalho.Points.DataBindXY(Momentos, Logs.Select(x => x.CicloTrabalho).ToList());
|
|
serieCicloTrabalho.ChartType = SeriesChartType.Line;
|
|
chart.Series.Add(serieCicloTrabalho);
|
|
Minimo = Logs.Any() && Logs.Min(x => x.CicloTrabalho) < Minimo ? Logs.Min(x => x.CicloTrabalho) : Minimo;
|
|
Maximo = Logs.Any() && Logs.Max(x => x.CicloTrabalho) > Maximo ? Logs.Max(x => x.CicloTrabalho) : Maximo;
|
|
|
|
foreach (var legend in chart.Legends)
|
|
{
|
|
legend.Docking = Docking.Bottom;
|
|
}
|
|
|
|
chart.ChartAreas[0].AxisY.Minimum = Minimo - 5;
|
|
chart.ChartAreas[0].AxisY.Maximum = Maximo + 5;
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
private void pic_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
DesenharGraficos(sender, e);
|
|
}
|
|
|
|
private void DesenharGraficos(object sender, PaintEventArgs e)
|
|
{
|
|
PictureBox pic = (PictureBox)sender;
|
|
string ID = pic.Name.Replace("pic", "");
|
|
|
|
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(m => m.Modulo_ID == ID);
|
|
Label lblA_SP = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + ID + "A_SP");
|
|
lblA_SP.Text = "Angulo SP: " + (Modulo.DirMotor.Angulo_SP).ToString("000") + "º";
|
|
Label lblA = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + ID + "A");
|
|
lblA.Text = "Angulo: " + Modulo.DirMotor.Angulo.ToString("000") + "º";
|
|
Label lblA_SentidoSP = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + ID + "A_SentidoSP");
|
|
lblA_SentidoSP.Text = "Sentido SP: " + Enum.GetName(typeof(Sentido), Modulo.DirMotor.Sentido_SP);
|
|
Label lblA_Sentido = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + ID + "A_Sentido");
|
|
lblA_Sentido.Text = "Sentido: " + Enum.GetName(typeof(Sentido), Modulo.DirMotor.Sentido) + " (" + Modulo.DirMotor.SentidoReal.ToString() + ")";
|
|
|
|
// Use o objeto Graphics para desenhar a representação do motor
|
|
Graphics g = e.Graphics;
|
|
|
|
int centerX = pic.Width / 2;
|
|
int centerY = pic.Height / 2;
|
|
int radius = Math.Min(centerX, centerY) - 30;
|
|
|
|
// Desenhe o círculo para representar o motor
|
|
g.DrawEllipse(Pens.Black, centerX - radius, centerY - radius, 2 * radius, 2 * radius);
|
|
|
|
|
|
|
|
// Desenhe a linha externa (set point)
|
|
double setPointAngleInRadians = ((Modulo.DirMotor.Angulo_SP * Math.PI) / 180);
|
|
int setPointX = centerX + (int)((radius + 10) * Math.Sin(setPointAngleInRadians));
|
|
int setPointY = centerY - (int)((radius + 10) * Math.Cos(setPointAngleInRadians));
|
|
g.DrawLine(Pens.Green, centerX, centerY, setPointX, setPointY);
|
|
|
|
// Desenhe a seta que indica o sentido
|
|
int arrowLength = 15; // Comprimento da seta
|
|
|
|
if (Modulo.DirMotor.Sentido_SP == Sentido.Horario)
|
|
{
|
|
// Desenhe uma seta para a direita (sentido horário)
|
|
Point arrowStart = new Point(setPointX, setPointY);
|
|
Point arrowEnd = new Point(setPointX + arrowLength, setPointY);
|
|
g.DrawLine(Pens.Green, arrowStart, arrowEnd);
|
|
|
|
// Desenhe a "ponta" da seta (triângulo) para a direita
|
|
Point arrowPoint1 = new Point(setPointX + arrowLength - 5, setPointY - 5);
|
|
Point arrowPoint2 = new Point(setPointX + arrowLength - 5, setPointY + 5);
|
|
g.DrawLine(Pens.Green, arrowEnd, arrowPoint1);
|
|
g.DrawLine(Pens.Green, arrowEnd, arrowPoint2);
|
|
}
|
|
else
|
|
{
|
|
// Desenhe uma seta para a esquerda (sentido anti-horário)
|
|
Point arrowStart = new Point(setPointX, setPointY);
|
|
Point arrowEnd = new Point(setPointX - arrowLength, setPointY);
|
|
g.DrawLine(Pens.Green, arrowStart, arrowEnd);
|
|
|
|
// Desenhe a "ponta" da seta (triângulo) para a esquerda
|
|
Point arrowPoint1 = new Point(setPointX - arrowLength + 5, setPointY - 5);
|
|
Point arrowPoint2 = new Point(setPointX - arrowLength + 5, setPointY + 5);
|
|
g.DrawLine(Pens.Green, arrowEnd, arrowPoint1);
|
|
g.DrawLine(Pens.Green, arrowEnd, arrowPoint2);
|
|
}
|
|
|
|
|
|
|
|
// Desenhe uma linha para representar a posição do eixo do motor
|
|
double angleInRadians = (Modulo.DirMotor.Angulo * Math.PI) / 180;
|
|
int x = centerX + (int)(radius * Math.Sin(angleInRadians));
|
|
int y = centerY - (int)(radius * Math.Cos(angleInRadians));
|
|
g.DrawLine(Pens.Red, centerX, centerY, x, y);
|
|
|
|
// Desenhe a seta que indica o sentido
|
|
if (Modulo.DirMotor.Sentido == Sentido.Horario)
|
|
{
|
|
// Desenhe uma seta para a direita (sentido horário)
|
|
Point arrowStart = new Point(x, y);
|
|
Point arrowEnd = new Point(x + arrowLength, y);
|
|
g.DrawLine(Pens.Red, arrowStart, arrowEnd);
|
|
|
|
// Desenhe a "ponta" da seta (triângulo) para a direita
|
|
Point arrowPoint1 = new Point(x + arrowLength - 5, y - 5);
|
|
Point arrowPoint2 = new Point(x + arrowLength - 5, y + 5);
|
|
g.DrawLine(Pens.Red, arrowEnd, arrowPoint1);
|
|
g.DrawLine(Pens.Red, arrowEnd, arrowPoint2);
|
|
}
|
|
else
|
|
{
|
|
// Desenhe uma seta para a esquerda (sentido anti-horário)
|
|
Point arrowStart = new Point(x, y);
|
|
Point arrowEnd = new Point(x - arrowLength, y);
|
|
g.DrawLine(Pens.Red, arrowStart, arrowEnd);
|
|
|
|
// Desenhe a "ponta" da seta (triângulo) para a esquerda
|
|
Point arrowPoint1 = new Point(x - arrowLength + 5, y - 5);
|
|
Point arrowPoint2 = new Point(x - arrowLength + 5, y + 5);
|
|
g.DrawLine(Pens.Red, arrowEnd, arrowPoint1);
|
|
g.DrawLine(Pens.Red, arrowEnd, arrowPoint2);
|
|
}
|
|
|
|
|
|
|
|
// Desenhe os pontos nos angulos fixos
|
|
int radiusCircle = 5;
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
double angle = ((i * 90) * Math.PI) / 180;
|
|
int xA = centerX + (int)((radius) * Math.Sin(angle)); // Adicione 20 para afastar do círculo principal
|
|
int yA = centerY - (int)((radius) * Math.Cos(angle)); // Adicione 20 para afastar do círculo principal
|
|
|
|
Rectangle rect = new Rectangle(xA - radiusCircle, yA - radiusCircle, 2 * radiusCircle, 2 * radiusCircle);
|
|
bool Acionado = false;
|
|
Acionado =
|
|
(angle == 0 && Modulo.DirMotor.IN1_Atuado) ||
|
|
(angle == Math.PI / 2 && Modulo.DirMotor.IN2_Atuado);
|
|
using (SolidBrush brush = new SolidBrush(Acionado ? Color.Red : Color.DarkRed))
|
|
{
|
|
g.FillEllipse(brush, rect);
|
|
}
|
|
|
|
string angleText = ((i * 90).ToString() + "°");
|
|
SizeF textSize = g.MeasureString(angleText, Font);
|
|
|
|
float textX = xA;
|
|
float textY = yA;
|
|
float textOffset = 12;
|
|
|
|
// Ajuste as coordenadas do texto com base no ângulo
|
|
if (angle == 0)
|
|
{
|
|
textX -= textSize.Width / 2;
|
|
textY -= textSize.Height - (textOffset * 2);
|
|
}
|
|
else if (angle == Math.PI / 2)
|
|
{
|
|
textX -= textSize.Width + textOffset;
|
|
textY -= textSize.Height / 2;
|
|
}
|
|
else if (angle == Math.PI)
|
|
{
|
|
textX -= textSize.Width / 2;
|
|
textY -= (textOffset * 2);
|
|
}
|
|
else if (angle == 3 * Math.PI / 2)
|
|
{
|
|
textX += textOffset;
|
|
textY -= textSize.Height / 2;
|
|
}
|
|
|
|
g.DrawString(angleText, Font, Brushes.Black, textX, textY);
|
|
}
|
|
|
|
}
|
|
|
|
private void pnlOrientacaoGPS_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
var _Sensoriamento = Variaveis.OperacaoEmAndamento.Sensoriamento;
|
|
double Angulo = _Sensoriamento.Gps.OrientacaoReal;
|
|
double AnguloMovimento = _Sensoriamento.Gps.OrientacaoMovimento;
|
|
FuncoesGlobais.DesenharInclinacao((Panel)sender, e, (float)Angulo, -90, (float)AnguloMovimento);
|
|
}
|
|
|
|
private void pnlOrientacaoMagnetometro_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
var _Sensoriamento = Variaveis.OperacaoEmAndamento.Sensoriamento;
|
|
double Angulo = _Sensoriamento.IMU.Rotacao;
|
|
double AnguloCorrigido = _Sensoriamento.IMU.RotacaoCorrigida;
|
|
FuncoesGlobais.DesenharInclinacao((Panel)sender, e, (float)Angulo, -90, (float)AnguloCorrigido);
|
|
}
|
|
|
|
|
|
}
|
|
}
|