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