Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
Este repositório está arquivado. Você pode visualizar os arquivos e realizar clone, mas não poderá realizar push nem abrir issues e pull requests.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
  2. This software may be distributed and modified under the terms of the GNU
  3. General Public License version 2 (GPL2) as published by the Free Software
  4. Foundation and appearing in the file GPL2.TXT included in the packaging of
  5. this file. Please note that GPL2 Section 2[b] requires that all works based
  6. on this software must also be made publicly available under the terms of
  7. the GPL2 ("Copyleft").
  8. Contact information
  9. -------------------
  10. Circuits At Home, LTD
  11. Web : http://www.circuitsathome.com
  12. e-mail : [email protected]
  13. */
  14. #if !defined(_usb_h_) || defined(__PRINTHEX_H__)
  15. #error "Never include printhex.h directly; include Usb.h instead"
  16. #else
  17. #define __PRINTHEX_H__
  18. void E_Notifyc(char c, int lvl);
  19. template <class T>
  20. void PrintHex(T val, int lvl) {
  21. int num_nibbles = sizeof (T) * 2;
  22. do {
  23. char v = 48 + (((val >> (num_nibbles - 1) * 4)) & 0x0f);
  24. if(v > 57) v += 7;
  25. E_Notifyc(v, lvl);
  26. } while(--num_nibbles);
  27. }
  28. template <class T>
  29. void PrintBin(T val, int lvl) {
  30. for(T mask = (((T)1) << ((sizeof (T) << 3) - 1)); mask; mask >>= 1)
  31. if(val & mask)
  32. E_Notifyc('1', lvl);
  33. else
  34. E_Notifyc('0', lvl);
  35. }
  36. template <class T>
  37. void SerialPrintHex(T val) {
  38. int num_nibbles = sizeof (T) * 2;
  39. do {
  40. char v = 48 + (((val >> (num_nibbles - 1) * 4)) & 0x0f);
  41. if(v > 57) v += 7;
  42. USB_HOST_SERIAL.print(v);
  43. } while(--num_nibbles);
  44. }
  45. template <class T>
  46. void PrintHex2(Print *prn, T val) {
  47. T mask = (((T)1) << (((sizeof (T) << 1) - 1) << 2));
  48. while(mask > 1) {
  49. if(val < mask)
  50. prn->print("0");
  51. mask >>= 4;
  52. }
  53. prn->print((T)val, HEX);
  54. }
  55. template <class T> void D_PrintHex(T val, int lvl) {
  56. #ifdef DEBUG_USB_HOST
  57. PrintHex<T > (val, lvl);
  58. #endif
  59. }
  60. template <class T>
  61. void D_PrintBin(T val, int lvl) {
  62. #ifdef DEBUG_USB_HOST
  63. PrintBin<T > (val, lvl);
  64. #endif
  65. }
  66. #endif // __PRINTHEX_H__