public void TestManualBlinkingSequence() { LightsDeviceController controller = new LightsDeviceController(Config.GetUsbProductId(), Config.GetUsbVendorId(), Config.GetUsbUsage(), Config.GetUsbUsagePage(), Config.GetWaitForDeviceRetryPeriod(), Config.GetUsbControlTransferType()); controller.Start(); int sleepTime = 150; int iterations = 10; Thread.Sleep(sleepTime); Console.WriteLine("Start"); string command = "red=on\ngreen=on\nyellow=on\n"; Console.WriteLine(string.Format("Send: {0}", command.Replace('\n', '|'))); Console.WriteLine(string.Format("Recv: {0}", controller.SendCommand(Encoding.ASCII.GetBytes(command)))); Thread.Sleep(sleepTime); for (int i = 0; i < iterations; i++) { Console.WriteLine(string.Format("Iteration {0}", i)); command = "red=on\ngreen=off\nyellow=off\n"; Console.WriteLine(string.Format("\tSend: {0}", command.Replace('\n', '|'))); Console.WriteLine(string.Format("\tRecv: {0}", controller.SendCommand(Encoding.ASCII.GetBytes(command)))); Thread.Sleep(sleepTime); command = "red=off\ngreen=on\nyellow=off\n"; Console.WriteLine(string.Format("\tSend: {0}", command.Replace('\n', '|'))); Console.WriteLine(string.Format("\tRecv: {0}", controller.SendCommand(Encoding.ASCII.GetBytes(command)))); Thread.Sleep(sleepTime); command = "red=off\ngreen=off\nyellow=on\n"; Console.WriteLine(string.Format("\tSend: {0}", command.Replace('\n', '|'))); Console.WriteLine(string.Format("\tRecv: {0}", controller.SendCommand(Encoding.ASCII.GetBytes(command)))); Thread.Sleep(sleepTime); } Console.WriteLine("Stop"); command = "red=on\ngreen=on\nyellow=on\n"; Console.WriteLine(string.Format("\tSend: {0}", command.Replace('\n', '|'))); Console.WriteLine(string.Format("\tRecv: {0}", controller.SendCommand(Encoding.ASCII.GetBytes(command)))); Thread.Sleep(sleepTime); }
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(); }