2024-05-24 20:05:51 +00:00
using AgroBase.Forms ;
2024-07-15 19:02:36 +00:00
using AgroBase.Models ;
2024-05-24 20:05:51 +00:00
using AgroBase.Services ;
2024-07-12 19:44:56 +00:00
using AgroMonitor.Forms ;
2024-05-24 20:05:51 +00:00
using System ;
using System.Drawing ;
using System.Windows.Forms ;
namespace AgroMonitor
{
public partial class frmInicial : Form
{
2024-10-04 13:11:23 +00:00
Timer tmrDispositivos = new Timer ( ) { Interval = 1000 , Enabled = false } ;
2024-09-13 16:47:55 +00:00
2024-05-24 20:05:51 +00:00
public frmInicial ( )
{
InitializeComponent ( ) ;
IniciarDependencias ( ) ;
2024-07-15 19:02:36 +00:00
2024-09-24 19:02:54 +00:00
FuncoesGlobais . DefinirEventosPicBtn ( picAjustes , "Erro ao definir ajustes!" , async ( ) = >
2024-07-15 19:02:36 +00:00
{
frmAjustesOperacao frm = new frmAjustesOperacao ( ) ;
frm . ShowDialog ( ) ;
2024-09-24 19:02:54 +00:00
} , true ) ;
2024-07-15 19:02:36 +00:00
2024-09-24 19:02:54 +00:00
FuncoesGlobais . DefinirEventosPicBtn ( picRede , "Erro ao parametrizar módulo de comunicação!" , async ( ) = >
2024-07-15 19:02:36 +00:00
{
if ( LoRaService . Iniciado )
{
2024-10-04 13:11:23 +00:00
frmLoraConfig frm = new frmLoraConfig ( ) ;
2024-07-15 19:02:36 +00:00
frm . ShowDialog ( ) ;
}
else
{
MessageBox . Show ( "Módulo LoRa de comunicação não está conectado ou não está no modo de parametrização!" , "Alerta" , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
}
2024-09-24 19:02:54 +00:00
} , true ) ;
2024-07-15 19:02:36 +00:00
2024-09-24 19:02:54 +00:00
FuncoesGlobais . DefinirEventosPicBtn ( picRastreamento , "Erro ao carregar monitoramento!" , async ( ) = >
2024-07-15 19:02:36 +00:00
{
frmMonitoramento frm = new frmMonitoramento ( ) ;
frm . ShowDialog ( ) ;
2024-09-24 19:02:54 +00:00
} , true ) ;
2024-05-24 20:05:51 +00:00
}
private void IniciarDependencias ( )
{
2024-10-04 13:11:23 +00:00
tmrDispositivos . Tick + = TmrDispositivos_Elapsed ;
2024-05-24 20:05:51 +00:00
tmrDispositivos . Start ( ) ;
}
2024-10-03 18:21:30 +00:00
private async void TmrDispositivos_Elapsed ( object sender , EventArgs e )
2024-05-24 20:05:51 +00:00
{
2024-10-04 13:11:23 +00:00
var tmr = ( ( Timer ) sender ) ;
tmr . Stop ( ) ;
2024-09-13 16:47:55 +00:00
Func < bool > funcao = new Func < bool > ( ( ) = >
{
lblMqtt . Text = "MQTT: " + ( Variaveis . MqttService . StatusConexao ( ) ? "Conectado" : "Desconectado" ) ;
lblMqtt . ForeColor = Variaveis . MqttService . StatusConexao ( ) ? Color . Green : Color . Red ;
lblLoRa . Text = "LoRa: " + ( LoRaService . Iniciado ? "Conectado" : "Desconectado" ) ;
lblLoRa . ForeColor = LoRaService . Iniciado ? Color . Green : Color . Red ;
2024-05-24 20:05:51 +00:00
2024-09-13 16:47:55 +00:00
lblGps . Text = "GPS: " + ( GPSService . Iniciado ? "Conectado" : "Desconectado" ) ;
lblGps . ForeColor = GPSService . Iniciado ? Color . Green : Color . Red ;
return true ;
} ) ;
2024-05-24 20:05:51 +00:00
2024-09-13 16:47:55 +00:00
FuncoesGlobais . ExecutarMetodoComVerificacaoCrossThread ( this , funcao ) ;
2024-07-12 19:44:56 +00:00
2024-10-04 13:11:23 +00:00
if ( ! GPSService . Iniciado | | ! LoRaService . Iniciado )
{
await SerialService . RealizarVarreduraPortasUSB ( new System . Timers . Timer ( ) ) ;
2024-10-04 20:08:48 +00:00
tmr . Interval = SerialService . InteraloVerificacao ;
2024-10-04 13:11:23 +00:00
}
else
{
tmr . Interval = 10000 ;
}
2024-10-03 18:21:30 +00:00
2024-10-04 13:11:23 +00:00
tmr . Start ( ) ;
2024-07-12 19:44:56 +00:00
}
2024-05-24 20:05:51 +00:00
}
}