yc_terminal.c 63 KB

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