File: livedrive_common.c

package info (click to toggle)
lirc 0.10.1-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 8,364 kB
  • sloc: ansic: 26,717; cpp: 9,066; sh: 5,521; python: 4,362; makefile: 1,034; xml: 63
file content (85 lines) | stat: -rw-r--r-- 1,995 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * hw_livedrive.c - lirc routines for a Creative Labs LiveDrive.
 *
 *     Copyright (C) 2003 Stephen Beahm <stephenbeahm@adelphia.net>
 *
 *     This program is free software; you can redistribute it and/or
 *     modify it under the terms of the GNU General Public License as
 *     published by the Free Software Foundation; either version 2 of
 *     the License, or (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public
 *     License along with this program; if not, write to the Free
 *     Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *     Boston, MA  02110-1301 USA.
 */

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

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "lirc_driver.h"

#include "livedrive_common.h"

static const logchannel_t logchannel = LOG_DRIVER;

struct timeval start, end, last;
ir_code pre, code;

int livedrive_init(void)
{
	drv.fd = open(drv.device, O_RDONLY, 0);
	if (drv.fd < 0) {
		log_error("could not open %s", drv.device);
		return 0;
	}

	return 1;
}

int livedrive_deinit(void)
{
	close(drv.fd);
	return 1;
}

int livedrive_decode(struct ir_remote* remote, struct decode_ctx_t* ctx)
{
	lirc_t gap;

	if (!map_code(remote, ctx, 16, pre, 16, code, 0, 0))
		return 0;

	gap = 0;
	if (start.tv_sec - last.tv_sec >= 2) {
		ctx->repeat_flag = 0;
	} else {
		gap = time_elapsed(&last, &start);

		if (gap < 300000)
			ctx->repeat_flag = 1;
		else
			ctx->repeat_flag = 0;
	}

	log_trace("repeat_flag: %d", ctx->repeat_flag);
	log_trace("gap: %lu", (uint32_t)gap);

	return 1;
}