public MainForm() { InitializeComponent(); connectBtn.Text = connectText; fontLoading(); Font = new Font(fontCollection.Families[0], 8.25f); coloringComponents(); tip.SetToolTip(barsCheckBox, "Передвигать ползунки одновременно на уровень передвигаемого"); tip.SetToolTip(fadeCheckBox, "Включение плавной смены цвета после 5 секунд отсутствия звука"); tip.SetToolTip(lightCheckBox, "Переключение между режимами цветомузыки и постоянного свечения"); tip.SetToolTip(scanBtn, "Поиск доступных устройств TheSoundLights"); tip.SetToolTip(deviceCombo, "Список доступных устройств TheSoundLights для подключения"); myBt = new MyBluetooth(connectBtn, connectBtn_Click); if (myBt.getRadio() == null) { MessageForm.Show(MessageForm.ping_sad, "На Вашем устройстве отключен или отсутствует Bluetooth!", "Проверьте состояние Bluetooth"); Environment.Exit(0); } else { lightShow = new LightShow(myBt, spectrumChart, trackInit(), fadeCheckBox, barsCheckBox, lightCheckBox); } }
public void TestResourceHas300Commands() { var show = new LightShow(); using (var stream = CreateResource()) { var textStream = InputReader.ReadResource(stream); var commands = show.CreateCommands(new Tokenizer().Tokenize(textStream)); Assert.AreEqual(300, commands.ToList().Count); } }
//Light:光线 private void LightButton_Tapped(object sender, TappedRoutedEventArgs e) { if (LightPanel.Opacity == 0) { LightShow.Begin(); } else { LightFade.Begin(); } }
public void LitDiodsAre400410() { var show = new LightShow(); using (var stream = CreateResource()) { var textStream = InputReader.ReadResource(stream); var commands = show.CreateCommands(new Tokenizer().Tokenize(textStream)); var grid = new LightGrid<LightDiod>(1000, 1000, () => new LightDiod(false)); foreach (var command in commands) { grid.Execute(command); } Assert.AreEqual(400410, grid.GetDiods().Count(x => x.Item2.On)); } }
public void BrightnessIs15343601() { var show = new LightShow(); using (var stream = CreateResource()) { var textStream = InputReader.ReadResource(stream); var commands = show.CreateCommands(new Tokenizer().Tokenize(textStream)); var grid = new LightGrid<DimmedLightDiod>(1000, 1000, () => new DimmedLightDiod(0)); foreach (var command in commands) { grid.Execute(command); } Assert.AreEqual(15343601, grid.GetDiods().Sum(x => x.Item2.Brightness)); } }
private void MainForm_KeyDown(object sender, KeyEventArgs e) { e.SuppressKeyPress = true; if (e.KeyData == Keys.S) { int channelsNumber = Settings.Default.channelsNumber; new SettingsForm().ShowDialog(); TopMost = Settings.Default.topMost; coloringComponents(); if (channelsNumber != Settings.Default.channelsNumber) { for (int i = 0; i < 4; i++) { tbValues[0, i] = tbValues[1, i] = 0; } if (connectBtn.Text == disconnectText) { lightShow.Stop(); } TrackBar[] bars = trackInit(); lightShow = new LightShow(myBt, spectrumChart, bars, fadeCheckBox, barsCheckBox, lightCheckBox); if (connectBtn.Text == disconnectText) { lightShow.Start(); } } e.Handled = true; } }
public static async Task ReceiveMessagesFromDeviceAsync(string partition, CancellationToken ct) { var eventHubReceiver = s_eventHubClient.CreateReceiver("$Default", partition, EventPosition.FromEnqueuedTime(DateTime.Now)); Console.WriteLine("Create receiver on partition: " + partition); while (true) { if (ct.IsCancellationRequested) { break; } Console.WriteLine("Listening for messages on: " + partition); var events = await eventHubReceiver.ReceiveAsync(100); // If there is data in the batch, process it. if (events == null) { ClearRegister(); continue; } foreach (EventData eventData in events) { string data = Encoding.UTF8.GetString(eventData.Body.Array); Console.WriteLine("Message received on partition {0}:", partition); XmlDocument eventProcessResult = ProcessIoTEvent(eventData); if (eventProcessResult != null) { LightShow lightShow = new LightShow(eventProcessResult); foreach (Show show in lightShow.Shows) { RunShow(show); } } } } }
static void ListenToEventStream(string eventURI) { if (eventURI == null || eventURI.Length == 0) { throw new ApplicationException("Specify the URI of the resource to retrieve."); } HttpWebRequest request = null; while (true) { try { request = WebRequest.CreateHttp(eventURI); WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); string line = null; while (null != (line = reader.ReadLine())) { ConsoleOut("Received data", 1); if (line.Equals(string.Empty)) { ConsoleOut("Empty data", 10); } else { XmlDocument controllerXML = new XmlDocument(); try { controllerXML.LoadXml(line); ConsoleOut(controllerXML.OuterXml, 8); } catch (Exception ex) { ConsoleOut("Error loading XML", 0); ConsoleOut(ex.GetType().ToString(), 0); ConsoleOut(ex.ToString(), 10); controllerXML = null; } LightShow lightShow = null; try { lightShow = new LightShow(controllerXML); } catch { ConsoleOut("Error parsing XML", 0); controllerXML = null; } if (lightShow != null) { gpioController = new GpioController(); ConsoleOut("Setup GPIO", 0); SetupGPIO(); foreach (Show show in lightShow.Shows) { RunShow(show); } ConsoleOut("Clean up GPIO", 0); gpioController.Dispose(); } } } if (null == line) { Console.WriteLine("Response stream ended."); } else { Console.WriteLine("Listener stop request received."); break; } } catch (Exception ex) { ConsoleOut("Listener Exception : " + ex.GetType().ToString(), 0); ConsoleOut(ex.ToString(), 10); } finally { if (null != request) { request.Abort(); } } } Console.WriteLine("Listener stopped."); Console.ReadLine(); }