receiver.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. void receiverTask(void *pvParameter)
  24. {
  25. ESP_LOGI("RX", "Receiver task starting.");
  26. uint32_t width;
  27. while (1) {
  28. while( xQueueReceive( rxQueue, &width, portMAX_DELAY ) == pdTRUE ) {
  29. //ESP_LOGI("D", "%u", width);
  30. //dataArr[dataArrIdx++] = width;
  31. //if( dataArrIdx == 1000 ) dataArrIdx=0;
  32. // Receive the Toshiba IR
  33. union ToshibaProtocolU* data = (union ToshibaProtocolU*)nextPulseToshiba_ir(width);
  34. if( data != NULL ) {
  35. ESP_LOGI("TOSHIBA", "Data: %02X %02X %02X %02X %02X %02X %02X %02X %02X",data->raw[8],data->raw[7],data->raw[6],data->raw[5],data->raw[4],data->raw[3],data->raw[2],data->raw[1],data->raw[0]);
  36. const uint8_t fan = (data->data.Fan > 0) ? data->data.Fan-1 : data->data.Fan;
  37. const uint8_t power = (data->data.Mode == 3) ? 1 : 0;
  38. ESP_LOGI("TOSHIBA","Mode:%u Temp:%u Fan:%u",power,data->data.Temp+17u,fan);
  39. #ifdef WIFI_ENABLED
  40. sendUDPMessage(dataStr, true);
  41. #endif
  42. }
  43. }
  44. }
  45. vTaskDelete(NULL);
  46. }
  47. void initReceiver() {
  48. gpio_pad_select_gpio(GPIO_RX_DATA);
  49. gpio_set_direction(GPIO_RX_DATA, GPIO_MODE_INPUT);
  50. //ClasO_ResetDecoder();
  51. ESP_LOGI("RX", "Receiver has been initialized.");
  52. xTaskCreatePinnedToCore(&receiverTask, "receiverTask", 8192, NULL, tskIDLE_PRIORITY + 5, NULL, 0);
  53. }