Ejemplo n.º 1
0
        public byte[] WritePage(byte pageNumber, byte[] pageData)
        {
            byte[] writePage = new byte[pageData.Length + 2];
            writePage[0] = pageNumber;
            pageData.CopyTo(writePage, 1);
            writePage[writePage.Length - 1] = XBoxConnection.CalculateCrc(writePage, 0, pageData.Length - 1);

            // 'W'rite <byte[0..63]>
            Command('W', writePage);


            // 'R'ead <byte[0..63]>
            byte[] verifyPage = Command('R', new byte[] { pageNumber });
            if (XBoxConnection.CalculateCrc(verifyPage, 0, verifyPage.Length - 1) == verifyPage[verifyPage.Length - 1])
            {
                Array.Resize <byte>(ref verifyPage, verifyPage.Length - 1);
            }
            else
            {
                throw new System.IO.InvalidDataException("XBoxConnection.WritePage Failed CRC Check.");
            }

            for (int i = 0; i < pageData.Length; i++)
            {
                if (pageData[i] != verifyPage[i])
                {
                    throw new System.IO.InvalidDataException("XBoxConnection.WritePage Failed to Verify Page.");
                }
            }
            ;

            return(verifyPage);
        }
Ejemplo n.º 2
0
 public XBoxController(string portName)
 {
     xboxConnection       = new XBoxConnection(portName);
     xboxButtons          = new XBoxButtons(xboxConnection);
     xboxDPad             = new XBoxDPad(xboxConnection);
     xboxTriggers         = new XBoxTriggers(xboxConnection);
     xboxThumbSticks      = new XBoxThumbSticks(xboxConnection);
     xboxControllerConfig = new XBoxControllerConfiguration(xboxConnection);
     CalibrationEnabled   = false;
     IsWireless           = false;
 }
Ejemplo n.º 3
0
        public byte[] ReadPage(byte pageNumber)
        {
            // 'R'ead <byte[0..63]>
            byte[] pageData = Command('R', new byte[] { pageNumber });
            if (XBoxConnection.CalculateCrc(pageData, 0, pageData.Length - 1) == pageData[pageData.Length - 1])
            {
                Array.Resize <byte>(ref pageData, pageData.Length - 1);
            }
            else
            {
                throw new System.IO.InvalidDataException("XBoxConnection.ReadPage Failed CRC Check.");
            }

            return(pageData);
        }
Ejemplo n.º 4
0
        // Page 0 in the pg3b EEPROM is the system configuration record. It stores the state of
        // the calibration record for each analog control (on/off), and an enum representing the
        // type of controller.
        //
        // Byte 0: 8 Bit CRC
        //  1 - 4: magic number : "PG3B"
        //      5: record size : 9 bytes
        //      6: version : 1
        //      7: model : XBoxGamePad_t, where 0 <= XBoxGamePad_t <= 1.
        //      8: calibration : bitfield 2^XBoxTarget_t, where 0 <= XBoxTarget_t <= 7.

        public byte[] GetConfigPage()
        {
            byte[] xboxConfiguration = xboxConnection.ReadPage(ConfigPage);
            string magicNumber       = System.Text.Encoding.ASCII.GetString(xboxConfiguration, MagicOffset, MagicNumber.Length);

            if (magicNumber != MagicNumber)
            {
                throw new System.IO.InvalidDataException("XBoxCalibration.GetConfigPage failed to validate magic number.");
            }
            byte crc8 = XBoxConnection.CalculateCrc(xboxConfiguration, CrcOffset + 1, xboxConfiguration[SizeOffset] - 1);

            if (crc8 != xboxConfiguration[CrcOffset])
            {
                throw new System.IO.InvalidDataException("XBoxCalibration.GetConfigPage failed to validate the CRC.");
            }

            return(xboxConfiguration);
        }
Ejemplo n.º 5
0
        // NOTE: The concept of a "page" is used to simplify the implementation of pg3b <-> PC comms,
        // and as a unit of reference for statically assigned blocks of EEPROM data.
        //
        // Calibration data is written to consecutive pages. Pages are nominally 32 bytes each. A
        // calibration record is 256 bytes, or 8 sequential pages.
        //
        // Pages 1 -  8: LeftStickX
        //       9 - 16: LeftStickY
        //      17 - 24: RightStickX
        //      25 - 32: RightStickY
        //      33 - 40: LeftTrigger
        //      41 - 48: RightTrigger

        public void UpdateCalibration(XBTarget_t xboxTarget, byte[] calibrationData)
        {
            byte[] pageData       = new byte[PageSize];
            int    pagesPerRecord = calibrationData.Length / PageSize;
            int    firstPage      = ((int)xboxTarget * pagesPerRecord) + 1;

            for (int pageCount = 0; pageCount < calibrationData.Length / PageSize; pageCount++)
            {
                for (int pageOffset = 0; pageOffset < PageSize; pageOffset++)
                {
                    pageData[pageOffset] = calibrationData[pageCount * PageSize + pageOffset];
                }
                xboxConnection.WritePage((byte)(firstPage + pageCount), pageData);
            }

            byte[] xboxConfiguration = GetConfigPage();
            xboxConfiguration[CalibrationOffset] |= (byte)(1 << (int)xboxTarget);
            xboxConfiguration[CrcOffset]          = XBoxConnection.CalculateCrc(xboxConfiguration, CrcOffset + 1, xboxConfiguration[SizeOffset] - 1);
            xboxConnection.WritePage(ConfigPage, xboxConfiguration);
        }
