]>
cloudbase.mooo.com Git - irmp.git/blob - irmpextlog.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * irmpextlog.c - external logging
4 * $Id: irmpextlog.c,v 1.6 2017/02/17 09:13:06 fm Exp $
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.
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 *---------------------------------------------------------------------------------------------------------------------------------------------------
18 #if IRMP_EXT_LOGGING == 1
20 #include "irmpextlog.h"
21 #include "system/usb/usb.h"
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
;
31 /*---------------------------------------------------------------------------------------------------------------------------------------------------
32 * Initialize external logging
33 *---------------------------------------------------------------------------------------------------------------------------------------------------
36 initextlog (void) // reset all data to default, only during init
40 for (i
= 0; i
< loglen
; i
++)
50 /*---------------------------------------------------------------------------------------------------------------------------------------------------
51 * Send logging data via device (e.g. USB on PIC)
52 *---------------------------------------------------------------------------------------------------------------------------------------------------
55 sendextlog (unsigned char data
)
57 if (logindex
== loglen
|| data
== '\n') // buffer full or \n --> send to application
59 if (mUSBUSARTIsTxTrfReady()) // check USB, if ready send
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
67 logdata
[2] = data
; // \n --> save \n=0xA in to check in app that \n was received
70 mUSBUSARTTxRam((unsigned char *) &logdata
, loglen
); // send all Data to main Seoftware
72 logindex
= 3; // reset index
73 bitindex
= 7; // reset bit position
74 logdata
[logindex
] = 0; // reset value of new logindex to 0
83 bit_set(logdata
[logindex
], bitindex
); // all logdata[logindex] on start = 0 --> only 1 must be set
86 bitindex
--; // decrease bitposition, wirte from left to right
88 if (bitindex
== -1) // byte complete Bit 7->0 --> next one
93 if (logindex
< loglen
)
95 logdata
[logindex
] = 0; // set next byte to 0
101 #endif //IRMP_EXT_LOGGING
107 // Only to avoid C18 compiler error