home_easy.h 3.2 KB

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