2012-07-17 18:41:05 +02:00
|
|
|
/* Copyright (C) 2012 Kristian Lauszus, TKJ Electronics. All rights reserved.
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2012-07-17 18:41:05 +02:00
|
|
|
This software may be distributed and modified under the terms of the GNU
|
|
|
|
General Public License version 2 (GPL2) as published by the Free Software
|
|
|
|
Foundation and appearing in the file GPL2.TXT included in the packaging of
|
|
|
|
this file. Please note that GPL2 Section 2[b] requires that all works based
|
|
|
|
on this software must also be made publicly available under the terms of
|
|
|
|
the GPL2 ("Copyleft").
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2012-07-17 18:41:05 +02:00
|
|
|
Contact information
|
|
|
|
-------------------
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2012-07-17 18:41:05 +02:00
|
|
|
Kristian Lauszus, TKJ Electronics
|
|
|
|
Web : http://www.tkjelectronics.com
|
|
|
|
e-mail : kristianl@tkjelectronics.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "XBOXUSB.h"
|
|
|
|
#define DEBUG // Uncomment to print data for debugging
|
|
|
|
//#define EXTRADEBUG // Uncomment to get even more debugging data
|
|
|
|
//#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller
|
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
XBOXUSB::XBOXUSB(USB *p) :
|
2012-07-17 18:41:05 +02:00
|
|
|
pUsb(p), // pointer to USB class instance - mandatory
|
|
|
|
bAddress(0), // device address - mandatory
|
|
|
|
bPollEnable(false) { // don't start polling before dongle is connected
|
2013-03-28 09:46:43 +01:00
|
|
|
for (uint8_t i = 0; i < XBOX_MAX_ENDPOINTS; i++) {
|
|
|
|
epInfo[i].epAddr = 0;
|
|
|
|
epInfo[i].maxPktSize = (i) ? 0 : 8;
|
|
|
|
epInfo[i].epAttribs = 0;
|
|
|
|
epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pUsb) // register in USB subsystem
|
|
|
|
pUsb->RegisterDeviceClass(this); //set devConfig[] entry
|
2012-07-17 18:41:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
2013-03-28 09:46:43 +01:00
|
|
|
uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)];
|
|
|
|
uint8_t rcode;
|
|
|
|
UsbDevice *p = NULL;
|
|
|
|
EpInfo *oldep_ptr = NULL;
|
|
|
|
uint16_t PID;
|
|
|
|
uint16_t VID;
|
|
|
|
|
|
|
|
// get memory address of USB device address pool
|
|
|
|
AddressPool &addrPool = pUsb->GetAddressPool();
|
2012-07-17 18:41:05 +02:00
|
|
|
#ifdef EXTRADEBUG
|
2013-03-28 09:46:43 +01:00
|
|
|
Notify(PSTR("\r\nXBOXUSB Init"), 0x80);
|
2012-07-17 18:41:05 +02:00
|
|
|
#endif
|
2013-03-28 09:46:43 +01:00
|
|
|
// check if address has already been assigned to an instance
|
|
|
|
if (bAddress) {
|
2012-07-17 18:41:05 +02:00
|
|
|
#ifdef DEBUG
|
2013-03-28 09:46:43 +01:00
|
|
|
Notify(PSTR("\r\nAddress in use"), 0x80);
|
2012-07-17 18:41:05 +02:00
|
|
|
#endif
|
2013-03-28 09:46:43 +01:00
|
|
|
return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
|
|
|
|
}
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
// Get pointer to pseudo device with address 0 assigned
|
|
|
|
p = addrPool.GetUsbDevicePtr(0);
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
if (!p) {
|
2012-07-17 18:41:05 +02:00
|
|
|
#ifdef DEBUG
|
2013-03-28 09:46:43 +01:00
|
|
|
Notify(PSTR("\r\nAddress not found"), 0x80);
|
2012-07-17 18:41:05 +02:00
|
|
|
#endif
|
2013-03-28 09:46:43 +01:00
|
|
|
return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
|
|
|
|
}
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
if (!p->epinfo) {
|
2012-07-17 18:41:05 +02:00
|
|
|
#ifdef DEBUG
|
2013-03-28 09:46:43 +01:00
|
|
|
Notify(PSTR("\r\nepinfo is null"), 0x80);
|
2012-07-17 18:41:05 +02:00
|
|
|
#endif
|
2013-03-28 09:46:43 +01:00
|
|
|
return USB_ERROR_EPINFO_IS_NULL;
|
|
|
|
}
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
// Save old pointer to EP_RECORD of address 0
|
|
|
|
oldep_ptr = p->epinfo;
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
// Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
|
|
|
|
p->epinfo = epInfo;
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
p->lowspeed = lowspeed;
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
// Get device descriptor
|
|
|
|
rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
|
|
|
|
// Restore p->epinfo
|
|
|
|
p->epinfo = oldep_ptr;
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
if (rcode)
|
|
|
|
goto FailGetDevDescr;
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor;
|
|
|
|
PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
if (VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID) // We just check if it's a xbox controller using the Vendor ID
|
|
|
|
goto FailUnknownDevice;
|
|
|
|
if (PID == XBOX_WIRELESS_PID) {
|
2012-08-08 17:32:45 +02:00
|
|
|
#ifdef DEBUG
|
2013-03-28 09:46:43 +01:00
|
|
|
Notify(PSTR("\r\nYou have plugged in a wireless Xbox 360 controller - it doesn't support USB communication"), 0x80);
|
2012-08-08 17:32:45 +02:00
|
|
|
#endif
|
2013-03-28 09:46:43 +01:00
|
|
|
goto FailUnknownDevice;
|
|
|
|
} else if (PID == XBOX_WIRELESS_RECEIVER_PID || PID == XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) {
|
2012-08-08 17:32:45 +02:00
|
|
|
#ifdef DEBUG
|
2013-03-28 09:46:43 +01:00
|
|
|
Notify(PSTR("\r\nThis library only supports Xbox 360 controllers via USB"), 0x80);
|
2012-08-08 17:32:45 +02:00
|
|
|
#endif
|
2013-03-28 09:46:43 +01:00
|
|
|
goto FailUnknownDevice;
|
|
|
|
}
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
// Allocate new address according to device class
|
|
|
|
bAddress = addrPool.AllocAddress(parent, false, port);
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
if (!bAddress)
|
|
|
|
return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL;
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
// Extract Max Packet Size from device descriptor
|
|
|
|
epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0;
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
// Assign new address to the device
|
|
|
|
rcode = pUsb->setAddr(0, 0, bAddress);
|
|
|
|
if (rcode) {
|
|
|
|
p->lowspeed = false;
|
|
|
|
addrPool.FreeAddress(bAddress);
|
|
|
|
bAddress = 0;
|
2012-07-17 18:41:05 +02:00
|
|
|
#ifdef DEBUG
|
2013-03-28 09:46:43 +01:00
|
|
|
Notify(PSTR("\r\nsetAddr: "), 0x80);
|
2012-07-17 18:41:05 +02:00
|
|
|
#endif
|
2013-03-28 09:46:43 +01:00
|
|
|
PrintHex<uint8_t > (rcode, 0x80);
|
|
|
|
return rcode;
|
|
|
|
}
|
2012-07-17 18:41:05 +02:00
|
|
|
#ifdef EXTRADEBUG
|
2013-03-28 09:46:43 +01:00
|
|
|
Notify(PSTR("\r\nAddr: "), 0x80);
|
|
|
|
PrintHex<uint8_t > (bAddress, 0x80);
|
2012-07-17 18:41:05 +02:00
|
|
|
#endif
|
2013-03-28 09:46:43 +01:00
|
|
|
p->lowspeed = false;
|
|
|
|
|
|
|
|
//get pointer to assigned address record
|
|
|
|
p = addrPool.GetUsbDevicePtr(bAddress);
|
|
|
|
if (!p)
|
|
|
|
return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
|
|
|
|
|
|
|
|
p->lowspeed = lowspeed;
|
|
|
|
|
|
|
|
// Assign epInfo to epinfo pointer - only EP0 is known
|
|
|
|
rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
|
|
|
|
if (rcode)
|
|
|
|
goto FailSetDevTblEntry;
|
|
|
|
|
|
|
|
/* The application will work in reduced host mode, so we can save program and data
|
|
|
|
memory space. After verifying the VID we will use known values for the
|
|
|
|
configuration values for device, interface, endpoints and HID for the XBOX360 Controllers */
|
|
|
|
|
|
|
|
/* Initialize data structures for endpoints of device */
|
|
|
|
epInfo[ XBOX_INPUT_PIPE ].epAddr = 0x01; // XBOX 360 report endpoint
|
|
|
|
epInfo[ XBOX_INPUT_PIPE ].epAttribs = EP_INTERRUPT;
|
|
|
|
epInfo[ XBOX_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
|
|
|
|
epInfo[ XBOX_INPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
|
|
|
|
epInfo[ XBOX_INPUT_PIPE ].bmSndToggle = bmSNDTOG0;
|
|
|
|
epInfo[ XBOX_INPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
|
|
|
|
epInfo[ XBOX_OUTPUT_PIPE ].epAddr = 0x02; // XBOX 360 output endpoint
|
|
|
|
epInfo[ XBOX_OUTPUT_PIPE ].epAttribs = EP_INTERRUPT;
|
|
|
|
epInfo[ XBOX_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
|
|
|
|
epInfo[ XBOX_OUTPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
|
|
|
|
epInfo[ XBOX_OUTPUT_PIPE ].bmSndToggle = bmSNDTOG0;
|
|
|
|
epInfo[ XBOX_OUTPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
|
|
|
|
|
|
|
|
rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
|
|
|
|
if (rcode)
|
|
|
|
goto FailSetDevTblEntry;
|
|
|
|
|
|
|
|
delay(200); //Give time for address change
|
|
|
|
|
|
|
|
rcode = pUsb->setConf(bAddress, epInfo[ XBOX_CONTROL_PIPE ].epAddr, 1);
|
|
|
|
if (rcode)
|
2013-03-30 15:29:16 +01:00
|
|
|
goto FailSetConfDescr;
|
2012-07-17 18:41:05 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2013-03-28 09:46:43 +01:00
|
|
|
Notify(PSTR("\r\nXbox 360 Controller Connected\r\n"), 0x80);
|
2013-03-28 09:37:09 +01:00
|
|
|
#endif
|
2013-03-28 09:46:43 +01:00
|
|
|
setLedOn(LED1);
|
|
|
|
Xbox360Connected = true;
|
|
|
|
bPollEnable = true;
|
|
|
|
return 0; // successful configuration
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
/* diagnostic messages */
|
2012-07-17 18:41:05 +02:00
|
|
|
FailGetDevDescr:
|
2013-03-30 15:29:16 +01:00
|
|
|
NotifyFailGetDevDescr();
|
2013-03-28 09:46:43 +01:00
|
|
|
goto Fail;
|
2013-03-30 15:29:16 +01:00
|
|
|
|
2012-07-17 18:41:05 +02:00
|
|
|
FailSetDevTblEntry:
|
2013-03-30 15:29:16 +01:00
|
|
|
NotifyFailSetDevTblEntry();
|
2013-03-28 09:46:43 +01:00
|
|
|
goto Fail;
|
2013-03-30 15:29:16 +01:00
|
|
|
|
|
|
|
FailSetConfDescr:
|
|
|
|
NotifyFailSetConfDescr();
|
2013-03-28 09:46:43 +01:00
|
|
|
goto Fail;
|
2012-07-17 18:41:05 +02:00
|
|
|
FailUnknownDevice:
|
2013-03-30 15:29:16 +01:00
|
|
|
NotifyFailUnknownDevice(VID,PID);
|
2013-03-28 09:46:43 +01:00
|
|
|
rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
|
2013-03-30 15:29:16 +01:00
|
|
|
|
2012-07-17 18:41:05 +02:00
|
|
|
Fail:
|
|
|
|
#ifdef DEBUG
|
2013-03-28 09:46:43 +01:00
|
|
|
Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80);
|
2013-03-28 09:37:09 +01:00
|
|
|
#endif
|
2013-03-30 15:29:16 +01:00
|
|
|
NotifyFail(rcode);
|
2013-03-28 09:46:43 +01:00
|
|
|
Release();
|
|
|
|
return rcode;
|
2012-07-17 18:41:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Performs a cleanup after failed Init() attempt */
|
|
|
|
uint8_t XBOXUSB::Release() {
|
2013-03-28 09:46:43 +01:00
|
|
|
Xbox360Connected = false;
|
|
|
|
pUsb->GetAddressPool().FreeAddress(bAddress);
|
|
|
|
bAddress = 0;
|
|
|
|
bPollEnable = false;
|
|
|
|
return 0;
|
2012-07-17 18:41:05 +02:00
|
|
|
}
|
2013-03-28 09:46:43 +01:00
|
|
|
|
2013-03-28 09:37:09 +01:00
|
|
|
uint8_t XBOXUSB::Poll() {
|
2013-03-28 09:46:43 +01:00
|
|
|
if (!bPollEnable)
|
|
|
|
return 0;
|
|
|
|
uint16_t BUFFER_SIZE = EP_MAXPKTSIZE;
|
|
|
|
pUsb->inTransfer(bAddress, epInfo[ XBOX_INPUT_PIPE ].epAddr, &BUFFER_SIZE, readBuf); // input on endpoint 1
|
|
|
|
readReport();
|
2012-07-17 18:41:05 +02:00
|
|
|
#ifdef PRINTREPORT
|
2013-03-28 09:46:43 +01:00
|
|
|
printReport(); // Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller
|
2012-07-17 18:41:05 +02:00
|
|
|
#endif
|
2013-03-28 09:46:43 +01:00
|
|
|
return 0;
|
2012-07-17 18:41:05 +02:00
|
|
|
}
|
|
|
|
|
2013-03-28 09:37:09 +01:00
|
|
|
void XBOXUSB::readReport() {
|
2013-03-28 09:46:43 +01:00
|
|
|
if (readBuf == NULL)
|
|
|
|
return;
|
|
|
|
if (readBuf[0] != 0x00 || readBuf[1] != 0x14) { // Check if it's the correct report - the controller also sends different status reports
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonState = (uint32_t)(readBuf[5] | ((uint16_t)readBuf[4] << 8) | ((uint32_t)readBuf[3] << 16) | ((uint32_t)readBuf[2] << 24));
|
|
|
|
|
|
|
|
hatValue[LeftHatX] = (int16_t)(((uint16_t)readBuf[7] << 8) | readBuf[6]);
|
|
|
|
hatValue[LeftHatY] = (int16_t)(((uint16_t)readBuf[9] << 8) | readBuf[8]);
|
|
|
|
hatValue[RightHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
|
|
|
|
hatValue[RightHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
|
|
|
|
|
|
|
|
//Notify(PSTR("\r\nButtonState"), 0x80);
|
|
|
|
//PrintHex<uint32_t>(ButtonState, 0x80);
|
|
|
|
|
|
|
|
if (ButtonState != OldButtonState) {
|
|
|
|
ButtonClickState = (ButtonState >> 16) & ((~OldButtonState) >> 16); // Update click state variable, but don't include the two trigger buttons L2 and R2
|
|
|
|
if (((uint8_t)OldButtonState) == 0 && ((uint8_t)ButtonState) != 0) // The L2 and R2 buttons are special as they are analog buttons
|
|
|
|
R2Clicked = true;
|
|
|
|
if ((uint8_t)(OldButtonState >> 8) == 0 && (uint8_t)(ButtonState >> 8) != 0)
|
|
|
|
L2Clicked = true;
|
|
|
|
OldButtonState = ButtonState;
|
|
|
|
}
|
2013-03-28 09:37:09 +01:00
|
|
|
}
|
2012-07-17 18:41:05 +02:00
|
|
|
|
|
|
|
void XBOXUSB::printReport() { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller
|
2013-01-19 15:43:28 +01:00
|
|
|
#ifdef PRINTREPORT
|
2013-03-28 09:46:43 +01:00
|
|
|
if (readBuf == NULL)
|
|
|
|
return;
|
|
|
|
for (uint8_t i = 0; i < XBOX_REPORT_BUFFER_SIZE; i++) {
|
|
|
|
PrintHex<uint8_t > (readBuf[i], 0x80);
|
2013-04-26 23:50:39 +02:00
|
|
|
Notify(PSTR(" "), 0x80);
|
2013-03-28 09:46:43 +01:00
|
|
|
}
|
2013-04-26 23:50:39 +02:00
|
|
|
Notify(PSTR("\r\n"), 0x80);
|
2013-03-28 09:37:09 +01:00
|
|
|
#endif
|
2012-07-17 18:41:05 +02:00
|
|
|
}
|
|
|
|
|
2013-02-17 01:03:32 +01:00
|
|
|
uint8_t XBOXUSB::getButtonPress(Button b) {
|
2013-03-28 09:46:43 +01:00
|
|
|
if (b == L2) // These are analog buttons
|
|
|
|
return (uint8_t)(ButtonState >> 8);
|
|
|
|
else if (b == R2)
|
|
|
|
return (uint8_t)ButtonState;
|
|
|
|
return (ButtonState & ((uint32_t)pgm_read_word(&XBOXBUTTONS[(uint8_t)b]) << 16));
|
2013-02-17 01:03:32 +01:00
|
|
|
}
|
2013-03-28 09:46:43 +01:00
|
|
|
|
2013-02-17 01:03:32 +01:00
|
|
|
bool XBOXUSB::getButtonClick(Button b) {
|
2013-03-28 09:46:43 +01:00
|
|
|
if (b == L2) {
|
|
|
|
if (L2Clicked) {
|
|
|
|
L2Clicked = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} else if (b == R2) {
|
|
|
|
if (R2Clicked) {
|
|
|
|
R2Clicked = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2013-02-17 01:03:32 +01:00
|
|
|
}
|
2013-03-28 09:46:43 +01:00
|
|
|
uint16_t button = pgm_read_word(&XBOXBUTTONS[(uint8_t)b]);
|
|
|
|
bool click = (ButtonClickState & button);
|
|
|
|
ButtonClickState &= ~button; // clear "click" event
|
|
|
|
return click;
|
2012-07-17 18:41:05 +02:00
|
|
|
}
|
2013-03-28 09:46:43 +01:00
|
|
|
|
2012-07-17 18:41:05 +02:00
|
|
|
int16_t XBOXUSB::getAnalogHat(AnalogHat a) {
|
2013-03-28 09:46:43 +01:00
|
|
|
return hatValue[a];
|
2012-07-17 18:41:05 +02:00
|
|
|
}
|
|
|
|
|
2013-02-17 01:03:32 +01:00
|
|
|
/* Xbox Controller commands */
|
2012-07-17 18:41:05 +02:00
|
|
|
void XBOXUSB::XboxCommand(uint8_t* data, uint16_t nbytes) {
|
2013-03-28 09:46:43 +01:00
|
|
|
//bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x00), Report Type (Output 0x02), interface (0x00), datalength, datalength, data)
|
|
|
|
pUsb->ctrlReq(bAddress, epInfo[XBOX_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x00, 0x02, 0x00, nbytes, nbytes, data, NULL);
|
2012-07-17 18:41:05 +02:00
|
|
|
}
|
2013-03-28 09:46:43 +01:00
|
|
|
|
2013-02-17 01:03:32 +01:00
|
|
|
void XBOXUSB::setLedRaw(uint8_t value) {
|
2013-03-28 09:46:43 +01:00
|
|
|
writeBuf[0] = 0x01;
|
|
|
|
writeBuf[1] = 0x03;
|
|
|
|
writeBuf[2] = value;
|
2013-03-28 09:37:09 +01:00
|
|
|
|
2013-03-28 09:46:43 +01:00
|
|
|
XboxCommand(writeBuf, 3);
|
2012-07-17 18:41:05 +02:00
|
|
|
}
|
2013-03-28 09:46:43 +01:00
|
|
|
|
2013-02-17 01:03:32 +01:00
|
|
|
void XBOXUSB::setLedOn(LED led) {
|
2013-03-28 09:46:43 +01:00
|
|
|
if (led != ALL) // All LEDs can't be on a the same time
|
|
|
|
setLedRaw((pgm_read_byte(&XBOXLEDS[(uint8_t)led])) + 4);
|
2012-07-17 18:41:05 +02:00
|
|
|
}
|
2013-03-28 09:46:43 +01:00
|
|
|
|
2013-02-17 01:03:32 +01:00
|
|
|
void XBOXUSB::setLedBlink(LED led) {
|
2013-03-28 09:46:43 +01:00
|
|
|
setLedRaw(pgm_read_byte(&XBOXLEDS[(uint8_t)led]));
|
2013-02-17 01:03:32 +01:00
|
|
|
}
|
2013-03-28 09:46:43 +01:00
|
|
|
|
2013-02-17 01:03:32 +01:00
|
|
|
void XBOXUSB::setLedMode(LEDMode ledMode) { // This function is used to do some speciel LED stuff the controller supports
|
2013-03-28 09:46:43 +01:00
|
|
|
setLedRaw((uint8_t)ledMode);
|
2012-07-17 18:41:05 +02:00
|
|
|
}
|
2013-03-28 09:46:43 +01:00
|
|
|
|
2012-07-17 18:41:05 +02:00
|
|
|
void XBOXUSB::setRumbleOn(uint8_t lValue, uint8_t rValue) {
|
2013-03-28 09:46:43 +01:00
|
|
|
writeBuf[0] = 0x00;
|
|
|
|
writeBuf[1] = 0x08;
|
|
|
|
writeBuf[2] = 0x00;
|
|
|
|
writeBuf[3] = lValue; // big weight
|
|
|
|
writeBuf[4] = rValue; // small weight
|
|
|
|
writeBuf[5] = 0x00;
|
|
|
|
writeBuf[6] = 0x00;
|
|
|
|
writeBuf[7] = 0x00;
|
|
|
|
|
|
|
|
XboxCommand(writeBuf, 8);
|
2013-03-28 09:37:09 +01:00
|
|
|
}
|