My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UHS_printhex.h 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Copyright (C) 2015-2016 Andrew J. Kroll
  2. and
  3. Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. Contact information
  16. -------------------
  17. Circuits At Home, LTD
  18. Web : https://www.circuitsathome.com
  19. e-mail : support@circuitsathome.com
  20. */
  21. #if !defined(_UHS_host_h_) || defined(__PRINTHEX_H__)
  22. #error "Never include UHS_printhex.h directly; include UHS_Usb.h instead"
  23. #else
  24. #define __PRINTHEX_H__
  25. void E_Notifyc(char c, int lvl);
  26. template <class T>
  27. void PrintHex(T val, int lvl) {
  28. int num_nybbles = sizeof (T) * 2;
  29. do {
  30. char v = 48 + (((val >> (num_nybbles - 1) * 4)) & 0x0F);
  31. if(v > 57) v += 7;
  32. E_Notifyc(v, lvl);
  33. } while(--num_nybbles);
  34. }
  35. template <class T>
  36. void PrintBin(T val, int lvl) {
  37. for(T mask = (((T)1) << ((sizeof (T) << 3) - 1)); mask; mask >>= 1)
  38. if(val & mask)
  39. E_Notifyc('1', lvl);
  40. else
  41. E_Notifyc('0', lvl);
  42. }
  43. template <class T>
  44. void SerialPrintHex(T val) {
  45. int num_nybbles = sizeof (T) * 2;
  46. do {
  47. char v = 48 + (((val >> (num_nybbles - 1) * 4)) & 0x0F);
  48. if(v > 57) v += 7;
  49. USB_HOST_SERIAL.print(v);
  50. } while(--num_nybbles);
  51. }
  52. template <class T>
  53. void PrintHex2(Print *prn, T val) {
  54. T mask = (((T)1) << (((sizeof (T) << 1) - 1) << 2));
  55. while(mask > 1) {
  56. if(val < mask)
  57. prn->print("0");
  58. mask >>= 4;
  59. }
  60. prn->print((T)val, HEX);
  61. }
  62. #ifdef DEBUG_USB_HOST
  63. template <class T> void D_PrintHex(T val, int lvl) {
  64. PrintHex<T > (val, lvl);
  65. #else
  66. template <class T> void D_PrintHex(NOTUSED(T val), NOTUSED(int lvl)) {
  67. #endif
  68. }
  69. #ifdef DEBUG_USB_HOST
  70. template <class T> void D_PrintBin(T val, int lvl) {
  71. PrintBin<T > (val, lvl);
  72. #else
  73. template <class T> void D_PrintBin(NOTUSED(T val), NOTUSED(int lvl)) {
  74. #endif
  75. }
  76. #endif // __PRINTHEX_H__