int sirc_code(int pin, int bits) { set_io_dt(CLKFREQ/1000000); set_io_timeout(CLKFREQ/50); unsigned int irPulse; int irCode = 0; if(tLimit) t = CNT; do{ irPulse = pulse_in(pin, 0); if(tLimit) { if((CNT - t) >= tLimit) return -1; } }while((irPulse <= 2000) || (irPulse >= 2800)); for(int i = 0; i < bits; i++) { irPulse = pulse_in(pin, 0); if((irPulse > 1000) && (irPulse < 1400)) irCode |= (1 << i); if((irPulse < 300) || (irPulse > 1400)) return -1; if(tLimit) { if((CNT - t) >= tLimit) return -1; } } return irCode; }
void pulse_outCtrAux(int pin, int time) { if(iodt == 0) { set_io_dt(CLKFREQ/1000000); set_io_timeout(CLKFREQ/4); } signed long phsVal = -time * iodt; int ctr = 0; int frq = 1; int phs = 0; int state = get_output(pin); if(state == 1) { phsVal = -phsVal; phs = -1; frq = -1; } if(ta == 0 || (dta && (CNT - ta > dta))) { PHSA = phs; FRQA = frq; CTRA = pin; CTRA += (4 << 26); low(pin); PHSA = phsVal; dta = abs(phsVal); ta = CNT; } else if(tb == 0 || (dtb && (CNT - tb > dtb))) { PHSB = phs; FRQB = frq; CTRB = pin; CTRB += (4 << 26); low(pin); PHSB = phsVal; dtb = abs(phsVal); tb = CNT; } }