From 5d8cdd9bea07acd276b260b34bea299a45a9088a Mon Sep 17 00:00:00 2001
From: Dean Camera <dean@fourwalledcubicle.com>
Date: Mon, 20 Jul 2009 02:59:16 +0000
Subject: [PATCH] Fix unfinished printer host demo - some printer languages use
 embedded NULLs and so strlen() won't work in all cases. Ensure NULL
 terminator for the test page is not transmitted to the device.

---
 Demos/Host/Incomplete/PrinterHost/Lib/PrinterCommands.c | 4 ++--
 Demos/Host/Incomplete/PrinterHost/Lib/PrinterCommands.h | 2 +-
 Demos/Host/Incomplete/PrinterHost/PrinterHost.c         | 4 ++--
 Demos/Host/LowLevel/StillImageHost/StillImageHost.c     | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Demos/Host/Incomplete/PrinterHost/Lib/PrinterCommands.c b/Demos/Host/Incomplete/PrinterHost/Lib/PrinterCommands.c
index 668421d91..03d307094 100644
--- a/Demos/Host/Incomplete/PrinterHost/Lib/PrinterCommands.c
+++ b/Demos/Host/Incomplete/PrinterHost/Lib/PrinterCommands.c
@@ -37,14 +37,14 @@
  *
  *  \return A value from the Pipe_Stream_RW_ErrorCodes_t enum
  */
-uint8_t Printer_SendData(char* PrinterCommands)
+uint8_t Printer_SendData(char* PrinterCommands, uint16_t DataLength)
 {
 	uint8_t ErrorCode;
 
 	Pipe_SelectPipe(PRINTER_DATA_OUT_PIPE);
 	Pipe_Unfreeze();
 	
-	if ((ErrorCode = Pipe_Write_Stream_LE(PrinterCommands, strlen(PrinterCommands))) != PIPE_RWSTREAM_NoError)
+	if ((ErrorCode = Pipe_Write_Stream_LE(PrinterCommands, DataLength)) != PIPE_RWSTREAM_NoError)
 	  return ErrorCode;
 
 	Pipe_ClearOUT();
diff --git a/Demos/Host/Incomplete/PrinterHost/Lib/PrinterCommands.h b/Demos/Host/Incomplete/PrinterHost/Lib/PrinterCommands.h
index 01f1f1408..b296d86f6 100644
--- a/Demos/Host/Incomplete/PrinterHost/Lib/PrinterCommands.h
+++ b/Demos/Host/Incomplete/PrinterHost/Lib/PrinterCommands.h
@@ -54,7 +54,7 @@
 		#define PRINTER_DATA_OUT_PIPE        2
 		
 	/* Function Prototypes: */
-		uint8_t Printer_SendData(char* PrinterCommands);
+		uint8_t Printer_SendData(char* PrinterCommands, uint16_t DataLength);
 		uint8_t Printer_GetDeviceID(char* DeviceIDString, uint8_t BufferSize);
 		uint8_t Printer_GetPortStatus(uint8_t* PortStatus);
 		uint8_t Printer_SoftReset(void);
diff --git a/Demos/Host/Incomplete/PrinterHost/PrinterHost.c b/Demos/Host/Incomplete/PrinterHost/PrinterHost.c
index 220046574..bff5e2020 100644
--- a/Demos/Host/Incomplete/PrinterHost/PrinterHost.c
+++ b/Demos/Host/Incomplete/PrinterHost/PrinterHost.c
@@ -207,9 +207,9 @@ void USB_Printer_Host(void)
 			char PCL_Test_Page[]   = "\033%-12345X\033E LUFA PCL Test Page \033E\033%-12345X";
 //			char ESCP2_Test_Page[] =  "\033@\033i\001\033X\001\060\000\r\nLUFA ESCP/2 Test Page\r\n";
 
-			printf_P(PSTR("Sending Test Page (%d bytes)...\r\n"), strlen(PCL_Test_Page));
+			printf_P(PSTR("Sending Test Page (%d bytes)...\r\n"), (sizeof(PCL_Test_Page) - 1));
 
-			if ((ErrorCode = Printer_SendData(PCL_Test_Page)) != PIPE_RWSTREAM_NoError)
+			if ((ErrorCode = Printer_SendData(PCL_Test_Page, (sizeof(PCL_Test_Page) - 1))) != PIPE_RWSTREAM_NoError)
 			{
 				puts_P(PSTR(ESC_FG_RED "Error Sending Test Page.\r\n"));
 				printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);
diff --git a/Demos/Host/LowLevel/StillImageHost/StillImageHost.c b/Demos/Host/LowLevel/StillImageHost/StillImageHost.c
index dfc7cb7c1..5cfaf46be 100644
--- a/Demos/Host/LowLevel/StillImageHost/StillImageHost.c
+++ b/Demos/Host/LowLevel/StillImageHost/StillImageHost.c
@@ -352,7 +352,7 @@ void UnicodeToASCII(uint8_t* UnicodeString, char* Buffer)
 	/* Loop through the entire unicode string */
 	while (CharactersRemaining--)
 	{
-		/* Load in the next unicode character (only the lower byte, only Unicode coded ASCII supported) */
+		/* Load in the next unicode character (only the lower byte, as only Unicode coded ASCII is supported) */
 		*(Buffer++) = *UnicodeString;
 		
 		/* Jump to the next unicode character */
-- 
GitLab