home_easy.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. /**
  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. * Configure the GPIO output pin
  65. *
  66. * @param pinNumber wiringPi pin number
  67. */
  68. void setHomeEasyTransmittorPin(unsigned char pinNumber);
  69. /**
  70. * read the GPIO output pin
  71. *
  72. * @return wiringPi pin number
  73. */
  74. unsigned char getHomeEasyTransmittorPin();
  75. /**
  76. * Configure the GPIO input pin
  77. *
  78. * @param pinNumber wiringPi pin number
  79. */
  80. void setHomeEasyReceptorPin(unsigned char pinNumber);
  81. /**
  82. * read the GPIO input pin
  83. *
  84. * @return wiringPi pin number
  85. */
  86. unsigned char getHomeEasyReceptorPin();
  87. /**
  88. * Send a bit to the RF transmitter
  89. *
  90. * @param bit the bit to transmit (0 | 1 | TRIGGER0 | TRIGGER1 | END_OF_FRAME)
  91. */
  92. void sendHomeEasyBit(unsigned char bit);
  93. /**
  94. * Send a byte to the RF transmitter
  95. *
  96. * @param byte the byte to transmit
  97. */
  98. void sendHomeEasyByte(unsigned char byte);
  99. /**
  100. * Send the content of a buffer to the RF transmitter
  101. *
  102. * @param buffer the buffer to transmit
  103. */
  104. void sendHomeEasyBytes(BYTE_BUFFER buffer);
  105. /**
  106. * Calculate the length of the frame
  107. *
  108. * @param data data to scan (each byte represent a bit)
  109. * @param high length of high level
  110. * @param low length of low level
  111. *
  112. * @return total length of the frame
  113. */
  114. unsigned int frameSize(unsigned char* data, unsigned int* high, unsigned int* low);
  115. /**
  116. * Reading data from GPIO
  117. *
  118. * @param samples number of samples to read
  119. * @param duration waiting time between samples
  120. *
  121. * @return buffer
  122. */
  123. BYTE_BUFFER readData(unsigned long int samples, unsigned int duration);
  124. #endif