项目作者: maximkulkin

项目描述 :
Library for ESP-OPEN-RTOS to send IR commands.
高级语言: C
项目地址: git://github.com/maximkulkin/esp-ir.git
创建时间: 2019-03-19T06:30:57Z
项目社区:https://github.com/maximkulkin/esp-ir

开源协议:MIT License

下载


esp-ir

Library for ESP-OPEN-RTOS to send and receive IR commands.

Receiving IR codes can be done on arbitrary pin (which supports GPIO mode and pin change interrupts),

Receiver wiring

(big black thing being IR decoder, e.g. TSOP38238. Consult datasheet on particular part pinout).

Transmission though can only be done on GPIO14:

Transmitter wiring

(pretty much any NPN transistor will do, e.g. 2N2222; transistor base resistor could be 10K Om; LED resistor is calculated based on LED parameters, but you probably safe by assuming it can handle 10-20mA and go with ~220 Om).

Example sending command:

  1. #include <ir/ir.h>
  2. #include <ir/raw.h>
  3. static int16_t[] command1 = {
  4. 3291, -1611,
  5. 443, -370, 425, -421, 421, -1185, 424, -422,
  6. 421, -1185, 425, -421, 421, -370, 424, -392,
  7. 448, -1188, 423, -1214, 444, -372, 422, -395,
  8. 447, -397, 420, -1186, 449, -1185, 424, -423,
  9. 419, -375, 441, -372, 423, -422, 420, -372,
  10. 444, -370, 424, -422, 420, -372, 421, -393,
  11. 424, -421, 421, -371, 422, -392, 449, -398,
  12. 420, -1185, 450, -396, 421, -370, 422, -423,
  13. };
  14. ir_tx_init();
  15. ir_raw_send(command1, sizeof(command1) / sizeof(*command1));

Example receiving NEC-like command:

  1. #include "ir/ir.h"
  2. #include "ir/generic.h"
  3. #define IR_RX_GPIO 12
  4. static ir_generic_config_t my_protocol_config = {
  5. .header_mark = 3200,
  6. .header_space = -1600,
  7. .bit1_mark = 400,
  8. .bit1_space = -1200,
  9. .bit0_mark = 400,
  10. .bit0_space = -400,
  11. .footer_mark = 400,
  12. .footer_space = -8000,
  13. .tolerance = 10,
  14. };
  15. ir_rx_init(IR_RX_GPIO, 1024);
  16. ir_decoder_t *generic_decoder = ir_generic_make_decoder(&my_protocol_config);
  17. uint8_t buffer[32];
  18. while (1) {
  19. uint16_t size = ir_recv(generic_decoder, 0, buffer, sizeof(buffer));
  20. if (size <= 0)
  21. continue;
  22. printf("Decoded packet (size = %d): ", size);
  23. for (int i=0; i < size; i++) {
  24. printf("0x%02x ", buffer[i]);
  25. if (i % 16 == 15)
  26. // newline after every 16 bytes of packet data
  27. printf("\n");
  28. }
  29. if (size % 16)
  30. // print final newline unless packet size is multiple of 16 and newline
  31. // was printed inside of loop
  32. printf("\n");
  33. }

License

MIT licensed. See the bundled LICENSE file for more details.