]> sigrok.org Git - libsigrokdecode.git/blob - irmp/irmp-main-sharedlib.c
irmp: introduce PC side shared library code for IRMP core logic
[libsigrokdecode.git] / irmp / irmp-main-sharedlib.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2  * irmpharedLib.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
14
15 #include "irmp.h"
16 #include "irmp.c"
17
18
19 #ifndef IRMP_DLLEXPORT
20
21 #if defined WIN32 && defined _MSC_VER
22 # define IRMP_DLLEXPORT __declspec(dllexport)
23 #else
24 # define IRMP_DLLEXPORT
25 #endif
26 #endif // !IRMP_DLLEXPORT
27
28 #include "irmp-main-sharedlib.h"
29
30
31
32 static uint32_t s_endSample = 0;
33
34 uint32_t IRMP_GetSampleRate(void) {
35     return F_INTERRUPTS;
36 }
37
38
39 void IRMP_Reset(void) {
40     IRMP_PIN = 0xff;
41     IRMP_DATA data;
42     int i;
43     for (i = 0; i < (int)(( F_INTERRUPTS )); i++)  // long pause of 1s
44     {
45         (void)irmp_ISR();
46     }
47     (void)irmp_get_data(&data);
48     time_counter = 0;
49     s_startBitSample = 0;
50     s_curSample = 0;
51     s_endSample = 0;
52 }
53
54
55 uint32_t IRMP_AddSample(const uint8_t i_sample) {
56     IRMP_PIN = i_sample;
57     uint_fast8_t r = irmp_ISR();
58     if (r) {
59         s_endSample = s_curSample;
60         return 1;
61     }
62     s_curSample++;
63     return 0;
64 }
65
66
67 uint32_t IRMP_GetData(IRMP_DataExt* o_data) {
68
69     IRMP_DATA d;
70     if (irmp_get_data(&d))
71     {  
72         o_data->address      = d.address;
73         o_data->command      = d.command;
74         o_data->protocol     = d.protocol;
75         o_data->protocolName = IRMP_GetProtocolName(d.protocol);
76         o_data->flags        = d.flags;
77         o_data->startSample  = s_startBitSample;
78         o_data->endSample    = s_endSample;
79         return TRUE;
80     }
81     return FALSE;
82 }
83
84
85 IRMP_DataExt IRMP_Detect(const uint8_t* i_buff, uint32_t i_len) {
86     IRMP_DataExt ret = { 0 };
87     while (s_curSample < i_len) {
88         if (IRMP_AddSample(i_buff[s_curSample])) {
89             IRMP_GetData(&ret);
90             return ret;
91         }
92     }
93     return ret;
94 }
95
96
97 const char* IRMP_GetProtocolName(uint32_t i_protocol) {
98     if (i_protocol < IRMP_N_PROTOCOLS) {
99         return irmp_protocol_names[i_protocol];
100     }
101     else {
102         return "unknown";
103     }
104 }
105