Skip to content

Commit

Permalink
Successful start/stop of comms
Browse files Browse the repository at this point in the history
  • Loading branch information
davepl committed Dec 11, 2023
1 parent dc27f7e commit ac2ff43
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
31 changes: 29 additions & 2 deletions Server/LEDControllerChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,46 @@ protected LEDControllerChannel(string hostName,
CompressData = compressData;
RedGreenSwap = swapRedGreen;
BatchSize = batchSize;
}

~LEDControllerChannel()
{
Stop();
}

public bool Start()
{
_cancellationTokenSource = new CancellationTokenSource();
_Worker = new Thread(WorkerConnectAndSendLoop);
_Worker.Name = hostName + " Connect and Send Loop";
_Worker.Name = HostName + " Connect and Send Loop";
_Worker.IsBackground = true;
_Worker.Priority = ThreadPriority.BelowNormal;
_Worker.Start();
return true;
}

~LEDControllerChannel()
// Stop
//
// Signals the worker thread to exit, waits for it, and closes the socket (if open)

public bool Stop()
{
// If we don't have a cancellation source, we've been told to stop before startingl likely

if (null == _cancellationTokenSource)
return false;

// Shut down the controller socket for this strip

ControllerSocket controllerSocket = ControllerSocketForHost(HostName);
if (controllerSocket != null && controllerSocket._socket != null)
controllerSocket.Close();

// Wrap up the worker thread

_cancellationTokenSource.Cancel();
_Worker.Join();
return true;
}

public bool HasSocket // Is there a socket at all yet?
Expand Down
4 changes: 2 additions & 2 deletions Server/SiteController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,8 +1092,8 @@ public class CeilingStrip : Location

private LightStrip[] _StripControllers =
{
new LightStrip("192.168.8.196", "Ceiling A", true, LENGTH, 1, START, true, 0, false) { FramesPerBuffer = 24, BatchSize = 1 }, // 216
new LightStrip("192.168.8.1", "Ceiling B", true, LENGTH, 1, START, true, 0, false) { FramesPerBuffer = 24, BatchSize = 1 } // 216
new LightStrip("192.168.8.196", "Ceiling A", true, LENGTH, 1, START, true, 0, false) { FramesPerBuffer = 24, BatchSize = 4 }, // 216
//new LightStrip("192.168.8.1", "Ceiling B", true, LENGTH, 1, START, true, 0, false) { FramesPerBuffer = 24, BatchSize = 1 } // 216
};

public ScheduledEffect[] _LEDEffects =
Expand Down

0 comments on commit ac2ff43

Please sign in to comment.