summaryrefslogtreecommitdiff
path: root/irmp/irmp-main-sharedlib.h
blob: 94065f383c3ae41453e981b9836d9e1dd5b01f17 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * irmp-main-sharedlib.h
 *
 * Copyright (c) 2009-2019 Frank Meyer - frank(at)fli4l.de
 * Copyright (c) 2009-2019 René Staffen - r.staffen(at)gmx.de
 *
 * 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.
 */

#ifndef IRMP_SHAREDLIB_H
#define IRMP_SHAREDLIB_H

#include <stdint.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif

/* Export the public API routines. */
#ifndef IRMP_DLLEXPORT
#  if defined WIN32 && defined _MSC_VER
#    define IRMP_DLLEXPORT __declspec(dllexport)
#  else
#    define IRMP_DLLEXPORT __attribute__((visibility("default")))
#  endif
#endif

/* Part of the library API is optional. */
#define WITH_IRMP_DETECT_BUFFER 0

/**
 * @brief IR decoder result data at the library's public API.
 */
struct irmp_result_data {
	uint32_t protocol;	/**!< protocol, e.g. NEC_PROTOCOL */
	const char *protocol_name;	/**!< name of the protocol */
	uint32_t address;	/**!< address */
	uint32_t command;	/**!< command */
	uint32_t flags;		/**!< flags currently only repetition (bit 0) */
	uint32_t start_sample;	/**!< the sampleindex there the detected command started */
	uint32_t end_sample;	/**!< the sampleindex there the detected command ended */
};

#define IRMP_DATA_FLAG_REPETITION	(1 << 0)
#define IRMP_DATA_FLAG_RELEASE		(1 << 1)

/**
 * @brief Query the IRMP library's configured sample rate.
 *
 * The internally used sample rate is a compile time option. Any data
 * that is provided at runtime needs to match this rate, or detection
 * will fail.
 */
IRMP_DLLEXPORT uint32_t irmp_get_sample_rate(void);

/**
 * @brief Reset internal decoder state.
 *
 * This must be called before data processing starts.
 */
IRMP_DLLEXPORT void irmp_reset_state(void);

/**
 * @brief Feed an individual sample to the detector.
 *
 * See @ref irmp_get_result_data() for result retrieval when detection
 * of an IR frame completes. Make sure @ref irmp_reset_state() was
 * called before providing the first sample.
 *
 * @param[in] sample The pin value to feed to the detector.
 *
 * @returns Non-zero when an IR frame was detected.
 */
IRMP_DLLEXPORT int irmp_add_one_sample(int sample);

#if WITH_IRMP_DETECT_BUFFER
/**
 * @brief Process the given buffer until an IR frame is found.
 *
 * Stops at the first detected IR frame, and returns its data. Subsequent
 * calls resume processing at the previously stopped position. Make sure
 * @ref irmp_reset_state() was called before the first detect call.
 *
 * @param[in] buf Pointer to the data buffer.
 * @param[in] len Number of samples in the Buffer.
 */
IRMP_DLLEXPORT struct irmp_result_data irmp_detect_buffer(const uint8_t *buf, size_t len);
#endif

/**
 * @brief Query result data after detection succeeded.
 *
 * @param[out] data The caller provided result buffer.
 *
 * @returns Non-zero if data was available, zero otherwise.
 */
IRMP_DLLEXPORT int irmp_get_result_data(struct irmp_result_data *data);

/**
 * @brief Resolve the protocol identifer to the protocol's name.
 *
 * @param[in] protocol The numerical identifier.
 *
 * @returns A pointer to the string literal, or #NULL in case of failure.
 */
IRMP_DLLEXPORT const char *irmp_get_protocol_name(uint32_t protocol);

#ifdef __cplusplus
}
#endif

#endif