void StepperMotor::step() { string lsw("LSW: "); lsw.append(((this->gpio_LSW->getValue() == GPIO::LOW) ? "LOW" : "HIGH")); string rsw("RSW: "); rsw.append(((this->gpio_RSW->getValue() == GPIO::LOW) ? "LOW" : "HIGH")); console::debug(lsw.c_str()); console::debug(rsw.c_str()); string dir("Direction: "); dir.append(((this->getDirection() == DIRECTION::CLOCKWISE)?"CLOCKWISE":"ANTICLOCKWISE")); console::debug(dir.c_str()); // if ((this->gpio_LSW->getValue() == GPIO::HIGH) // && (this->direction == DIRECTION::ANTICLOCKWISE)) { // //switch is tripped...should go right... //// this->setDirection(DIRECTION::CLOCKWISE); // return;//limit reached // } // if ((this->gpio_RSW->getValue() == GPIO::HIGH) // && (this->direction == DIRECTION::CLOCKWISE)) { //// this->setDirection(DIRECTION::ANTICLOCKWISE); // return;//limit reached // } if(!this->isAtLimit()){ this->gpio_STEP->setValue(GPIO::LOW); this->gpio_STEP->setValue(GPIO::HIGH); } }
void JVMSPI_CheckEvents(JVMSPI_BlockedThreadInfo * blocked_threads, int blocked_threads_count, jlong timeout_milli_seconds) { fd_set read_fds; fd_set write_fds; fd_set except_fds; int i, num_fds, num_ready; bool debugger_active = JVM_IsDebuggerActive(); #if ENABLE_JAVA_DEBUGGER int dbg_socket_fd = -1; if (debugger_active) { dbg_socket_fd = JVM_GetDebuggerSocketFd(); } #endif FD_ZERO(&read_fds); FD_ZERO(&write_fds); FD_ZERO(&except_fds); // [1] Gather the FDs that we want to check event for num_fds = 1; for (i=0; i<blocked_threads_count; i++) { BlockingSocket *socket = (BlockingSocket *)blocked_threads[i].reentry_data; if (socket->check_flags & CHECK_READ) { FD_SET(socket->fd, &read_fds); } if (socket->check_flags & CHECK_WRITE) { FD_SET(socket->fd, &write_fds); } if (socket->check_flags & CHECK_EXCEPTION) { FD_SET(socket->fd, &except_fds); } if (num_fds < socket->fd) { num_fds = socket->fd; } } #if ENABLE_JAVA_DEBUGGER if (debugger_active) { if (dbg_socket_fd != -1) { FD_SET(dbg_socket_fd, &read_fds); if (num_fds < dbg_socket_fd) { num_fds = dbg_socket_fd; } } } #endif // [2] Call select() on the FDs, without appropriate timeout value if (timeout_milli_seconds < 0) { // Sleep forever until an event happens GUARANTEE(blocked_threads_count > 0, "can't sleep forever with no event sources!"); num_ready = jvm_select(num_fds+1, &read_fds, &write_fds, &except_fds, NULL); } else if (!debugger_active && blocked_threads_count == 0) { // It's better to call Os::sleep than select() with no fds -- WinSock // returns immediately with an error status if you don't pass any // fds. Os::sleep(timeout_milli_seconds); num_ready = 0; } else { jlong sec, usec; struct timeval timeout; sec = timeout_milli_seconds / 1000; usec = (timeout_milli_seconds % 1000) * 1000; if (msw(sec) <= 0) { timeout.tv_sec = lsw(sec); } else { // mmmm, are you sure you want to sleep so long?? timeout.tv_sec = 0x7fffffff; } timeout.tv_usec = lsw(usec); num_ready = jvm_select(num_fds+1, &read_fds, &write_fds, &except_fds, &timeout); } // [3] If a thread's FD is ready, change the thread's status to ready if (num_ready > 0) { for (i = 0; i < blocked_threads_count; i++) { BlockingSocket *socket = (BlockingSocket *)blocked_threads[i].reentry_data; jboolean is_ready = KNI_FALSE; if (socket->check_flags & CHECK_READ) { if (FD_ISSET(socket->fd, &read_fds)) { is_ready = KNI_TRUE; } } if (socket->check_flags & CHECK_WRITE) { if (FD_ISSET(socket->fd, &write_fds)) { is_ready = KNI_TRUE; } } if (socket->check_flags & CHECK_EXCEPTION) { if (FD_ISSET(socket->fd, &except_fds)) { // This happens only if a connect() call failed. Let's close // the socket and make sure open0() returns -1: // // Note to QA: this block needs more testing! jvm_shutdown(socket->fd, 2); closesocket(socket->fd); socket->fd = -1; is_ready = KNI_TRUE; } } if (is_ready) { SNI_UnblockThread(blocked_threads[i].thread_id); } } #if ENABLE_JAVA_DEBUGGER if (debugger_active) { if (FD_ISSET(dbg_socket_fd, &read_fds)) { JVM_ProcessDebuggerCmds(); } } #endif } }