public void TestStartAlreadyStarted() { // Setup LightsDeviceController lightsDeviceController = new LightsDeviceController(); Assert.That(lightsDeviceController.Running, NUnit.Framework.Is.False); lightsDeviceController.Start(); Assert.That(lightsDeviceController.Running, NUnit.Framework.Is.True); // Test lightsDeviceController.Start(); Assert.That(lightsDeviceController.Running, NUnit.Framework.Is.True); // Clean-up lightsDeviceController.Stop(); Assert.That(lightsDeviceController.Running, NUnit.Framework.Is.False); }
public void TestManualSequenceLightsDevice() { LightsDeviceController controller = new LightsDeviceController(Config.GetUsbProductId(), Config.GetUsbVendorId(), Config.GetUsbUsage(), Config.GetUsbUsagePage(), Config.GetWaitForDeviceRetryPeriod(), Config.GetUsbControlTransferType()); controller.Start(); int sleepTimeout = 3000; int sosSleepTimeout = 8000; List<IRequest> requests = new List<IRequest>(); // RGY-RGX-RGY-RXY-XGY-RXY-SXY-XGY-RGY requests.Add(new StatusRequest(false)); requests.Add(new BuildActiveRequest(false)); requests.Add(new BuildActiveRequest(true)); requests.Add(new AttentionRequest(true)); requests.Add(new AttentionRequest(false)); requests.Add(new AttentionRequest(true)); requests.Add(new AttentionRequest(true, true)); requests.Add(new AttentionRequest(false)); requests.Add(new StatusRequest(false)); Thread.Sleep(sleepTimeout); foreach (IRequest request in requests) { controller.SendCommand(Parser.TranslateForDasBlinkenlichten(request)); Thread.Sleep((request.GetType() == typeof(AttentionRequest)) && ((AttentionRequest)request).IsPriority ? sosSleepTimeout : sleepTimeout); } controller.Stop(); }
public void TestManualSequenceLightsDeviceBlink1Device() { LightsDeviceController controller = new LightsDeviceController(0x01ED, 0x27B8, 0x0001, 0xFF00, Config.GetWaitForDeviceRetryPeriod(), UsbControlTransferType.FeatureReport); controller.Start(); Assert.IsTrue(controller.Running); int sleepTimeout = 1000; List<IRequest> requests = new List<IRequest>(); // B-Y-R-Y-R-Y-G-B requests.Add(new StatusRequest(false)); requests.Add(new BuildActiveRequest(true)); requests.Add(new AttentionRequest(true)); requests.Add(new BuildActiveRequest(true)); requests.Add(new AttentionRequest(true, true)); requests.Add(new BuildActiveRequest(true)); requests.Add(new AttentionRequest(false)); requests.Add(new StatusRequest(false)); Thread.Sleep(sleepTimeout); foreach (IRequest request in requests) { if (request.GetType() == typeof(StatusRequest)) { controller.SendCommand(Parser.TranslateForBlink1((StatusRequest)request, controller.GetFeatureReportByteLength())); } else if (request.GetType() == typeof(AttentionRequest)) { controller.SendCommand(Parser.TranslateForBlink1((AttentionRequest)request, controller.GetFeatureReportByteLength())); } else if (request.GetType() == typeof(BuildActiveRequest)) { controller.SendCommand(Parser.TranslateForBlink1((BuildActiveRequest)request, controller.GetFeatureReportByteLength())); } Thread.Sleep(sleepTimeout); } controller.Stop(); }
public void TestManualInsertRemoveBlink1() { object insertedLock = new object(); object removedLock = new object(); LightsDeviceController controller = new LightsDeviceController(0x01ED, 0x27B8, 0x0001, 0xFF00, Config.GetWaitForDeviceRetryPeriod(), UsbControlTransferType.FeatureReport); controller.OnDeviceInserted += (sender, args) => { lock (insertedLock) { Monitor.Pulse(insertedLock); } }; controller.OnDeviceRemoved += (sender, args) => { lock (removedLock) { Monitor.Pulse(removedLock); } }; controller.Start(); Assert.IsTrue(controller.Running); for (int i = 0; i < 10; i++) { Console.WriteLine("Please insert the device"); lock (insertedLock) { Monitor.Wait(insertedLock); } Console.WriteLine("Device inserted"); controller.SendCommand(Parser.TranslateForBlink1(new AttentionRequest(false), controller.GetFeatureReportByteLength())); Console.WriteLine("Please remove the device"); lock (removedLock) { Monitor.Wait(removedLock); } Console.WriteLine("Device removed"); } controller.Stop(); }