yc_terminal.c 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "freertos/FreeRTOS.h"
  5. #include "freertos/task.h"
  6. #include "freertos/queue.h"
  7. #include "freertos/semphr.h"
  8. #include "esp_log.h"
  9. #include "esp_system.h"
  10. #include "freertos/event_groups.h"
  11. #include "esp_timer.h"
  12. #include "esp_err.h"
  13. #include "user_config.h"
  14. //#include "lvgl/lvgl.h"
  15. #include"LED.h"
  16. #include"list.h"
  17. #include "freertos/timers.h"
  18. #include "user_sleep.h"
  19. #include "esp_sleep.h"
  20. #include "esp_sleep.h"
  21. //#include "ble_ota.h"
  22. #include "batt_charge.h"
  23. #include "user_time.h"
  24. #include "driver/uart.h"
  25. #include "driver/rtc_io.h"
  26. char user_device_id[50] ={0};
  27. RTC_FAST_ATTR unsigned char power = 0;
  28. #define MAX_RETRY_ACK 3 //最大重传次数停止发送数据
  29. int retry_times = 0;
  30. bool powerOn_flag = false;
  31. static const char *LOG_TAG = "user_main";
  32. extern Node *Send_list; //发送数据链表
  33. YC_DATA_T yc_data;
  34. //ListNode *list_head = NULL;
  35. adc_oneshot_unit_handle_t adc1_handle;
  36. QueueHandle_t left_screen_queue;
  37. QueueHandle_t right_screen_queue;
  38. QueueHandle_t lora_data_queue;
  39. QueueHandle_t yc_data_queue;
  40. QueueHandle_t button_Data_queue;
  41. EventGroupHandle_t screen_event;
  42. extern QueueHandle_t lora_receiveQueue; //lora底层数据上报
  43. extern QueueHandle_t lora_dealhandle; //开始处理逻辑的数据
  44. QueueHandle_t sleep_queue;
  45. QueueHandle_t wakeup_queue;
  46. QueueHandle_t Send_Data_queue; //发送链表任务
  47. SemaphoreHandle_t button_semaphore; //刷新屏幕时都得加上按键互斥锁
  48. SemaphoreHandle_t screen_semaphore; //刷新屏幕时都得加上互斥锁
  49. #if !HARDWARE_SPI
  50. struct EPD_INFO_SET left_screen = {};
  51. struct EPD_INFO_SET right_screen = {};
  52. #endif
  53. extern LORA_DATA_T lora_data;
  54. extern TERMINAL_INFO_T terminal_info;
  55. #include "y_ringbuf.h"
  56. extern struct RINGBUF_st;
  57. extern RINGBUF_st *lora_ringbuf;
  58. // static void board_init(void);
  59. // static void info_init(void);
  60. static void left_screen_task(void* arg);
  61. static void right_screen_task(void* arg);
  62. static void unpack_task(void* arg);
  63. static void lora_task(void* arg);
  64. static void button_task(void* arg);
  65. static void business_logic_task(void* arg);
  66. static void gui_task(void* pvParameter);
  67. void read_deal_data_callback_handler();
  68. // void Sendlist_task_callback_handler();
  69. void uart_task_callback_handler();
  70. void beep_open()
  71. {
  72. // Set duty to 50%
  73. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY));
  74. // Update duty to apply the new value
  75. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  76. }
  77. void beep_close()
  78. {
  79. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0));
  80. // Update duty to apply the new value
  81. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  82. }
  83. void beep_blink(uint16_t ms,uint16_t count)
  84. {
  85. for(int i =0;i<count;i++)
  86. {
  87. //printf("beep\r\n");
  88. beep_open();
  89. vTaskDelay(ms / portTICK_PERIOD_MS);
  90. beep_close();
  91. vTaskDelay(ms / portTICK_PERIOD_MS);
  92. }
  93. }
  94. /*********************************************************************************
  95. * function : user_nvs_init
  96. * Description : 添加NVS相关 获取出厂设备ID等相关参数
  97. * Input :
  98. * Output :
  99. * Author : Data : 2023 11.08
  100. **********************************************************************************/
  101. void user_nvs_init()
  102. {
  103. #include "nvs_flash.h"
  104. #include "nvs.h"
  105. nvs_handle_t my_handle;
  106. esp_err_t ret;
  107. /* Initialize NVS. */
  108. ret = nvs_flash_init();
  109. if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
  110. ESP_ERROR_CHECK(nvs_flash_erase());
  111. ret = nvs_flash_init();
  112. printf("nvs_flash_init ok\r\n");
  113. }
  114. ret = ESP_OK;
  115. if ((ret = nvs_flash_init_partition("nvs")) != ESP_OK)
  116. {
  117. printf("nvs init fail\r\n");
  118. }else
  119. {
  120. printf("nvs init ok\r\n");
  121. }
  122. ret = nvs_open_from_partition("nvs", "user_config", NVS_READONLY, &my_handle);
  123. if (ret != ESP_OK) {
  124. printf("nvs_open failed with\r\n");
  125. }
  126. size_t len = 0;
  127. char cid[50] ={0};
  128. //size_t required_size;
  129. //nvs_get_str(my_handle, "server_name", NULL, &required_size);
  130. //char* server_name = malloc(required_size);
  131. //nvs_get_str(my_handle, "server_name", server_name, &required_size);
  132. ret = nvs_get_str(my_handle,"deviceid",NULL,&len);
  133. char* result = malloc(len);
  134. nvs_get_str(my_handle, "deviceid", result, &len);
  135. switch (ret) {
  136. case ESP_OK:
  137. //printf("Read string from NVS: %s\r\n", cid);
  138. break;
  139. case ESP_ERR_NVS_NOT_FOUND:
  140. printf( "Value not found in NVS");
  141. break;
  142. default:
  143. printf("Error (%d) reading from NVS", ret);
  144. }
  145. memcpy(user_device_id,cid,len);
  146. memcpy(Machine_info.cid,cid,len);
  147. strcpy((char *)Machine_info.cid,result);
  148. // strcpy((char *)Machine_info.cid,"1tpmQwHNS");
  149. printf("device id %s,result = %s,len = %d\r\n",cid,result,len);
  150. printf("Machine_info cid %s\r\n",Machine_info.cid);
  151. nvs_close(my_handle);
  152. free(result);
  153. }
  154. extern void app_init();
  155. Machine_info_t default_info={
  156. .left_display_mode = 0,
  157. .left_state = 1,
  158. .paired = 0, //未配网
  159. .power_status = 0, //关机
  160. // .is_setting = 0, //设置模式
  161. .eflagID = 0xFF,
  162. .left_max_Quick_refresh_time = 5, //最大快刷次数
  163. .left_current_Quick_refresh_time = 0,//当前已经快刷的次数 当前快刷的次数大于设置 慢刷一次
  164. .lora_factory_channel = LORA_CHANENL,
  165. .right_max_Quick_refresh_time = 5, //最大快刷次数
  166. .right_current_Quick_refresh_time = 0,//当前已经快刷的次数 当前快刷的次数大于设置 慢刷一次
  167. .current_button.button_info = 0x01, //初始化为1(运行)
  168. .last_button.button_info = 0x01,
  169. .terminal_name = {0xD2,0xCF,0xB3,0xB2,0xD6,0xD5,0xB6,0xCB,0x00,0x00},//蚁巢终端
  170. .terminal_number = {0xD2,0xCF,0xB3,0xB2,0xB1,0xE0,0xBA,0xC5,0x00,0x00},//蚁巢编号
  171. .station_name = {0xB9,0xA4,0xD5,0xBE,0xC3,0xFB,0xB3,0xC6,0x00,0x00},//工站名称
  172. .station_number = {0xB9,0xA4,0xD5,0xBE,0xB1,0xE0,0xBA,0xC5,0x00,0x00},//工站编号
  173. .rssi = 0x64,
  174. .refresh_cycle = 2,
  175. .batt_precent = 100,
  176. .btn_operation = {0xd4,0xcb,0xd0,0xd0,0x00,0x00},
  177. .btn_breakDown_info = {0xb9,0xca,0xd5,0xcf,0x00,0x00},
  178. .btn_shutDown_info = {0xcd,0xa3,0xbb,0xfa,0x00,0x00},
  179. .btn_safeKeep_info = {0xb7,0xe2,0xb4,0xe6,0x00,0x00},
  180. .btn_upKeep_info = {0xb1,0xa3,0xd1,0xf8,0x00,0x00},
  181. .btn_waitMaterials_info = {0xb4,0xfd,0xc1,0xcf,0x00,0x00},
  182. .btn_dis_flag = {true,true,true,true,true,true},
  183. .checkIn_set[0] ={
  184. .other_name = {0xC9,0xFA,0xB2,0xFA,0x00,0x00},
  185. .checkIn_close = false,
  186. },
  187. .checkIn_set[1] ={
  188. .other_name = {0xCE,0xAC,0xD0,0xDE,0x00,0x00},
  189. .checkIn_close = false,
  190. },
  191. .checkIn_set[2] ={
  192. .other_name = {0xD1,0xB2,0xBC,0xEC,0x00,0x00},
  193. .checkIn_close = false,
  194. },
  195. .checkIn_set[3] ={
  196. .other_name = {0xB1,0xA3,0xD1,0xF8,0x00,0x00},
  197. .checkIn_close = false,
  198. },
  199. .person[0] = {
  200. .Charge_close = false,
  201. .other_name = {0xb9,0xdc,0x20,0x20,0xc0,0xed,0x20,0x20,0xd4,0xb1,0x3a,0x00,0x00,0x00},
  202. },
  203. .person[1] = {
  204. .Charge_close = false,
  205. .other_name = {0xc9,0xfa,0xb2,0xfa,0xd4,0xf0,0xc8,0xce,0xc8,0xcb,0x3a,0x00,0x00,0x00},
  206. },
  207. .person[2] = {
  208. .Charge_close = false,
  209. .other_name = {0xce,0xac,0xd0,0xde,0xd4,0xf0,0xc8,0xce,0xc8,0xcb,0x3a,0x00,0x00,0x00},
  210. },
  211. .person[3] = {
  212. .Charge_close = false,
  213. .other_name = {0xb1,0xa3,0xd1,0xf8,0xd4,0xf0,0xc8,0xce,0xc8,0xcb,0x3a,0x00,0x00,0x00},
  214. },
  215. .person[4] = {
  216. .Charge_close = false,
  217. .other_name = {0xd1,0xb2,0xbc,0xec,0xd4,0xf0,0xc8,0xce,0xc8,0xcb,0x3a,0x00,0x00,0x00},
  218. },
  219. };
  220. #define PRINT_SPIFFS 0
  221. #if PRINT_SPIFFS
  222. void printHexData(const void *ptr, size_t size) {
  223. const unsigned char *p = (const unsigned char *)ptr;
  224. for (size_t i = 0; i < size; ++i) {
  225. printf("%02x ", p[i]);
  226. if(i%16 == 0)
  227. {
  228. printf("\r\n");
  229. }
  230. }
  231. //printf("\n");
  232. }
  233. #endif
  234. void app_init()
  235. {
  236. #if 0
  237. gpio_reset_pin(4);
  238. gpio_config_t io_conf = {};
  239. io_conf.pin_bit_mask = (1<<4);
  240. io_conf.mode = GPIO_MODE_INPUT;
  241. io_conf.pull_up_en = false;
  242. gpio_config(&io_conf);
  243. while(1)
  244. {
  245. printf("power gpio is %s\r\n",gpio_get_level(4)?"high":"low");
  246. vTaskDelay(100 / portTICK_PERIOD_MS);
  247. }
  248. #endif
  249. //设置蜂鸣器声音
  250. #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
  251. led_init();
  252. #endif
  253. #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
  254. font_init();
  255. #endif
  256. #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
  257. epd_init();
  258. #endif
  259. user_sleep_into(); //休眠定时器初始化
  260. //charge_init();
  261. //decection_charging_init();
  262. left_screen_queue = xQueueCreate(10, sizeof(Machine_info_t));
  263. right_screen_queue = xQueueCreate(10, sizeof(Machine_info_t));
  264. lora_data_queue = xQueueCreate(20, sizeof(LORA_DATA_T));
  265. yc_data_queue = xQueueCreate(20, sizeof(int));
  266. button_Data_queue = xQueueCreate(10, sizeof(uint8_t));
  267. screen_semaphore = xSemaphoreCreateMutex();
  268. screen_event = xEventGroupCreate();
  269. // button_semaphore = xSemaphoreCreateMutex();
  270. #if 0
  271. lora_receiveQueue = xQueueCreate(100, sizeof(int));
  272. #else
  273. lora_dealhandle = xQueueCreate(100, sizeof(int));
  274. #endif
  275. sleep_queue = xQueueCreate(10, sizeof(uint8_t));
  276. // Send_Data_queue= xQueueCreate(10, sizeof(uint8_t)); //发送缓存数据任务
  277. if (sleep_queue != NULL) {
  278. // 创建队列成功,myQueue 包含有效的队列句柄
  279. // 在这里可以继续使用该队列
  280. } else {
  281. // 创建队列失败,myQueue 是 NULL
  282. // 需要处理创建失败的情况
  283. printf("---------------create fail-----------------\r\n");
  284. }
  285. wakeup_queue = xQueueCreate(10, sizeof(uint8_t));
  286. if (wakeup_queue != NULL) {
  287. // 创建队列成功,myQueue 包含有效的队列句柄
  288. // 在这里可以继续使用该队列
  289. } else {
  290. // 创建队列失败,myQueue 是 NULL
  291. // 需要处理创建失败的情况
  292. printf("---------------create fail-----------------\r\n");
  293. }
  294. extern unsigned char *last_paint_buf_left;
  295. extern unsigned char *last_paint_buf_right;
  296. extern uint32_t display_size;
  297. #if 0
  298. extern unsigned char *tmp_paint_buf;
  299. tmp_paint_buf = heap_caps_malloc(display_size,MALLOC_CAP_8BIT|MALLOC_CAP_SPIRAM); // 开辟 结构体句柄 所需要的空间
  300. if(tmp_paint_buf!=NULL)
  301. {
  302. //printf("tmp_paint_buf malloc success\r\n");
  303. }else
  304. {
  305. printf("tmp_paint_buf malloc fail\r\n");
  306. heap_caps_free(tmp_paint_buf);
  307. }
  308. #endif
  309. #if 1
  310. last_paint_buf_left = heap_caps_malloc(display_size,MALLOC_CAP_8BIT|MALLOC_CAP_SPIRAM); // 开辟所需要的空间
  311. if(last_paint_buf_left!=NULL)
  312. {
  313. //printf("last_paint_buf_left malloc success\r\n");
  314. }else
  315. {
  316. printf("last_paint_buf_left malloc fail\r\n");
  317. heap_caps_free(last_paint_buf_left);
  318. }
  319. last_paint_buf_right = heap_caps_malloc(display_size,MALLOC_CAP_8BIT|MALLOC_CAP_SPIRAM); // 开辟所需要的空间
  320. if(last_paint_buf_right!=NULL)
  321. {
  322. //printf("last_paint_buf_right malloc success\r\n");
  323. }else
  324. {
  325. printf("last_paint_buf_right malloc fail\r\n");
  326. heap_caps_free(last_paint_buf_right);
  327. }
  328. #endif
  329. int reson = esp_sleep_get_wakeup_cause(); //获取当前唤醒原因
  330. if(reson == ESP_SLEEP_WAKEUP_EXT1)
  331. {
  332. adc1_init();
  333. extern void dis_right_instructions();
  334. dis_right_instructions();
  335. int power_key = 0;
  336. int charge_key = 0;
  337. int value_count = 0;
  338. charge_key = gpio_get_level(2);
  339. printf("charge_key is %s\r\n",!charge_key?"charge in":"charge out");
  340. printf("charge_key is %s\r\n",!charge_key?"charge in":"charge out");
  341. printf("charge_key is %s\r\n",!charge_key?"charge in":"charge out");
  342. printf("charge_key is %s\r\n",!charge_key?"charge in":"charge out");
  343. Machine_info.batt_precent = read_battery_voltage();
  344. Machine_info.last_batt_precent = Machine_info.batt_precent;
  345. while(1)
  346. {
  347. //value++;
  348. charge_key = gpio_get_level(2);
  349. if(!charge_key) //充电中
  350. {
  351. Machine_info.batt_precent = read_battery_voltage();
  352. if(Machine_info.batt_precent <96)
  353. {
  354. user_compare_power_off(Machine_info.last_batt_precent,Machine_info.batt_precent);
  355. printf("charge_key is %s,batt=%d,last batt=%d\r\n",!charge_key?"charge in":"charge out",Machine_info.batt_precent,Machine_info.last_batt_precent);
  356. value_count++;
  357. if(value_count>60)
  358. {
  359. Machine_info.last_batt_precent = Machine_info.batt_precent;
  360. value_count = 0;
  361. }
  362. #if 0
  363. power_key = gpio_get_level(4);
  364. vTaskDelay(4000 / portTICK_PERIOD_MS);
  365. if( 0 == gpio_get_level(4))
  366. {
  367. uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
  368. printf("power on\r\n");
  369. #if 1//USER_DEEP_SLEEP_ENABLE
  370. reson = is_wake_up_reson(); //返回唤醒的原因
  371. /* ULP Risc-V read and detected a temperature above the limit */
  372. if (reson == ESP_SLEEP_WAKEUP_EXT0)
  373. {
  374. if(Machine_info.power_status == 0)
  375. {
  376. Machine_info.power_status = 1; //开机
  377. lora_set_power_level(1); //打开lora电源
  378. // Set duty to 50%
  379. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY));
  380. // Update duty to apply the new value
  381. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  382. vTaskDelay(1000/ portTICK_PERIOD_MS);
  383. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0));
  384. // Update duty to apply the new value
  385. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  386. Machine_info.left_current_Quick_refresh_time = 5;
  387. vTaskDelay(1000/ portTICK_PERIOD_MS);
  388. if(xQueueSend(left_screen_queue,&Machine_info,portMAX_DELAY) != true)
  389. {
  390. printf("left send fail\r\n");
  391. }
  392. }else if(Machine_info.power_status == 1)
  393. {
  394. printf("aready power on\r\n");
  395. }
  396. }
  397. #endif
  398. break;
  399. }
  400. #endif
  401. }
  402. }else //未充电
  403. {
  404. printf("charge_key is %s\r\n",!charge_key?"charge in":"charge out");
  405. extern void dis_right_instructions();
  406. dis_right_instructions();
  407. printf("start power off\r\n");
  408. uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
  409. #if 1 //电源按键
  410. // adc_oneshot_del_unit(adc1_handle);
  411. gpio_reset_pin(4);
  412. int ext_wakeup_pin_0 = 4;
  413. printf("Enabling EXT0 wakeup on pin GPIO%d\n", ext_wakeup_pin_0);
  414. ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(ext_wakeup_pin_0, 0));
  415. // Configure pullup/downs via RTCIO to tie wakeup pins to inactive level during deepsleep.
  416. // EXT0 resides in the same power domain (RTC_PERIPH) as the RTC IO pullup/downs.
  417. // No need to keep that power domain explicitly, unlike EXT1.
  418. ESP_ERROR_CHECK(rtc_gpio_pullup_en(ext_wakeup_pin_0));
  419. ESP_ERROR_CHECK(rtc_gpio_pulldown_dis(ext_wakeup_pin_0));
  420. gpio_reset_pin(2);
  421. const int ext_wakeup_pin_1 = 2;
  422. const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
  423. printf("Enabling EXT1 wakeup on pins GPIO%d\r\n",ext_wakeup_pin_1);
  424. ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask, ESP_EXT1_WAKEUP_ALL_LOW));
  425. #endif
  426. esp_deep_sleep_start();
  427. break;
  428. }
  429. vTaskDelay(1000 / portTICK_PERIOD_MS);
  430. }
  431. }
  432. xTaskCreate( left_screen_task, "left_screen_task", 25*1024, NULL, configMAX_PRIORITIES - 1, NULL);
  433. //idf.py 设置分区
  434. spiffs_init();
  435. extern uint32_t ulp_wakeup_result;
  436. if
  437. (
  438. (reson !=ESP_SLEEP_WAKEUP_EXT0)&&
  439. (reson !=ESP_SLEEP_WAKEUP_ULP)&&
  440. (reson !=ESP_SLEEP_WAKEUP_TIMER)
  441. )
  442. {
  443. #if PRINT_SPIFFS
  444. printHexData(&default_info,sizeof(Machine_info_t));
  445. // spiffs_write(&default_info);
  446. #endif
  447. spiffs_read_powerOn(&Machine_info);
  448. //重新初始化开机后默认关机
  449. Machine_info.power_status = 0;
  450. user_nvs_init();
  451. }
  452. if(reson == ESP_SLEEP_WAKEUP_EXT0)
  453. {
  454. #if 0
  455. adc1_init();
  456. int value = 0;
  457. while(1)
  458. {
  459. value++;
  460. adc_read_left_key_pin(adc1_handle);
  461. vTaskDelay(10 / portTICK_PERIOD_MS);
  462. if(value>10)
  463. {
  464. break;
  465. }
  466. }
  467. #else
  468. int power_key =0;
  469. adc1_init();
  470. while(1)
  471. {
  472. //value++;
  473. power_key = gpio_get_level(4);
  474. vTaskDelay(4000 / portTICK_PERIOD_MS);
  475. if( 0 == gpio_get_level(4))
  476. {
  477. if(read_battery_voltage()<10) //判断电压小于10% 不让开机
  478. {
  479. printf("start power off\r\n");
  480. uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
  481. #if 1 //电源按键
  482. // adc_oneshot_del_unit(adc1_handle);
  483. gpio_reset_pin(4);
  484. int ext_wakeup_pin_0 = 4;
  485. printf("Enabling EXT0 wakeup on pin GPIO%d\n", ext_wakeup_pin_0);
  486. ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(ext_wakeup_pin_0, 0));
  487. // Configure pullup/downs via RTCIO to tie wakeup pins to inactive level during deepsleep.
  488. // EXT0 resides in the same power domain (RTC_PERIPH) as the RTC IO pullup/downs.
  489. // No need to keep that power domain explicitly, unlike EXT1.
  490. ESP_ERROR_CHECK(rtc_gpio_pullup_en(ext_wakeup_pin_0));
  491. ESP_ERROR_CHECK(rtc_gpio_pulldown_dis(ext_wakeup_pin_0));
  492. gpio_reset_pin(2);
  493. const int ext_wakeup_pin_1 = 2;
  494. const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
  495. printf("Enabling EXT1 wakeup on pins GPIO%d\r\n",ext_wakeup_pin_1);
  496. ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask, ESP_EXT1_WAKEUP_ALL_LOW));
  497. #endif
  498. esp_deep_sleep_start();
  499. }
  500. adc_oneshot_del_unit(adc1_handle); //删除adc使用
  501. uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
  502. printf("power on-\r\n");
  503. #if 1//USER_DEEP_SLEEP_ENABLE
  504. reson = is_wake_up_reson(); //返回唤醒的原因
  505. /* ULP Risc-V read and detected a temperature above the limit */
  506. if (reson == ESP_SLEEP_WAKEUP_EXT0)
  507. {
  508. if(Machine_info.power_status == 0)
  509. {
  510. Machine_info.power_status = 1; //开机
  511. lora_set_power_level(1); //打开lora电源
  512. // Set duty to 50%
  513. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY));
  514. // Update duty to apply the new value
  515. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  516. vTaskDelay(1000/ portTICK_PERIOD_MS);
  517. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0));
  518. // Update duty to apply the new value
  519. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  520. Machine_info.left_current_Quick_refresh_time = 5;
  521. vTaskDelay(1000/ portTICK_PERIOD_MS);
  522. printf("开机刷屏\r\n");
  523. if(xQueueSend(left_screen_queue,&Machine_info,portMAX_DELAY) != true)
  524. {
  525. printf("left send fail\r\n");
  526. }
  527. }else if(Machine_info.power_status == 1){
  528. printf("aready power on\r\n");
  529. }
  530. }
  531. #endif
  532. break;
  533. }else
  534. {
  535. printf("start power off\r\n");
  536. uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
  537. #if 1 //电源按键
  538. // adc_oneshot_del_unit(adc1_handle);
  539. gpio_reset_pin(4);
  540. int ext_wakeup_pin_0 = 4;
  541. printf("Enabling EXT0 wakeup on pin GPIO%d\n", ext_wakeup_pin_0);
  542. ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(ext_wakeup_pin_0, 0));
  543. // Configure pullup/downs via RTCIO to tie wakeup pins to inactive level during deepsleep.
  544. // EXT0 resides in the same power domain (RTC_PERIPH) as the RTC IO pullup/downs.
  545. // No need to keep that power domain explicitly, unlike EXT1.
  546. ESP_ERROR_CHECK(rtc_gpio_pullup_en(ext_wakeup_pin_0));
  547. ESP_ERROR_CHECK(rtc_gpio_pulldown_dis(ext_wakeup_pin_0));
  548. gpio_reset_pin(2);
  549. const int ext_wakeup_pin_1 = 2;
  550. const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
  551. printf("Enabling EXT1 wakeup on pins GPIO%d\r\n",ext_wakeup_pin_1);
  552. ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask, ESP_EXT1_WAKEUP_ALL_LOW));
  553. #endif
  554. esp_deep_sleep_start();
  555. }
  556. }
  557. #endif
  558. printf("deep Wake up from ext0\n");
  559. }else if(reson == ESP_SLEEP_WAKEUP_ULP)
  560. {
  561. printf("wakeup_result = %ld\r\n",ulp_wakeup_result);
  562. // int key = find_key_value(ulp_wakeup_result);
  563. // printf("key = %d\r\n",key);
  564. #if 1
  565. //reson = is_wake_up_reson(); //返回唤醒的原因
  566. /* ULP Risc-V read and detected a temperature above the limit */
  567. if (reson == ESP_SLEEP_WAKEUP_ULP)
  568. {
  569. if(Machine_info.power_status == 0)
  570. {
  571. printf("left key press power off\r\n");
  572. uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
  573. #if 1
  574. font_into_sleep();
  575. #include "EPD.h"
  576. epd_sleep(SCREEN_LEFT);
  577. epd_sleep(SCREEN_RIGHT);
  578. //gpio_hold_en(PIN_L_CS);
  579. //gpio_hold_en(PIN_R_CS);
  580. // gpio_set_level(PIN_L_CS,1);
  581. // gpio_set_level(PIN_R_CS,1);
  582. //gpio_reset_pin(46);
  583. //uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
  584. //ESP_ERROR_CHECK(uart_wait_tx_done(UART_NUM_1,portMAX_DELAY));
  585. esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
  586. // gpio_set_level(LORA_TXD_PIN, 0);
  587. // gpio_set_level(LORA_RXD_PIN, 0);
  588. //uart_sleep_in_config();
  589. uart_driver_delete(UART_NUM_1);
  590. gpio_reset_pin(LORA_TXD_PIN);
  591. gpio_reset_pin(LORA_RXD_PIN);
  592. gpio_config_t io_conf = {};
  593. io_conf.pin_bit_mask = (1<<LORA_TXD_PIN);
  594. io_conf.mode = GPIO_MODE_OUTPUT;
  595. io_conf.pull_up_en = false;
  596. gpio_config(&io_conf);
  597. io_conf.pin_bit_mask = (1<<LORA_RXD_PIN);
  598. io_conf.mode = GPIO_MODE_OUTPUT;
  599. io_conf.pull_up_en = false;
  600. gpio_config(&io_conf);
  601. gpio_set_level(LORA_TXD_PIN, 0);
  602. gpio_set_level(LORA_RXD_PIN, 0);
  603. gpio_hold_en(LORA_TXD_PIN);
  604. gpio_hold_en(LORA_RXD_PIN);
  605. //电源按键
  606. // adc_oneshot_del_unit(adc1_handle);
  607. gpio_reset_pin(4);
  608. int ext_wakeup_pin_0 = 4;
  609. //printf("Enabling EXT0 wakeup on pin GPIO%d\n", ext_wakeup_pin_0);
  610. ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(ext_wakeup_pin_0, 0));
  611. // Configure pullup/downs via RTCIO to tie wakeup pins to inactive level during deepsleep.
  612. // EXT0 resides in the same power domain (RTC_PERIPH) as the RTC IO pullup/downs.
  613. // No need to keep that power domain explicitly, unlike EXT1.
  614. ESP_ERROR_CHECK(rtc_gpio_pullup_en(ext_wakeup_pin_0));
  615. ESP_ERROR_CHECK(rtc_gpio_pulldown_dis(ext_wakeup_pin_0));
  616. //充电按键
  617. gpio_reset_pin(2);
  618. const int ext_wakeup_pin_1 = 2;
  619. const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
  620. printf("Enabling EXT1 wakeup on pins GPIO%d\r\n",ext_wakeup_pin_1);
  621. ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask, ESP_EXT1_WAKEUP_ALL_LOW));
  622. esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
  623. ESP_ERROR_CHECK( esp_sleep_enable_ulp_wakeup());
  624. #endif
  625. esp_deep_sleep_start();
  626. }else
  627. {
  628. int btn = left_adc_wake_btn_send();
  629. ESP_LOGE(LOG_TAG,"btn = %d",btn);
  630. Machine_info.left_state = btn;
  631. // Set duty to 50%
  632. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY));
  633. // Update duty to apply the new value
  634. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  635. vTaskDelay(30 / portTICK_PERIOD_MS);
  636. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0));
  637. // Update duty to apply the new value
  638. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  639. #if 1
  640. if(xQueueSend(left_screen_queue,&Machine_info,portMAX_DELAY) != true)
  641. {
  642. printf("left send fail\r\n");
  643. }
  644. #endif
  645. while(1)
  646. {
  647. vTaskDelay(20 / portTICK_PERIOD_MS);
  648. }
  649. }
  650. }
  651. #endif
  652. }
  653. #if 0
  654. // info_init();
  655. // board_init();
  656. #else
  657. #if USER_DEEP_SLEEP_ENABLE
  658. int reson = is_wake_up_reson(); //返回唤醒的原因
  659. printf(" info_init reson = %d\r\n",reson);
  660. //idf.py 设置分区
  661. spiffs_init();
  662. /* not a wakeup from ULP, load the firmware */
  663. if ((reson != ESP_SLEEP_WAKEUP_ULP) && (reson != ESP_SLEEP_WAKEUP_TIMER))
  664. {
  665. #if 1
  666. //uint8_t yc_name[6] = {0xd2,0xcf,0xb3,0xb2,0x00,0x00};
  667. Machine_info_t default_info={
  668. .left_display_mode = 0,
  669. //.left_state =1,
  670. .eflagID = 0xFF,
  671. .rssi = 0x64,
  672. .refresh_cycle = 2,
  673. .batt_precent = 100,
  674. };
  675. spiffs_write(&default_info);
  676. #endif
  677. spiffs_read(&Machine_info);
  678. }else
  679. {
  680. }
  681. #endif
  682. #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
  683. lora_init();
  684. #endif
  685. #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
  686. adc1_init();
  687. #endif
  688. #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
  689. button_init(adc1_handle); //左侧按键
  690. power_button_init(adc1_handle); //右侧电源按键
  691. Machine_info.batt_precent = read_battery_voltage();
  692. Machine_info.last_batt_precent = Machine_info.batt_precent;
  693. #endif
  694. #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
  695. //timer_init();
  696. #endif
  697. //////////////////////////////////////////////////////////////////////////////////////////////////
  698. #endif
  699. xTaskCreate( button_task,"button_task",5*2048, NULL, configMAX_PRIORITIES, NULL);
  700. xTaskCreate( right_screen_task, "right_screen_task",15*1024, NULL, configMAX_PRIORITIES - 2, NULL);
  701. printf("=================================UPDATE OK===========================\r\n");
  702. #if 1
  703. xTaskCreate( business_logic_task, "business_logic_task", 25*1024, NULL, YC_TASK_NONE, NULL);
  704. //xTaskCreate( unpack_task, "unpack_task", 5*1024, NULL, YC_TASK_UNPACK, NULL);
  705. #if !USER_QIXIN //
  706. xTaskCreate( lora_task, "lora_task", 5*1024, NULL, configMAX_PRIORITIES, NULL);
  707. #endif
  708. #if 0
  709. xTaskCreate(gui_task, "gui_task", 4096 * 2, NULL, 5, NULL);
  710. #endif
  711. #if 1 //任务处理函数
  712. xTaskCreate(read_deal_data_callback_handler, "read_deal_data_task", 1024*8, NULL, configMAX_PRIORITIES , NULL);
  713. #endif
  714. //添加定时发送当前是否有链表数据
  715. // xTaskCreate(Sendlist_task_callback_handler, "Sendlist_task", 1024*8, NULL, configMAX_PRIORITIES, NULL);
  716. #endif
  717. //打印系统信息
  718. print_systenInfo();
  719. }
  720. // static void board_init(void)
  721. // {
  722. // #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
  723. // led_init();
  724. // #endif
  725. // #if USER_DEEP_SLEEP_ENABLE
  726. // int reson = is_wake_up_reson(); //返回唤醒的原因
  727. // /* ULP Risc-V read and detected a temperature above the limit */
  728. // if (reson == ESP_SLEEP_WAKEUP_ULP)
  729. // {
  730. // // Set duty to 50%
  731. // ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY));
  732. // // Update duty to apply the new value
  733. // ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  734. // vTaskDelay(30 / portTICK_PERIOD_MS);
  735. // ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0));
  736. // // Update duty to apply the new value
  737. // ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  738. // }
  739. // #endif
  740. // #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
  741. // font_init();
  742. // #endif
  743. // #if HARDWARE_SPI
  744. // #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
  745. // epd_init();
  746. // #endif
  747. // #else
  748. // left_screen.epd_name = "left_screen";
  749. // left_screen.busy_pin = 42;
  750. // left_screen.res_pin = 41;
  751. // left_screen.dc_pin = 40;
  752. // left_screen.cs_pin = 39;
  753. // left_screen.sclk_pin = 48;
  754. // left_screen.sda_pin = 45;
  755. // epd_screen_init(&left_screen);
  756. // right_screen.epd_name = "right_screen";
  757. // right_screen.busy_pin = 13;
  758. // right_screen.res_pin = 14;
  759. // right_screen.dc_pin = 21;
  760. // right_screen.cs_pin = 47;
  761. // right_screen.sclk_pin = 48;
  762. // right_screen.sda_pin = 45;
  763. // epd_screen_init(&right_screen);
  764. // #endif
  765. // #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
  766. // timer_init();
  767. // #endif
  768. // #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
  769. // //adc1_init();
  770. // #endif
  771. // //adc_read_power_pin();
  772. // //ESP_LOGI(LOG_TAG,"board_init");
  773. // #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
  774. // button_init(adc1_handle);
  775. // #endif
  776. // #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
  777. // lora_init();
  778. // #endif
  779. // }
  780. static void left_screen_task(void* arg)
  781. {
  782. extern bool is_sleep;
  783. #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE
  784. int reson = is_wake_up_reson(); //返回唤醒的原因
  785. if ((reson != ESP_SLEEP_WAKEUP_ULP) && (reson != ESP_SLEEP_WAKEUP_TIMER)&&(reson != ESP_SLEEP_WAKEUP_EXT0))
  786. {
  787. Paint_leftScreen_main_powerOn();
  788. }
  789. #endif
  790. Machine_info_t info;
  791. // if(reson == ESP_SLEEP_WAKEUP_EXT0)
  792. // {
  793. // //开机刷新左屏慕
  794. // Paint_leftScreen_main_slow(&info);
  795. // }
  796. while(1)
  797. {
  798. if(xQueueReceive(left_screen_queue, &info,(TickType_t)portMAX_DELAY))
  799. {
  800. font_exit_sleep();
  801. printf("left 拿锁\n");
  802. if(xSemaphoreTake(screen_semaphore, portMAX_DELAY) == true)
  803. // if(1)
  804. {
  805. if(Machine_info.left_current_Quick_refresh_time >= Machine_info.left_max_Quick_refresh_time)
  806. {
  807. Machine_info.left_current_Quick_refresh_time = 0;
  808. Paint_leftScreen_main_slow(&info);
  809. }
  810. else
  811. {
  812. // printf("left_current_Quick_refresh_time = %d,Machine_info.left_max_Quick_refresh_time= %d\r\n",Machine_info.left_current_Quick_refresh_time,Machine_info.left_max_Quick_refresh_time);
  813. Machine_info.left_current_Quick_refresh_time++;
  814. Paint_leftScreen_main_quick(&info);
  815. }
  816. printf("left 还锁\n");
  817. xSemaphoreGive(screen_semaphore);
  818. }
  819. else
  820. {
  821. ESP_LOGE(LOG_TAG,"left 拿锁失败 \n");
  822. }
  823. while(1)
  824. {
  825. if( (left_refresh_timer_isActive() == false) )
  826. {
  827. printf("7left refresh complete %s\r\n",left_refresh_timer_isActive()?"true":"false");
  828. break;
  829. }
  830. vTaskDelay(100/ portTICK_PERIOD_MS);
  831. }
  832. if(
  833. (Machine_info.power_status == 1)&&
  834. (Machine_info.paired == 1) //已配对
  835. )
  836. {
  837. sleep_timer_start(100); //进入睡眠
  838. }
  839. if(Machine_info.power_status == 0)
  840. {
  841. printf("=>deep sleep\r\n");
  842. uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
  843. //vTaskDelay(100/ portTICK_PERIOD_MS);
  844. #if 1 //电源按键
  845. // adc_oneshot_del_unit(adc1_handle);
  846. gpio_reset_pin(4);
  847. int ext_wakeup_pin_0 = 4;
  848. printf("Enabling EXT0 wakeup on pin GPIO%d\n", ext_wakeup_pin_0);
  849. ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup(ext_wakeup_pin_0, 0));
  850. // Configure pullup/downs via RTCIO to tie wakeup pins to inactive level during deepsleep.
  851. // EXT0 resides in the same power domain (RTC_PERIPH) as the RTC IO pullup/downs.
  852. // No need to keep that power domain explicitly, unlike EXT1.
  853. ESP_ERROR_CHECK(rtc_gpio_pullup_en(ext_wakeup_pin_0));
  854. ESP_ERROR_CHECK(rtc_gpio_pulldown_dis(ext_wakeup_pin_0));
  855. esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
  856. ESP_ERROR_CHECK( esp_sleep_enable_ulp_wakeup());
  857. #endif
  858. //adc_oneshot_del_unit(adc1_handle);
  859. esp_deep_sleep_start();
  860. }
  861. // if(Machine_info.paired == 1) //已配对
  862. // {
  863. // if(is_sleep == false) //已经进入sleep定时器
  864. // {
  865. // printf("已配对 进入睡眠\n");
  866. // sleep_timer_start(100); //进入睡眠
  867. // }
  868. // }
  869. #if 0
  870. int reson = is_wake_up_reson(); //返回唤醒的原因
  871. /* ULP Risc-V read and detected a temperature above the limit */
  872. if (reson == ESP_SLEEP_WAKEUP_ULP || reson == ESP_SLEEP_WAKEUP_TIMER) {
  873. //lora_set_power_level(0);
  874. #if 0
  875. font_into_sleep(); //关闭外设电源
  876. epd_sleep(SCREEN_LEFT);
  877. epd_sleep(SCREEN_RIGHT);
  878. #endif
  879. #if USER_LIGHT_SLEEP_ENABLE
  880. if(is_sleep == true) //已经进入sleep定时器
  881. {
  882. printf("display refresh commplete ready sleep\r\n");
  883. if(Machine_info.paired == 1) //已配对
  884. {
  885. //if(is_sleep == false) //已经进入sleep定时器
  886. {
  887. sleep_timer_start(100); //进入睡眠
  888. }
  889. }
  890. }else
  891. {
  892. printf("display refresh commplete not into sleep\r\n");
  893. }
  894. //esp_sleep_enable_timer_wakeup(TIMER_WAKEUP_TIME_US); //配置当前休眠的唤醒时间
  895. //esp_light_sleep_start();
  896. #endif
  897. #if USER_DEEP_SLEEP_ENABLE
  898. //esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
  899. //重新配置休眠唤醒时间
  900. //esp_sleep_enable_timer_wakeup(TIMER_WAKEUP_TIME_US); //配置当前休眠的唤醒时间
  901. //esp_deep_sleep_start();
  902. #endif
  903. }else
  904. {
  905. if(Machine_info.paired == 1) //已配对
  906. {
  907. if(is_sleep == false) //已经进入sleep定时器
  908. {
  909. printf("已配对 进入睡眠\n");
  910. sleep_timer_start(100); //进入睡眠
  911. }
  912. }
  913. }
  914. #endif
  915. }
  916. }
  917. }
  918. static void right_screen_task(void* arg)
  919. {
  920. extern bool is_sleep;
  921. #if USER_DEEP_SLEEP_ENABLE
  922. int reson = is_wake_up_reson(); //返回唤醒的原因
  923. if ((reson != ESP_SLEEP_WAKEUP_ULP) && (reson != ESP_SLEEP_WAKEUP_TIMER))
  924. {
  925. vTaskDelay(1000 / portTICK_PERIOD_MS);
  926. Paint_rightScreen_main_powerON();
  927. }
  928. #endif
  929. // #if USER_NOT_SLEEP_ENABLE || USER_LIGHT_SLEEP_ENABLE
  930. // //vTaskDelay(1000 / portTICK_PERIOD_MS);
  931. // Paint_rightScreen_main_powerON();
  932. // #endif
  933. int reson = is_wake_up_reson(); //返回唤醒的原因
  934. //if ((reson != ESP_SLEEP_WAKEUP_ULP) && (reson != ESP_SLEEP_WAKEUP_TIMER)&&(reson != ESP_SLEEP_WAKEUP_EXT0))
  935. {
  936. Paint_rightScreen_main_powerON();
  937. }
  938. vTaskDelay(3000 / portTICK_PERIOD_MS);
  939. Machine_info.rssi = 100;//没有获取到真数据,默认100
  940. Machine_info_t info;
  941. while(1)
  942. {
  943. if(xQueueReceive(right_screen_queue, &info, (TickType_t)portMAX_DELAY))
  944. {
  945. font_exit_sleep();
  946. ESP_LOGD(LOG_TAG,"right_screen_task");
  947. // printf("refresh %d,max %d\r\n",Machine_info.right_current_Quick_refresh_time,Machine_info.right_max_Quick_refresh_time);
  948. printf("right 拿锁\n");
  949. if(xSemaphoreTake(screen_semaphore, portMAX_DELAY) == true)
  950. // if(1)
  951. {
  952. if(Machine_info.right_current_Quick_refresh_time >= Machine_info.right_max_Quick_refresh_time)
  953. {
  954. Machine_info.right_current_Quick_refresh_time = 0;
  955. Paint_rightScreen_main_slow(&info);
  956. }else
  957. {
  958. Machine_info.right_current_Quick_refresh_time++;
  959. // Paint_rightScreen_main_quick(&info);
  960. Paint_rightScreen_main_slow(&info);
  961. }
  962. printf("right 还锁\n");
  963. xSemaphoreGive(screen_semaphore);
  964. }
  965. else
  966. {
  967. ESP_LOGE(LOG_TAG,"right 拿锁失败 \n");
  968. }
  969. while(1)
  970. {
  971. if( (right_refresh_timer_isActive() == false) )
  972. {
  973. printf("8left refresh complete %s\r\n",right_refresh_timer_isActive()?"true":"false");
  974. break;
  975. }
  976. vTaskDelay(100/ portTICK_PERIOD_MS);
  977. }
  978. #if 1
  979. int reson = is_wake_up_reson(); //返回唤醒的原因
  980. /* ULP Risc-V read and detected a temperature above the limit */
  981. if (reson == ESP_SLEEP_WAKEUP_ULP || reson == ESP_SLEEP_WAKEUP_TIMER) {
  982. //lora_set_power_level(0);
  983. #if USER_LIGHT_SLEEP_ENABLE
  984. if(is_sleep == true) //已经进入sleep定时器
  985. {
  986. printf("display right refresh commplete ready sleep\r\n");
  987. if(Machine_info.paired == 1) //已配对
  988. {
  989. //if(is_sleep == false) //已经进入sleep定时器
  990. {
  991. sleep_timer_start(100); //进入睡眠
  992. }
  993. }
  994. }else
  995. {
  996. printf("display right refresh commplete not into sleep\r\n");
  997. }
  998. //esp_sleep_enable_timer_wakeup(TIMER_WAKEUP_TIME_US); //配置当前休眠的唤醒时间
  999. //esp_light_sleep_start();
  1000. #endif
  1001. #if 0
  1002. font_into_sleep(); //关闭外设电源
  1003. epd_sleep(SCREEN_LEFT);
  1004. epd_sleep(SCREEN_RIGHT);
  1005. #endif
  1006. #if USER_LIGHT_SLEEP_ENABLE
  1007. //esp_sleep_enable_timer_wakeup(TIMER_WAKEUP_TIME_US); //配置当前休眠的唤醒时间
  1008. //esp_light_sleep_start();
  1009. #endif
  1010. #if USER_DEEP_SLEEP_ENABLE
  1011. //重新配置休眠唤醒时间
  1012. //esp_sleep_enable_timer_wakeup(TIMER_WAKEUP_TIME_US); //配置当前休眠的唤醒时间
  1013. //esp_deep_sleep_start();
  1014. #endif
  1015. }else
  1016. {
  1017. if(Machine_info.paired == 1) //已配对
  1018. {
  1019. if(is_sleep == false) //已经进入sleep定时器
  1020. {
  1021. sleep_timer_start(100); //进入睡眠
  1022. }
  1023. }
  1024. printf("sleep = %d\r\n",is_sleep);
  1025. }
  1026. #endif
  1027. }
  1028. }
  1029. }
  1030. static void button_task(void* arg)
  1031. {
  1032. //update_last_button_info(Machine_info.current_button.button_info);//初始化上个按键为运行,用作paint0703计时
  1033. uint8_t button_info;
  1034. while(1)
  1035. {
  1036. if(xQueueReceive(button_Data_queue, &button_info, (TickType_t)portMAX_DELAY))
  1037. {
  1038. ESP_LOGI(LOG_TAG,"btn_flag[%d][%d][%d][%d][%d][%d],button_info = [%d]%s ",Machine_info.btn_dis_flag[0],\
  1039. Machine_info.btn_dis_flag[1],Machine_info.btn_dis_flag[2],Machine_info.btn_dis_flag[3],Machine_info.btn_dis_flag[4],\
  1040. Machine_info.btn_dis_flag[5],button_info,Machine_info.power_status?"开机":"关机");
  1041. ESP_LOGI(LOG_TAG,"batt_precent[%d]\ncid[%s]\nlast_button[%d]\nlora_new_channel[%d]\neflagID[%d]\nDuration_time[%ld]rssi[%d]paired[%s]",\
  1042. Machine_info.batt_precent,\
  1043. Machine_info.cid,\
  1044. Machine_info.last_button.button_info,\
  1045. Machine_info.lora_new_channel,\
  1046. Machine_info.eflagID,\
  1047. Machine_info.Duration_time,\
  1048. Machine_info.rssi,\
  1049. Machine_info.paired?"已配网":"未配网");
  1050. if(button_info < 0x12) //左屏慕按键
  1051. {
  1052. if(Machine_info.btn_dis_flag[button_info-1] == false)
  1053. {
  1054. printf("按键关闭,默认运行\n");
  1055. button_info = STATE_OPERATION;//按键关闭,默认运行
  1056. if((Machine_info.power_status == 1) && (Machine_info.paired == 1))
  1057. {
  1058. sleep_timer_start(100); //进入睡眠
  1059. }
  1060. }
  1061. Machine_info .current_button.button_info = button_info;
  1062. //判断当前的按键状态 设置为当前状态后 再次按键不处理
  1063. printf("last btn = %d ,curr btn = %d\n",Machine_info.last_button.button_info , Machine_info.current_button.button_info);
  1064. if(Machine_info.last_button.button_info != Machine_info.current_button.button_info)
  1065. {
  1066. if(Machine_info.paired == 1)
  1067. {
  1068. printf("paired add data to list chanl = 0x%02x\r\n",Machine_info.lora_new_channel);
  1069. getRtcTime(&Machine_info); //获取当前时间
  1070. //更新当前时间
  1071. Machine_info.current_button.button_info = button_info;
  1072. Machine_info.current_button.Year = Machine_info.year;
  1073. Machine_info.current_button.Month = Machine_info.month;
  1074. Machine_info.current_button.Day = Machine_info.day;
  1075. Machine_info.current_button.Hour = Machine_info.hour;
  1076. Machine_info.current_button.Minute = Machine_info.min;
  1077. Machine_info.current_button.Second = Machine_info.sec;
  1078. long long current_Duration_time = calculate_minutes_difference
  1079. (
  1080. Machine_info.last_button.Year,
  1081. Machine_info.last_button.Month ,
  1082. Machine_info.last_button.Day ,
  1083. Machine_info.last_button.Hour ,
  1084. Machine_info.last_button.Minute ,
  1085. Machine_info.last_button.Second ,
  1086. Machine_info.current_button.Year,
  1087. Machine_info.current_button.Month ,
  1088. Machine_info.current_button.Day ,
  1089. Machine_info.current_button.Hour ,
  1090. Machine_info.current_button.Minute ,
  1091. Machine_info.current_button.Second
  1092. );
  1093. Machine_info.Duration_time = current_Duration_time;//持续时长
  1094. printf("Machine_info.Duration_time = %ld\r\n",Machine_info.Duration_time);
  1095. reset_btn_last_time();
  1096. #if 0
  1097. printf("list before\r\n");
  1098. printList(Send_list);
  1099. if(Machine_info.Duration_time == 0)
  1100. {
  1101. deleteNode_head(Send_list);
  1102. }
  1103. printf("list after\r\n");
  1104. printList(Send_list);
  1105. #endif
  1106. set_status_heights();
  1107. Machine_info.Duration_time = 0;
  1108. //更新上次的状态
  1109. update_last_button_info(Machine_info.last_button.button_info);
  1110. }else
  1111. {
  1112. // f_send_get_chart_data();
  1113. printf("not add data to list\r\n");
  1114. }
  1115. Machine_info.last_button.button_info = Machine_info.current_button.button_info;
  1116. // Machine_info.left_state = button_info;
  1117. Machine_info.left_state = Machine_info.current_button.button_info;
  1118. ESP_LOGE(LOG_TAG,"----Machine_info.left_state = %d",Machine_info.left_state);
  1119. #if 1
  1120. if(xQueueSend(left_screen_queue,&Machine_info,portMAX_DELAY) != true)
  1121. {
  1122. ESP_LOGE(LOG_TAG,"queue:left_screen_queue");
  1123. }
  1124. #endif
  1125. // Set duty to 50%
  1126. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY));
  1127. // Update duty to apply the new value
  1128. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  1129. vTaskDelay(30 / portTICK_PERIOD_MS);
  1130. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0));
  1131. // Update duty to apply the new value
  1132. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  1133. //printList(Send_list);
  1134. //printList(list_head);
  1135. }
  1136. else//和上个按键重复,唤醒原因为ulp唤醒,不进入休眠
  1137. {
  1138. printf("和上个按键重复,唤醒原因为ulp唤醒,不进入休眠\r\n");
  1139. sleep_timer_start(100); //开始进入倒计时休眠
  1140. }
  1141. }else //右屏幕按键触发
  1142. {
  1143. if(button_info == POWER_ON_PRESS_VALUE) //power 开机时短按
  1144. {
  1145. // Set duty to 50%
  1146. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY));
  1147. // Update duty to apply the new value
  1148. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  1149. vTaskDelay(30 / portTICK_PERIOD_MS);
  1150. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0));
  1151. // Update duty to apply the new value
  1152. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  1153. if( (Machine_info.power_status == 1) && (Machine_info.paired == 1))
  1154. {
  1155. //判断当前开机 是否配对 继续执行时间片操作
  1156. sleep_timer_start(100); //开始进入倒计时休眠
  1157. }
  1158. }
  1159. if(button_info == POWER_OFF_PRESS_VALUE) //power 关机时短按
  1160. {
  1161. sleep_timer_start(100); //开始进入倒计时休眠
  1162. }
  1163. if(button_info == POWER_ON_INTO_STATUS_CHANGE_VALUE) //power 长按触发
  1164. {
  1165. // Set duty to 50%
  1166. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY));
  1167. // Update duty to apply the new value
  1168. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  1169. vTaskDelay(1000 / portTICK_PERIOD_MS);
  1170. ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0));
  1171. // Update duty to apply the new value
  1172. ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
  1173. if(Machine_info.power_status == 1) //开机状态
  1174. {
  1175. Machine_info.power_status = 0;
  1176. dis_instructions();
  1177. vTaskDelay(1000 / portTICK_PERIOD_MS);
  1178. sleep_timer_start(100); //开始进入倒计时休眠
  1179. printf("last power on current power off ready sleep\r\n");
  1180. // sleep_timer_start(100); //开始进入倒计时休眠 //更改为刷完两个屏幕,倒计时
  1181. }
  1182. else if(Machine_info.power_status == 0)
  1183. {
  1184. printf("power on\r\n");
  1185. Machine_info.power_status = 1;
  1186. lora_set_power_level(1);
  1187. font_exit_sleep();
  1188. gpio_hold_dis(LORA_TXD_PIN);
  1189. gpio_hold_dis(LORA_RXD_PIN);
  1190. gpio_hold_dis(PIN_L_CS);
  1191. gpio_hold_dis(PIN_R_CS);
  1192. //恢复串口i功能
  1193. uart_sleep_out_config();
  1194. Paint_leftScreen_main_slow(&Machine_info);
  1195. Paint_rightScreen_main_slow(&Machine_info);
  1196. // Paint_leftScreen_main_quick(&Machine_info);
  1197. // Paint_rightScreen_main_quick(&Machine_info);
  1198. if( (Machine_info.power_status == 1) && (Machine_info.paired == 1))
  1199. {
  1200. //判断当前开机 是否配对 继续执行时间片操作
  1201. sleep_timer_start(100); //开始进入倒计时休眠
  1202. }
  1203. }
  1204. }
  1205. if(button_info == POWER_ON_INTO_DIS_RIGHT)
  1206. {
  1207. if(xQueueSend(right_screen_queue,&Machine_info,portMAX_DELAY) != true)
  1208. {
  1209. ESP_LOGE(LOG_TAG,"queue:right_screen_queue");
  1210. }
  1211. }
  1212. if(button_info == POWER_ON_INTO_OTA_VALUE) //进入OTA模式
  1213. {
  1214. beep_blink(50,3);
  1215. printf("into ota mode\r\n");
  1216. #include "iot_button.h"
  1217. iot_button_stop();
  1218. esp_ble_ota();
  1219. }
  1220. if(button_info == POWER_ON_INTO_RESET_VALUE) //进入配网模式
  1221. {
  1222. beep_blink(2000,1);
  1223. printf("into reset mode\r\n");
  1224. font_exit_sleep();
  1225. lora_set_power_level(1);
  1226. uart_sleep_out_config();
  1227. #include "user_sleep.h"
  1228. //#include "esp_sleep.h"
  1229. extern void sleep_timer_stop();
  1230. extern void Already_send_timer_stop();
  1231. sleep_timer_stop();
  1232. Already_send_timer_stop();
  1233. // //修改信道前修改设备ID 及 设备ID
  1234. // dymatic_change_device_id(0x00000001);
  1235. // dymatic_change_dst_device_id(0xFFFFFFFF);
  1236. // //切换信道
  1237. // dymatic_change_chanel(Machine_info.lora_factory_channel); //切换信道
  1238. // // spiffs_read(&Machine_info);
  1239. vTaskDelay(300 / portTICK_PERIOD_MS);
  1240. reset_default(true,1);
  1241. reset_lora(LORA_CHANENL);
  1242. vTaskDelay(300 / portTICK_PERIOD_MS);
  1243. }
  1244. }
  1245. }
  1246. }
  1247. }
  1248. static void business_logic_task(void* arg)
  1249. {
  1250. //YC_DATA_T tmp;
  1251. int len = 0;
  1252. bool is_refresh =false;
  1253. for(;;)
  1254. {
  1255. if(xQueueReceive(yc_data_queue, &len, (TickType_t)portMAX_DELAY))
  1256. {
  1257. #if 1
  1258. is_refresh = subcontract(&yc_data);
  1259. if(is_refresh)
  1260. {
  1261. screen_display();
  1262. }else
  1263. {
  1264. printf("not display fresh\r\n");
  1265. }
  1266. #endif
  1267. free(yc_data.data); //释放内存
  1268. yc_data.data = NULL;
  1269. yc_data.len = 0;
  1270. yc_data.index = 0;
  1271. }
  1272. }
  1273. }
  1274. static void unpack_task(void* arg)
  1275. {
  1276. LORA_DATA_T tmp_data;
  1277. extern esp_timer_handle_t lora_timer;
  1278. for(;;)
  1279. {
  1280. if(xQueueReceive(lora_data_queue, &tmp_data, (TickType_t)portMAX_DELAY))
  1281. {
  1282. if(!esp_timer_is_active(lora_timer))
  1283. {
  1284. lora_timer_start();
  1285. }
  1286. else
  1287. {
  1288. lora_timer_restart();
  1289. }
  1290. yc_data.len += tmp_data.data_len;
  1291. memcpy(yc_data.data+yc_data.index,tmp_data.data_buf,tmp_data.data_len);
  1292. yc_data.index += tmp_data.data_len;
  1293. }
  1294. }
  1295. }
  1296. static void lora_task(void* arg)
  1297. {
  1298. lora_event_task(arg);
  1299. }
  1300. // /*********************************************************************************
  1301. // * function : Sendlist_task_callback_handler
  1302. // * Description : 发送处理链表函数
  1303. // * Input :
  1304. // * Output :
  1305. // * Author : 祁鑫 Data : 2023 9.12
  1306. // **********************************************************************************/
  1307. // void Sendlist_task_callback_handler()
  1308. // {
  1309. // int length = 0;
  1310. // uint8_t* result = (uint8_t*) malloc(buffer_size+1);
  1311. // TickType_t xLastWakeTime;
  1312. // #if 0
  1313. // const TickType_t xFrequency = 400/10; // 定时通知的间隔
  1314. // #else
  1315. // const TickType_t xFrequency = 500/10; // 定时通知的间隔
  1316. // #endif
  1317. // // 初始化xLastWakeTime
  1318. // xLastWakeTime = xTaskGetTickCount();
  1319. // int receive_times = 0;
  1320. // int user_size = 0;
  1321. // int result_length = 0;
  1322. // //int result_length = 0;
  1323. // static int result_index = 0;
  1324. // int result_data_len = 0;
  1325. // while (1) {
  1326. // #if 0
  1327. // //定时通知数据处理任务有新数据可用
  1328. // vTaskDelayUntil(&xLastWakeTime, xFrequency);
  1329. // #endif
  1330. // if(xQueueReceive(Send_Data_queue, &length, portMAX_DELAY) == pdPASS)
  1331. // {
  1332. // //int len = countNodes(Send_list); /* returns the number of nodes in the list */
  1333. // Node *list = Send_list; //发送数据链表
  1334. // int len = countNodes(Send_list); /* returns the number of nodes in the list */
  1335. // if(len!=0)
  1336. // {
  1337. // printf("current wait send num data=%d\r\n",len);
  1338. // #if 1
  1339. // //int len = countNodes(list); /* returns the number of nodes in the list */
  1340. // while(len)
  1341. // {
  1342. // //int busy = get_lora_busy_pin();
  1343. // //printf("busy = %d\r\n",busy);
  1344. // printf("send times\r\n");
  1345. // //if()
  1346. // lora_send_data((char *)list->data,list->len);
  1347. // list=list->next;
  1348. // len--;
  1349. // }
  1350. // //Send_list = deleteList(Send_list);
  1351. // free(list);
  1352. // #endif
  1353. // }
  1354. // #if 0
  1355. // for (int i = 0; i < len; i++)
  1356. // {
  1357. // printf("%02x",result[i]);
  1358. // }
  1359. // #endif
  1360. // }
  1361. // }
  1362. // }
  1363. /*********************************************************************************
  1364. * function : uart_task_callback_handler
  1365. * Description : 串口0函数
  1366. * Input :
  1367. * Output :
  1368. * Author : 祁鑫 Data : 2023 9.12
  1369. **********************************************************************************/
  1370. void uart_task_callback_handler()
  1371. {
  1372. // #include "driver/uart.h"
  1373. // uint8_t dtmp[200]= {0};
  1374. // while (1)
  1375. // {
  1376. // printf("uart 0 rev = ");
  1377. // int len = uart_read_bytes(UART_NUM_0, dtmp, 1024,200/portTICK_PERIOD_MS);
  1378. // if(len)
  1379. // {
  1380. // for(int i = 0;i<len;i++)
  1381. // printf("%02X",dtmp[i]);
  1382. // printf("\r\n");
  1383. // }
  1384. // printf("\r\n");
  1385. // vTaskDelay(1000 / portTICK_PERIOD_MS);
  1386. // }
  1387. }
  1388. /*********************************************************************************
  1389. * function : read_deal_data_callback_handler
  1390. * Description : 定时处理函数
  1391. * Input :
  1392. * Output :
  1393. * Author : 祁鑫 Data : 2023 9.12
  1394. **********************************************************************************/
  1395. void read_deal_data_callback_handler()
  1396. {
  1397. #if 0
  1398. int length = 0;
  1399. uint8_t* result = (uint8_t*) malloc(buffer_size+1);
  1400. TickType_t xLastWakeTime;
  1401. #if 1
  1402. const TickType_t xFrequency = 100/10; // 定时通知的间隔
  1403. #else
  1404. const TickType_t xFrequency = 500; // 定时通知的间隔
  1405. #endif
  1406. // 初始化xLastWakeTime
  1407. xLastWakeTime = xTaskGetTickCount();
  1408. int receive_times = 0;
  1409. int user_size = 0;
  1410. int result_length = 0;
  1411. //int result_length = 0;
  1412. static int result_index = 0;
  1413. int result_data_len = 0;
  1414. #include "y_ringbuf.h"
  1415. extern struct RINGBUF_st;
  1416. extern RINGBUF_st *lora_ringbuf;
  1417. while (1) {
  1418. // 定时通知数据处理任务有新数据可用
  1419. vTaskDelayUntil(&xLastWakeTime, xFrequency);
  1420. user_size = y_ringbuf_get_used_size(lora_ringbuf);
  1421. #if USER_OTA
  1422. if(user_size>=0)
  1423. #endif
  1424. if(user_size>0)
  1425. {
  1426. #if 0
  1427. for (int i = 0; i < len; i++)
  1428. {
  1429. printf("%02x",result[i]);
  1430. }
  1431. #endif
  1432. printf("times comming length=%d\r\n",user_size);
  1433. if(user_size == 36)
  1434. {
  1435. y_ringbuf_read_clear(lora_ringbuf, result, user_size); //读取并清除数据
  1436. }
  1437. #if 1
  1438. int len = y_ringbuf_read_clear(lora_ringbuf, result, user_size); //读取并清除数据
  1439. yc_data.len = user_size;
  1440. yc_data.data = malloc(sizeof(uint8_t)*user_size);//分配内存
  1441. memcpy(yc_data.data,result,user_size);
  1442. //lora_send_queue_callback(result,len); //发送消息处理函数
  1443. if(xQueueSend(yc_data_queue,&len,0) != true)
  1444. {
  1445. ESP_LOGE(LOG_TAG,"yc_data_queue send is fail");
  1446. }
  1447. #endif
  1448. #if USER_OTA
  1449. if((user_size>1024)||(user_size == 0) || (((user_size<1024))&&(is_ota ==true)) )
  1450. if(xQueueSend(ota_queue,&user_size,0) != true)
  1451. {
  1452. ESP_LOGE(LOG_TAG,"ota_queue send is fail");
  1453. }
  1454. #endif
  1455. }
  1456. }
  1457. #else
  1458. int length = 0;
  1459. uint8_t* result = (uint8_t*) malloc(buffer_size+1);
  1460. int user_size = 0;
  1461. while(1){
  1462. if(xQueueReceive(lora_dealhandle, &length, portMAX_DELAY) == pdPASS)
  1463. {
  1464. if(rssi!=0)
  1465. {
  1466. Machine_info.rssi = rssi;
  1467. }
  1468. //printf("deal data\r\n");
  1469. user_size = y_ringbuf_get_used_size(lora_ringbuf);
  1470. if(user_size>0)
  1471. {
  1472. printf("times comming length=%d\r\n",user_size);
  1473. #if 0
  1474. if(user_size == 36)
  1475. {
  1476. y_ringbuf_read_clear(lora_ringbuf, result, user_size); //读取并清除数据
  1477. #if 1
  1478. for (int i = 0; i < user_size; i++)
  1479. {
  1480. printf("%02x",result[i]);
  1481. }
  1482. #endif
  1483. }else
  1484. #endif
  1485. {
  1486. #if 1
  1487. int len = y_ringbuf_read_clear(lora_ringbuf, result, user_size); //读取并清除数据
  1488. #if 1
  1489. for (int i = 0; i < user_size; i++)
  1490. {
  1491. printf("%02x",result[i]);
  1492. }
  1493. printf("\r\n");
  1494. #endif
  1495. yc_data.len = user_size;
  1496. yc_data.data = malloc(sizeof(uint8_t)*user_size);//分配内存
  1497. memcpy(yc_data.data,result,user_size);
  1498. //lora_send_queue_callback(result,len); //发送消息处理函数
  1499. if(xQueueSend(yc_data_queue,&len,(TickType_t)portMAX_DELAY) != true)
  1500. {
  1501. ESP_LOGE(LOG_TAG,"yc_data_queue send is fail");
  1502. }
  1503. #endif
  1504. }
  1505. }
  1506. }
  1507. }
  1508. #endif
  1509. }
  1510. // #define MY_DISP_HOR_RES 648
  1511. // #define MY_DISP_VER_RES 480
  1512. // #define DISP_BUF_SIZE (480 * 648)
  1513. // volatile bool disp_flush_enabled = true;
  1514. // /* Enable updating the screen (the flushing process) when disp_flush() is called by LVGL
  1515. // */
  1516. // void disp_enable_update(void)
  1517. // {
  1518. // disp_flush_enabled = true;
  1519. // }
  1520. // /* Disable updating the screen (the flushing process) when disp_flush() is called by LVGL
  1521. // */
  1522. // void disp_disable_update(void)
  1523. // {
  1524. // disp_flush_enabled = false;
  1525. // }
  1526. // /*Flush the content of the internal buffer the specific area on the display.
  1527. // *`px_map` contains the rendered image as raw pixel map and it should be copied to `area` on the display.
  1528. // *You can use DMA or any hardware acceleration to do this operation in the background but
  1529. // *'lv_display_flush_ready()' has to be called when it's finished.*/
  1530. // void disp_driver_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map)
  1531. // // static void disp_flush(lv_display_t * disp_drv, const lv_area_t * area, lv_color_t * px_map)
  1532. // {
  1533. // //printf("-------------------disp_flush \r\n");
  1534. // if(disp_flush_enabled) {
  1535. // /*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
  1536. // int32_t x;
  1537. // int32_t y;
  1538. // printf("%d,%d,%d,%d\r\n",area->x1, area->y1, area->x2, area->y2);
  1539. // epd_partial_cache1( area->x1, area->y1, area->x2, area->y2,SCREEN_LEFT,color_map);
  1540. // epd_powerOn_refresh(SCREEN_LEFT);
  1541. // #if 0
  1542. // for(y = area->y1; y <= area->y2; y++) {
  1543. // for(x = area->x1; x <= area->x2; x++) {
  1544. // printf("%ld,%ld\r\n",x,y);
  1545. // /*Put a pixel to the display. For example:*/
  1546. // /*put_px(x, y, *px_map)*/
  1547. // px_map++;
  1548. // }
  1549. // }
  1550. // #endif
  1551. // }
  1552. // /*IMPORTANT!!!
  1553. // *Inform the graphics library that you are ready with the flushing*/
  1554. // #if 0
  1555. // lv_display_flush_ready(disp_drv);
  1556. // #else
  1557. // lv_disp_flush_ready(drv);
  1558. // #endif
  1559. // }
  1560. // #if 0
  1561. // static uint8_t *buf_3_1;
  1562. // static uint8_t *buf_3_2;
  1563. // #else
  1564. // static uint8_t *buf;
  1565. // #endif
  1566. // static void gui_task(void* pvParameter)
  1567. // {
  1568. // #if 0
  1569. // lv_init();
  1570. // //buf= heap_caps_malloc(DISP_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA|MALLOC_CAP_SPIRAM);
  1571. // //assert(buf != NULL);
  1572. // /*------------------------------------
  1573. // * Create a display and set a flush_cb
  1574. // * -----------------------------------*/
  1575. // lv_display_t * disp = lv_display_create(MY_DISP_HOR_RES, MY_DISP_VER_RES);
  1576. // lv_display_set_flush_cb(disp, disp_flush);
  1577. // /* Example 3
  1578. // * Two buffers screen sized buffer for double buffering.
  1579. // * Both LV_DISPLAY_RENDER_MODE_DIRECT and LV_DISPLAY_RENDER_MODE_FULL works, see their comments*/
  1580. // buf_3_1= heap_caps_malloc(MY_DISP_HOR_RES *MY_DISP_VER_RES, MALLOC_CAP_8BIT);
  1581. // buf_3_2= heap_caps_malloc(MY_DISP_HOR_RES *MY_DISP_VER_RES, MALLOC_CAP_8BIT);
  1582. // if(buf_3_1 ==NULL)
  1583. // {
  1584. // printf("-------------------buf_3_1 \r\n");
  1585. // }
  1586. // if(buf_3_2 ==NULL)
  1587. // {
  1588. // printf("-------------------buf_3_2 \r\n");
  1589. // }
  1590. // lv_display_set_draw_buffers(disp, buf_3_1, buf_3_2, sizeof(buf_3_1)*MY_DISP_HOR_RES *MY_DISP_VER_RES, LV_DISPLAY_RENDER_MODE_DIRECT);
  1591. // lv_theme_t * th = lv_theme_mono_init(disp, true, &lv_font_montserrat_14);
  1592. // bool is = lv_theme_mono_is_inited();
  1593. // if(is)printf("========================ok=================\r\n");
  1594. // else printf("========================fail=================\r\n");
  1595. // lv_disp_set_theme(disp, th); /*Assign the theme to the display*/
  1596. // /*Create a white label, set its text and align it to the center*/
  1597. // lv_obj_t * label = lv_label_create(lv_scr_act());
  1598. // lv_label_set_text(label, "Hello world");
  1599. // lv_obj_set_style_text_color(lv_scr_act(), lv_color_hex(0xffffff), LV_PART_MAIN);
  1600. // lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
  1601. // #else
  1602. // lv_init();
  1603. // //disp_driver_init();
  1604. // static lv_disp_draw_buf_t disp_buf;
  1605. // uint32_t size_in_px = DISP_BUF_SIZE;
  1606. // buf= heap_caps_malloc(MY_DISP_HOR_RES *MY_DISP_VER_RES, MALLOC_CAP_8BIT);
  1607. // lv_disp_draw_buf_init(&disp_buf, buf, NULL, size_in_px);
  1608. // lv_disp_drv_t disp_drv;
  1609. // lv_disp_drv_init(&disp_drv);
  1610. // disp_drv.flush_cb = disp_driver_flush;
  1611. // disp_drv.hor_res = 648;
  1612. // disp_drv.ver_res = 480;
  1613. // disp_drv.full_refresh = 1;
  1614. // disp_drv.draw_buf = &disp_buf;
  1615. // lv_disp_t * disp = lv_disp_drv_register(&disp_drv);
  1616. // lv_disp_rot_t dir = lv_disp_get_rotation(disp);
  1617. // lv_disp_set_rotation(disp, LV_DISP_ROT_180);
  1618. // printf("dir=%d\r\n",dir);
  1619. // /*Create a white label, set its text and align it to the center*/
  1620. // lv_obj_t * label = lv_label_create(lv_scr_act());
  1621. // lv_label_set_text(label, "Hello world");
  1622. // lv_obj_set_style_bg_color(lv_scr_act(), lv_color_make(0,0,0), 0);//设置背景颜色为白色
  1623. // lv_obj_set_style_text_color(lv_scr_act(), lv_color_hex(0xffffff), LV_PART_MAIN);
  1624. // lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
  1625. // lv_obj_t * label1 = lv_label_create(lv_scr_act());
  1626. // lv_label_set_text(label1, "world");
  1627. // //lv_obj_set_style_bg_color(lv_scr_act(), lv_color_make(0,0,0), 0);//设置背景颜色为白色
  1628. // lv_obj_set_style_text_color(lv_scr_act(), lv_color_hex(0xffffff), LV_PART_MAIN);
  1629. // //lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
  1630. // lv_obj_set_pos(label1,0,20);
  1631. // //sgf_lvgl_display(&info);
  1632. // lv_refr_now(NULL);
  1633. // // if (wait_second != 0) {
  1634. // // ESP_LOGI(TAG, "wait=%ds", wait_second);
  1635. // // vTaskDelay(pdMS_TO_TICKS(1000 * wait_second));
  1636. // // }
  1637. // // gpio_weekup_init_s(sleep_second);
  1638. // #endif
  1639. // //lv_refr_now(disp);
  1640. // for(;;) {
  1641. // lv_tick_inc(10); /*Use a not round number to cover more anim states */
  1642. // lv_timer_handler();
  1643. // vTaskDelay(10 / portTICK_PERIOD_MS);
  1644. // }
  1645. // }