void top::testbed(){ while(true){ wait(long_time); cout << "Testbed started... " << endl; wait(long_time); finger(0); wait(long_time); finger(3); finger(4); finger(1); finger(9); finger(6); finger(8); finger(7); finger(2); finger(5); sc_stop (); } }
static DEFPORT(FingerPort) { struct passwd *pwd; VU child; switch(event) { case VU_CREATE: to[0] = 0; if(access("/usr/tycho/spool/flash", R_OK)) blocked = TRUE; break; case VU_BUTTON: if(p1 != VU_ACCEPT) break; if(!strchr(to, '@')) { pwd = getpwnam(to); endpwent(); if(!pwd) { vu->vustatline = (STRING)MSG_INVALID; vu->vustatcolor = STAT_ERROR; VUTermAlert(1); fixcursor(); VUPostEvent(vu, VU_KEYBOARD, 0x15, 0); return TRUE; } child = finger(pwd); child->vuparent = vu->vuparent; vu->vuparent = child; } else { child = netfinger(to); if(!child) { vu->vustatline = (STRING)MSG_INVALID; vu->vustatcolor = STAT_ERROR; VUTermAlert(1); fixcursor(); VUPostEvent(vu, VU_KEYBOARD, 0x15, 0); return TRUE; } child->vuparent = vu->vuparent; vu->vuparent = child; } default: break; } return USEPORT(VUWindowPort); }
void SixenseManager::update(float deltaTime) { #ifdef HAVE_SIXENSE if (sixenseGetNumActiveControllers() == 0) { return; } MyAvatar* avatar = Application::getInstance()->getAvatar(); Hand* hand = avatar->getHand(); int maxControllers = sixenseGetMaxControllers(); // we only support two controllers sixenseControllerData controllers[2]; int numActiveControllers = 0; for (int i = 0; i < maxControllers && numActiveControllers < 2; i++) { if (!sixenseIsControllerEnabled(i)) { continue; } sixenseControllerData* data = controllers + numActiveControllers; ++numActiveControllers; sixenseGetNewestData(i, data); // Set palm position and normal based on Hydra position/orientation // Either find a palm matching the sixense controller, or make a new one PalmData* palm; bool foundHand = false; for (size_t j = 0; j < hand->getNumPalms(); j++) { if (hand->getPalms()[j].getSixenseID() == data->controller_index) { palm = &(hand->getPalms()[j]); foundHand = true; } } if (!foundHand) { PalmData newPalm(hand); hand->getPalms().push_back(newPalm); palm = &(hand->getPalms()[hand->getNumPalms() - 1]); palm->setSixenseID(data->controller_index); printf("Found new Sixense controller, ID %i\n", data->controller_index); } palm->setActive(true); // Read controller buttons and joystick into the hand palm->setControllerButtons(data->buttons); palm->setTrigger(data->trigger); palm->setJoystick(data->joystick_x, data->joystick_y); glm::vec3 position(data->pos[0], data->pos[1], data->pos[2]); // Transform the measured position into body frame. glm::vec3 neck = _neckBase; // Zeroing y component of the "neck" effectively raises the measured position a little bit. neck.y = 0.f; position = _orbRotation * (position - neck); // Rotation of Palm glm::quat rotation(data->rot_quat[3], -data->rot_quat[0], data->rot_quat[1], -data->rot_quat[2]); rotation = glm::angleAxis(PI, glm::vec3(0.f, 1.f, 0.f)) * _orbRotation * rotation; const glm::vec3 PALM_VECTOR(0.0f, -1.0f, 0.0f); glm::vec3 newNormal = rotation * PALM_VECTOR; palm->setRawNormal(newNormal); palm->setRawRotation(rotation); // Compute current velocity from position change glm::vec3 rawVelocity = (position - palm->getRawPosition()) / deltaTime / 1000.f; palm->setRawVelocity(rawVelocity); // meters/sec palm->setRawPosition(position); // use the velocity to determine whether there's any movement (if the hand isn't new) const float MOVEMENT_SPEED_THRESHOLD = 0.05f; if (glm::length(rawVelocity) > MOVEMENT_SPEED_THRESHOLD && foundHand) { _lastMovement = usecTimestampNow(); } // initialize the "finger" based on the direction FingerData finger(palm, hand); finger.setActive(true); finger.setRawRootPosition(position); const float FINGER_LENGTH = 300.0f; // Millimeters const glm::vec3 FINGER_VECTOR(0.0f, 0.0f, FINGER_LENGTH); const glm::vec3 newTipPosition = position + rotation * FINGER_VECTOR; finger.setRawTipPosition(position + rotation * FINGER_VECTOR); // Store the one fingertip in the palm structure so we can track velocity glm::vec3 oldTipPosition = palm->getTipRawPosition(); palm->setTipVelocity((newTipPosition - oldTipPosition) / deltaTime / 1000.f); palm->setTipPosition(newTipPosition); // three fingers indicates to the skeleton that we have enough data to determine direction palm->getFingers().clear(); palm->getFingers().push_back(finger); palm->getFingers().push_back(finger); palm->getFingers().push_back(finger); } if (numActiveControllers == 2) { updateCalibration(controllers); } // if the controllers haven't been moved in a while, disable const unsigned int MOVEMENT_DISABLE_DURATION = 30 * 1000 * 1000; if (usecTimestampNow() - _lastMovement > MOVEMENT_DISABLE_DURATION) { for (std::vector<PalmData>::iterator it = hand->getPalms().begin(); it != hand->getPalms().end(); it++) { it->setActive(false); } } #endif // HAVE_SIXENSE }
/* content-defined chunking */ int file_chunk_cdc(int fd_src, CDCFileDescriptor *file_descr, SeafileCrypt *crypt, gboolean write_data) { char *buf; uint32_t buf_sz; SHA_CTX file_ctx; CDCDescriptor chunk_descr; SHA1_Init (&file_ctx); init_cdc_file_descriptor (fd_src, file_descr); uint32_t block_min_sz = file_descr->block_min_sz; uint32_t block_mask = file_descr->block_sz - 1; int fingerprint = 0; int offset = 0; int ret = 0; int tail, cur, rsize; buf_sz = file_descr->block_max_sz; buf = chunk_descr.block_buf = malloc (buf_sz); if (!buf) return -1; /* buf: a fix-sized buffer. * cur: data behind (inclusive) this offset has been scanned. * cur + 1 is the bytes that has been scanned. * tail: length of data loaded into memory. buf[tail] is invalid. */ tail = cur = 0; while (1) { if (cur < block_min_sz) { rsize = block_min_sz - cur + READ_SIZE; } else { rsize = (buf_sz - tail < READ_SIZE) ? (buf_sz - tail) : READ_SIZE; } ret = readn (fd_src, buf + tail, rsize); if (ret < 0) { free (buf); return -1; } tail += ret; /* We've read all the data in this file. Output the block immediately * in two cases: * 1. The data left in the file is less than block_min_sz; * 2. We cannot find the break value until the end of this file. */ if (tail < block_min_sz || cur >= tail) { if (tail > 0) { if (file_descr->block_nr == file_descr->max_block_nr) { g_warning ("File size changed while chunking it.\n"); return -1; } WRITE_CDC_BLOCK (tail, write_data); } break; } /* * A block is at least of size block_min_sz. */ if (cur < block_min_sz - 1) cur = block_min_sz - 1; while (cur < tail) { fingerprint = (cur == block_min_sz - 1) ? finger(buf + cur - BLOCK_WIN_SZ + 1, BLOCK_WIN_SZ) : rolling_finger (fingerprint, BLOCK_WIN_SZ, *(buf+cur-BLOCK_WIN_SZ), *(buf + cur)); /* get a chunk, write block info to chunk file */ if (((fingerprint & block_mask) == ((BREAK_VALUE & block_mask))) || cur + 1 >= file_descr->block_max_sz) { if (file_descr->block_nr == file_descr->max_block_nr) { g_warning ("File size changed while chunking it.\n"); return -1; } WRITE_CDC_BLOCK (cur + 1, write_data); break; } else { cur ++; } } } SHA1_Final (file_descr->file_sum, &file_ctx); free (buf); return 0; }
static DEFPORT(WhoPort) { char *argv[] = {"/usr/tycho/sys/userlist", NULL}; int fd[2]; char *p; FILE *fp; char **list; char *item; SELECT opts = (SELECT)vu->vuoptions; static char buf[18]; char lbuf[128]; VU child; int pid; char *oldstat; int oldcolor; switch(event) { case VU_DESTROY: list = (char **)vu->vupaint; while(*list) free(*(list++)); free(vu->vupaint); break; case VU_BUTTON: list = (char **)vu->vupaint; strncpy(buf, list[opts->sel_mark], 16); buf[17] = 0; strtok(buf, " "); child = NULL; switch(p1) { case VU_MESSAGE: child = VUCreateQ(SendNotice, NULL, -1, -1, buf); break; case VU_FINGER: if(!strchr(buf, '@')) child = finger(getpwnam(buf)); else child = netfinger(buf); endpwent(); break; } if(child) { child->vuparent = vu->vuparent; vu->vuparent = child; } break; case VU_CREATE: oldstat = (char *)front->vustatline; oldcolor = front->vustatcolor; front->vustatline = (STRING)MSG_LOADING; front->vustatcolor = STAT_BUSY; fixcursor(); front->vustatline = (STRING)oldstat; front->vustatcolor = oldcolor; if(!USEPORT(VUSelectPort)) return FALSE; vu->vupaint = (char *)malloc(128 * sizeof(char *)); list = (char **)vu->vupaint; list[0] = 0; pipe(fd); pid = fork(); if(pid < 0) return FALSE; if(pid == 0) { dup2(fd[1], 1); close(fd[1]); close(fd[0]); write(1, "USERLIST\n", 9); execvp(*argv, argv); exit(-1); } close(fd[1]); fp = fdopen(fd[0], "r"); fgets(lbuf, sizeof(lbuf) - 1, fp); while(!feof(fp)) { fgets(lbuf, sizeof(lbuf) - 1, fp); if(feof(fp)) break; p = strchr(lbuf, '\n'); *p = 0; item = (char *)malloc(strlen(lbuf) + 1); strcpy(item, lbuf); VUSelectInsert(vu, VUSelectLocate(vu, item, (int(*)(const char *s1, const char *s2)) VUStricmp), item); } fclose(fp); waitpid(pid, NULL, 0); opts->sel_mark = opts->sel_base = 0; return TRUE; default: break; } return USEPORT(VUSelectPort); }