ajuste no envio do soltar botao da base

This commit is contained in:
Diego Freitas 2026-03-27 08:39:53 -03:00
parent 1857c60e80
commit 90e071858e
1 changed files with 7 additions and 7 deletions

View File

@ -73,7 +73,7 @@ public sealed class ManualControlSender : IDisposable
// fora do lock
if (isNeutral)
_ = SendStopBurstIfNeededAsync();
_ = SendStopBurstIfNeededAsync(msg);
else
_ = SendBurstAsync(msg, BurstStartCount, BurstStartIntervalMs);
}
@ -112,12 +112,12 @@ public sealed class ManualControlSender : IDisposable
var ms = (DateTime.UtcNow - _lastSendOkUtc).TotalMilliseconds;
if (_lastSendOkUtc != DateTime.MinValue && ms > SendFailDeadmanMs)
{
await SendStopBurstIfNeededAsync(_currentMsg);
lock (_lock)
{
_armed = false;
_currentMsg = null;
}
await SendStopBurstIfNeededAsync();
}
}
}
@ -133,7 +133,7 @@ public sealed class ManualControlSender : IDisposable
private Task SendOnceAsync(UdpCtrlMessage msg)
=> _udp.SendBurstAsync(UdpReliableChannel.TYPE_COMMAND, msg.ToBytes(), count: 1, intervalMs: 25, requestAck: false);
private async Task SendStopBurstIfNeededAsync()
private async Task SendStopBurstIfNeededAsync(UdpCtrlMessage msg)
{
var now = DateTime.UtcNow;
if ((now - _lastStopSentUtc).TotalMilliseconds < MinStopIntervalMs)
@ -141,7 +141,7 @@ public sealed class ManualControlSender : IDisposable
_lastStopSentUtc = now;
var stop = BuildStopMsg();
var stop = BuildStopMsg(msg.Key);
try { await SendBurstAsync(stop, BurstStopCount, BurstStopIntervalMs); }
catch { /* não derruba */ }
}
@ -149,14 +149,14 @@ public sealed class ManualControlSender : IDisposable
private static bool IsNeutral(UdpCtrlMessage msg)
=> msg.Key == AgroBase.Models.Enums.BotoesJoystick.Vazio || msg.released;
private UdpCtrlMessage BuildStopMsg()
private UdpCtrlMessage BuildStopMsg(AgroBase.Models.Enums.BotoesJoystick botao)
{
return new UdpCtrlMessage
{
Device = _device,
Flags = UdpCtrlFlags.HasKey | UdpCtrlFlags.HasPayload,
Key = AgroBase.Models.Enums.BotoesJoystick.Vazio,
released = false,
Key = botao,
released = true,
P1 = 0,
P2 = 0
};