/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
* main.c - demo main module to test irmp decoder\r
*\r
- * Copyright (c) 2009-2014 Frank Meyer - frank(at)fli4l.de\r
+ * Copyright (c) 2009-2015 Frank Meyer - frank(at)fli4l.de\r
*\r
- * $Id: main.c,v 1.23 2014/11/17 11:56:19 fm Exp $\r
+ * $Id: main.c,v 1.27 2015/02/27 10:19:20 fm Exp $\r
*\r
* This demo module is runnable on AVRs and LM4F120 Launchpad (ARM Cortex M4)\r
*\r
}\r
}\r
\r
-static uint8_t\r
-itox (uint8_t val)\r
+static char *\r
+itoh (char * buf, uint8_t digits, uint16_t number)\r
{\r
- uint8_t rtc;\r
-\r
- val &= 0x0F;\r
-\r
- if (val <= 9)\r
+ for (buf[digits] = 0; digits--; number >>= 4)\r
{\r
- rtc = val + '0';\r
+ buf[digits] = "0123456789ABCDEF"[number & 0x0F];\r
}\r
- else\r
- {\r
- rtc = val - 10 + 'A';\r
- }\r
- return (rtc);\r
-}\r
-\r
-static void\r
-itoxx (char * xx, unsigned char i)\r
-{\r
- *xx++ = itox (i >> 4);\r
- *xx++ = itox (i & 0x0F);\r
- *xx = '\0';\r
+ return buf;\r
}\r
\r
static void\r
if (irmp_get_data (&irmp_data))\r
{\r
uart_puts_P (PSTR("protocol: 0x"));\r
- itoxx (buf, irmp_data.protocol);\r
+ itoh (buf, 2, irmp_data.protocol);\r
uart_puts (buf);\r
\r
#if IRMP_PROTOCOL_NAMES == 1\r
#endif\r
\r
uart_puts_P (PSTR(" address: 0x"));\r
- itoxx (buf, irmp_data.address >> 8);\r
- uart_puts (buf);\r
- itoxx (buf, irmp_data.address & 0xFF);\r
+ itoh (buf, 4, irmp_data.address);\r
uart_puts (buf);\r
\r
uart_puts_P (PSTR(" command: 0x"));\r
- itoxx (buf, irmp_data.command >> 8);\r
- uart_puts (buf);\r
- itoxx (buf, irmp_data.command & 0xFF);\r
+ itoh (buf, 4, irmp_data.command);\r
uart_puts (buf);\r
\r
uart_puts_P (PSTR(" flags: 0x"));\r
- itoxx (buf, irmp_data.flags);\r
+ itoh (buf, 2, irmp_data.flags);\r
uart_puts (buf);\r
\r
uart_puts_P (PSTR("\r\n"));\r