defines.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. #pragma once
  2. #ifndef defines_h
  3. #define defines_h
  4. /////////////////////////////////////////////
  5. //// Global definitions ////
  6. /////////////////////////////////////////////
  7. //********* debug options : *************
  8. //can be set in platformio with -D OPTION_TO_ACTIVATE
  9. //#define DEBUG_DETAIL_ON
  10. //#define DEBUG_DISABLE_BROWNOUT_DETECTOR
  11. //#define DEBUG_ENABLE_SYSINFO
  12. //#define DEBUG_ENABLE_PERFMON
  13. //#define DEBUG_HIMEM_MEMORY_CHECK
  14. // need [env:esp32cam-dev-himem]
  15. //=> CONFIG_SPIRAM_BANKSWITCH_ENABLE=y
  16. //=> CONFIG_SPIRAM_BANKSWITCH_RESERVE=4
  17. // use himem //https://github.com/jomjol/AI-on-the-edge-device/issues/1842
  18. #define USE_HIMEM_IF_AVAILABLE
  19. /* Uncomment this to generate task list with stack sizes using the /heap handler
  20. PLEASE BE AWARE: The following CONFIG parameters have to to be set in
  21. sdkconfig.defaults before use of this function is possible!!
  22. CONFIG_FREERTOS_USE_TRACE_FACILITY=1
  23. CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y
  24. CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y
  25. */
  26. // server_tflite.cpp
  27. //#define TASK_ANALYSIS_ON
  28. /* Uncomment this to keep the logfile open for appending.
  29. * If commented out, the logfile gets opened/closed for each log measage (old behaviour) */
  30. // ClassLogFile
  31. //#define KEEP_LOGFILE_OPEN_FOR_APPENDING
  32. //****************************************
  33. //compiler optimization for tflite-micro-esp-examples
  34. #define XTENSA
  35. //#define CONFIG_IDF_TARGET_ARCH_XTENSA //not needed with platformio/espressif32 @ 5.2.0
  36. //ClassControllCamera + ClassFlowMakeImage + connect_wlan + main
  37. #define FLASH_GPIO GPIO_NUM_4
  38. #define BLINK_GPIO GPIO_NUM_33
  39. //ClassFlowMQTT + interface_mqtt + connect_wlan + main
  40. #define __HIDE_PASSWORD
  41. //ClassControllCamera
  42. #define USE_PWM_LEDFLASH // if __LEDGLOBAL is defined, a global variable is used for LED control, otherwise locally and each time a new
  43. //server_GPIO
  44. #define __LEDGLOBAL
  45. //ClassControllCamera + ClassFlowMakeImage
  46. #define CAMERA_MODEL_AI_THINKER
  47. #define BOARD_ESP32CAM_AITHINKER
  48. //server_GPIO + server_file + SoftAP
  49. #define CONFIG_FILE "/sdcard/config/config.ini"
  50. //ClassFlowControll + Main + SoftAP
  51. #define WLAN_CONFIG_FILE "/sdcard/wlan.ini"
  52. //main
  53. #define __SD_USE_ONE_LINE_MODE__
  54. // server_file + Helper
  55. #define FILE_PATH_MAX (255) //Max length a file path can have on storage
  56. //server_file +(ota_page.html + upload_script.html)
  57. #define MAX_FILE_SIZE (8000*1024) // 8 MB Max size of an individual file. Make sure this value is same as that set in upload_script.html and ota_page.html!
  58. #define MAX_FILE_SIZE_STR "8MB"
  59. #define LOGFILE_LAST_PART_BYTES SERVER_FILER_SCRATCH_BUFSIZE * 20 // 80 kBytes // Size of partial log file to return
  60. #define SERVER_FILER_SCRATCH_BUFSIZE 4096
  61. #define SERVER_HELPER_SCRATCH_BUFSIZE 8192
  62. #define SERVER_OTA_SCRATCH_BUFSIZE 1024
  63. //server_file + server_help
  64. #define IS_FILE_EXT(filename, ext) \
  65. (strcasecmp(&filename[strlen(filename) - sizeof(ext) + 1], ext) == 0)
  66. //server_ota
  67. #define HASH_LEN 32 // SHA-256 digest length
  68. #define OTA_URL_SIZE 256
  69. //ClassFlow + ClassFlowImage + server_tflite
  70. #define LOGFILE_TIME_FORMAT "%Y%m%d-%H%M%S"
  71. #define LOGFILE_TIME_FORMAT_DATE_EXTR substr(0, 8)
  72. #define LOGFILE_TIME_FORMAT_HOUR_EXTR substr(9, 2)
  73. //ClassFlowControll
  74. #define READOUT_TYPE_VALUE 0
  75. #define READOUT_TYPE_PREVALUE 1
  76. #define READOUT_TYPE_RAWVALUE 2
  77. #define READOUT_TYPE_ERROR 3
  78. //ClassFlowControll: Serve alg_roi.jpg from memory as JPG
  79. #define ALGROI_LOAD_FROM_MEM_AS_JPG // Load ALG_ROI.JPG as rendered JPG from RAM
  80. #define ALGROI_LOAD_FROM_MEM_AS_JPG__SHOW_TAKE_IMAGE_PROCESS // Show take image image processing on webinterface (overview.html)
  81. //ClassFlowMQTT
  82. #define LWT_TOPIC "connection"
  83. #define LWT_CONNECTED "connected"
  84. #define LWT_DISCONNECTED "connection lost"
  85. //ClassFlowPostProcessing
  86. #define PREVALUE_TIME_FORMAT_OUTPUT "%Y-%m-%dT%H:%M:%S%z"
  87. #define PREVALUE_TIME_FORMAT_INPUT "%d-%d-%dT%d:%d:%d"
  88. //CImageBasis
  89. #define HTTP_BUFFER_SENT 1024
  90. #define GET_MEMORY(X) heap_caps_malloc(X, MALLOC_CAP_SPIRAM)
  91. #define MAX_JPG_SIZE 128000
  92. //CAlignAndCutImage + CImageBasis
  93. #define _USE_MATH_DEFINES
  94. #define GET_MEMORY(X) heap_caps_malloc(X, MALLOC_CAP_SPIRAM)
  95. //make_stb + stb_image_resize + stb_image_write + stb_image //do not work if not in make_stb.cpp
  96. //#define STB_IMAGE_IMPLEMENTATION
  97. //#define STB_IMAGE_WRITE_IMPLEMENTATION
  98. //#define STB_IMAGE_RESIZE_IMPLEMENTATION
  99. #define STBI_ONLY_JPEG // (save 2% of Flash, but breaks the alignment mark generation, see https://github.com/jomjol/AI-on-the-edge-device/issues/1721)
  100. //interface_influxdb
  101. #define MAX_HTTP_OUTPUT_BUFFER 2048
  102. //server_mqtt
  103. #define LWT_TOPIC "connection"
  104. #define LWT_CONNECTED "connected"
  105. #define LWT_DISCONNECTED "connection lost"
  106. //CTfLiteClass
  107. #define TFLITE_MINIMAL_CHECK(x) \
  108. if (!(x)) { \
  109. fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); \
  110. exit(1); \
  111. }
  112. #define SUPRESS_TFLITE_ERRORS // use, to avoid error messages from TFLITE
  113. //connect_wlan
  114. #define WLAN_USE_MESH_ROAMING
  115. #define WLAN_WIFI_RSSI_THRESHOLD -50
  116. #define EXAMPLE_ESP_MAXIMUM_RETRY 1000
  117. /* The event group allows multiple bits for each event, but we only care about two events:
  118. * - we are connected to the AP with an IP
  119. * - we failed to connect after the maximum amount of retries */
  120. #define WIFI_CONNECTED_BIT BIT0
  121. #define WIFI_FAIL_BIT BIT1
  122. //ClassFlowCNNGeneral
  123. #define Analog_error 3
  124. #define AnalogToDigtalFehler 0.8
  125. #define Digital_Uncertainty 0.2
  126. #define DigitalBand 3
  127. #define Digital_Transition_Range_Predecessor 2
  128. #define Digital_Transition_Area_Predecessor 0.7 // 9.3 - 0.7
  129. #define Digital_Transition_Area_Forward 9.7 // Pre-run zero crossing only happens from approx. 9.7 onwards
  130. //#define DEBUG_DETAIL_ON
  131. /////////////////////////////////////////////
  132. //// Conditionnal definitions ////
  133. /////////////////////////////////////////////
  134. //******* camera model
  135. #if defined(CAMERA_MODEL_WROVER_KIT)
  136. #define PWDN_GPIO_NUM -1
  137. #define RESET_GPIO_NUM -1
  138. #define XCLK_GPIO_NUM 21
  139. #define SIOD_GPIO_NUM 26
  140. #define SIOC_GPIO_NUM 27
  141. #define Y9_GPIO_NUM 35
  142. #define Y8_GPIO_NUM 34
  143. #define Y7_GPIO_NUM 39
  144. #define Y6_GPIO_NUM 36
  145. #define Y5_GPIO_NUM 19
  146. #define Y4_GPIO_NUM 18
  147. #define Y3_GPIO_NUM 5
  148. #define Y2_GPIO_NUM 4
  149. #define VSYNC_GPIO_NUM 25
  150. #define HREF_GPIO_NUM 23
  151. #define PCLK_GPIO_NUM 22
  152. #elif defined(CAMERA_MODEL_M5STACK_PSRAM)
  153. #define PWDN_GPIO_NUM -1
  154. #define RESET_GPIO_NUM 15
  155. #define XCLK_GPIO_NUM 27
  156. #define SIOD_GPIO_NUM 25
  157. #define SIOC_GPIO_NUM 23
  158. #define Y9_GPIO_NUM 19
  159. #define Y8_GPIO_NUM 36
  160. #define Y7_GPIO_NUM 18
  161. #define Y6_GPIO_NUM 39
  162. #define Y5_GPIO_NUM 5
  163. #define Y4_GPIO_NUM 34
  164. #define Y3_GPIO_NUM 35
  165. #define Y2_GPIO_NUM 32
  166. #define VSYNC_GPIO_NUM 22
  167. #define HREF_GPIO_NUM 26
  168. #define PCLK_GPIO_NUM 21
  169. #elif defined(CAMERA_MODEL_AI_THINKER)
  170. #define PWDN_GPIO_NUM GPIO_NUM_32
  171. #define RESET_GPIO_NUM -1
  172. #define XCLK_GPIO_NUM GPIO_NUM_0
  173. #define SIOD_GPIO_NUM GPIO_NUM_26
  174. #define SIOC_GPIO_NUM GPIO_NUM_27
  175. #define Y9_GPIO_NUM GPIO_NUM_35
  176. #define Y8_GPIO_NUM GPIO_NUM_34
  177. #define Y7_GPIO_NUM GPIO_NUM_39
  178. #define Y6_GPIO_NUM GPIO_NUM_36
  179. #define Y5_GPIO_NUM GPIO_NUM_21
  180. #define Y4_GPIO_NUM GPIO_NUM_19
  181. #define Y3_GPIO_NUM GPIO_NUM_18
  182. #define Y2_GPIO_NUM GPIO_NUM_5
  183. #define VSYNC_GPIO_NUM GPIO_NUM_25
  184. #define HREF_GPIO_NUM GPIO_NUM_23
  185. #define PCLK_GPIO_NUM GPIO_NUM_22
  186. #else
  187. #error "Camera model not selected"
  188. #endif //camera model
  189. // ******* Board type
  190. #ifdef BOARD_WROVER_KIT // WROVER-KIT PIN Map
  191. #define CAM_PIN_PWDN -1 //power down is not used
  192. #define CAM_PIN_RESET -1 //software reset will be performed
  193. #define CAM_PIN_XCLK 21
  194. #define CAM_PIN_SIOD 26
  195. #define CAM_PIN_SIOC 27
  196. #define CAM_PIN_D7 35
  197. #define CAM_PIN_D6 34
  198. #define CAM_PIN_D5 39
  199. #define CAM_PIN_D4 36
  200. #define CAM_PIN_D3 19
  201. #define CAM_PIN_D2 18
  202. #define CAM_PIN_D1 5
  203. #define CAM_PIN_D0 4
  204. #define CAM_PIN_VSYNC 25
  205. #define CAM_PIN_HREF 23
  206. #define CAM_PIN_PCLK 22
  207. #endif //// WROVER-KIT PIN Map
  208. #ifdef BOARD_ESP32CAM_AITHINKER // ESP32Cam (AiThinker) PIN Map
  209. #define CAM_PIN_PWDN 32
  210. #define CAM_PIN_RESET -1 //software reset will be performed
  211. #define CAM_PIN_XCLK 0
  212. #define CAM_PIN_SIOD 26
  213. #define CAM_PIN_SIOC 27
  214. #define CAM_PIN_D7 35
  215. #define CAM_PIN_D6 34
  216. #define CAM_PIN_D5 39
  217. #define CAM_PIN_D4 36
  218. #define CAM_PIN_D3 21
  219. #define CAM_PIN_D2 19
  220. #define CAM_PIN_D1 18
  221. #define CAM_PIN_D0 5
  222. #define CAM_PIN_VSYNC 25
  223. #define CAM_PIN_HREF 23
  224. #define CAM_PIN_PCLK 22
  225. #endif // ESP32Cam (AiThinker) PIN Map
  226. // ******* LED definition
  227. #ifdef USE_PWM_LEDFLASH
  228. //// PWM für Flash-LED
  229. #define LEDC_TIMER LEDC_TIMER_1 // LEDC_TIMER_0
  230. #define LEDC_MODE LEDC_LOW_SPEED_MODE
  231. #define LEDC_OUTPUT_IO FLASH_GPIO // Define the output GPIO
  232. #define LEDC_CHANNEL LEDC_CHANNEL_1
  233. #define LEDC_DUTY_RES LEDC_TIMER_13_BIT // Set duty resolution to 13 bits
  234. //#define LEDC_DUTY (195) // Set duty to 50%. ((2 ** 13) - 1) * 50% = 4095
  235. #define LEDC_FREQUENCY (5000) // Frequency in Hertz. Set frequency at 5 kHz
  236. #endif //USE_PWM_LEDFLASH
  237. //softAP
  238. #ifdef ENABLE_SOFTAP
  239. #define EXAMPLE_ESP_WIFI_SSID "AI-on-the-Edge"
  240. #define EXAMPLE_ESP_WIFI_PASS ""
  241. #define EXAMPLE_ESP_WIFI_CHANNEL 11
  242. #define EXAMPLE_MAX_STA_CONN 1
  243. #endif // ENABLE_SOFTAP
  244. #endif // ifndef defines_h