// Sets the LED with the same format as the wired controller
void WirelessHIDDevice::SetLEDs(int mode)
{
    unsigned char buf[] = {0x00, 0x00, 0x08, (unsigned char)(0x40 + (mode % 0x0e)), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    WirelessDevice *device = OSDynamicCast(WirelessDevice, getProvider());

    if (device != NULL)
    {
        device->SendPacket(buf, sizeof(buf));
        device->SendPacket(weirdStart, sizeof(weirdStart));
    }
}
void Wireless360Controller::SetRumbleMotors(unsigned char large, unsigned char small)
{
    unsigned char buf[] = {0x00, 0x01, 0x0f, 0xc0, 0x00, large, small, 0x00, 0x00, 0x00, 0x00, 0x00};
    WirelessDevice *device = OSDynamicCast(WirelessDevice, getProvider());
    
    if (device != NULL)
        device->SendPacket(buf, sizeof(buf));
}
void WirelessHIDDevice::PowerOff(void)
{
    static const unsigned char buf[] = {0x00, 0x00, 0x08, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    WirelessDevice *device = OSDynamicCast(WirelessDevice, getProvider());
    
    if (device != NULL)
    {
        device->SendPacket(buf, sizeof(buf));
        // device->SendPacket(weirdStart, sizeof(weirdStart));
    }
}
// Start up the driver
bool WirelessHIDDevice::handleStart(IOService *provider)
{
    WirelessDevice *device;
    
    if (!super::handleStart(provider))
        return false;

    device = OSDynamicCast(WirelessDevice, provider);
    if (device == NULL)
        return false;
        
    device->RegisterWatcher(this, _receivedData, NULL);
    
    device->SendPacket(weirdStart, sizeof(weirdStart));
    
    return true;
}
// Start up the driver
bool WirelessHIDDevice::handleStart(IOService *provider)
{
    WirelessDevice *device;
    IOWorkLoop *workloop;
    
    if (!super::handleStart(provider))
        goto fail;

    device = OSDynamicCast(WirelessDevice, provider);
    if (device == NULL)
        goto fail;
    
    serialTimerCount = 0;
    
	serialTimer = IOTimerEventSource::timerEventSource(this, ChatPadTimerActionWrapper);
	if (serialTimer == NULL)
	{
		IOLog("start - failed to create timer for chatpad\n");
		goto fail;
	}
    workloop = getWorkLoop();
	if ((workloop == NULL) || (workloop->addEventSource(serialTimer) != kIOReturnSuccess))
	{
		IOLog("start - failed to connect timer for chatpad\n");
		goto fail;
	}
    
    device->RegisterWatcher(this, _receivedData, NULL);
    
    device->SendPacket(weirdStart, sizeof(weirdStart));

    serialTimer->setTimeoutMS(1000);

    return true;
    
fail:
    return false;
}