yc_terminal.c 63 KB

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