receiver.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. // Receive the Toshiba IR
  31. union ToshibaProtocolU* data = (union ToshibaProtocolU*)nextPulseToshiba_ir(width);
  32. if( data != NULL ) {
  33. 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]);
  34. const uint8_t fan = (data->data.Fan > 0) ? data->data.Fan-1 : data->data.Fan;
  35. const uint8_t power = (data->data.Mode == 3) ? 1 : 0;
  36. ESP_LOGI("TOSHIBA","Mode:%u Temp:%u Fan:%u",power,data->data.Temp+17u,fan);
  37. #ifdef WIFI_ENABLED
  38. //sendUDPMessage(dataStr, true);
  39. #endif
  40. }
  41. }
  42. }
  43. vTaskDelete(NULL);
  44. }
  45. void initReceiver() {
  46. gpio_pad_select_gpio(GPIO_RX_DATA);
  47. gpio_set_direction(GPIO_RX_DATA, GPIO_MODE_INPUT);
  48. //ClasO_ResetDecoder();
  49. ESP_LOGI("RX", "Receiver has been initialized.");
  50. xTaskCreatePinnedToCore(&receiverTask, "receiverTask", 8192, NULL, tskIDLE_PRIORITY + 5, NULL, 0);
  51. }