home_easy.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 frame 32-bit frame to encode
  16. *
  17. * @return new buffer
  18. * */
  19. BYTE_BUFFER homeEasyEncode(unsigned long int frame);
  20. /**
  21. * Decode bits with HomeEasy encoding (1 => 10, 0 => 01)
  22. *
  23. * @param buffer the buffuer to decode
  24. *
  25. * @return new frame
  26. * */
  27. unsigned long int 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. * Create 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. * @return HomeEasy frame
  53. */
  54. unsigned long int createHomeEasyCommand(unsigned long int id, char section, unsigned char nb, unsigned char on);
  55. /**
  56. * Send a complete command according to Chacon protocole
  57. *
  58. * @param id command id (refer to your remote)
  59. * @param section button section ('A' | 'B' | 'C' | 'D' | 'G')
  60. * @param nb button number(1, 2, 3, 4)
  61. * @param on boolean for on/off
  62. * @param repeat number of repeatition
  63. */
  64. void sendHomeEasyCommand(unsigned long int id, char section, unsigned char nb, unsigned char on, unsigned char repeat);
  65. /**
  66. * Send n times a data frame
  67. *
  68. * @param frame the data to send
  69. * @param repeat number of repeatition
  70. */
  71. void sendFrame(BYTE_BUFFER frame, unsigned int repeat);
  72. /**
  73. * Configure the GPIO output pin
  74. *
  75. * @param pinNumber wiringPi pin number
  76. */
  77. void setHomeEasyTransmittorPin(unsigned char pinNumber);
  78. /**
  79. * Init input/output
  80. *
  81. * @return status
  82. */
  83. int initIO();
  84. /**
  85. * retrieve the HomeEasy device ID from a frame
  86. *
  87. * @param buffer the buffer that hold the frame
  88. *
  89. * @return the device id
  90. */
  91. unsigned long int getHomeEasyId(unsigned long int frame);
  92. /**
  93. * Get all information about the homeEasy frame
  94. *
  95. * @param frame the frame to read
  96. * @param id the identifier to extract
  97. * @param onOff boolean to extract; if true : on
  98. * @param section letter section to extract
  99. * @param number number to extract
  100. */
  101. void getHomeEasyInfo(unsigned long int frame, unsigned long int* id, unsigned char* onOff, unsigned char* section, unsigned char* number);
  102. /**
  103. * read the GPIO output pin
  104. *
  105. * @return wiringPi pin number
  106. */
  107. unsigned char getHomeEasyTransmittorPin();
  108. /**
  109. * Configure the GPIO input pin
  110. *
  111. * @param pinNumber wiringPi pin number
  112. */
  113. void setHomeEasyReceptorPin(unsigned char pinNumber);
  114. /**
  115. * read the GPIO input pin
  116. *
  117. * @return wiringPi pin number
  118. */
  119. unsigned char getHomeEasyReceptorPin();
  120. /**
  121. * Send a bit to the RF transmitter
  122. *
  123. * @param bit the bit to transmit (0 | 1 | TRIGGER0 | TRIGGER1 | END_OF_FRAME)
  124. */
  125. void sendHomeEasyBit(unsigned char bit);
  126. /**
  127. * Send a byte to the RF transmitter
  128. *
  129. * @param byte the byte to transmit
  130. */
  131. void sendHomeEasyByte(unsigned char byte);
  132. /**
  133. * Send the content of a buffer to the RF transmitter
  134. *
  135. * @param buffer the buffer to transmit
  136. */
  137. void sendHomeEasyBytes(BYTE_BUFFER buffer);
  138. /**
  139. * Calculate the length of the frame
  140. *
  141. * @param data data to scan (each byte represent a bit)
  142. * @param high length of high level
  143. * @param low length of low level
  144. *
  145. * @return total length of the frame
  146. */
  147. unsigned int frameSize(unsigned char* data, unsigned int* high, unsigned int* low);
  148. /**
  149. * Reading data from GPIO
  150. *
  151. * @param samples number of samples to read
  152. * @param duration waiting time between samples
  153. *
  154. * @return buffer
  155. */
  156. BYTE_BUFFER readData(unsigned long int samples, unsigned int duration);
  157. #endif