Skip to content

Commit

Permalink
allow to configure the interval between actions #39
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsilva committed Jun 30, 2018
1 parent fa6536f commit 1220360
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/KNXLib/KnxConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ internal void Status(string address, string state)
Logger.Debug(ClassName, "Device {0} has status {1}", address, state);
}

/// <summary>
/// Set the lock interval between requests sent to the network (in ms)
/// </summary>
/// <param name="interval">time in ms for the interval</param>
public void SetLockIntervalMs(int interval)
{
_lockManager.IntervalMs = interval;
}

/// <summary>
/// Send a bit value as data to specified address
/// </summary>
Expand Down
10 changes: 9 additions & 1 deletion src/KNXLib/KnxLockManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ internal class KnxLockManager
private readonly object _connectedLock = new object();
private bool _isConnected;

internal int IntervalMs { get; set; } = 200;

public int LockCount
{
get { return _sendLock.CurrentCount; }
Expand Down Expand Up @@ -65,13 +67,19 @@ private void SendUnlock()

private void SendUnlockPause()
{
if (IntervalMs == 0)
{
_sendLock.Release();
return;
}

var t = new Thread(SendUnlockPauseThread) { IsBackground = true };
t.Start();
}

private void SendUnlockPauseThread()
{
Thread.Sleep(200);
Thread.Sleep(IntervalMs);
_sendLock.Release();
}
}
Expand Down

0 comments on commit 1220360

Please sign in to comment.