make desktop serial more responsive

This commit is contained in:
Andrew Tridgell 2011-10-30 12:40:54 +11:00
parent 4e09ea5fa2
commit de0a7117a8
2 changed files with 28 additions and 8 deletions

View File

@ -45,6 +45,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "desktop.h"
#define LISTEN_BASE_PORT 5760
#define BUFFER_SIZE 128
@ -305,3 +306,19 @@ void FastSerial::_freeBuffer(Buffer *buffer)
{
}
/*
return true if any bytes are pending
*/
void desktop_serial_select_setup(fd_set *fds, int *fd_high)
{
int i;
for (i=0; i<FS_MAX_PORTS; i++) {
if (tcp_state[i].connected) {
FD_SET(tcp_state[i].fd, fds);
if (tcp_state[i].fd > *fd_high) {
*fd_high = tcp_state[i].fd;
}
}
}
}

View File

@ -4,6 +4,7 @@
#include <sys/time.h>
#include <sched.h>
#include <wiring.h>
#include "desktop.h"
void setup(void);
void loop(void);
@ -16,15 +17,17 @@ int main(void)
setup();
while (true) {
struct timeval tv;
unsigned long t1, t2;
t1 = micros();
fd_set fds;
int fd_high = 0;
FD_ZERO(&fds);
loop();
t2 = micros();
if (t2 - t1 < 2) {
desktop_serial_select_setup(&fds, &fd_high);
tv.tv_sec = 0;
tv.tv_usec = 1;
select(0, NULL, NULL, NULL, &tv);
}
tv.tv_usec = 100;
select(fd_high+1, &fds, NULL, NULL, &tv);
}
return 0;
}