Subversion Repositories HomeAutomation

Rev

Rev 608 | Rev 617 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 608 Rev 610
Line -... Line 1...
-
 
1
/**
-
 
2
 * IR receiver and transmitter protocols.
-
 
3
 *
-
 
4
 * @date    2006-12-10
-
 
5
 *
-
 
6
 * @author  Anders Runeson, Andreas Fritiofson
-
 
7
 *  
-
 
8
 */
-
 
9
 
1
#include "protocols.h"
10
#include "protocols.h"
2
#include <avr/io.h>
-
 
-
 
11
 
3
int8_t parseProtocol(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
12
int8_t parseProtocol(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
-
 
13
    proto->protocol=IR_PROTO_UNKNOWN;
-
 
14
    proto->data=0;
-
 
15
    proto->timeout=100;
4
    /* Try all protocols in order. */
16
    /* Try all protocols in order. */
5
#if (IR_PROTOCOLS_USE_SIRC)
17
#if (IR_PROTOCOLS_USE_SIRC)
6
    if (parseSIRC(buf, len, proto)) return IR_OK;
18
    if (parseSIRC(buf, len, proto)==IR_OK) return IR_OK;
7
#endif
19
#endif
8
#if (IR_PROTOCOLS_USE_RC5)
20
#if (IR_PROTOCOLS_USE_RC5)
9
    if (parseRC5(buf, len, proto)) return IR_OK;
21
    if (parseRC5(buf, len, proto)==IR_OK) return IR_OK;
10
#endif
22
#endif
11
#if (IR_PROTOCOLS_USE_SHARP)
23
#if (IR_PROTOCOLS_USE_SHARP)
12
    if (parseSharp(buf, len, proto)) return IR_OK;
24
    if (parseSharp(buf, len, proto)==IR_OK) return IR_OK;
13
#endif
25
#endif
14
#if (IR_PROTOCOLS_USE_NEC)
26
#if (IR_PROTOCOLS_USE_NEC)
15
    if (parseNEC(buf, len, proto)) return IR_OK;
27
    if (parseNEC(buf, len, proto)==IR_OK) return IR_OK;
16
#endif
28
#endif
17
#if (IR_PROTOCOLS_USE_SAMSUNG)
29
#if (IR_PROTOCOLS_USE_SAMSUNG)
18
    if (parseSamsung(buf, len, proto)) return IR_OK;
30
    if (parseSamsung(buf, len, proto)==IR_OK) return IR_OK;
19
#endif
31
#endif
20
    /* No protocol matched. */
32
    /* No protocol matched. */
-
 
33
    proto->protocol = IR_PROTO_UNKNOWN;
21
    return IR_NOT_CORRECT_DATA;
34
    return IR_NOT_CORRECT_DATA;
22
}
35
}
23
 
36
 
24
int8_t parseHash(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
37
int8_t parseHash(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
25
    //TODO: Transform the buffer in some clever way to a 32 bit word. */
38
    //TODO: Transform the buffer in some clever way to a 32 bit word. */
26
    proto->protocol = IR_PROTO_HASH;
39
    proto->protocol = IR_PROTO_HASH;
27
    proto->timeout = 0;
40
    proto->timeout = 200;
28
    proto->data = 0;
41
    proto->data = 0;
29
   
42
   
30
    return 0;
43
    return 0;
31
}
44
}
32
 
45
 
Line 51... Line 64...
51
#if (IR_PROTOCOLS_USE_SIRC)
64
#if (IR_PROTOCOLS_USE_SIRC)
52
/**
65
/**
53
 * Test data on SIRC protocol, 12-bit version
66
 * Test data on SIRC protocol, 12-bit version
54
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
67
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
55
 *
68
 *
56
 * @param address
69
 * @param buf
57
 *      Pointer to store the address of the received data
70
 *      Pointer to buffer to where to data to parse is stored
58
 * @param command
71
 * @param len
-
 
72
 *      Length of the data
-
 
73
 * @param proto
59
 *      Pointer to store the command of the received data
74
 *      Pointer to protocol information
60
 * @return
75
 * @return
61
 *      IR_OK if data parsed successfully, one of several errormessages if not
76
 *      IR_OK if data parsed successfully, one of several errormessages if not
62
 */
