char * s_video_helper_irman_getcode (void) { int ret; unsigned char *code; char *code_text; code = ir_poll_code(); if (code == NULL) { return NULL; } code_text = ir_code_to_text(code); ret = ir_valid_code(code_text); if (ret == 0) { return NULL; } ir_clear_buffer(); return code_text; }
/* A modified port initialization - seems to work everytime */ void irapp_init_port(gchar * ir_port) { gint i; for (i = 0; i < 2; i++) { if (ir_open_port(ir_port) < 0) fprintf(stderr, _("unable to open port `%s' (%s)\n"), ir_port, strerror(errno)); else { ir_write_char('I'); ir_usleep(IR_HANDSHAKE_GAP); ir_write_char('R'); ir_set_enabled(1); ir_clear_buffer(); /* Take the 'OK' */ } } }
static int ir_init (char *filename) { int rdchar; if (ir_enabled) { errno = EBUSY; /* we already have a high level ir setup */ return -1; } if (ir_open_port(filename) < 0) { return -1; } ir_clear_buffer(); if (ir_write_char('I') < 0) { return -1; } ir_usleep(IR_HANDSHAKE_GAP); if (ir_write_char('R') < 0) { return -1; } /* we'll be nice and give the box a good chance to send an 'O' */ while ((rdchar = ir_read_char(IR_HANDSHAKE_TIMEOUT)) != 'O') { if (rdchar < 0) { /* error or timeout */ return -1; } } /* as regards the 'K', however, that really must be the next character */ rdchar = ir_read_char(IR_HANDSHAKE_TIMEOUT); if (rdchar < 0) { return -1; } /* ENOEXEC is the closest error I could find, that would also not be * generated by ir_read_char(). Anyway, ENOEXEC does more or less mean * "I don't understand this data I've been given" */ if (rdchar != 'K') { errno = ENOEXEC; return -1; } /* we are now ready to roll */ ir_enabled = 1; return 0; }