]> sigrok.org Git - libsigrokdecode.git/blob - irmp/irmp-main-sharedlib.h
94065f383c3ae41453e981b9836d9e1dd5b01f17
[libsigrokdecode.git] / irmp / irmp-main-sharedlib.h
1 /*
2  * irmp-main-sharedlib.h
3  *
4  * Copyright (c) 2009-2019 Frank Meyer - frank(at)fli4l.de
5  * Copyright (c) 2009-2019 RenĂ© Staffen - r.staffen(at)gmx.de
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  */
12
13 #ifndef IRMP_SHAREDLIB_H
14 #define IRMP_SHAREDLIB_H
15
16 #include <stdint.h>
17 #include <stdlib.h>
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 /* Export the public API routines. */
24 #ifndef IRMP_DLLEXPORT
25 #  if defined WIN32 && defined _MSC_VER
26 #    define IRMP_DLLEXPORT __declspec(dllexport)
27 #  else
28 #    define IRMP_DLLEXPORT __attribute__((visibility("default")))
29 #  endif
30 #endif
31
32 /* Part of the library API is optional. */
33 #define WITH_IRMP_DETECT_BUFFER 0
34
35 /**
36  * @brief IR decoder result data at the library's public API.
37  */
38 struct irmp_result_data {
39         uint32_t protocol;      /**!< protocol, e.g. NEC_PROTOCOL */
40         const char *protocol_name;      /**!< name of the protocol */
41         uint32_t address;       /**!< address */
42         uint32_t command;       /**!< command */
43         uint32_t flags;         /**!< flags currently only repetition (bit 0) */
44         uint32_t start_sample;  /**!< the sampleindex there the detected command started */
45         uint32_t end_sample;    /**!< the sampleindex there the detected command ended */
46 };
47
48 #define IRMP_DATA_FLAG_REPETITION       (1 << 0)
49 #define IRMP_DATA_FLAG_RELEASE          (1 << 1)
50
51 /**
52  * @brief Query the IRMP library's configured sample rate.
53  *
54  * The internally used sample rate is a compile time option. Any data
55  * that is provided at runtime needs to match this rate, or detection
56  * will fail.
57  */
58 IRMP_DLLEXPORT uint32_t irmp_get_sample_rate(void);
59
60 /**
61  * @brief Reset internal decoder state.
62  *
63  * This must be called before data processing starts.
64  */
65 IRMP_DLLEXPORT void irmp_reset_state(void);
66
67 /**
68  * @brief Feed an individual sample to the detector.
69  *
70  * See @ref irmp_get_result_data() for result retrieval when detection
71  * of an IR frame completes. Make sure @ref irmp_reset_state() was
72  * called before providing the first sample.
73  *
74  * @param[in] sample The pin value to feed to the detector.
75  *
76  * @returns Non-zero when an IR frame was detected.
77  */
78 IRMP_DLLEXPORT int irmp_add_one_sample(int sample);
79
80 #if WITH_IRMP_DETECT_BUFFER
81 /**
82  * @brief Process the given buffer until an IR frame is found.
83  *
84  * Stops at the first detected IR frame, and returns its data. Subsequent
85  * calls resume processing at the previously stopped position. Make sure
86  * @ref irmp_reset_state() was called before the first detect call.
87  *
88  * @param[in] buf Pointer to the data buffer.
89  * @param[in] len Number of samples in the Buffer.
90  */
91 IRMP_DLLEXPORT struct irmp_result_data irmp_detect_buffer(const uint8_t *buf, size_t len);
92 #endif
93
94 /**
95  * @brief Query result data after detection succeeded.
96  *
97  * @param[out] data The caller provided result buffer.
98  *
99  * @returns Non-zero if data was available, zero otherwise.
100  */
101 IRMP_DLLEXPORT int irmp_get_result_data(struct irmp_result_data *data);
102
103 /**
104  * @brief Resolve the protocol identifer to the protocol's name.
105  *
106  * @param[in] protocol The numerical identifier.
107  *
108  * @returns A pointer to the string literal, or #NULL in case of failure.
109  */
110 IRMP_DLLEXPORT const char *irmp_get_protocol_name(uint32_t protocol);
111
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #endif