//----------------------------------------------------------------------------- // When the controller could not connect, it is paused for a certain time, and // then a connect attempt needs to be made again. static void controller_wait_handler(int fd, short int flags, void *arg) { controller_t *ct; assert(fd < 0); assert((flags & EV_TIMEOUT) == EV_TIMEOUT); assert(arg); ct = (controller_t *) arg; assert(ct->connect_event); event_free(ct->connect_event); ct->connect_event = NULL; // only retry the connect if the controller is not marked as FAILED. if (BIT_TEST(ct->flags, FLAG_CONTROLLER_FAILED) == 0) { controller_connect(ct); } }
/*! * \brief init function : do init and loop (poll if configured so) */ static int app_engine(void) { // configure GUI gui_init(CPU_CLK_FREQ(),CPU_CLK_FREQ(),CPU_CLK_FREQ(),PBA_CLK_FREQ()); // configure controller controller_init(CPU_CLK_FREQ(),CPU_CLK_FREQ(),CPU_CLK_FREQ(), PBA_CLK_FREQ()); // initializes t2BF AppEngineInit( gui_callback, "Atmel Spp Lite" ); /* do a loop */ while (true) { OSTimeDlyHMSM(0, 0, 0, 200); controller_task(); if (controller_inquiry() == true) { AppEngineInquiryButton( ); } else if (controller_select() == true) { AppEngineSelectDeviceButton( ); } else if (controller_connect() == true) { AppEngineConnectButton( ); } else if (controller_send() == true) { AppEngineJoystickButton( AppEngine_Left ); } if (display) { OSTimeDlyHMSM(0, 0, 0, 200); // A delay so that it is humanly possible to see the OSTimeDlyHMSM(0, 0, 0, 200); // character(s) before they are cleared display = 0; } } }
static void init_controllers(system_data_t *sysdata) { char *str; controller_t *ct; assert(sysdata); assert(sysdata->controllers == NULL); sysdata->controllers = (list_t *) malloc(sizeof(list_t)); ll_init(sysdata->controllers); // now that everything else is configured, connect to other controllers. assert(sysdata->controllers); while ((str = ll_pop_head(sysdata->settings->controllers))) { ct = (controller_t *) malloc(sizeof(controller_t)); controller_init(ct, str); ct->sysdata = sysdata; logger(sysdata->logging, 1, "Connecting to controller: %s.", str); controller_connect(ct); ll_push_tail(sysdata->controllers, ct); ct = NULL; } }