<commit_before>/*      $Id: release.c,v 1.7 2010/04/11 18:50:38 lirc Exp $      */

/****************************************************************************
 ** release.c ***************************************************************
 ****************************************************************************
 *
 * release.c - automatic release event generation
 * 
 * Copyright (C) 2007 <NAME> (<EMAIL>)
 *
 */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>

#include "release.h"
#include "receive.h"
#include "lircd.h"

static struct timeval release_time;
static struct ir_remote *release_remote;
static struct ir_ncode *release_ncode;
static ir_code release_code;
static int release_reps;
static lirc_t release_gap;

static struct ir_remote *release_remote2;
static struct ir_ncode *release_ncode2;
static ir_code release_code2;
static const char *release_suffix = LIRC_RELEASE_SUFFIX;
static char message[PACKET_SIZE+1];

void register_input(void)
{
	struct timeval gap;
	
	if(release_remote == NULL) return;
	
	timerclear(&gap);
	gap.tv_usec = release_gap;
	
	gettimeofday(&release_time,NULL);
	timeradd(&release_time, &gap, &release_time);
}

void register_button_press(struct ir_remote *remote, struct ir_ncode *ncode,
			   ir_code code, int reps)
{
	if(reps == 0 && release_remote != NULL)
	{
		release_remote2 = release_remote;
		release_ncode2 = release_ncode;
		release_code2 = release_code;
	}
	
	release_remote = remote;
	release_ncode = ncode;
	release_code = code;
	release_reps = reps;
	/* must take into account that the decoder waits at least
	   100ms for the end of signal */
	release_gap = receive_timeout
		(upper_limit(remote, remote->max_total_signal_length -
			     remote->min_gap_length));
	
	LOGPRINTF(1, "release_gap: %lu", release_gap);

	register_input();
}

void get_release_data(const char **remote_name,
		      const char **button_name,
		      int *reps)
{
	*remote_name = release_remote->name;
	*button_name = release_ncode->name;
	*reps = release_reps;
}

void set_release_suffix(const char *s)
{
	release_suffix = s;
}

void get_release_time(struct timeval *tv)
{
	*tv = release_time;
}

const char *check_release_event(const char **remote_name,
				const char **button_name)
{<commit_msg>trying to get the release timeout calculation right<commit_after>/*      $Id: release.c,v 1.8 2010/04/17 13:39:29 lirc Exp $      */

/****************************************************************************
 ** release.c ***************************************************************
 ****************************************************************************
 *
 * release.c - automatic release event generation
 * 
 * Copyright (C) 2007 <NAME> (<EMAIL>)
 *
 */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>

#include "release.h"
#include "receive.h"
#include "lircd.h"

static struct timeval release_time;
static struct ir_remote *release_remote;
static struct ir_ncode *release_ncode;
static ir_code release_code;
static int release_reps;
static lirc_t release_gap;

static struct ir_remote *release_remote2;
static struct ir_ncode *release_ncode2;
static ir_code release_code2;
static const char *release_suffix = LIRC_RELEASE_SUFFIX;
static char message[PACKET_SIZE+1];

void register_input(void)
{
	struct timeval gap;
	
	if(release_remote == NULL) return;
	
	timerclear(&gap);
	gap.tv_usec = release_gap;
	
	gettimeofday(&release_time,NULL);
	timeradd(&release_time, &gap, &release_time);
}

void register_button_press(struct ir_remote *remote, struct ir_ncode *ncode,
			   ir_code code, int reps)
{
	if(reps == 0 && release_remote != NULL)
	{
		release_remote2 = release_remote;
		release_ncode2 = release_ncode;
		release_code2 = release_code;
	}
	
	release_remote = remote;
	release_ncode = ncode;
	release_code = code;
	release_reps = reps;
	release_gap = upper_limit(remote, remote->max_total_signal_length -
			     remote->min_gap_length) +
		receive_timeout(upper_limit(remote, remote->min_gap_length)) +
		10000; /* some additional safety margin */
	
	LOGPRINTF(1, "release_gap: %lu", release_gap);

	register_input();
}

void get_release_data(const char **remote_name,
		      const char **button_name,
		      int *reps)
{
	*remote_name = release_remote->name;
	*button_name = release_ncode->name;
	*reps = release_reps;
}

void set_release_suffix(const char *s)
{
	release_suffix = s;
}

void get_release_time(struct timeval *tv)
{
	*tv = release_time;
}

const char *check_release_event(const char **remote_name,
				const char **button_name)
{
{'fraction_non_alphanumeric': 0.19233254361404264, 'fraction_numerical': 0.01421494723239285, 'mean_word_length': 5.361643835616438, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3258453', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1501, 'n_words': 359}