Ejemplo n.º 6
0
 public XBoxDPad(XBoxConnection _xboxConnection)
 {
     xboxConnection = _xboxConnection;
 }
Ejemplo n.º 7
0
 public XBoxControllerConfiguration(XBoxConnection _xboxConnection)
 {
     xboxConnection  = _xboxConnection;
     xboxCalibration = new XBoxCalibration(xboxConnection);
 }
Ejemplo n.º 8
0
 public XBoxCalibration(XBoxConnection _xboxConnection)
 {
     xboxConnection = _xboxConnection;
 }
Ejemplo n.º 9
0
 public XBoxVector2(XBoxConnection _xboxConnection, XBTarget_t _targetCodeX, XBTarget_t _targetCodeY)
 {
     xboxConnection = _xboxConnection;
     targetCodeX    = _targetCodeX;
     targetCodeY    = _targetCodeY;
 }
Ejemplo n.º 10
0
 public XBoxThumbSticks(XBoxConnection _xboxConnection)
 {
     xboxConnection  = _xboxConnection;
     leftThumbStick  = new XBoxVector2(xboxConnection, XBTarget_t.LeftStickX, XBTarget_t.LeftStickY);
     rightThumbStick = new XBoxVector2(xboxConnection, XBTarget_t.RightStickX, XBTarget_t.RightStickY);
 }
Ejemplo n.º 11
0
 public XBoxController(string portName)
 {
     xboxConnection = new XBoxConnection(portName);
     xboxButtons = new XBoxButtons(xboxConnection);
     xboxDPad = new XBoxDPad(xboxConnection);
     xboxTriggers = new XBoxTriggers(xboxConnection);
     xboxThumbSticks = new XBoxThumbSticks(xboxConnection);
     xboxControllerConfig = new XBoxControllerConfiguration(xboxConnection);
     CalibrationEnabled = false;
     IsWireless = false;
 }
Ejemplo n.º 12
0
 public XBoxButtons(XBoxConnection _xboxConnection)
 {
     xboxConnection = _xboxConnection;
 }
Ejemplo n.º 13
0
 public XBoxButtons(XBoxConnection _xboxConnection)
 {
     xboxConnection = _xboxConnection;
 }
Ejemplo n.º 14
0
 public XBoxVector2(XBoxConnection _xboxConnection, XBTarget_t _targetCodeX, XBTarget_t _targetCodeY)
 {
     xboxConnection = _xboxConnection;
     targetCodeX = _targetCodeX;
     targetCodeY = _targetCodeY;
 }
Ejemplo n.º 15
0
 public XBoxTriggers(XBoxConnection _xboxConnection)
 {
     xboxConnection = _xboxConnection;
 }
Ejemplo n.º 16
0
 public XBoxThumbSticks(XBoxConnection _xboxConnection)
 {
     xboxConnection = _xboxConnection;
     leftThumbStick = new XBoxVector2(xboxConnection, XBTarget_t.LeftStickX, XBTarget_t.LeftStickY);
     rightThumbStick = new XBoxVector2(xboxConnection, XBTarget_t.RightStickX, XBTarget_t.RightStickY);
 }
Ejemplo n.º 17
0
 public XBoxDPad(XBoxConnection _xboxConnection)
 {
     xboxConnection = _xboxConnection;
 }
Ejemplo n.º 18
0
 public XBoxControllerConfiguration(XBoxConnection _xboxConnection)
 {
     xboxConnection = _xboxConnection;
     xboxCalibration = new XBoxCalibration(xboxConnection);
 }
Ejemplo n.º 19
0
 public XBoxTriggers(XBoxConnection _xboxConnection)
 {
     xboxConnection = _xboxConnection;
 }
Ejemplo n.º 20
0
 public XBoxCalibration(XBoxConnection _xboxConnection)
 {
     xboxConnection = _xboxConnection;
 }