1
0

main.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "freertos/FreeRTOS.h"
  2. #include "freertos/task.h"
  3. #include "esp_log.h"
  4. #include "config.h"
  5. #include "wifi.h"
  6. #include "mqtt.h"
  7. #include "readTemps.h"
  8. #include "rxTimer.h"
  9. #include "receiver.h"
  10. #include "ir_transmit.h"
  11. #include "toshiba_ir.h"
  12. // Chip info:
  13. // This is esp32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash
  14. /*
  15. I (43709) TOSHIBA: MQTT: F20D03FC0170A300D2
  16. I (43709) TOSHIBA: Data: F2 0D 03 FC 01 70 A3 00 D2
  17. I (43709) TOSHIBA: Mode:1 Temp:24 Fan:4
  18. I (43839) TOSHIBA: MQTT: F20D03FC0170A300D2
  19. I (43839) TOSHIBA: Data: F2 0D 03 FC 01 70 A3 00 D2
  20. I (43839) TOSHIBA: Mode:1 Temp:24 Fan:4
  21. */
  22. void app_main(void)
  23. {
  24. ESP_LOGI("MAIN", "IRTransceiver ESP32. Core:%d",xPortGetCoreID());
  25. // Wait for stable environment
  26. vTaskDelay(1000.0 / portTICK_PERIOD_MS);
  27. #ifdef RX_TIMER
  28. rxTimerInit(); // First we start the Timer (which samples Rx and handles uS-delays)
  29. #endif
  30. #ifdef ENABLE_DS18B20
  31. initTempReadings();
  32. #endif
  33. #ifdef WIFI_ENABLED
  34. initWifi(); // Init WIFI
  35. #endif
  36. // MQTT Task is receiving orders for IR and is triggering a send of Transmit IR Codes
  37. #ifdef MQTT_ENABLED
  38. mqtt_init();
  39. #endif
  40. #ifdef IR_RECEIVER
  41. initReceiver(); // Init receiver-task
  42. #endif
  43. vTaskDelay(1000 / portTICK_PERIOD_MS);
  44. TickType_t vLastWakeTime = xTaskGetTickCount();
  45. // Do an initial delay to make the different tasks to work out of sync to each other (not send all data at same time)
  46. vTaskDelayUntil( &vLastWakeTime, 2000 / portTICK_PERIOD_MS );
  47. #ifdef IR_TRANSMIT
  48. initIrTransmit();
  49. #endif
  50. ESP_LOGI("MAIN","Lets go...");
  51. // ---------------- MAIN WHILE -------------------
  52. while(1) {
  53. vTaskDelayUntil( &vLastWakeTime, 10000 / portTICK_PERIOD_MS );
  54. // Start temp measuring task
  55. #ifdef ENABLE_DS18B20
  56. xTaskCreatePinnedToCore(readAndSendTemps, "readAndSendTemps", 1024*10, NULL, 2, NULL,1);
  57. #endif
  58. /*ESP_LOGI("MAIN","Send a test-IR Tx Data");
  59. const uint8_t data[kPanasonicNumberOfBytes] = { 0xF2, 0x0D, 0x03, 0xFC, 0x01, 0x30, 0xA3, 0x00, 0x92 };
  60. // F2 0D 03 FC 01 30 A3 00 92
  61. xQueueSend( toshibaTxQueue, &(data[0]), 0 );*/
  62. }
  63. vTaskDelete(NULL);
  64. }