int run_daemon() { #if defined(__linux) || defined(__APPLE__) moved_monitor *monitor = moved_monitor_new(on_monitor_update_pair, NULL); int monitor_fd = moved_monitor_get_fd(monitor); struct pollfd pfd; pfd.fd = monitor_fd; pfd.events = POLLIN; while (1) { if (poll(&pfd, 1, 0) > 0) { moved_monitor_poll(monitor); } } moved_monitor_free(monitor); #else for(;;) { psmove_port_sleep_ms(5000); pair(NULL); } #endif return 0; }
int run_daemon() { // On Linux we use moved_monitor, which is based on udev, to detect // controller connection #ifdef __linux moved_monitor *monitor = moved_monitor_new(on_monitor_update, NULL); int monitor_fd = moved_monitor_get_fd(monitor); struct pollfd pfd; pfd.fd = monitor_fd; pfd.events = POLLIN; while (1) { if (poll(&pfd, 1, 0) > 0) { moved_monitor_poll(monitor); } } moved_monitor_free(monitor); #else // On non-Linux systems we just try to pair every 5 seconds for now while (1) { psmove_sleep(5); pair(NULL); } #endif // __linux return 0; }
int main(int argc, char *argv[]) { move_daemon moved; #ifdef __linux moved_monitor *monitor = moved_monitor_new(on_monitor_update_moved, &moved); #endif /* Never act as a client in "moved" mode */ psmove_set_remote_config(PSMove_OnlyLocal); moved.dump_devices(); int id, count = psmove_count_connected(); for (id=0; id<count; id++) { moved.handle_connection(NULL, NULL); } #ifdef __linux fd_set fds; int server_fd = moved.get_socket(); int monitor_fd = moved_monitor_get_fd(monitor); int nfds = ((server_fd > monitor_fd)?(server_fd):(monitor_fd)) + 1; #endif for (;;) { #ifdef __linux FD_ZERO(&fds); FD_SET(server_fd, &fds); FD_SET(monitor_fd, &fds); if (select(nfds, &fds, NULL, NULL, NULL)) { if (FD_ISSET(monitor_fd, &fds)) { moved_monitor_poll(monitor); } if (FD_ISSET(server_fd, &fds)) { moved.handle_request(); } } #else moved.handle_request(); #endif moved.write_reports(); } #ifdef __linux moved_monitor_free(monitor); #endif return 0; }