static void Main(string[] args) { bool running; bool connected; int maxPacketLen = (int)Math.Pow(2, 13); ILogger logger = new LoggerConfiguration().WriteTo.File("log.txt", rollingInterval: RollingInterval.Month).CreateLogger(); ICommunicationService communicationService = new SerialService(logger); IAudioCaptureService audioCaptureService = new NAudioCaptureService(96000, maxPacketLen, logger); IFFTService fftService = new FFTService(); ILedService ledService = new AdafruitLedService(communicationService, fftService); running = true; // Attempt to connect to the device and start the equalizer. try { AttemptConnect(ledService, logger); ledService.EqualizerStart(maxPacketLen, audioCaptureService); connected = true; } catch (Exception e) { connected = false; logger.Error("Unable to connect to device: " + e.ToString()); } // USEFUL DEBUG: Print everything to the Console. communicationService.ResponseSubscribe((response) => { Console.WriteLine(JsonConvert.SerializeObject(response)); }); // Listen for user input. Console.WriteLine("Yo hit the spacebar to hit the lights bro, P to ping, Q/ESC to quit"); while (running) { try { Console.Write('>'); ConsoleKeyInfo input = Console.ReadKey(); switch (Char.ToUpper(input.KeyChar)) { case ' ': { if (connected == true) { ledService.Disconnect(); connected = false; } else { AttemptConnect(ledService, logger); ledService.EqualizerStart(maxPacketLen, audioCaptureService); connected = true; } } break; case 'P': ledService.Ping(5000); break; case 'Q': case (char)27: // ESC running = false; ledService.Disconnect(); break; default: break; } Console.WriteLine(); } catch (Exception e) { Console.WriteLine(">:( Okay now how did we get here?\n" + e.ToString()); continue; //momma didn't raise no quitter! } } }
public async Task UpdateDisplayedMetadataSegments(JPEGByteFile file) { loadingTextBlock.Visibility = Visibility.Visible; SourceByteFile = file; ClearBlockChildren(); int segmentCntr = 0; foreach (Segment s in SourceByteFile.Segments) { TextBlock title = new TextBlock { Text = s.Name, Style = (Style)Application.Current.Resources["DetailSubTitleStyle"], Margin = (Thickness)Application.Current.Resources["SmallTopMargin"] }; block.Children.Add(title); TextBlock content = new TextBlock { Text = "Length: " + s.Length.ToString() + " B, Excess bytes after segment: " + s.ExcessBytesAfterSegment.ToString() + " B", Style = (Style)Application.Current.Resources["DetailBodyBaseMediumStyle"] }; block.Children.Add(content); StackPanel buttons = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 20 }; if (s.ExcessBytesAfterSegment > 0) { Button removeExcessBytesAfterSegmentButton = new Button() { Content = "Remove excess bytes", Tag = "BTN-" + segmentCntr }; removeExcessBytesAfterSegmentButton.Click += RemoveExcessBytesAfterSegmentButton_Click; buttons.Children.Add(removeExcessBytesAfterSegmentButton); } if (s.Removable) { Button removeSegmentButton = new Button() { Content = "Remove segment", Tag = "BTN-" + segmentCntr }; removeSegmentButton.Click += RemoveSegmentButton_Click; buttons.Children.Add(removeSegmentButton); } if (buttons.Children.Count > 0) { block.Children.Add(buttons); } if (s.Removable) { TextBlock t0 = new TextBlock() { Text = "Content:", Padding = new Thickness(0, 5, 0, 3) }; block.Children.Add(t0); TextBlock t = new TextBlock() { Text = Encoding.ASCII.GetString(s.Content), TextWrapping = TextWrapping.Wrap }; block.Children.Add(t); } segmentCntr++; } FFTService ImgFFT = new FFTService(file.File); await ImgFFT.ReadImage(); ImgFFT.ForwardFFT();// Finding 2D FFT of Image ImgFFT.FFTShift(); await ImgFFT.FFTPlotAsync(ImgFFT.FFTShifted); TextBlock magnitudeTitle = new TextBlock { Text = "Fourier transform magnitude", Style = (Style)Application.Current.Resources["DetailSubTitleStyle"], Margin = (Thickness)Application.Current.Resources["SmallTopMargin"] }; block.Children.Add(magnitudeTitle); block.Children.Add(new Image() { Source = ImgFFT.FourierPlot }); TextBlock phaseTitle = new TextBlock { Text = "Fourier transform phase", Style = (Style)Application.Current.Resources["DetailSubTitleStyle"], Margin = (Thickness)Application.Current.Resources["SmallTopMargin"] }; block.Children.Add(phaseTitle); block.Children.Add(new Image() { Source = ImgFFT.PhasePlot }); loadingTextBlock.Visibility = Visibility.Collapsed; }