77
 */
63
int8_t parseSIRC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
78
int8_t parseSIRC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
64
    /* parse buf[], max is len */
79
    /* parse buf[], max is len */
Line 84... Line 99...
84
        } else {            /* if even, ir-bit */
99
        } else {            /* if even, ir-bit */
85
            if (buf[i] > IR_SIRC_HIGH_ONE - IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ONE + IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV) {
100
            if (buf[i] > IR_SIRC_HIGH_ONE - IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ONE + IR_SIRC_HIGH_ONE/IR_SIRC_TOL_DIV) {
86
                /* write a one */
101
                /* write a one */
87
                rawbits |= 1<<((i-2)>>1);
102
                rawbits |= 1<<((i-2)>>1);
88
            } else if (buf[i] > IR_SIRC_HIGH_ZERO - IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ZERO + IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV) {
103
            } else if (buf[i] > IR_SIRC_HIGH_ZERO - IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV && buf[i] < IR_SIRC_HIGH_ZERO + IR_SIRC_HIGH_ZERO/IR_SIRC_TOL_DIV) {
89
                /* do nothing, a zero is already in rawbits */
104
                /* do nothing, a zero is already in rawbits */
90
            } else {
105
            } else {
91
                return IR_NOT_CORRECT_DATA;
106
                return IR_NOT_CORRECT_DATA;
92
            }
107
            }
93
        }
108
        }
94
    }
109
    }
95
   
110
   
96
    proto->protocol = IR_PROTO_SIRC;
111
    proto->protocol = IR_PROTO_SIRC;
97
    proto->timeout = IR_SIRC_TIMEOUT;
112
    proto->timeout = IR_SIRC_TIMEOUT;
98
    proto->data = rawbits; //TODO: Should some other mapping be used?
113
    proto->data = rawbits;
99
   
114
   
100
    return IR_OK;
115
    return IR_OK;
101
}
116
}
102
#endif
117
#endif
103
 
118
 
-
 
119
/**
-
 
120
 * Expand data from SIRC protocol
-
 
121
 * http://www.sbprojects.com/knowledge/ir/sirc.htm
-
 
122
 *
-
 
123
 * @param buf
-
 
124
 *      Pointer to buffer to store the expanded data
-
 
125
 * @param len
-
 
126
 *      Pointer to length of the data
-
 
127
 * @param proto
-
 
128
 *      Pointer to protocol information
-
 
129
 * @return
-
 
130
 *      IR_OK if data expanded successfully, one of several errormessages if not
-
 
131
 */
104
int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
132
int8_t expandSIRC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
105
    //TODO: Implement this function.
133
    //TODO: Implement this function.
106
    return IR_NOT_CORRECT_DATA;
134
    return IR_NOT_CORRECT_DATA;
107
}
135
}
-
 
136
 
108
 
137
 
109
#if (IR_PROTOCOLS_USE_RC5)
138
#if (IR_PROTOCOLS_USE_RC5)
110
/**
139
/**
111
 * Test data on RC5 protocol
140
 * Test data on RC5 protocol
112
 * http://www.sbprojects.com/knowledge/ir/rc5.htm
141
 * http://www.sbprojects.com/knowledge/ir/rc5.htm
113
 *
142
 *
114
 * @param address
143
 * @param buf
115
 *      Pointer to store the address of the received data
144
 *      Pointer to buffer to where to data to parse is stored
116
 * @param command
145
 * @param len
-
 
146
 *      Length of the data
-
 
147
 * @param proto
117
 *      Pointer to store the command of the received data
148
 *      Pointer to protocol information
118
 * @return
149
 * @return
119
 *      IR_OK if data parsed successfully, one of several errormessages if not
150
 *      IR_OK if data parsed successfully, one of several errormessages if not
120
 */
151
 */
