Ejemplo n.º 1
0
        private static NusbioPixel ConnectToMCU(NusbioPixel nusbioPixel, int maxLed)
        {
            if (nusbioPixel != null)
            {
                nusbioPixel.Dispose();
                nusbioPixel = null;
            }
            var comPort = new NusbioPixel().DetectMcuComPort();

            if (comPort == null)
            {
                Logger _logger = new Logger(Path.Combine(ConfigurationManager.AppSettings["rootDirectory"], "log.txt"));
                _logger.LogInfo("Nusbio Pixel not detected.");
                return(null);
            }
            nusbioPixel = new NusbioPixel(maxLed, comPort);
            if (nusbioPixel.Initialize().Succeeded)
            {
                if (nusbioPixel.SetBrightness(nusbioPixel.DEFAULT_BRIGHTNESS).Succeeded)
                {
                    return(nusbioPixel);
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        public MainWindow()
        {
            KonamiCode[0]  = Key.R;
            KonamiCode[1]  = Key.R;
            KonamiCode[2]  = Key.F;
            KonamiCode[3]  = Key.F;
            KonamiCode[4]  = Key.D;
            KonamiCode[5]  = Key.G;
            KonamiCode[6]  = Key.D;
            KonamiCode[7]  = Key.G;
            KonamiCode[8]  = Key.A;
            KonamiCode[9]  = Key.S;
            KonamiCode[10] = Key.C;
            InitializeComponent();
            _cabinetLights = CabinetLights.Off;
            _rootDirectory = ConfigurationManager.AppSettings["rootDirectory"];
            _mameArgs      = ConfigurationManager.AppSettings["MAME_Args"];
            _logFile       = Path.Combine(_rootDirectory, "log.txt");
            _mameExe       = Path.Combine(_rootDirectory, "MAME64.EXE");
            _snapDirectory = Path.Combine(_rootDirectory, "snap");
            _snapshots     = new Dictionary <string, System.Windows.Media.ImageSource>();
            _gamesJson     = Path.Combine(_rootDirectory, "games.json");
            _supportCamera = Boolean.Parse(ConfigurationManager.AppSettings["Support_Camera"]);
            _supportNusbio = Boolean.Parse(ConfigurationManager.AppSettings["Support_Nusbio"]);
            JUMPDISTANCE   = Int32.Parse(ConfigurationManager.AppSettings["JUMPDISTANCE"]);
            _logger        = new Logger(_logFile);

            Boolean.Parse(ConfigurationManager.AppSettings["Support_Nusbio"]);
            string errorText;

            if (!File.Exists(_mameExe))
            {
                errorText = $"{_mameExe} does not exist.";
                MessageBox.Show(errorText, "Fatal Error");
                _logger.LogException(errorText, new Exception("MAME executable not found"));
                Environment.Exit(1);
            }
            else if (!File.Exists(_gamesJson))
            {
                GameListCreator glc = new GameListCreator();
                glc.GenerateGameList(_mameExe, _gamesJson, _snapDirectory);
            }
            else if (!Directory.Exists(_snapDirectory))
            {
                errorText = $"{_snapDirectory} does not exist.";
                MessageBox.Show(errorText, "Fatal Error");
                _logger.LogException(errorText, new Exception("Snap directory not found"));
                Environment.Exit(1);
            }

            Application.Current.MainWindow.Left = 0;
            Application.Current.MainWindow.Top  = 0;
            HideMouse();
            _logger.LogInfo("===============================================================================");
            _logger.LogInfo("Starting MAME");
            _logger.LogInfo("===============================================================================");
            Loaded += MainWindow_Loaded;

            _lastMotionDetectedTime = DateTime.Now.AddSeconds(20);

            if (_supportNusbio)
            {
                _whiteStripPWMIntensity = 254;

                nusbioPixel = ConnectToMCU(null, MAX_LED);
                if (nusbioPixel != null)
                {
                    _logger.LogVerbose("About to turn on the cabinet lights at the beginning.");
                    //FadeIn();
                    _logger.LogVerbose("Done with light initialization.");
                }
                //_logger.WriteToLogFile("FadeIn() complete");
                //PlaySound really only makes sense during the FadeIn sequence. If there are no lights, don't play the sound
                PlaySound("startup.wav");
                //_logger.WriteToLogFile("Intro sound was played");
            }


            #region Load games from disk and bind to the ListView
            LoadGamesFromJSON();
            lvGames.ItemsSource = GetUpdatedGameList();

            CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(lvGames.ItemsSource);
            lvGames.Focus();
            lvGames.SelectionMode = SelectionMode.Single;
            lvGames.SelectedIndex = 0;
            #endregion



            if (_supportCamera)
            {
                //Turn on the motion detection & voice recognition
                AForge.Controls.VideoSourcePlayer videoSourcePlayer2 = new AForge.Controls.VideoSourcePlayer();
                //            try
                //            {
                //                detector = GetDefaultMotionDetector();
                //                //videoSourcePlayer2.VideoSource = new VideoCaptureDevice(EnumerateVideoDevices().MonikerString);
                //                videoSourcePlayer2.NewFrame += Cam_NewFrame2;
                ////                videoSourcePlayer2.Start();
                //                //videoSourcePlayer2.Show();
                //                _localWebCam.Start();

                //            }
                //            catch (Exception ex)
                //            {
                //                //Do nothing. There is probably no webcam hooked up.
                //            }
                //this.LogRecognitionStart();
                //if (this.micClient == null)
                //{
                //    this.CreateMicrophoneRecoClient();
                //}
            }
        }