emitlib.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <stdio.h>
  2. typedef struct {
  3. unsigned long int byteSize;
  4. unsigned int bitSize;
  5. char* data;
  6. } BUFFER;
  7. #define BIT0 0
  8. #define BIT1 1
  9. #define START_OF_FRAME 2
  10. #define END_OF_DATA 3
  11. #define ON 1
  12. #define OFF 0
  13. #define NUMBER1 0
  14. #define NUMBER2 1
  15. #define NUMBER3 2
  16. #define NUMBER4 3
  17. #define SECTION_A 0
  18. #define SECTION_B 1
  19. #define SECTION_C 2
  20. #define SECTION_D 3
  21. #define GLOBAL 1
  22. #define NO_GLOBAL 0
  23. /**
  24. * Create a new buffer
  25. *
  26. * @return the created buffer
  27. */
  28. BUFFER createBuffer();
  29. /**
  30. * Release the memory
  31. *
  32. * @param buffer the buffer to destroy
  33. */
  34. void destroyBuffer(BUFFER buffer);
  35. /**
  36. * Print all the bits from a buffer
  37. *
  38. * @param buffer the buffer holding the data
  39. */
  40. void printfBinaryBuffer(BUFFER buffer);
  41. /**
  42. * Push a bit in a buffer
  43. *
  44. * @param buffer the buffer holding the data
  45. * @param bit the bit to push
  46. */
  47. void pushBit(BUFFER* buffer, unsigned char bit);
  48. /**
  49. * Append a bit that will be emitted for a specific time
  50. *
  51. * @param buffer the buffer holding the data
  52. * @param bit the bit to push
  53. * @param usec time in µs
  54. * @param clock frequency
  55. */
  56. void appendBit(BUFFER* buffer, unsigned char bit, unsigned int usec, unsigned int freq);
  57. /**
  58. * Append data according to Chacon protocole
  59. *
  60. * @param buffer the buffer holding the data
  61. * @param type data type (BIT0 | BIT1 | START_OF_FRAME | END_OF_DATA)
  62. * @param clock frequency
  63. */
  64. void appendData(BUFFER* buffer, unsigned int type, unsigned int freq);
  65. /**
  66. * Append a byte according to Chacon protocole
  67. *
  68. * @param buffer the buffer holding the data
  69. * @param byte the byte to append
  70. * @param clock frequency
  71. */
  72. void appendByte(BUFFER* buffer, unsigned char byte, unsigned int freq);
  73. /**
  74. * Append a complete command according to Chacon protocole
  75. *
  76. * @param buffer the buffer holding the data
  77. * @param id command id (refer to your remote)
  78. * @param section button section (0:A, 1:B, 2:C, 3:D)
  79. * @param nb button number(1, 2, 3, 4)
  80. * @param on boolean for on/off
  81. * @param global if true G button is selected (nb will be ignore)
  82. * @param clock frequency
  83. */
  84. void pushCode(BUFFER* buffer, unsigned char* id, unsigned char section, unsigned char nb, unsigned char on, unsigned char global, unsigned int freq);