121
int8_t parseRC5(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
152
int8_t parseRC5(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
122
    uint8_t halfbitscnt = 1;
153
    uint8_t halfbitscnt = 1;
Line 149... Line 180...
149
   
180
   
150
    return IR_OK;
181
    return IR_OK;
151
}
182
}
152
#endif
183
#endif
153
 
184
 
-
 
185
/**
-
 
186
 * Expand data from RC5 protocol
-
 
187
 * http://www.sbprojects.com/knowledge/ir/rc5.htm
-
 
188
 *
-
 
189
 * @param buf
-
 
190
 *      Pointer to buffer to store the expanded data
-
 
191
 * @param len
-
 
192
 *      Pointer to length of the data
-
 
193
 * @param proto
-
 
194
 *      Pointer to protocol information
-
 
195
 * @return
-
 
196
 *      IR_OK if data expanded successfully, one of several errormessages if not
-
 
197
 */
154
int8_t expandRC5(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
198
int8_t expandRC5(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
155
    //TODO: Implement this function.
199
    //TODO: Implement this function.
156
    return IR_NOT_CORRECT_DATA;
200
    return IR_NOT_CORRECT_DATA;
157
}
201
}
-
 
202
 
158
 
203
 
159
#if (IR_PROTOCOLS_USE_SHARP)
204
#if (IR_PROTOCOLS_USE_SHARP)
160
/**
205
/**
161
 * Test data on SHARP protocol
206
 * Test data on SHARP protocol
162
 * http://www.sbprojects.com/knowledge/ir/sharp.htm
207
 * http://www.sbprojects.com/knowledge/ir/sharp.htm
163
 *
208
 *
164
 * @param address
209
 * @param buf
165
 *      Pointer to store the address of the received data
210
 *      Pointer to buffer to where to data to parse is stored
166
 * @param command
211
 * @param len
-
 
212
 *      Length of the data
-
 
213
 * @param proto
167
 *      Pointer to store the command of the received data
214
 *      Pointer to protocol information
168
 * @return
215
 * @return
169
 *      IR_OK if data parsed successfully, one of several errormessages if not
216
 *      IR_OK if data parsed successfully, one of several errormessages if not
170
 */
217
 */
171
int8_t parseSharp(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
218
int8_t parseSharp(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
172
    /* parse buf[], max is len */
219
    /* parse buf[], max is len */
173
 
220
 
174
    /* check if we have correct amount of data */
221
    /* check if we have correct amount of data */
175
    if (len != 31) {
222
    if (len != 31) {
176
        return IR_NOT_CORRECT_DATA;
223
        return IR_NOT_CORRECT_DATA;
177
    }
224
    }
178
   
225
   
179
    uint16_t rawbits=0;
226
    uint16_t rawbits=0;
180
   
227
   
181
    for (uint8_t i = 1; i < len; i++) {
228
    for (uint8_t i = 1; i < len; i++) {
182
        if ((i&1) == 1) {       /* if odd, ir-pause */
229
        if ((i&1) == 1) {       /* if odd, ir-pause */
183
            /* check length of pause between bits */
230
            /* check length of pause between bits */
Line 189... Line 236...
189
            } else {
236
            } else {
190
                return IR_NOT_CORRECT_DATA;
237
                return IR_NOT_CORRECT_DATA;
191
            }
238
            }
192
        } else {            /* if even, ir-bit */
239
        } else {            /* if even, ir-bit */
193
            if (buf[i] > IR_SHARP_HIGH + IR_SHARP_HIGH/IR_SHARP_TOL_DIV || buf[i] < IR_SHARP_HIGH - IR_SHARP_HIGH/IR_SHARP_TOL_DIV) {
240
            if (buf[i] > IR_SHARP_HIGH + IR_SHARP_HIGH/IR_SHARP_TOL_DIV || buf[i] < IR_SHARP_HIGH - IR_SHARP_HIGH/IR_SHARP_TOL_DIV) {
194
                return IR_NOT_CORRECT_DATA;
241
                return IR_NOT_CORRECT_DATA;
195
            }
242
            }
196
        }
243
        }
197
    }
244
    }
