Exemple #1
0
int default_send(struct ir_remote* remote, struct ir_ncode* code)
{
	/* things are easy, because we only support one mode */
	if (drv.send_mode != LIRC_MODE_PULSE)
		return 0;

	if (drv.features & LIRC_CAN_SET_SEND_CARRIER) {
		unsigned int freq;

		freq = remote->freq == 0 ? DEFAULT_FREQ : remote->freq;
		if (default_ioctl(LIRC_SET_SEND_CARRIER, &freq) == -1) {
			log_error("could not set modulation frequency");
			log_perror_err(NULL);
			return 0;
		}
	}
	if (drv.features & LIRC_CAN_SET_SEND_DUTY_CYCLE) {
		unsigned int duty_cycle;

		duty_cycle = remote->duty_cycle == 0 ? 50 : remote->duty_cycle;
		if (default_ioctl(LIRC_SET_SEND_DUTY_CYCLE, &duty_cycle) == -1) {
			log_error("could not set duty cycle");
			log_perror_err(NULL);
			return 0;
		}
	}
	if (!send_buffer_put(remote, code))
		return 0;
	if (write_send_buffer(drv.fd) == -1) {
		log_error("write failed");
		log_perror_err(NULL);
		return 0;
	}
	return 1;
}
Exemple #2
0
static int uirt2_send(struct ir_remote* remote, struct ir_ncode* code)
{
	int i, length;
	unsigned long delay;
	const lirc_t* signals;
	int res = 0;

	if (!send_buffer_put(remote, code))
		return 0;

	length = send_buffer_length();
	signals = send_buffer_data();

	if (length <= 0 || signals == NULL) {
		log_trace("nothing to send");
		return 0;
	}


	log_trace("Trying REMSTRUC1 transmission");
	res = uirt2_send_mode2_struct1(dev, remote, signals, length);
	if (!res && (length < 48)) {
		log_trace("Using RAW transission");
		res = uirt2_send_mode2_raw(dev, remote, signals, length);
	}

	if (!res) {
		log_error("uirt2_send: remote not supported");
	} else {
		log_trace("uirt2_send: succeeded");
	}
	/*
	 * Some devices send the sequence in the background.  Wait for
	 * the sequence to complete before returning in order to avoid
	 * disturbing DTR which is used by certain hardware revisions
	 * to enable the builtin emitter.  We wait 1.1 times the expected
	 * time in order to handle any differences between the device and
	 * our clock.
	 */
	delay = remote->min_remaining_gap;
	for (i = 0; i < length; i++)
		delay += signals[i];
	delay = (delay * 11) / 10;
	usleep(delay);

	return res;
}
Exemple #3
0
static int hwftdi_send(struct ir_remote* remote, struct ir_ncode* code)
{
	__u32 f_sample = tx_baud_rate * 8;
	__u32 f_carrier = remote->freq == 0 ? DEFAULT_FREQ : remote->freq;
	__u32 div_carrier;
	int val_carrier;
	const lirc_t* pulseptr;
	lirc_t pulse;
	int n_pulses;
	int pulsewidth;
	int bufidx;
	int sendpulse;
	unsigned char buf[TXBUFSZ];

	logprintf(LIRC_DEBUG, "hwftdi_send() carrier=%dHz f_sample=%dHz ", f_carrier, f_sample);

	/* initialize decoded buffer: */
	if (!send_buffer_put(remote, code))
		return 0;

	/* init vars: */
	n_pulses = send_buffer_length();
	pulseptr = send_buffer_data();
	bufidx = 0;
	div_carrier = 0;
	val_carrier = 0;
	sendpulse = 0;

	while (n_pulses--) {
		/* take pulse from buffer */
		pulse = *pulseptr++;

		/* compute the pulsewidth (in # samples) */
		pulsewidth = ((__u64)f_sample) * ((__u32)(pulse & PULSE_MASK)) / 1000000ul;

		/* toggle pulse / space */
		sendpulse = sendpulse ? 0 : 1;

		while (pulsewidth--) {
			/* carrier generator (generates a carrier
			 * continously, will be modulated by the
			 * requested signal): */
			div_carrier += f_carrier * 2;
			if (div_carrier >= f_sample) {
				div_carrier -= f_sample;
				val_carrier = val_carrier ? 0 : 255;
			}

			/* send carrier or send space ? */
			if (sendpulse)
				buf[bufidx++] = val_carrier;
			else
				buf[bufidx++] = 0;

			/* flush txbuffer? */
			/* note: be sure to have room for last '0' */
			if (bufidx >= (TXBUFSZ - 1)) {
				logprintf(LIRC_ERROR, "buffer overflow while generating IR pattern");
				return 0;
			}
		}
	}

	/* always end with 0 to turn off transmitter: */
	buf[bufidx++] = 0;

	/* let the child process transmit the pattern */
	chk_write(pipe_main2tx[1], buf, bufidx);

	/* wait for child process to be ready with it */
	chk_read(pipe_tx2main[0], buf, 1);

	return 1;
}