/* eloWaitReply */ int eloWaitReply(unsigned char type, unsigned char *reply, int fd) { int ok; int i, result; int reply_p = 0; int sum = ELO_INIT_CHECKSUM; i = ELO_MAX_TRIALS; do { ok = 0; result = eloWaitForInput(fd, ELO_MAX_WAIT); if (result > 0) { ok = eloGetPacket(reply, &reply_p, &sum, fd); if (ok && reply[1] != type && type != ELO_PARAMETER) { #ifdef DEBUG_MOUSE fprintf(stderr, "Wrong reply received\n"); #endif ok = 0; } } else { #ifdef DEBUG_MOUSE fprintf(stderr, "No input!\n"); #endif } if (result == 0) { i--; } } while(!ok && (i>0)); return ok; }
int eloReadPosition(_THIS, int fd, int *x, int *y, int *button_state, int *realx, int *realy) { unsigned char buffer[ELO_PACKET_SIZE]; int pointer = 0; int checksum = ELO_INIT_CHECKSUM; while (pointer < ELO_PACKET_SIZE) { if (eloGetPacket(buffer, &pointer, &checksum, fd)) { break; } } if (!eloParsePacket(buffer, realx, realy, button_state)) { return 0; } *x = *realx; *y = *realy; eloConvertXY(this, x, y); return 1; }