198
   
245
   
199
    proto->protocol=IR_PROTO_SHARP;
246
    proto->protocol=IR_PROTO_SHARP;
200
    proto->timeout=IR_SHARP_TIMEOUT;
247
    proto->timeout=IR_SHARP_TIMEOUT;
201
    proto->data=rawbits;
248
    proto->data=rawbits;
202
    return IR_OK;
249
    return IR_OK;
203
}
250
}
204
#endif
251
#endif
205
 
252
 
-
 
253
/**
-
 
254
 * Expand data from Sharp protocol
-
 
255
 * http://www.sbprojects.com/knowledge/ir/sharp.htm
-
 
256
 *
-
 
257
 * @param buf
-
 
258
 *      Pointer to buffer to store the expanded data
-
 
259
 * @param len
-
 
260
 *      Pointer to length of the data
-
 
261
 * @param proto
-
 
262
 *      Pointer to protocol information
-
 
263
 * @return
-
 
264
 *      IR_OK if data expanded successfully, one of several errormessages if not
-
 
265
 */
206
int8_t expandSharp(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
266
int8_t expandSharp(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
207
    //TODO: Implement this function.
267
    //TODO: Implement this function.
208
    return IR_NOT_CORRECT_DATA;
268
    return IR_NOT_CORRECT_DATA;
209
}
269
}
-
 
270
 
210
 
271
 
211
#if (IR_PROTOCOLS_USE_NEC)
272
#if (IR_PROTOCOLS_USE_NEC)
212
/**
273
/**
213
 * Test data on NEC protocol
274
 * Test data on NEC protocol
214
 * http://www.sbprojects.com/knowledge/ir/nec.htm
275
 * http://www.sbprojects.com/knowledge/ir/nec.htm
215
 *
276
 *
216
 * @param address
277
 * @param buf
217
 *      Pointer to store the address of the received data
278
 *      Pointer to buffer to where to data to parse is stored
218
 * @param command
279
 * @param len
-
 
280
 *      Length of the data
-
 
281
 * @param proto
219
 *      Pointer to store the command of the received data
282
 *      Pointer to protocol information
220
 * @return
283
 * @return
221
 *      IR_OK if data parsed successfully, one of several errormessages if not
284
 *      IR_OK if data parsed successfully, one of several errormessages if not
222
 */
285
 */
