Hid_Cmd.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "stdafx.h"
  2. #include "Hid_Cmd.h"
  3. #include "AutoFunc.h"
  4. void InitKeyNode(KEY_CMD *pKey)
  5. {
  6. memset(pKey, 0, sizeof(KEY_CMD));
  7. pKey->Len = 10;
  8. pKey->Cmd = 1;
  9. }
  10. void InitMouseNode(MOUSE_CMD *pMouse)
  11. {
  12. memset(pMouse, 0, sizeof(MOUSE_CMD));
  13. pMouse->Len = 6;
  14. pMouse->Cmd = 0x11;
  15. }
  16. Hid_Cmd::Hid_Cmd()
  17. {
  18. }
  19. Hid_Cmd::~Hid_Cmd()
  20. {
  21. }
  22. bool Hid_Cmd::PostKeyCmd(KEY_CMD *pKey)
  23. {
  24. //user need fill the Func & key area
  25. return WriteToHid((char*)pKey, 10);
  26. }
  27. bool Hid_Cmd::PostMouseCmd(MOUSE_CMD *pMouse)
  28. {
  29. return WriteToHid((char*)pMouse, 6);
  30. }
  31. bool Hid_Cmd::GetLightStatus(LIGHT_FUNCTION_BIT *pVal)
  32. {
  33. char szCmd[2] = { 0x02, 0x21 };
  34. if (WriteToHid(szCmd, 2))
  35. {
  36. int ret = 0;
  37. do
  38. {
  39. char szRes[MAX_PATH] = { 0 };
  40. ret = ReadFromHid(szRes, MAX_PATH);
  41. if (ret >= 3)
  42. {
  43. if ((szRes[0] == (char)0x03) &&
  44. (szRes[1] == (char)0xA1))
  45. {
  46. memcpy(pVal, &(szRes[2]), 1);
  47. return true;
  48. }
  49. }
  50. } while (ret > 0);
  51. }
  52. return false;
  53. }
  54. bool Hid_Cmd::TryReadErrResponse(char Res, DWORD timeout)
  55. {
  56. int ret = 0;
  57. return true;
  58. do
  59. {
  60. char szRes[MAX_PATH] = { 0 };
  61. ret = ReadFromHid(szRes, MAX_PATH, timeout);
  62. if (ret >= 3)
  63. {
  64. if ((szRes[0] == 0x03) &&
  65. (szRes[1] == 0xA4))
  66. {
  67. Res = szRes[2];
  68. return true;
  69. }
  70. }
  71. } while (ret > 0);
  72. return false;
  73. }