home_easy.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. * read the GPIO output pin
  84. *
  85. * @return wiringPi pin number
  86. */
  87. unsigned char getHomeEasyTransmittorPin();
  88. /**
  89. * Configure the GPIO input pin
  90. *
  91. * @param pinNumber wiringPi pin number
  92. */
  93. void setHomeEasyReceptorPin(unsigned char pinNumber);
  94. /**
  95. * read the GPIO input pin
  96. *
  97. * @return wiringPi pin number
  98. */
  99. unsigned char getHomeEasyReceptorPin();
  100. /**
  101. * Send a bit to the RF transmitter
  102. *
  103. * @param bit the bit to transmit (0 | 1 | TRIGGER0 | TRIGGER1 | END_OF_FRAME)
  104. */
  105. void sendHomeEasyBit(unsigned char bit);
  106. /**
  107. * Send a byte to the RF transmitter
  108. *
  109. * @param byte the byte to transmit
  110. */
  111. void sendHomeEasyByte(unsigned char byte);
  112. /**
  113. * Send the content of a buffer to the RF transmitter
  114. *
  115. * @param buffer the buffer to transmit
  116. */
  117. void sendHomeEasyBytes(BYTE_BUFFER buffer);
  118. /**
  119. * Calculate the length of the frame
  120. *
  121. * @param data data to scan (each byte represent a bit)
  122. * @param high length of high level
  123. * @param low length of low level
  124. *
  125. * @return total length of the frame
  126. */
  127. unsigned int frameSize(unsigned char* data, unsigned int* high, unsigned int* low);
  128. /**
  129. * Reading data from GPIO
  130. *
  131. * @param samples number of samples to read
  132. * @param duration waiting time between samples
  133. *
  134. * @return buffer
  135. */
  136. BYTE_BUFFER readData(unsigned long int samples, unsigned int duration);
  137. #endif