223
int8_t parseNEC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
286
int8_t parseNEC(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
224
    /* parse buf[], max is len */
287
    /* parse buf[], max is len */
225
 
288
 
226
    /* check if we have correct amount of data */
289
    /* check if we have correct amount of data */
Line 236... Line 299...
236
    /* check pause after startbit */
299
    /* check pause after startbit */
237
    if (buf[1] > IR_NEC_ST_PAUSE + IR_NEC_ST_PAUSE/IR_NEC_TOL_DIV || buf[1] < IR_NEC_ST_PAUSE - IR_NEC_ST_PAUSE/IR_NEC_TOL_DIV) {
300
    if (buf[1] > IR_NEC_ST_PAUSE + IR_NEC_ST_PAUSE/IR_NEC_TOL_DIV || buf[1] < IR_NEC_ST_PAUSE - IR_NEC_ST_PAUSE/IR_NEC_TOL_DIV) {
238
        return IR_NOT_CORRECT_DATA;
301
        return IR_NOT_CORRECT_DATA;
239
    }
302
    }
240
 
303
 
241
    uint32_t tmpdata = 0;
304
    uint32_t rawbits = 0;
242
 
305
 
243
    for (uint8_t i = 3; i < len; i++) {
306
    for (uint8_t i = 3; i < len; i++) {
244
        if ((i&1) == 1) {       /* if odd, ir-pause */
307
        if ((i&1) == 1) {       /* if odd, ir-pause */
245
            /* check length of pause between bits */
308
            /* check length of pause between bits */
246
            if (buf[i] > IR_NEC_LOW_ONE - IR_NEC_LOW_ONE/IR_NEC_TOL_DIV && buf[i] < IR_NEC_LOW_ONE + IR_NEC_LOW_ONE/IR_NEC_TOL_DIV) {
309
            if (buf[i] > IR_NEC_LOW_ONE - IR_NEC_LOW_ONE/IR_NEC_TOL_DIV && buf[i] < IR_NEC_LOW_ONE + IR_NEC_LOW_ONE/IR_NEC_TOL_DIV) {
247
                /* write a one */
310
                /* write a one */
248
                tmpdata |= 1UL<<((i-3)>>1);
311
                rawbits |= 1UL<<((i-3)>>1);
249
            } else if (buf[i] > IR_NEC_LOW_ZERO - IR_NEC_LOW_ZERO/IR_NEC_TOL_DIV && buf[i] < IR_NEC_LOW_ZERO + IR_NEC_LOW_ZERO/IR_NEC_TOL_DIV) {
312
            } else if (buf[i] > IR_NEC_LOW_ZERO - IR_NEC_LOW_ZERO/IR_NEC_TOL_DIV && buf[i] < IR_NEC_LOW_ZERO + IR_NEC_LOW_ZERO/IR_NEC_TOL_DIV) {
250
                /* do nothing, a zero is already in place */
313
                /* do nothing, a zero is already in place */
251
            } else {
314
            } else {
252
                return IR_NOT_CORRECT_DATA;
315
                return IR_NOT_CORRECT_DATA;
253
            }
316
            }
254
        } else {            /* if even, ir-bit */
317
        } else {            /* if even, ir-bit */
255
            if (buf[i] > IR_NEC_HIGH + IR_NEC_HIGH/IR_NEC_TOL_DIV || buf[i] < IR_NEC_HIGH - IR_NEC_HIGH/IR_NEC_TOL_DIV) {
318
            if (buf[i] > IR_NEC_HIGH + IR_NEC_HIGH/IR_NEC_TOL_DIV || buf[i] < IR_NEC_HIGH - IR_NEC_HIGH/IR_NEC_TOL_DIV) {
256
                return IR_NOT_CORRECT_DATA;
319
                return IR_NOT_CORRECT_DATA;
257
            }
320
            }
258
        }
321
        }
259
    }
322
    }
260
 
323
 
261
    proto->protocol=IR_PROTO_NEC;
324
    proto->protocol=IR_PROTO_NEC;
262
    proto->timeout=IR_NEC_TIMEOUT;
325
    proto->timeout=IR_NEC_TIMEOUT;
263
    proto->data=tmpdata;   
326
    proto->data=rawbits;   
264
    return IR_OK;
327
    return IR_OK;
265
}
328
}
266
#endif
329
#endif
267
 
330
 
-
 
331
/**
-
 
332
 * Expand data from NEC protocol
-
 
333
 * http://www.sbprojects.com/knowledge/ir/nec.htm
-
 
334
 *
-
 
335
 * @param buf
-
 
336
 *      Pointer to buffer to store the expanded data
-
 
337
 * @param len
-
 
338
 *      Pointer to length of the data
-
 
339
 * @param proto
-
 
340
 *      Pointer to protocol information
-
 
341
 * @return
-
 
342
 *      IR_OK if data expanded successfully, one of several errormessages if not
-
 
343
 */
268
int8_t expandNEC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
344
int8_t expandNEC(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
269
    /* Set up startbit */
345
    /* Set up startbit */
270
    buf[0] = IR_NEC_ST_BIT;
346
    buf[0] = IR_NEC_ST_BIT;
271
    buf[1] = IR_NEC_ST_PAUSE;
347
    buf[1] = IR_NEC_ST_PAUSE;
272
 
348
 
Line 286... Line 362...
286
    proto->modfreq=(((F_CPU/2000)/IR_NEC_F_MOD) -1);
362
    proto->modfreq=(((F_CPU/2000)/IR_NEC_F_MOD) -1);
287
    proto->timeout=IR_NEC_TIMEOUT;
363
    proto->timeout=IR_NEC_TIMEOUT;
288
    proto->repeats=IR_NEC_REPS;
364
    proto->repeats=IR_NEC_REPS;
289
    return IR_OK;
365
    return IR_OK;
290
}
366
}
-
 
