ir_remote.h
Go to the documentation of this file.
/****************************************************************************
** ir_remote.h *************************************************************
****************************************************************************
*
* ir_remote.h - describes and decodes the signals from IR remotes
*
* Copyright (C) 1996,97 Ralph Metzler <rjkm@thp.uni-koeln.de>
* Copyright (C) 1998 Christoph Bartelmus <lirc@bartelmus.de>
*
*/
#ifndef IR_REMOTE_H
#define IR_REMOTE_H
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include "driver.h"
#include "ir_remote_types.h"
#ifdef __cplusplus
extern "C" {
#endif
struct ir_ncode* ncode_dup(struct ir_ncode* ncode);
void ncode_free(struct ir_ncode* ncode);
extern struct ir_remote* last_remote;
extern struct ir_remote* repeat_remote;
extern struct ir_ncode* repeat_code;
static inline ir_code get_ir_code(const struct ir_ncode* ncode,
const struct ir_code_node* node)
{
if (ncode->next && node != NULL)
return node->code;
return ncode->code;
}
static inline struct ir_code_node*
get_next_ir_code_node(const struct ir_ncode* ncode,
const struct ir_code_node* node)
{
if (node == NULL)
return ncode->next;
return node->next;
}
static inline int bit_count(const struct ir_remote* remote)
{
return remote->pre_data_bits + remote->bits + remote->post_data_bits;
}
static inline int bits_set(ir_code data)
{
int ret = 0;
while (data) {
if (data & 1)
ret++;
data >>= 1;
}
return ret;
}
static inline ir_code reverse(ir_code data, int bits)
{
int i;
ir_code c;
c = 0;
for (i = 0; i < bits; i++)
c |= (ir_code)(((data & (((ir_code)1) << i)) ? 1 : 0))
<< (bits - 1 - i);
return c;
}
static inline int is_pulse(lirc_t data)
{
return data & PULSE_BIT ? 1 : 0;
}
static inline int is_space(lirc_t data)
{
return !is_pulse(data);
}
static inline int has_repeat(const struct ir_remote* remote)
{
if (remote->prepeat > 0 && remote->srepeat > 0)
return 1;
else
return 0;
}
static inline void set_protocol(struct ir_remote* remote, int protocol)
{
remote->flags &= ~(IR_PROTOCOL_MASK);
remote->flags |= protocol;
}
static inline int is_raw(const struct ir_remote* remote)
{
if ((remote->flags & IR_PROTOCOL_MASK) == RAW_CODES)
return 1;
else
return 0;
}
static inline int is_space_enc(const struct ir_remote* remote)
{
if ((remote->flags & IR_PROTOCOL_MASK) == SPACE_ENC)
return 1;
else
return 0;
}
static inline int is_space_first(const struct ir_remote* remote)
{
if ((remote->flags & IR_PROTOCOL_MASK) == SPACE_FIRST)
return 1;
else
return 0;
}
static inline int is_rc5(const struct ir_remote* remote)
{
if ((remote->flags & IR_PROTOCOL_MASK) == RC5)
return 1;
else
return 0;
}
static inline int is_rc6(const struct ir_remote* remote)
{
if ((remote->flags & IR_PROTOCOL_MASK) == RC6 || remote->rc6_mask)
return 1;
else
return 0;
}
static inline int is_biphase(const struct ir_remote* remote)
{
if (is_rc5(remote) || is_rc6(remote))
return 1;
else
return 0;
}
static inline int is_rcmm(const struct ir_remote* remote)
{
if ((remote->flags & IR_PROTOCOL_MASK) == RCMM)
return 1;
else
return 0;
}
static inline int is_goldstar(const struct ir_remote* remote)
{
if ((remote->flags & IR_PROTOCOL_MASK) == GOLDSTAR)
return 1;
else
return 0;
}
static inline int is_grundig(const struct ir_remote* remote)
{
if ((remote->flags & IR_PROTOCOL_MASK) == GRUNDIG)
return 1;
else
return 0;
}
static inline int is_bo(const struct ir_remote* remote)
{
if ((remote->flags & IR_PROTOCOL_MASK) == BO)
return 1;
else
return 0;
}
static inline int is_serial(const struct ir_remote* remote)
{
if ((remote->flags & IR_PROTOCOL_MASK) == SERIAL)
return 1;
else
return 0;
}
static inline int is_xmp(const struct ir_remote* remote)
{
if ((remote->flags & IR_PROTOCOL_MASK) == XMP)
return 1;
else
return 0;
}
static inline int is_const(const struct ir_remote* remote)
{
if (remote->flags & CONST_LENGTH)
return 1;
else
return 0;
}
static inline int has_repeat_gap(const struct ir_remote* remote)
{
if (remote->repeat_gap > 0)
return 1;
else
return 0;
}
static inline int has_pre(const struct ir_remote* remote)
{
if (remote->pre_data_bits > 0)
return 1;
else
return 0;
}
static inline int has_post(const struct ir_remote* remote)
{
if (remote->post_data_bits > 0)
return 1;
else
return 0;
}
static inline int has_header(const struct ir_remote* remote)
{
if (remote->phead > 0 && remote->shead > 0)
return 1;
else
return 0;
}
static inline int has_foot(const struct ir_remote* remote)
{
if (remote->pfoot > 0 && remote->sfoot > 0)
return 1;
else
return 0;
}
static inline int has_toggle_bit_mask(const struct ir_remote* remote)
{
if (remote->toggle_bit_mask > 0)
return 1;
else
return 0;
}
static inline int has_ignore_mask(const struct ir_remote* remote)
{
if (remote->ignore_mask > 0)
return 1;
else
return 0;
}
static inline int has_repeat_mask(struct ir_remote* remote)
{
if (remote->repeat_mask > 0)
return 1;
else
return 0;
}
static inline int has_toggle_mask(const struct ir_remote* remote)
{
if (remote->toggle_mask > 0)
return 1;
else
return 0;
}
static inline lirc_t min_gap(const struct ir_remote* remote)
{
if (remote->gap2 != 0 && remote->gap2 < remote->gap)
return remote->gap2;
else
return remote->gap;
}
static inline lirc_t max_gap(const struct ir_remote* remote)
{
if (remote->gap2 > remote->gap)
return remote->gap2;
else
return remote->gap;
}
/* check if delta is inside exdelta +/- exdelta*eps/100 */
static inline int expect(const struct ir_remote* remote,
lirc_t delta,
lirc_t exdelta)
{
int aeps = curr_driver->resolution > remote->aeps ?
curr_driver->resolution : remote->aeps;
if (abs(exdelta - delta) <= exdelta * remote->eps / 100
|| abs(exdelta - delta) <= aeps)
return 1;
return 0;
}
static inline int expect_at_least(const struct ir_remote* remote,
lirc_t delta,
lirc_t exdelta)
{
int aeps = curr_driver->resolution > remote->aeps ?
curr_driver->resolution : remote->aeps;
if (delta + exdelta * remote->eps / 100 >= exdelta
|| delta + aeps >= exdelta)
return 1;
return 0;
}
static inline int expect_at_most(const struct ir_remote* remote,
lirc_t delta,
lirc_t exdelta)
{
int aeps = curr_driver->resolution > remote->aeps ?
curr_driver->resolution : remote->aeps;
if (delta <= exdelta + exdelta * remote->eps / 100
|| delta <= exdelta + aeps)
return 1;
return 0;
}
static inline lirc_t upper_limit(const struct ir_remote* remote, lirc_t val)
{
int aeps = curr_driver->resolution > remote->aeps ?
curr_driver->resolution : remote->aeps;
lirc_t eps_val = val * (100 + remote->eps) / 100;
lirc_t aeps_val = val + aeps;
return eps_val > aeps_val ? eps_val : aeps_val;
}
static inline lirc_t lower_limit(const struct ir_remote* remote, lirc_t val)
{
int aeps = curr_driver->resolution > remote->aeps ?
curr_driver->resolution : remote->aeps;
lirc_t eps_val = val * (100 - remote->eps) / 100;
lirc_t aeps_val = val - aeps;
if (eps_val <= 0)
eps_val = 1;
if (aeps_val <= 0)
aeps_val = 1;
return eps_val < aeps_val ? eps_val : aeps_val;
}
/* only works if last <= current */
static inline unsigned long time_elapsed(const struct timeval* last,
const struct timeval* current)
{
unsigned long secs, diff;
secs = current->tv_sec - last->tv_sec;
diff = 1000000 * secs + current->tv_usec - last->tv_usec;
return diff;
}
static inline ir_code gen_mask(int bits)
{
int i;
ir_code mask;
mask = 0;
for (i = 0; i < bits; i++) {
mask <<= 1;
mask |= 1;
}
return mask;
}
static inline ir_code gen_ir_code(const struct ir_remote* remote,
ir_code pre,
ir_code code,
ir_code post)
{
ir_code all;
all = (pre & gen_mask(remote->pre_data_bits));
all <<= remote->bits;
all |= is_raw(remote) ? code : (code & gen_mask(remote->bits));
all <<= remote->post_data_bits;
all |= post & gen_mask(remote->post_data_bits);
return all;
}
const struct ir_remote* is_in_remotes(const struct ir_remote* remotes,
const struct ir_remote* remote);
struct ir_remote* get_ir_remote(const struct ir_remote* remotes,
const char* name);
void get_frequency_range(const struct ir_remote* remotes,
unsigned int* min_freq,
unsigned int* max_freq);
void get_filter_parameters(const struct ir_remote* remotes,
lirc_t* max_gap_lengthp,
lirc_t* min_pulse_lengthp,
lirc_t* min_space_lengthp,
lirc_t* max_pulse_lengthp,
lirc_t* max_space_lengthp);
int map_code(const struct ir_remote* remote,
struct decode_ctx_t* ctx,
int pre_bits,
ir_code pre,
int bits,
ir_code code,
int post_bits,
ir_code post);
void map_gap(const struct ir_remote* remote,
struct decode_ctx_t* ctx,
const struct timeval* start,
const struct timeval* last,
lirc_t signal_length);
struct ir_ncode* get_code_by_name(const struct ir_remote* remote,
const char* name);
int write_message(char* buffer,
size_t size,
const char* remote_name,
const char* button_name,
const char* button_suffix,
ir_code code,
int reps);
char* decode_all(struct ir_remote* remotes);
int send_ir_ncode(struct ir_remote* remote, struct ir_ncode* code, int delay);
#ifdef __cplusplus
}
#endif
void ir_remote_init(int use_dyncodes);
const struct ir_remote* get_decoding(void);
#endif
last_remote
struct ir_remote * last_remote
Definition: ir_remote.c:58
repeat_code
struct ir_ncode * repeat_code
Definition: ir_remote.c:62
ir_remote
Definition: ir_remote_types.h:167
ir_remote::bits
int bits
Definition: ir_remote_types.h:171
RC6
#define RC6
Definition: ir_remote_types.h:123
ir_code_node
Definition: ir_remote_types.h:65
GOLDSTAR
#define GOLDSTAR
Definition: ir_remote_types.h:127
ir_remote_init
void ir_remote_init(int use_dyncodes)
Definition: ir_remote.c:123
curr_driver
const struct driver *const curr_driver
Definition: driver.c:28
ir_remote::repeat_mask
ir_code repeat_mask
Definition: ir_remote_types.h:234
get_filter_parameters
void get_filter_parameters(const struct ir_remote *remotes, lirc_t *max_gap_lengthp, lirc_t *min_pulse_lengthp, lirc_t *min_space_lengthp, lirc_t *max_pulse_lengthp, lirc_t *max_space_lengthp)
Definition: ir_remote.c:192
ir_ncode::next
struct ir_code_node * next
Definition: ir_remote_types.h:91
ir_remote::name
const char * name
Definition: ir_remote_types.h:168
SPACE_ENC
#define SPACE_ENC
Definition: ir_remote_types.h:125
get_code_by_name
struct ir_ncode * get_code_by_name(const struct ir_remote *remote, const char *name)
Definition: ir_remote.c:396
driver::resolution
unsigned int resolution
Definition: driver.h:225
driver.h
Interface to the userspace drivers.
ir_remote::eps
int eps
Definition: ir_remote_types.h:173
get_ir_remote
struct ir_remote * get_ir_remote(const struct ir_remote *remotes, const char *name)
Definition: ir_remote.c:250
ir_code
__u64 ir_code
Definition: ir_remote_types.h:59
map_code
int map_code(const struct ir_remote *remote, struct decode_ctx_t *ctx, int pre_bits, ir_code pre, int bits, ir_code code, int post_bits, ir_code post)
Definition: ir_remote.c:282
ir_remote::sfoot
lirc_t sfoot
Definition: ir_remote_types.h:193
decode_all
char * decode_all(struct ir_remote *remotes)
Definition: ir_remote.c:731
ir_remote::pre_data_bits
int pre_data_bits
Definition: ir_remote_types.h:196
ir_ncode::name
char * name
Definition: ir_remote_types.h:78
ir_remote::post_data_bits
int post_data_bits
Definition: ir_remote_types.h:198
RCMM
#define RCMM
Definition: ir_remote_types.h:124
ir_remote::toggle_mask
ir_code toggle_mask
Definition: ir_remote_types.h:222
ir_remote_types.h
Describes and decodes the signals from IR remotes.
write_message
int write_message(char *buffer, size_t size, const char *remote_name, const char *button_name, const char *button_suffix, ir_code code, int reps)
Definition: ir_remote.c:712
RC5
#define RC5
Definition: ir_remote_types.h:117
ir_remote::shead
lirc_t shead
Definition: ir_remote_types.h:186
is_in_remotes
const struct ir_remote * is_in_remotes(const struct ir_remote *remotes, const struct ir_remote *remote)
Definition: ir_remote.c:238
SPACE_FIRST
#define SPACE_FIRST
Definition: ir_remote_types.h:126
ir_remote::repeat_gap
__u32 repeat_gap
Definition: ir_remote_types.h:205
ir_remote::gap
__u32 gap
Definition: ir_remote_types.h:203
get_decoding
const struct ir_remote * get_decoding(void)
Definition: ir_remote.c:852
CONST_LENGTH
#define CONST_LENGTH
Definition: ir_remote_types.h:137
GRUNDIG
#define GRUNDIG
Definition: ir_remote_types.h:128
ncode_free
void ncode_free(struct ir_ncode *ncode)
Definition: ir_remote.c:103
ir_ncode
Definition: ir_remote_types.h:76
ir_remote::flags
int flags
Definition: ir_remote_types.h:172
ir_remote::aeps
unsigned int aeps
Definition: ir_remote_types.h:174
ir_remote::srepeat
lirc_t srepeat
Definition: ir_remote_types.h:194
decode_ctx_t
Definition: ir_remote_types.h:154
map_gap
void map_gap(const struct ir_remote *remote, struct decode_ctx_t *ctx, const struct timeval *start, const struct timeval *last, lirc_t signal_length)
Definition: ir_remote.c:328
SERIAL
#define SERIAL
Definition: ir_remote_types.h:130
ncode_dup
struct ir_ncode * ncode_dup(struct ir_ncode *ncode)
Definition: ir_remote.c:68
get_frequency_range
void get_frequency_range(const struct ir_remote *remotes, unsigned int *min_freq, unsigned int *max_freq)
Definition: ir_remote.c:155
BO
#define BO
Definition: ir_remote_types.h:129
ir_ncode::code
ir_code code
Definition: ir_remote_types.h:81
ir_remote::rc6_mask
ir_code rc6_mask
Definition: ir_remote_types.h:223
repeat_remote
struct ir_remote * repeat_remote
Definition: ir_remote.c:60
ir_remote::toggle_bit_mask
ir_code toggle_bit_mask
Definition: ir_remote_types.h:207
ir_remote::gap2
__u32 gap2
Definition: ir_remote_types.h:204
send_ir_ncode
int send_ir_ncode(struct ir_remote *remote, struct ir_ncode *code, int delay)
Definition: ir_remote.c:821
RAW_CODES
#define RAW_CODES
Definition: ir_remote_types.h:116
ir_remote::ignore_mask
ir_code ignore_mask
Definition: ir_remote_types.h:233
XMP
#define XMP
Definition: ir_remote_types.h:131