102 # define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) 105 static int irmp_lib_initialized;
106 static size_t irmp_lib_client_id;
107 static GMutex irmp_lib_mutex;
109 struct irmp_instance {
114 static void irmp_lib_autoinit(
void)
116 if (irmp_lib_initialized)
119 irmp_lib_client_id = 0;
120 g_mutex_init(&irmp_lib_mutex);
122 irmp_lib_initialized = 1;
125 static size_t irmp_next_client_id(
void)
130 id = ++irmp_lib_client_id;
138 struct irmp_instance *inst;
142 inst = g_malloc0(
sizeof(*inst));
146 inst->client_id = irmp_next_client_id();
147 inst->mutex = &irmp_lib_mutex;
168 return state ? state->client_id : 0;
174 PyGILState_STATE pyst;
178 if (!state || !state->mutex)
181 pyst = PyGILState_Ensure();
182 Py_BEGIN_ALLOW_THREADS
184 g_mutex_lock(state->mutex);
187 rc = g_mutex_trylock(state->mutex);
190 PyGILState_Release(pyst);
202 if (!state || !state->mutex)
205 g_mutex_unlock(state->mutex);
208 static uint32_t s_end_sample;
233 s_startBitSample = 0;
255 IRMP_PIN = sample ? 0xff : 0x00;
257 s_end_sample = s_curSample++;
278 #if WITH_IRMP_DETECT_BUFFER 283 memset(&ret, 0,
sizeof(ret));
284 while (s_curSample < len) {
298 if (protocol >=
ARRAY_SIZE(irmp_protocol_names))
300 name = irmp_protocol_names[
protocol];
306 static __attribute__((constructor))
void init(
void)
uint_fast8_t irmp_get_data(IRMP_DATA *irmp_data_p)
IRMP_DLLEXPORT const char * irmp_get_protocol_name(uint32_t protocol)
Resolve the protocol identifer to the protocol's name.
uint32_t command
!< address
IR decoder result data at the library's public API.
IRMP_DLLEXPORT void irmp_instance_free(struct irmp_instance *state)
Release a decoder instance.
uint32_t address
!< name of the protocol
uint32_t start_sample
!< flags currently only repetition (bit 0)
IRMP_DLLEXPORT int irmp_instance_lock(struct irmp_instance *state, int wait)
Acquire a decoder instance's lock.
IRMP_DLLEXPORT int irmp_add_one_sample(int sample)
Feed an individual sample to the detector.
uint_fast8_t irmp_ISR(void)
uint32_t end_sample
!< the sampleindex there the detected command started
IRMP_DLLEXPORT uint32_t irmp_get_sample_rate(void)
Query the IRMP library's configured sample rate.
IRMP_DLLEXPORT size_t irmp_instance_id(struct irmp_instance *state)
Get the client ID of an IRMP decoder core instance.
IRMP_DLLEXPORT struct irmp_instance * irmp_instance_alloc(void)
Allocate a decoder instance.
IRMP_DLLEXPORT void irmp_reset_state(void)
Reset internal decoder state.
const char * protocol_name
!< protocol, e.g.
IRMP_DLLEXPORT int irmp_get_result_data(struct irmp_result_data *data)
Query result data after detection succeeded.
IRMP_DLLEXPORT void irmp_instance_unlock(struct irmp_instance *state)
Release a decoder instance's lock.