367
 
291
 
368
 
292
#if (IR_PROTOCOLS_USE_SAMSUNG)
369
#if (IR_PROTOCOLS_USE_SAMSUNG)
293
/**
370
/**
294
 * Test data on Samsung protocol
371
 * Test data on Samsung protocol
295
 * Very much like NEC, different start bit/pause lengths etc.
372
 * Very much like NEC, different start bit/pause lengths etc.
296
 * http://www.sbprojects.com/knowledge/ir/nec.htm
373
 * http://www.sbprojects.com/knowledge/ir/nec.htm
297
 *
374
 *
298
 * @param address
375
 * @param buf
299
 *      Pointer to store the address of the received data
376
 *      Pointer to buffer to where to data to parse is stored
300
 * @param command
377
 * @param len
-
 
378
 *      Length of the data
-
 
379
 * @param proto
301
 *      Pointer to store the command of the received data
380
 *      Pointer to protocol information
302
 * @return
381
 * @return
303
 *      IR_OK if data parsed successfully, one of several errormessages if not
382
 *      IR_OK if data parsed successfully, one of several errormessages if not
304
 */
383
 */
305
int8_t parseSamsung(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
384
int8_t parseSamsung(const uint16_t *buf, uint8_t len, Ir_Protocol_Data_t *proto) {
306
    /* parse buf[], max is len */
385
    /* parse buf[], max is len */
307
 
386
 
308
    /* check if we have correct amount of data */
387
    /* check if we have correct amount of data */
309
    if (len != 67) {
388
    if (len != 67) {
310
        return IR_NOT_CORRECT_DATA;
389
        return IR_NOT_CORRECT_DATA;
311
    }
390
    }
312
   
391
   
313
    /* check startbit */
392
    /* check startbit */
314
    if (buf[0] > IR_SAMS_ST_BIT + IR_SAMS_ST_BIT/IR_SAMS_TOL_DIV || buf[0] < IR_SAMS_ST_BIT - IR_SAMS_ST_BIT/IR_SAMS_TOL_DIV) {
393
    if (buf[0] > IR_SAMS_ST_BIT + IR_SAMS_ST_BIT/IR_SAMS_TOL_DIV || buf[0] < IR_SAMS_ST_BIT - IR_SAMS_ST_BIT/IR_SAMS_TOL_DIV) {
315
        return IR_NOT_CORRECT_DATA;
-
 
316
    }
-
 
317
 
-
 
318
    /* check pause after startbit */
-
 
319
    if (buf[1] > IR_SAMS_ST_PAUSE + IR_SAMS_ST_PAUSE/IR_SAMS_TOL_DIV || buf[1] < IR_SAMS_ST_PAUSE - IR_SAMS_ST_PAUSE/IR_SAMS_TOL_DIV) {
-
 
320
        return IR_NOT_CORRECT_DATA;
394
        return IR_NOT_CORRECT_DATA;
321
    }
395
    }
322
 
396
 
-
 
397
    /* check pause after startbit */
-
 
398
    if (buf[1] > IR_SAMS_ST_PAUSE + IR_SAMS_ST_PAUSE/IR_SAMS_TOL_DIV || buf[1] < IR_SAMS_ST_PAUSE - IR_SAMS_ST_PAUSE/IR_SAMS_TOL_DIV) {
-
 
399
        return IR_NOT_CORRECT_DATA;
-
 
400
    }
-
 
401
 
323
    uint32_t tmpdata = 0;
402
    uint32_t rawbits = 0;
324
   
403
   
325
    for (uint8_t i = 3; i < len; i++) {
404
    for (uint8_t i = 3; i < len; i++) {
326
        if ((i&1) == 1) {       /* if odd, ir-pause */
405
        if ((i&1) == 1) {       /* if odd, ir-pause */
327
            /* check length of pause between bits */
406
            /* check length of pause between bits */
328
            if (buf[i] > IR_SAMS_LOW_ONE - IR_SAMS_LOW_ONE/IR_SAMS_TOL_DIV && buf[i] < IR_SAMS_LOW_ONE + IR_SAMS_LOW_ONE/IR_SAMS_TOL_DIV) {
407
            if (buf[i] > IR_SAMS_LOW_ONE - IR_SAMS_LOW_ONE/IR_SAMS_TOL_DIV && buf[i] < IR_SAMS_LOW_ONE + IR_SAMS_LOW_ONE/IR_SAMS_TOL_DIV) {
329
                /* write a one */
408
                /* write a one */
330
                tmpdata |= 1UL<<((i-3)>>1);
409
                rawbits |= 1UL<<((i-3)>>1);
331
            } else if (buf[i] > IR_SAMS_LOW_ZERO - IR_SAMS_LOW_ZERO/IR_SAMS_TOL_DIV && buf[i] < IR_SAMS_LOW_ZERO + IR_SAMS_LOW_ZERO/IR_SAMS_TOL_DIV) {
410
            } else if (buf[i] > IR_SAMS_LOW_ZERO - IR_SAMS_LOW_ZERO/IR_SAMS_TOL_DIV && buf[i] < IR_SAMS_LOW_ZERO + IR_SAMS_LOW_ZERO/IR_SAMS_TOL_DIV) {
332
                /* do nothing, a zero is already in rawbits */
411
                /* do nothing, a zero is already in rawbits */
333
            } else {
412
            } else {
334
                return IR_NOT_CORRECT_DATA;
413
                return IR_NOT_CORRECT_DATA;
335
            }
414
            }
336
        } else {            /* if even, ir-bit */
415
        } else {            /* if even, ir-bit */
337
            if (buf[i] > IR_SAMS_HIGH + IR_SAMS_HIGH/IR_SAMS_TOL_DIV || buf[i] < IR_SAMS_HIGH - IR_SAMS_HIGH/IR_SAMS_TOL_DIV) {
416
            if (buf[i] > IR_SAMS_HIGH + IR_SAMS_HIGH/IR_SAMS_TOL_DIV || buf[i] < IR_SAMS_HIGH - IR_SAMS_HIGH/IR_SAMS_TOL_DIV) {
338
                return IR_NOT_CORRECT_DATA;
417
                return IR_NOT_CORRECT_DATA;
339
            }
418
            }
340
        }
419
        }
341
    }
420
    }
342
   
421
   
343
    proto->protocol=IR_PROTO_SAMS;
422
    proto->protocol=IR_PROTO_SAMS;
344
    proto->timeout=IR_SAMS_TIMEOUT;
423
    proto->timeout=IR_SAMS_TIMEOUT;
345
    proto->data=tmpdata;   
424
    proto->data=rawbits;   
346
    return IR_OK;
425
    return IR_OK;
347
}
426
}
348
#endif
427
#endif
349
 
428
 
-
 
429
/**
-
 
430
 * Expand data from Samsung protocol
-
 
431
 * Very much like NEC, different start bit/pause lengths etc.
-
 
432
 * http://www.sbprojects.com/knowledge/ir/nec.htm
-
 
433
 *
-
 
434
 * @param buf
-
 
435
 *      Pointer to buffer to store the expanded data
-
 
436
 * @param len
-
 
437
 *      Pointer to length of the data
-
 
438
 * @param proto
-
 
439
 *      Pointer to protocol information
-
 
440
 * @return
-
 
441
 *      IR_OK if data expanded successfully, one of several errormessages if not
-
 
442
 */
350
int8_t expandSamsung(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
443
int8_t expandSamsung(uint16_t *buf, uint8_t *len, Ir_Protocol_Data_t *proto) {
351
    /* Set up startbit */
444
    /* Set up startbit */
352
    buf[0] = IR_SAMS_ST_BIT;
445
    buf[0] = IR_SAMS_ST_BIT;
353
    buf[1] = IR_SAMS_ST_PAUSE;
446
    buf[1] = IR_SAMS_ST_PAUSE;
354
   
447