receiver.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <sys/time.h>
  6. #include "freertos/FreeRTOS.h"
  7. #include "freertos/task.h"
  8. #include "esp_sleep.h"
  9. #include "esp_log.h"
  10. #include "driver/uart.h"
  11. #include "driver/rtc_io.h"
  12. #include "esp_intr_alloc.h"
  13. #include "esp_attr.h"
  14. #include "driver/timer.h"
  15. #include <stddef.h>
  16. #include "esp_intr_alloc.h"
  17. #include "receiver.h"
  18. #include "rxTimer.h"
  19. #include "toshiba_ir.h"
  20. #include "wifi.h"
  21. uint32_t dataArr[1000];
  22. uint32_t dataArrIdx = 0;
  23. static int convertToSignedTemp(unsigned int value)
  24. {
  25. //int signValue;
  26. return ( (value >> 11) == 0 )? value : ((-1 ^ 0xFFF) | value);
  27. }
  28. void receiverTask(void *pvParameter)
  29. {
  30. ESP_LOGI("RX", "Receiver task starting.");
  31. uint32_t width;
  32. while (1) {
  33. while( xQueueReceive( rxQueue, &width, portMAX_DELAY ) == pdTRUE ) {
  34. //ESP_LOGI("D", "%u", width);
  35. //dataArr[dataArrIdx++] = width;
  36. //if( dataArrIdx == 1000 ) dataArrIdx=0;
  37. // Receive the Toshiba IR
  38. int64_t data = nextPulseToshiba_ir(width);
  39. if( data != -1 ) {
  40. int value = convertToSignedTemp( data & 0xFFF );
  41. unsigned char id = (data>>12) & 0x007;
  42. ESP_LOGI("RX", "ClasO: <TR%08llX> %u %4.1f",data,id, (float)value/10);
  43. //sprintf(dataStr,"<TR%08llX>",data);
  44. #ifdef WIFI_ENABLED
  45. sendUDPMessage(dataStr, true);
  46. #endif
  47. }
  48. }
  49. }
  50. vTaskDelete(NULL);
  51. }
  52. void initReceiver() {
  53. gpio_pad_select_gpio(GPIO_RX_DATA);
  54. gpio_set_direction(GPIO_RX_DATA, GPIO_MODE_INPUT);
  55. //ClasO_ResetDecoder();
  56. ESP_LOGI("RX", "Receiver has been initialized.");
  57. xTaskCreatePinnedToCore(&receiverTask, "receiverTask", 8192, NULL, tskIDLE_PRIORITY + 5, NULL, 0);
  58. }