home_easy.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #ifndef __HOME_EASY_H__
  2. #define __HOME_EASY_H__
  3. #include <stdio.h>
  4. #include "buffer.h"
  5. #define BIT0 0
  6. #define BIT1 1
  7. #define START_OF_DATA 2
  8. #define START_OF_FRAME 3
  9. #define END_OF_FRAME 4
  10. #define ON 1
  11. #define OFF 0
  12. /**
  13. * Encode bits with HomeEasy encoding (1 => 10, 0 => 01)
  14. *
  15. * @param buffer the buffuer to encode
  16. *
  17. * @return new buffer
  18. * */
  19. BYTE_BUFFER homeEasyEncode(BYTE_BUFFER *buffer);
  20. /**
  21. * Decode bits with HomeEasy encoding (1 => 10, 0 => 01)
  22. *
  23. * @param buffer the buffuer to decode
  24. *
  25. * @return new buffer
  26. * */
  27. BYTE_BUFFER homeEasyDecode(BYTE_BUFFER *buffer);
  28. /**
  29. * Encode a byte according to HomeEasy
  30. *
  31. * @param byte the byte to encode
  32. *
  33. * @return the encoded byte
  34. */
  35. unsigned short int encodeByte(unsigned char byte);
  36. /**
  37. * Decode a byte according to HomeEasy
  38. *
  39. * @param byte the byte to decode
  40. *
  41. * @return the decoded byte
  42. */
  43. unsigned char decodeByte(unsigned short int word);
  44. /**
  45. * Creata a complete command according to Chacon protocole
  46. *
  47. * @param id command id (refer to your remote)
  48. * @param section button section ('A' | 'B' | 'C' | 'D' | 'G')
  49. * @param nb button number(1, 2, 3, 4)
  50. * @param on boolean for on/off
  51. */
  52. BYTE_BUFFER createHomeEasyCommand(unsigned char* id, char section, unsigned char nb, unsigned char on);
  53. /**
  54. * Send a complete command according to Chacon protocole
  55. *
  56. * @param id command id (refer to your remote)
  57. * @param section button section ('A' | 'B' | 'C' | 'D' | 'G')
  58. * @param nb button number(1, 2, 3, 4)
  59. * @param on boolean for on/off
  60. * @param repeat number of repeatition
  61. */
  62. void sendHomeEasyCommand(unsigned char* id, char section, unsigned char nb, unsigned char on, unsigned char repeat);
  63. /**
  64. * Send n times a data frame
  65. *
  66. * @param frame the data to send
  67. * @param repeat number of repeatition
  68. */
  69. void sendFrame(BYTE_BUFFER frame, unsigned int repeat);
  70. /**
  71. * Configure the GPIO output pin
  72. *
  73. * @param pinNumber wiringPi pin number
  74. */
  75. void setHomeEasyTransmittorPin(unsigned char pinNumber);
  76. /**
  77. * Init input/output
  78. *
  79. * @return status
  80. */
  81. int initIO();
  82. /**
  83. * retrieve the HomeEasy device ID from a frame
  84. *
  85. * @param buffer the buffer that hold the frame
  86. *
  87. * @return the device id
  88. */
  89. unsigned long int getHomeEasyId(BYTE_BUFFER buffer);
  90. /**
  91. * read the GPIO output pin
  92. *
  93. * @return wiringPi pin number
  94. */
  95. unsigned char getHomeEasyTransmittorPin();
  96. /**
  97. * Configure the GPIO input pin
  98. *
  99. * @param pinNumber wiringPi pin number
  100. */
  101. void setHomeEasyReceptorPin(unsigned char pinNumber);
  102. /**
  103. * read the GPIO input pin
  104. *
  105. * @return wiringPi pin number
  106. */
  107. unsigned char getHomeEasyReceptorPin();
  108. /**
  109. * Send a bit to the RF transmitter
  110. *
  111. * @param bit the bit to transmit (0 | 1 | TRIGGER0 | TRIGGER1 | END_OF_FRAME)
  112. */
  113. void sendHomeEasyBit(unsigned char bit);
  114. /**
  115. * Send a byte to the RF transmitter
  116. *
  117. * @param byte the byte to transmit
  118. */
  119. void sendHomeEasyByte(unsigned char byte);
  120. /**
  121. * Send the content of a buffer to the RF transmitter
  122. *
  123. * @param buffer the buffer to transmit
  124. */
  125. void sendHomeEasyBytes(BYTE_BUFFER buffer);
  126. /**
  127. * Calculate the length of the frame
  128. *
  129. * @param data data to scan (each byte represent a bit)
  130. * @param high length of high level
  131. * @param low length of low level
  132. *
  133. * @return total length of the frame
  134. */
  135. unsigned int frameSize(unsigned char* data, unsigned int* high, unsigned int* low);
  136. /**
  137. * Reading data from GPIO
  138. *
  139. * @param samples number of samples to read
  140. * @param duration waiting time between samples
  141. *
  142. * @return buffer
  143. */
  144. BYTE_BUFFER readData(unsigned long int samples, unsigned int duration);
  145. #endif