diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2020-02-22 07:09:37 +0100 |
---|---|---|
committer | Gerhard Sittig <gerhard.sittig@gmx.net> | 2020-07-18 15:28:29 +0200 |
commit | 53eb681dd5611931b6af949a8c50c22fc65661ac (patch) | |
tree | 9c0e63874c0c46cfbe7e3f0f3a065c5e76a9b2ab /irmp | |
parent | 7f8ea39e26770753a389ce1c7bac48c036a5e2e2 (diff) | |
download | libsigrokdecode-53eb681dd5611931b6af949a8c50c22fc65661ac.tar.gz libsigrokdecode-53eb681dd5611931b6af949a8c50c22fc65661ac.zip |
irmp: introduce PC side shared library code for IRMP core logic
Introduce sources which implement a shared object (DLL) which embeds the
IRMP core logic, receives pin values from an application, and makes IR
detection from previously captured data available in PC environments as
a library, in contrast to the text oriented desktop applications and the
MCU firmware which existed before in the upstream project.
Provided by: Rene Staffen
Diffstat (limited to 'irmp')
-rw-r--r-- | irmp/irmp-main-sharedlib.c | 105 | ||||
-rw-r--r-- | irmp/irmp-main-sharedlib.h | 91 |
2 files changed, 196 insertions, 0 deletions
diff --git a/irmp/irmp-main-sharedlib.c b/irmp/irmp-main-sharedlib.c new file mode 100644 index 0000000..824a05a --- /dev/null +++ b/irmp/irmp-main-sharedlib.c @@ -0,0 +1,105 @@ +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * irmpharedLib.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. + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ + + +#include "irmp.h" +#include "irmp.c" + + +#ifndef IRMP_DLLEXPORT + +#if defined WIN32 && defined _MSC_VER +# define IRMP_DLLEXPORT __declspec(dllexport) +#else +# define IRMP_DLLEXPORT +#endif +#endif // !IRMP_DLLEXPORT + +#include "irmp-main-sharedlib.h" + + + +static uint32_t s_endSample = 0; + +uint32_t IRMP_GetSampleRate(void) { + return F_INTERRUPTS; +} + + +void IRMP_Reset(void) { + IRMP_PIN = 0xff; + IRMP_DATA data; + int i; + for (i = 0; i < (int)(( F_INTERRUPTS )); i++) // long pause of 1s + { + (void)irmp_ISR(); + } + (void)irmp_get_data(&data); + time_counter = 0; + s_startBitSample = 0; + s_curSample = 0; + s_endSample = 0; +} + + +uint32_t IRMP_AddSample(const uint8_t i_sample) { + IRMP_PIN = i_sample; + uint_fast8_t r = irmp_ISR(); + if (r) { + s_endSample = s_curSample; + return 1; + } + s_curSample++; + return 0; +} + + +uint32_t IRMP_GetData(IRMP_DataExt* o_data) { + + IRMP_DATA d; + if (irmp_get_data(&d)) + { + o_data->address = d.address; + o_data->command = d.command; + o_data->protocol = d.protocol; + o_data->protocolName = IRMP_GetProtocolName(d.protocol); + o_data->flags = d.flags; + o_data->startSample = s_startBitSample; + o_data->endSample = s_endSample; + return TRUE; + } + return FALSE; +} + + +IRMP_DataExt IRMP_Detect(const uint8_t* i_buff, uint32_t i_len) { + IRMP_DataExt ret = { 0 }; + while (s_curSample < i_len) { + if (IRMP_AddSample(i_buff[s_curSample])) { + IRMP_GetData(&ret); + return ret; + } + } + return ret; +} + + +const char* IRMP_GetProtocolName(uint32_t i_protocol) { + if (i_protocol < IRMP_N_PROTOCOLS) { + return irmp_protocol_names[i_protocol]; + } + else { + return "unknown"; + } +} + diff --git a/irmp/irmp-main-sharedlib.h b/irmp/irmp-main-sharedlib.h new file mode 100644 index 0000000..27f8add --- /dev/null +++ b/irmp/irmp-main-sharedlib.h @@ -0,0 +1,91 @@ +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * irmpharedLib.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_SHARED_H +#define IRMP_SHARED_H + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef IRMP_DLLEXPORT + +#if defined WIN32 && defined _MSC_VER +# define IRMP_DLLEXPORT __declspec(dllimport) +#else +# define IRMP_DLLEXPORT +#endif +#endif // !IRMP_DLLEXPORT + + +/** + * result data + */ +typedef struct +{ + uint32_t protocol; ///< protocol, e.g. NEC_PROTOCOL + const char* protocolName; ///< name of the protocol + uint32_t address; ///< address + uint32_t command; ///< command + uint32_t flags; ///< flags currently only repetition (bit 0) + uint32_t startSample; ///< the sampleindex there the detected command started + uint32_t endSample; ///< the sampleindex there the detected command ended +} IRMP_DataExt; + + +/** + * Returns the sample rate for that the irmp library was compiled for. + * Any data provided has resamble this sample rate or detection will fail. + */ +IRMP_DLLEXPORT uint32_t IRMP_GetSampleRate(void); + +/** + * Resets the internal state of the detector + * This has to be called before start processing data. + */ +IRMP_DLLEXPORT void IRMP_Reset(void); + +/** + * Feeds a single sample into the detecor. + * Returns 1 if a ir command was detected. + * Use IRMP_GetData to retrieve the data. + * Make sure, that Reset was called before adding first Sample. + */ +IRMP_DLLEXPORT uint32_t IRMP_AddSample(const uint8_t i_sample); + + +/** + * Proceses the given buffer and stops on the first found command and returns it data. + * Further calls resume the processing at the previously stopped position. + * Make sure, that Reset was called before first calling Detect. + */ +IRMP_DLLEXPORT IRMP_DataExt IRMP_Detect(const uint8_t* i_buff, uint32_t i_len); + + +/** + * If a valid IR frame was detected the provided output structure is filled + * \returns 1 if data was available, 0 else + */ +IRMP_DLLEXPORT uint32_t IRMP_GetData(IRMP_DataExt* o_data); + +/** returns the the name of the given protocol number */ +IRMP_DLLEXPORT const char* IRMP_GetProtocolName(uint32_t i_protocol); + + +#ifdef __cplusplus +} +#endif + +#endif // IRMP_SHARED_H |