Example #1
0
        public MainWindow()
        {
            InitializeComponent();

            camIcon.Opacity  = 0.4;
            camLabel.Opacity = 0.4;
            joyIcon.Opacity  = 0.4;
            joyLabel.Opacity = 0.4;

            theReferenceUsbDevice = new usbReferenceDevice(0x16C0, 0x0486, 0x0200);

            // Add a listener for usb events
            theReferenceUsbDevice.usbEvent += new usbReferenceDevice.usbEventsHandler(usbEvent_receiver);

            // Perform an initial search for the target USB device (in case
            // it is already connected as we will not get an event for it)
            theReferenceUsbDevice.findTargetDevice();

            // Connect to joystick device
            connectedJoystick                    = new joystickDevice();
            connectedJoystick.OnUpdate          += new joystickEventHandler(joystick_updated);
            connectedJoystick.OnConnectionEvent += new joystickEventHandler(joystick_connected);
            connectedJoystick.startConnection();

            // Get application settings
            appSettings = new applicationSettings();
            appSettings.LoadAppSettings();
        }
Example #2
0
        // Deserializes the class from the config file.
        public bool LoadAppSettings()
        {
            XmlSerializer mySerializer = null;
            FileStream    myFileStream = null;
            bool          fileExists   = false;

            try
            {
                // Create an XmlSerializer for the ApplicationSettings type.
                mySerializer = new XmlSerializer(typeof(applicationSettings));
                FileInfo fi = new FileInfo(Application.LocalUserAppDataPath + @"\cameraController.config");
                // If the config file exists, open it.
                if (fi.Exists)
                {
                    myFileStream = fi.OpenRead();
                    // Create a new instance of the ApplicationSettings by
                    // deserializing the config file.
                    applicationSettings myAppSettings =
                        (applicationSettings)mySerializer.Deserialize(
                            myFileStream);
                    // Assign the property values to this instance of
                    // the ApplicationSettings class.
                    this._windowLocation      = myAppSettings.windowLocation;
                    this._joystickSensitivity = myAppSettings.joystickSensitivity;
                    this._presetRuntime       = myAppSettings.presetRuntime;
                    fileExists = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                // If the FileStream is open, close it.
                if (myFileStream != null)
                {
                    myFileStream.Close();
                }
            }

            return(fileExists);
        }