X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=ao-tools%2Flib%2Fcc-usb.c;h=53a507412bbb9189077671bb8b2e05969ef40d82;hb=e747954b6a9e71705f619684df8a118a909b1039;hp=80d9c04f7ec5271074c730b3bf01c17f2845f610;hpb=35c54b3a278fa9bc2bc7f4b5ee04866697c93ba0;p=fw%2Faltos diff --git a/ao-tools/lib/cc-usb.c b/ao-tools/lib/cc-usb.c index 80d9c04f..53a50741 100644 --- a/ao-tools/lib/cc-usb.c +++ b/ao-tools/lib/cc-usb.c @@ -53,6 +53,8 @@ struct cc_usb { struct cc_hex_read hex_buf[CC_NUM_HEX_READ]; int hex_count; + + int remote; }; #define NOT_HEX 0xff @@ -372,6 +374,28 @@ cc_usb_reset(struct cc_usb *cc) return 1; } +void +cc_usb_open_remote(struct cc_usb *cc) +{ + if (!cc->remote) { + cc_usb_printf(cc, "\np\nE 0\n"); + do { + cc->in_count = cc->in_pos = 0; + _cc_usb_sync(cc, 100); + } while (cc->in_count > 0); + cc->remote = 1; + } +} + +void +cc_usb_close_remote(struct cc_usb *cc) +{ + if (cc->remote) { + cc_usb_printf(cc, "~"); + cc->remote = 0; + } +} + static struct termios save_termios; struct cc_usb * @@ -395,7 +419,7 @@ cc_usb_open(char *tty) save_termios = termios; cfmakeraw(&termios); tcsetattr(cc->fd, TCSAFLUSH, &termios); - cc_usb_printf(cc, "E 0\nm 0\n"); + cc_usb_printf(cc, "\nE 0\nm 0\n"); do { cc->in_count = cc->in_pos = 0; _cc_usb_sync(cc, 100); @@ -406,6 +430,8 @@ cc_usb_open(char *tty) void cc_usb_close(struct cc_usb *cc) { + cc_usb_close_remote(cc); + cc_usb_sync(cc); tcsetattr(cc->fd, TCSAFLUSH, &save_termios); close (cc->fd); free (cc);