]> cloudbase.mooo.com Git - irmp.git/blob - irmpextlog.c
Version 2.6.0: added SAMSUNG48 protocol (yet only in IRMP).
[irmp.git] / irmpextlog.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * irmpextlog.c - external logging
3 *
4 * $Id: irmpextlog.c,v 1.4 2014/02/19 12:57:36 fm Exp $
5 *
6 * If you cannot use the internal UART logging routine, adapt the
7 * source below for your application. The following implementation
8 * is an example for a PIC 18F2550 with USB interface.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *---------------------------------------------------------------------------------------------------------------------------------------------------
15 */
16 #include "irmp.h"
17
18 #if IRMP_EXT_LOGGING == 1
19
20 #include "irmpextlog.h"
21 #include "system/usb/usb.h"
22
23 #define bit_set(var,bitnr) ((var) |= 1 << (bitnr)) // set single bit in byte
24 #define loglen 50 // byte length for saving the data from irmp.c
25 // check your USB settings for max length of USB interface used for this FW!
26 static unsigned char logdata[loglen]; // array for saveing the data from irmp.c
27 static unsigned char logindex = 3; // start index of logdata
28 static char bitindex = 7; // bit position in current byte
29 static unsigned int bitcount;
30
31 /*---------------------------------------------------------------------------------------------------------------------------------------------------
32 * Initialize external logging
33 *---------------------------------------------------------------------------------------------------------------------------------------------------
34 */
35 void
36 initextlog (void) // reset all data to default, only during init
37 {
38 unsigned char i;
39
40 for (i = 0; i < loglen; i++)
41 {
42 logdata[i] = 0;
43 }
44
45 bitcount = 0;
46 logindex = 3;
47 bitindex = 7;
48 }
49
50 /*---------------------------------------------------------------------------------------------------------------------------------------------------
51 * Send logging data via device (e.g. USB on PIC)
52 *---------------------------------------------------------------------------------------------------------------------------------------------------
53 */
54 void
55 sendextlog (unsigned char data)
56 {
57 if (logindex == loglen || data == '\n') // buffer full or \n --> send to application
58 {
59 if (mUSBUSARTIsTxTrfReady()) // check USB, if ready send
60 {
61 logdata[0] = 0x01; // indicator for logging, depends on your application
62 logdata[1] = logindex; // save how much bytes are send from irmp.c
63 logdata[2] = 0; // set \n Index to 0; 0=buffer full; 0xA=\n received
64
65 if (data == '\n')
66 {
67 logdata[2] = data; // \n --> save \n=0xA in to check in app that \n was received
68 }
69
70 mUSBUSARTTxRam((unsigned char *) &logdata, loglen); // send all Data to main Seoftware
71
72 logindex = 3; // reset index
73 bitindex = 7; // reset bit position
74 logdata[logindex] = 0; // reset value of new logindex to 0
75 }
76 }
77 else
78 {
79 bitcount++;
80
81 if (data == '1')
82 {
83 bit_set(logdata[logindex], bitindex); // all logdata[logindex] on start = 0 --> only 1 must be set
84 }
85
86 bitindex--; // decrease bitposition, wirte from left to right
87
88 if (bitindex == -1) // byte complete Bit 7->0 --> next one
89 {
90 bitindex = 7;
91 logindex++;
92
93 if (logindex < loglen)
94 {
95 logdata[logindex] = 0; // set next byte to 0
96 }
97 }
98 }
99 }
100
101 #endif //IRMP_EXT_LOGGING
102
103 #if defined(PIC_C18)
104 static void
105 dummy (void)
106 {
107 // Only to avoid C18 compiler error
108 }
109 #endif