// Internal state handling ---------------------------------------------------- uint8_t EndDevice::tick() { // Avoid reading packet in states that does not // check what the packet contains. switch(State) { case EndDeviceStart: case EndDeviceResetStart: case EndDeviceJoiningSend: case EndDeviceIdle: case EndDeviceSleeping: case EndDeviceWaking: case EndDeviceRequestSend: //case Error: //? break; default: xbee.readPacket(); } switch(State) { case EndDeviceStart: return start(); case EndDeviceFormingNetwork: return formingNetwork(); case EndDeviceJoiningSend: return joiningSend(); case EndDeviceJoiningWait: return joiningWait(); case EndDeviceJoiningWaitResponse: return joiningWaitResponse(); case EndDeviceIdle: return idle(); case EndDeviceSleepWait: return sleepWait(); case EndDeviceSleeping: return sleeping(); case EndDeviceError: return error(); case EndDeviceRequestSend: return requestSend(); case EndDeviceRequestStatus: return requestStatus(); case EndDeviceRequestWait: return requestWait(); case EndDeviceResetStart: return resetStart(); case EndDeviceResetWait: return resetWait(); case EndDeviceWaking: return waking(); default: { DEBUG_MSG("Bad state!"); } return TICK_UNKNOWN_ERROR; } }
void InputDaemon::refreshMapping(QString mapping, InputDevice *device) { bool found = false; for (int i=0; i < SDL_NumJoysticks() && !found; i++) { SDL_Joystick *joystick = SDL_JoystickOpen(i); SDL_JoystickID joystickID = SDL_JoystickInstanceID(joystick); if (device->getSDLJoystickID() == joystickID) { found = true; if (SDL_IsGameController(i)) { // Mapping string updated. Perform basic refresh QByteArray tempbarray = mapping.toUtf8(); SDL_GameControllerAddMapping(tempbarray.data()); } else { // Previously registered as a plain joystick. Add // mapping and check for validity. If SDL accepts it, // close current device and re-open as // a game controller. SDL_GameControllerAddMapping(mapping.toUtf8().constData()); if (SDL_IsGameController(i)) { device->closeSDLDevice(); trackjoysticks.remove(joystickID); joysticks->remove(joystickID); SDL_GameController *controller = SDL_GameControllerOpen(i); GameController *damncontroller = new GameController(controller, i, settings, this); connect(damncontroller, SIGNAL(requestWait()), eventWorker, SLOT(haltServices())); SDL_Joystick *sdlStick = SDL_GameControllerGetJoystick(controller); joystickID = SDL_JoystickInstanceID(sdlStick); joysticks->insert(joystickID, damncontroller); trackcontrollers.insert(joystickID, damncontroller); emit deviceUpdated(i, damncontroller); } } } // Make sure to decrement reference count SDL_JoystickClose(joystick); } }
void InputDaemon::addInputDevice(int index) { SDL_Joystick *joystick = SDL_JoystickOpen(index); if (joystick) { SDL_JoystickID tempJoystickID = SDL_JoystickInstanceID(joystick); if (!joysticks->contains(tempJoystickID)) { settings->getLock()->lock(); settings->beginGroup("Mappings"); QString temp; SDL_JoystickGUID tempGUID = SDL_JoystickGetGUID(joystick); char guidString[65] = {'0'}; SDL_JoystickGetGUIDString(tempGUID, guidString, sizeof(guidString)); temp = QString(guidString); bool disableGameController = settings->value(QString("%1Disable").arg(temp), false).toBool(); if (SDL_IsGameController(index) && !disableGameController) { // Make sure to decrement reference count SDL_JoystickClose(joystick); SDL_GameController *controller = SDL_GameControllerOpen(index); if (controller) { SDL_Joystick *sdlStick = SDL_GameControllerGetJoystick(controller); SDL_JoystickID tempJoystickID = SDL_JoystickInstanceID(sdlStick); if (!joysticks->contains(tempJoystickID)) { GameController *damncontroller = new GameController(controller, index, settings, this); connect(damncontroller, SIGNAL(requestWait()), eventWorker, SLOT(haltServices())); joysticks->insert(tempJoystickID, damncontroller); trackcontrollers.insert(tempJoystickID, damncontroller); settings->endGroup(); settings->getLock()->unlock(); emit deviceAdded(damncontroller); } } else { settings->endGroup(); settings->getLock()->unlock(); } } else { Joystick *curJoystick = new Joystick(joystick, index, settings, this); joysticks->insert(tempJoystickID, curJoystick); trackjoysticks.insert(tempJoystickID, curJoystick); settings->endGroup(); settings->getLock()->unlock(); emit deviceAdded(curJoystick); } } else { // Make sure to decrement reference count SDL_JoystickClose(joystick); } } }
void InputDaemon::refreshJoysticks() { QMapIterator<SDL_JoystickID, InputDevice*> iter(*joysticks); while (iter.hasNext()) { InputDevice *joystick = iter.next().value(); if (joystick) { delete joystick; joystick = 0; } } joysticks->clear(); #ifdef USE_SDL_2 trackjoysticks.clear(); trackcontrollers.clear(); #endif #ifdef USE_SDL_2 settings->getLock()->lock(); settings->beginGroup("Mappings"); #endif for (int i=0; i < SDL_NumJoysticks(); i++) { #ifdef USE_SDL_2 SDL_Joystick *joystick = SDL_JoystickOpen(i); QString temp; SDL_JoystickGUID tempGUID = SDL_JoystickGetGUID(joystick); char guidString[65] = {'0'}; SDL_JoystickGetGUIDString(tempGUID, guidString, sizeof(guidString)); temp = QString(guidString); bool disableGameController = settings->value(QString("%1Disable").arg(temp), false).toBool(); if (SDL_IsGameController(i) && !disableGameController) { SDL_GameController *controller = SDL_GameControllerOpen(i); GameController *damncontroller = new GameController(controller, i, settings, this); connect(damncontroller, SIGNAL(requestWait()), eventWorker, SLOT(haltServices())); SDL_Joystick *sdlStick = SDL_GameControllerGetJoystick(controller); SDL_JoystickID joystickID = SDL_JoystickInstanceID(sdlStick); joysticks->insert(joystickID, damncontroller); trackcontrollers.insert(joystickID, damncontroller); } else { Joystick *curJoystick = new Joystick(joystick, i, settings, this); connect(curJoystick, SIGNAL(requestWait()), eventWorker, SLOT(haltServices())); SDL_JoystickID joystickID = SDL_JoystickInstanceID(joystick); joysticks->insert(joystickID, curJoystick); trackjoysticks.insert(joystickID, curJoystick); } #else SDL_Joystick *joystick = SDL_JoystickOpen(i); Joystick *curJoystick = new Joystick(joystick, i, settings, this); connect(curJoystick, SIGNAL(requestWait()), eventWorker, SLOT(haltServices())); joysticks->insert(i, curJoystick); #endif } #ifdef USE_SDL_2 settings->endGroup(); settings->getLock()->unlock(); #endif emit joysticksRefreshed(joysticks); }