Add partial project documentation to the incomplete PrinterHost demo.
[pub/USBasp.git] / Demos / Host / Incomplete / PrinterHost / Lib / PrinterCommands.c
index 9324a14..075b2d6 100644 (file)
 \r
 #include "PrinterCommands.h"\r
 \r
-uint8_t Printer_GetDeviceID(Device_ID_String_t* DeviceIDString)\r
+uint8_t Printer_SendData(char* PrinterCommands)\r
+{\r
+       uint8_t ErrorCode;\r
+\r
+       Pipe_SelectPipe(PRINTER_DATA_OUT_PIPE);\r
+       Pipe_Unfreeze();\r
+       \r
+       if ((ErrorCode = Pipe_Write_Stream_LE(PrinterCommands, strlen(PrinterCommands))) != PIPE_RWSTREAM_NoError)\r
+         return ErrorCode;\r
+\r
+       Pipe_ClearOUT();\r
+       while (!(Pipe_IsOUTReady()));\r
+       \r
+       Pipe_Freeze();\r
+\r
+       return PIPE_RWSTREAM_NoError;\r
+}\r
+\r
+/** Issues a Printer class Get Device ID command to the attached device, to retrieve the device ID string (which indicates\r
+ *  the accepted printer languages, the printer's model and other pertinent information).\r
+ *\r
+ *  \param[out] DeviceIDString Pointer to the destination where the returned string should be stored\r
+ *  \param[in] BufferSize  Size in bytes of the allocated buffer for the returned Device ID string\r
+ *\r
+ *  \return A value from the USB_Host_SendControlErrorCodes_t enum\r
+ */\r
+uint8_t Printer_GetDeviceID(char* DeviceIDString, uint8_t BufferSize)\r
 {\r
        uint8_t  ErrorCode = HOST_SENDCONTROL_Successful;\r
        uint16_t DeviceIDStringLength;\r
@@ -41,28 +67,34 @@ uint8_t Printer_GetDeviceID(Device_ID_String_t* DeviceIDString)
                        bRequest:      GET_DEVICE_ID,\r
                        wValue:        0,\r
                        wIndex:        0,\r
-                       wLength:       sizeof(DeviceIDString->Length),\r
+                       wLength:       sizeof(DeviceIDStringLength),\r
                };\r
 \r
-       if ((ErrorCode = USB_Host_SendControlRequest(DeviceIDString)) != HOST_SENDCONTROL_Successful)\r
+       if ((ErrorCode = USB_Host_SendControlRequest(&DeviceIDStringLength)) != HOST_SENDCONTROL_Successful)\r
          return ErrorCode;\r
        \r
-       DeviceIDStringLength = SwapEndian_16(DeviceIDString->Length);\r
+       DeviceIDStringLength = SwapEndian_16(DeviceIDStringLength);\r
 \r
-       /* Protect against overflow for the null terminator if the string length is equal to or larger than the buffer */\r
-       if (DeviceIDStringLength >= sizeof(DeviceIDString->String))\r
-         DeviceIDStringLength = sizeof(DeviceIDString->String) - 1;\r
+       if (DeviceIDStringLength > BufferSize)\r
+         DeviceIDStringLength = BufferSize;\r
 \r
-       USB_ControlRequest.wLength = DeviceIDStringLength;\r
+       USB_ControlRequest.wLength = (DeviceIDStringLength - 1);\r
        \r
        if ((ErrorCode = USB_Host_SendControlRequest(DeviceIDString)) != HOST_SENDCONTROL_Successful)\r
          return ErrorCode;\r
        \r
-       DeviceIDString->String[DeviceIDStringLength] = 0x00;\r
+       DeviceIDString[DeviceIDStringLength] = 0x00;\r
        \r
        return HOST_SENDCONTROL_Successful;\r
 }\r
 \r
+/** Issues a Printer class Get Port Status command to the attached device, to retrieve the current status flags of the\r
+ *  printer.\r
+ *\r
+ *  \param[out] PortStatus  Pointer to the destination where the printer's status flag values should be stored\r
+ *\r
+ *  \return A value from the USB_Host_SendControlErrorCodes_t enum\r
+ */\r
 uint8_t Printer_GetPortStatus(uint8_t* PortStatus)\r
 {\r
        USB_ControlRequest = (USB_Request_Header_t)\r
@@ -77,6 +109,11 @@ uint8_t Printer_GetPortStatus(uint8_t* PortStatus)
        return USB_Host_SendControlRequest(PortStatus);\r
 }\r
 \r
+/** Issues a Printer class Soft Reset command to the attached device, to reset the printer ready for new input without\r
+ *  physically cycling the printer's power.\r
+ *\r
+ *  \return A value from the USB_Host_SendControlErrorCodes_t enum\r
+ */\r
 uint8_t Printer_SoftReset(void)\r
 {\r
        USB_ControlRequest = (USB_Request_Header_t)\r