593 lines
29 KiB
C#
593 lines
29 KiB
C#
using AgroBase.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using static AgroBase.Models.Enums;
|
|
using AgroBase.Services;
|
|
|
|
namespace AgroBase.Forms.Operacoes
|
|
{
|
|
public partial class frmOperacaoManual : Form
|
|
{
|
|
Timer tmrLeitura;
|
|
DateTime UltimoComandoDir = DateTime.Now;
|
|
|
|
public frmOperacaoManual()
|
|
{
|
|
InitializeComponent();
|
|
|
|
// Ativa o double buffering
|
|
this.DoubleBuffered = true;
|
|
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
|
this.SetStyle(ControlStyles.UserPaint, true);
|
|
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
|
|
|
pnlAtuadores.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(pnlAtuadores, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true });
|
|
pnlAnguloGPS.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(pnlAnguloGPS, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true });
|
|
pnlAnguloMagnetometro.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(pnlAnguloMagnetometro, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true });
|
|
pnlDir_DF.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(pnlDir_DF, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true });
|
|
pnlDir_DT.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(pnlDir_DT, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true });
|
|
pnlDir_EF.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(pnlDir_EF, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true });
|
|
pnlDir_ET.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(pnlDir_ET, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true });
|
|
}
|
|
|
|
private void frmOperacaoManual_Load(object sender, EventArgs e)
|
|
{
|
|
cmbTipoMovimento.Items.Clear();
|
|
cmbTipoMovimento.Items.AddRange(Enum.GetNames(typeof(TipoMovimentoDirecional)));
|
|
cmbTipoMovimento.SelectedIndex = (int)Variaveis.OperacaoEmAndamento.Controle.TipoMovimento;
|
|
|
|
Variaveis.OperacaoEmAndamento.AtualizaListaCameras(pnlCameraRua, new List<Panel>() { pnlCameraSoloE, pnlCameraSoloD }, true);
|
|
|
|
InicializarComandosDirecional();
|
|
PopularInformacoesGerais();
|
|
InicializarMapa();
|
|
PopularBicos();
|
|
Variaveis.OperacaoEmAndamento.chartGraficos = chartGraficos;
|
|
|
|
tmrLeitura = new Timer() { Interval = 500 };
|
|
tmrLeitura.Tick += tmrLeitura_Tick;
|
|
tmrLeitura.Start();
|
|
}
|
|
|
|
private void frmOperacaoManual_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
tmrLeitura.Stop();
|
|
tmrLeitura.Dispose();
|
|
Variaveis.OperacaoEmAndamento.FinalizarOperacao();
|
|
Variaveis.OperacaoEmAndamento.DesligarCameras();
|
|
}
|
|
|
|
private async void btnIniciarOperacao_Click(object sender, EventArgs e)
|
|
{
|
|
if (btnIniciarOperacao.Text == "Finalizar Operação")
|
|
{
|
|
// Atualiza a UI na thread principal
|
|
btnIniciarOperacao.Invoke((MethodInvoker)delegate
|
|
{
|
|
btnIniciarOperacao.Text = "Finalizando...";
|
|
btnIniciarOperacao.Enabled = false;
|
|
});
|
|
|
|
// Executa a finalização da operação
|
|
Variaveis.OperacaoEmAndamento.FinalizarOperacao();
|
|
|
|
// Atualiza a UI novamente na thread principal
|
|
btnIniciarOperacao.Invoke((MethodInvoker)delegate
|
|
{
|
|
btnIniciarOperacao.Text = "Iniciar Operação";
|
|
btnIniciarOperacao.Enabled = true;
|
|
});
|
|
}
|
|
else
|
|
{
|
|
// Atualiza a UI na thread principal
|
|
btnIniciarOperacao.Invoke((MethodInvoker)delegate
|
|
{
|
|
btnIniciarOperacao.Text = "Iniciando...";
|
|
btnIniciarOperacao.Enabled = false;
|
|
});
|
|
|
|
// Verifica se a operação está liberada
|
|
if (Variaveis.OperacaoEmAndamento.OperacaoLiberada)
|
|
{
|
|
// Inicia a operação de forma assíncrona
|
|
await Variaveis.OperacaoEmAndamento.IniciarOperacao(null, false);
|
|
|
|
// Atualiza a UI após o início da operação
|
|
btnIniciarOperacao.Invoke((MethodInvoker)delegate
|
|
{
|
|
btnIniciarOperacao.Text = "Finalizar Operação";
|
|
btnIniciarOperacao.Enabled = true;
|
|
});
|
|
}
|
|
else
|
|
{
|
|
// Mostra a mensagem de erro na thread principal
|
|
btnIniciarOperacao.Invoke((MethodInvoker)delegate
|
|
{
|
|
MessageBox.Show(Variaveis.OperacaoEmAndamento.ErroOperacaoLiberada, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
btnIniciarOperacao.Text = "Iniciar Operação";
|
|
btnIniciarOperacao.Enabled = true;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void tmrLeitura_Tick(object sender, EventArgs e)
|
|
{
|
|
AtualizarDados();
|
|
}
|
|
|
|
public void AtualizarDados()
|
|
{
|
|
this.Text = Variaveis.OperacaoEmAndamento.TextoFormOperacao("Manual");
|
|
|
|
pnlDir_DF.Invalidate();
|
|
pnlDir_DT.Invalidate();
|
|
pnlDir_EF.Invalidate();
|
|
pnlDir_ET.Invalidate();
|
|
|
|
pnlAtuadores.Invalidate();
|
|
pnlAnguloGPS.Invalidate();
|
|
pnlAnguloMagnetometro.Invalidate();
|
|
|
|
AtualizarInformacoesGerais();
|
|
|
|
lblDistanciaEsquerda.Text = "Distancia Esq: " + Variaveis.OperacaoEmAndamento.Sensoriamento.DistanciaEsquerda.ToString("0.00") + " cm";
|
|
lblDistanciaDireita.Text = "Distancia Dir: " + Variaveis.OperacaoEmAndamento.Sensoriamento.DistanciaDireita.ToString("0.00") + " cm";
|
|
lblGPSsatelites.Text = GPSService.UltimaLeitura.NumeroSatelites.ToString() + " satélites";
|
|
lblGPSprecisao.Text = "Precisão: " + GPSService.UltimaLeitura.PrecisaoHorizontal.ToString("0.00") + " m";
|
|
lblGPSvelocidade.Text = "Vel.: " + GPSService.UltimaLeitura.Velocidade.ToString("0.00") + " km/h";
|
|
lblGPSaltitude.Text = "Altitude: " + GPSService.UltimaLeitura.Altitude.ToString("0.0") + " m";
|
|
|
|
lblTensao.Text = PZEMService.UltimaLeitura.Tensao.ToString("0.00") + " v";
|
|
lblCorrente.Text = PZEMService.UltimaLeitura.Corrente.ToString("0.00") + " A";
|
|
lblRPM.Text = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Average(x => x.MovMotor.RPM_Motor).ToString("0") + " rpm";
|
|
lblVelocidade.Text = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Average(x => x.MovMotor.VelocidadeInstantanea).ToString("0.00");
|
|
|
|
chbSonar.Enabled = KinectService.Iniciado && KinectService.Parametros.SonarAtivado;
|
|
if (!chbSonar.Enabled)
|
|
{
|
|
chbSonar.Checked = false;
|
|
}
|
|
var Sonar = Variaveis.OperacaoEmAndamento.Sensoriamento.SonarFrontal_Kinect;
|
|
if (chbSonar.Checked && Sonar.DesvioNecessario && UltimoComandoDir.AddSeconds(1) < DateTime.Now)
|
|
{
|
|
Variaveis.OperacaoEmAndamento.Controle.Angulo = Sonar.AnguloDesvio;
|
|
Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.ForEach(Modulo =>
|
|
{
|
|
//Variaveis.OperacaoEmAndamento.DispMvd.AdicionarMensagemFila(Modulo.Modulo_ID, Modulo.DirMotor.ProtocoloComando(direcaoDesvio), true, false);
|
|
GeneralJoystick.EnviaComandoMotor(Sonar.DirecaoDesvio == Direcao.Esquerda ? Keys.Left : Sonar.DirecaoDesvio == Direcao.Direita ? Keys.Right : Keys.Escape, T_Code.Dir);
|
|
});
|
|
UltimoComandoDir = DateTime.Now;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Direcionais
|
|
|
|
private void InicializarComandosDirecional()
|
|
{
|
|
pnlDir_DF.Paint += pnlDir_Paint;
|
|
pnlDir_DT.Paint += pnlDir_Paint;
|
|
pnlDir_EF.Paint += pnlDir_Paint;
|
|
pnlDir_ET.Paint += pnlDir_Paint;
|
|
}
|
|
|
|
private void pnlDir_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
DesenharGraficos(sender, e);
|
|
}
|
|
|
|
private void DesenharGraficos(object sender, PaintEventArgs e)
|
|
{
|
|
Panel pnl = (Panel)sender;
|
|
string ID = pnl.Name.Replace("pnlDir_", "");
|
|
|
|
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(m => m.Modulo_ID == ID);
|
|
Label lblAngulo = pnl.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lblDir_" + ID);
|
|
lblAngulo.Text = ID + " " + (Modulo.DirMotor.Angulo).ToString("000") + "º";
|
|
|
|
// Use o objeto Graphics para desenhar a representação do motor
|
|
Graphics g = e.Graphics;
|
|
|
|
int centerX = pnl.Width / 2;
|
|
int centerY = pnl.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;
|
|
var fontText = new Font(FontFamily.GenericSerif, 7);
|
|
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;
|
|
using (SolidBrush brush = new SolidBrush(Acionado ? Color.Red : Color.DarkRed))
|
|
{
|
|
g.FillEllipse(brush, rect);
|
|
}
|
|
|
|
string angleText = ((i * 90).ToString() + "°");
|
|
SizeF textSize = g.MeasureString(angleText, fontText);
|
|
|
|
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, fontText, Brushes.Black, textX, textY);
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Angulo orientacao Magnetica
|
|
|
|
private void pnlAnguloGPS_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
double angulo = GPSService.CalcularOrientacao(GPSService.PenultimaLeitura, GPSService.UltimaLeitura);
|
|
FuncoesGlobais.DesenharInclinacao((Panel)sender, e, (float)angulo, -90);
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
private void pnlAnguloMagnetometro_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
double angulo = Variaveis.OperacaoEmAndamento.Sensoriamento.AnguloCarroBussola;
|
|
FuncoesGlobais.DesenharInclinacao((Panel)sender, e, (float)angulo, -90);
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Informacoes gerais
|
|
|
|
private void PopularInformacoesGerais()
|
|
{
|
|
gridDados.Rows.Clear();
|
|
gridDados.Columns.Clear();
|
|
gridDados.Columns.Add("clDado", "Dado");
|
|
gridDados.Columns.Add("clValor", "Valor");
|
|
gridDados.Columns.Add("clUnidade", "Un");
|
|
|
|
gridDados.Rows.Add("Tempo de Operação", "", "");
|
|
gridDados.Rows.Add("Tempo em Movimento", "", "");
|
|
gridDados.Rows.Add("Velocidade Média", "", "km/h");
|
|
gridDados.Rows.Add("Distância Percorrida", "", "m");
|
|
gridDados.Rows.Add("Nível de Bateria", "", "%");
|
|
gridDados.Rows.Add("Tensão da Bateria", "", "v");
|
|
gridDados.Rows.Add("Corrente da Bateria", "", "A");
|
|
gridDados.Rows.Add("Barramento 3V", "", "V");
|
|
gridDados.Rows.Add("Barramento 3V", "", "mA");
|
|
gridDados.Rows.Add("Barramento 5V", "", "V");
|
|
gridDados.Rows.Add("Barramento 5V", "", "mA");
|
|
gridDados.Rows.Add("Barramento 7,2V", "", "V");
|
|
gridDados.Rows.Add("Barramento 7,2V", "", "mA");
|
|
gridDados.Rows.Add("Barramento 12V", "", "V");
|
|
gridDados.Rows.Add("Barramento 12V", "", "mA");
|
|
gridDados.Rows.Add("Nível do Reservatório", "", "%");
|
|
gridDados.Rows.Add("Volume do Reservatório", "", "L");
|
|
gridDados.Rows.Add("Pressão da Linha", "", "psi");
|
|
gridDados.Rows.Add("Potência na Bomba", "", "%");
|
|
|
|
AtualizarInformacoesGerais();
|
|
}
|
|
|
|
private void AtualizarInformacoesGerais()
|
|
{
|
|
var AB3V = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB3V");
|
|
var AB5V = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB5V");
|
|
var AB7V2 = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB7V2");
|
|
var AB12V = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB12V");
|
|
|
|
gridDados.Rows[0].Cells[1].Value = Variaveis.OperacaoEmAndamento.Tempo.Hours.ToString("00") + ":" + Variaveis.OperacaoEmAndamento.Tempo.Minutes.ToString("00") + ":" + Variaveis.OperacaoEmAndamento.Tempo.Seconds.ToString("00");
|
|
gridDados.Rows[1].Cells[1].Value = TimeSpan.FromSeconds(Variaveis.OperacaoEmAndamento.DispMvd.Dados.TempoEmAtividade).ToString(@"hh\:mm\:ss");
|
|
gridDados.Rows[2].Cells[1].Value = Variaveis.OperacaoEmAndamento.Sensoriamento.VelocidadeMedia.ToString("0.00");
|
|
gridDados.Rows[3].Cells[1].Value = Variaveis.OperacaoEmAndamento.Sensoriamento.DistanciaPercorrida.Sum().ToString("0.00");
|
|
gridDados.Rows[4].Cells[1].Value = (PZEMService.Iniciado && PZEMService.UltimaLeitura != null ? Variaveis.OperacaoEmAndamento.Sensoriamento.PorcentagemBateria.ToString("00.00") : "");
|
|
gridDados.Rows[5].Cells[1].Value = (PZEMService.Iniciado && PZEMService.UltimaLeitura != null ? PZEMService.UltimaLeitura.Tensao.ToString("0.00") : "");
|
|
gridDados.Rows[6].Cells[1].Value = (PZEMService.Iniciado && PZEMService.UltimaLeitura != null ? PZEMService.UltimaLeitura.Corrente.ToString("0.00") : "");
|
|
gridDados.Rows[7].Cells[1].Value = (AB3V != null && AB3V.Leituras != null && AB3V.Leituras.Count() > 0 ? AB3V.Leituras[0] : 0).ToString("0.00");
|
|
gridDados.Rows[8].Cells[1].Value = (AB3V != null && AB3V.Leituras != null && AB3V.Leituras.Count() > 1 ? AB3V.Leituras[1] : 0).ToString("0.00");
|
|
gridDados.Rows[9].Cells[1].Value = (AB5V != null && AB5V.Leituras != null && AB5V.Leituras.Count() > 0 ? AB5V.Leituras[0] : 0).ToString("0.00");
|
|
gridDados.Rows[10].Cells[1].Value = (AB5V != null && AB5V.Leituras != null && AB5V.Leituras.Count() > 1 ? AB5V.Leituras[1] : 0).ToString("0.00");
|
|
gridDados.Rows[11].Cells[1].Value = (AB7V2 != null && AB7V2.Leituras != null && AB7V2.Leituras.Count() > 0 ? AB7V2.Leituras[0] : 0).ToString("0.00");
|
|
gridDados.Rows[12].Cells[1].Value = (AB7V2 != null && AB7V2.Leituras != null && AB7V2.Leituras.Count() > 1 ? AB7V2.Leituras[1] : 0).ToString("0.00");
|
|
gridDados.Rows[13].Cells[1].Value = (AB12V != null && AB12V.Leituras != null && AB12V.Leituras.Count() > 0 ? AB12V.Leituras[0] : 0).ToString("0.00");
|
|
gridDados.Rows[14].Cells[1].Value = (AB12V != null && AB12V.Leituras != null && AB12V.Leituras.Count() > 1 ? AB12V.Leituras[1] : 0).ToString("0.00");
|
|
gridDados.Rows[15].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispAtu.Dados.PercentualReservatorio.ToString("00.00");
|
|
gridDados.Rows[16].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispAtu.Dados.VolumeReservatorio.ToString("0.000");
|
|
gridDados.Rows[17].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispAtu.Dados.PressaoLinha.ToString("0.00");
|
|
gridDados.Rows[18].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispAtu.Dados.BombaPressurizadora.Potencia.ToString("0.00");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Mapa GPS
|
|
|
|
private void InicializarMapa()
|
|
{
|
|
Variaveis.OperacaoEmAndamento.Mapa = new MapasModel()
|
|
{
|
|
pnlMapa = pnlMapa,
|
|
};
|
|
Variaveis.OperacaoEmAndamento.Mapa.CarregarMapaGPS();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Bicos Pulverizadores
|
|
|
|
private void PopularBicos()
|
|
{
|
|
var Atuador = Variaveis.OperacaoEmAndamento.DispAtu;
|
|
nudPressaoSP.Value = Convert.ToInt32(Variaveis.OperacaoEmAndamento.Controle.PressaoLinha);
|
|
|
|
int panelWidth = pnlAtuadores.Width;
|
|
int circleDiameter = 40; // Diâmetro dos círculos grandes
|
|
int spaceBetweenCircles = (panelWidth - (circleDiameter * Atuador.Dados.QuantidadeBicos)) / (Atuador.Dados.QuantidadeBicos + 1);
|
|
int yPosition = (pnlAtuadores.Height - circleDiameter) / 3; // Centralizado verticalmente
|
|
|
|
|
|
for (int i = 0; i < Atuador.Dados.QuantidadeBicos; i++)
|
|
{
|
|
// Calcula a posição x do círculo
|
|
int xPosition = spaceBetweenCircles + (i * (circleDiameter + spaceBetweenCircles));
|
|
// Define a string que representa o número do bico
|
|
string bicoNumero = Atuador.Dados.BicosPulverizadores[i].ID;
|
|
|
|
Button btnDesligar = new Button()
|
|
{
|
|
Name = "btn_" + bicoNumero,
|
|
Size = new Size(75, 27),
|
|
Location = new Point(xPosition + (circleDiameter - 75) / 2, circleDiameter + yPosition + 25),
|
|
Text = "Ligar"
|
|
};
|
|
btnDesligar.Click -= btn_Click;
|
|
btnDesligar.Click += btn_Click;
|
|
Label lblCmd = new Label()
|
|
{
|
|
Name = "lblCmd_" + bicoNumero,
|
|
Size = new Size(110, 20),
|
|
Location = new Point(xPosition + (circleDiameter - 110) / 2, 0),
|
|
Text = "Comando: Desligado"
|
|
};
|
|
|
|
pnlAtuadores.Controls.Add(btnDesligar);
|
|
pnlAtuadores.Controls.Add(lblCmd);
|
|
}
|
|
|
|
}
|
|
|
|
private void btn_Click(object sender, EventArgs e)
|
|
{
|
|
Button btn = (Button)sender;
|
|
string ID = btn.Name.Replace("btn_", "");
|
|
var Bico = Variaveis.OperacaoEmAndamento.DispAtu.Dados.BicosPulverizadores.FirstOrDefault(x => x.ID == ID);
|
|
if (Bico != null)
|
|
{
|
|
GeneralJoystick.EnviarComandoAtuador(S_Code.sBIC, !Bico.Atuado, Bico.ID);
|
|
|
|
pnlAtuadores.Controls.OfType<Label>().First(x => x.Name == "lblCmd_" + ID).Text = "Comando: " + (Bico.Atuado ? "Ligado" : "Desligado");
|
|
btn.Text = Bico.Atuado ? "Desligar" : "Ligar";
|
|
}
|
|
}
|
|
|
|
private void btnLigarBomba_Click(object sender, EventArgs e)
|
|
{
|
|
GeneralJoystick.EnviarComandoAtuador(S_Code.sBMB, true);
|
|
}
|
|
|
|
private void btnDesligarBomba_Click(object sender, EventArgs e)
|
|
{
|
|
GeneralJoystick.EnviarComandoAtuador(S_Code.sBMB, false);
|
|
}
|
|
|
|
private void nudPressaoSP_ValueChanged(object sender, EventArgs e)
|
|
{
|
|
Variaveis.OperacaoEmAndamento.Controle.PressaoLinha = Convert.ToInt32(((NumericUpDown)sender).Value);
|
|
GeneralJoystick.EnviarComandoAtuador(S_Code.sBMB, Variaveis.OperacaoEmAndamento.DispAtu.Dados.BombaPressurizadora.BombaAtuada);
|
|
}
|
|
|
|
private void pnlAtuadores_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
var Atuador = Variaveis.OperacaoEmAndamento.DispAtu;
|
|
|
|
Graphics g = e.Graphics;
|
|
Panel myPanel = (Panel)sender;
|
|
int panelWidth = myPanel.Width;
|
|
int circleDiameter = 40; // Diâmetro dos círculos grandes
|
|
int smallCircleDiameter = circleDiameter / 2; // Diâmetro dos círculos pequenos
|
|
int spaceBetweenCircles = (panelWidth - (circleDiameter * Atuador.Dados.QuantidadeBicos)) / (Atuador.Dados.QuantidadeBicos + 1);
|
|
int yPosition = (myPanel.Height - circleDiameter) / 3; // Centralizado verticalmente
|
|
|
|
|
|
for (int i = 0; i < Atuador.Dados.QuantidadeBicos; i++)
|
|
{
|
|
// Calcula a posição x do círculo
|
|
int xPosition = spaceBetweenCircles + (i * (circleDiameter + spaceBetweenCircles));
|
|
// Desenha o contorno do círculo
|
|
g.DrawEllipse(Pens.Red, xPosition, yPosition, circleDiameter, circleDiameter);
|
|
// Se o bico estiver aceso, preenche o círculo
|
|
if (Atuador.Dados.BicosPulverizadores[i].Atuado)
|
|
{
|
|
g.FillEllipse(Brushes.Red, xPosition, yPosition, circleDiameter, circleDiameter);
|
|
}
|
|
|
|
// Define a string que representa o número do bico
|
|
string bicoNumero = Atuador.Dados.BicosPulverizadores[i].ID;
|
|
// Define a fonte para o texto
|
|
Font font = new Font("Arial", 10, FontStyle.Bold);
|
|
// Mede o tamanho do texto
|
|
SizeF stringSize = g.MeasureString(bicoNumero, font);
|
|
// Calcula as posições x e y para centralizar o texto no círculo
|
|
float textXPosition = xPosition + (circleDiameter - stringSize.Width) / 2;
|
|
float textYPosition = yPosition + (circleDiameter - stringSize.Height) / 2;
|
|
// Desenha o número do bico
|
|
g.DrawString(bicoNumero, font, Brushes.Black, textXPosition, textYPosition);
|
|
|
|
|
|
// Define a string que representa a atuacao do bico
|
|
string bicoAtuacao = Variaveis.OperacaoEmAndamento.OpMapaGPS.Sensoriamento.AtuacoesPorBico[i].Sum(x => x.Value).ToString("000");
|
|
// Define a fonte para o texto
|
|
Font fontA = new Font("Arial", 8, FontStyle.Bold);
|
|
// Mede o tamanho do texto
|
|
SizeF stringSizeA = g.MeasureString(bicoAtuacao, fontA);
|
|
// Calcula as posições x e y para centralizar o texto no círculo
|
|
float textXPositionA = xPosition + (circleDiameter - stringSizeA.Width) / 2;
|
|
float textYPositionA = circleDiameter + yPosition + 5;
|
|
// Desenha as atuacoes do bico
|
|
g.DrawString(bicoAtuacao, fontA, Brushes.Black, textXPositionA, textYPositionA);
|
|
|
|
|
|
// Calcula a posição x e y do círculo pequeno
|
|
int smallCircleXPosition = Convert.ToInt32(xPosition + circleDiameter - smallCircleDiameter / 1.3);
|
|
int smallCircleYPosition = Convert.ToInt32(yPosition + circleDiameter - smallCircleDiameter / 1.3);
|
|
|
|
// Define a cor de contorno e preenchimento para o círculo pequeno
|
|
Pen smallCirclePen = Pens.Blue; // Cor do contorno
|
|
Brush smallCircleBrush = Brushes.Transparent; // Cor de preenchimento padrão
|
|
|
|
// Se o status do bico for true, altera a cor de preenchimento para azul
|
|
if (Atuador.Dados.BicosPulverizadores[i].StatusBico)
|
|
{
|
|
smallCircleBrush = Brushes.Blue;
|
|
}
|
|
|
|
// Desenha o contorno do círculo pequeno
|
|
g.DrawEllipse(smallCirclePen, smallCircleXPosition, smallCircleYPosition, smallCircleDiameter, smallCircleDiameter);
|
|
// Preenche o círculo pequeno se o status do bico for true
|
|
g.FillEllipse(smallCircleBrush, smallCircleXPosition, smallCircleYPosition, smallCircleDiameter, smallCircleDiameter);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
private void cmbTipoMovimento_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
Variaveis.OperacaoEmAndamento.Controle.TipoMovimento = (TipoMovimentoDirecional)cmbTipoMovimento.SelectedIndex;
|
|
}
|
|
}
|
|
}
|