-
Notifications
You must be signed in to change notification settings - Fork 0
/
irtoy.h
82 lines (67 loc) · 1.99 KB
/
irtoy.h
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
/* IRToy and infrared definitions */
#ifndef __irtoy_h
#define __irtoy_h
#include <stdio.h>
#include <stdbool.h>
#include "dict.h"
typedef struct IRState IRState;
typedef struct IRPulse IRPulse;
typedef struct IRPacket IRPacket;
typedef struct IRSymbol IRSymbol;
typedef struct IRDict IRDict;
/* ------------------------------------------------------------
* IR Pulses and Packets
*/
struct IRPacket
{
IRPulse *pulses;
int n_pulses;
int n_pulses_allocated;
};
struct IRPulse
{
bool value;
unsigned short width;
};
extern IRPacket *new_irpacket (void);
extern void free_irpacket (IRPacket * k);
extern bool irpacket_complete (IRPacket * k);
extern void irpacket_pulse (IRPacket * k, IRPulse pulse);
extern void irpacket_printf (FILE * out, IRPacket * k);
extern void irpacket_render (FILE * out, IRPacket * k);
extern IRPacket *irpacket_scanf (FILE * in);
extern bool irpacket_match (IRPacket * a, IRPacket * b, int jitter);
extern IRDict *new_irdict (void);
extern IRPacket *irdict_lookup_name (IRDict * d, const char *name);
extern const char *irdict_lookup_packet (IRDict * d, IRPacket * k);
extern void irdict_insert (IRDict * d, const char *name, IRPacket * k);
extern IRState *new_irstate (void);
extern IRPacket *irstate_pulse (IRState * ir, unsigned short width);
extern IRPacket *irstate_timeout (IRState * ir);
extern int irstate_rxbytes (IRState * ir, int n_bytes, unsigned char *bytes,
IRPacket ** out_packets);
extern void irstate_open (IRState * ir, const char *dev);
extern int irtoy_gap; /* min gap between packets */
extern int irtoy_jitter; /* acceptable jitter */
struct IRState
{
bool value; /* current 0/1 state */
IRPacket *packet; /* packet under construction */
int last_width;
int fd;
unsigned char buf;
bool buf_valid;
bool timed_out;
};
struct IRSymbol
{
const char *name;
IRPacket *packet;
IRSymbol *next;
};
struct IRDict
{
IRSymbol *first;
Dict *by_name;
};
#endif /* __irtoy_h */