user_button.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "user_button.h"
  4. #include "iot_button.h"
  5. #include "esp_log.h"
  6. #include "freertos/FreeRTOS.h"
  7. #include "freertos/task.h"
  8. #include "freertos/queue.h"
  9. #include "freertos/semphr.h"
  10. #include "freertos/timers.h"
  11. #include "../EPD//include/EPD.h"
  12. #include <stdlib.h>
  13. #include <time.h>
  14. #include <unistd.h>
  15. #include <sys/time.h>
  16. static const char *LOG_TAG = "user button";
  17. static struct timeval btn_last_time; // 左屏超过30s,不发送按键lora信息
  18. extern QueueHandle_t button_Data_queue;
  19. // extern SemaphoreHandle_t button_semaphore;
  20. static button_handle_t user_button_handle[KEY_NUM] = {0};
  21. static button_handle_t user_powerbutton_handle[3] = {0};
  22. TimerHandle_t btn_timer_handle;
  23. RTC_FAST_ATTR static bool is_setting = false;
  24. RTC_FAST_ATTR static bool is_reset_net = false; // 配网
  25. RTC_FAST_ATTR static bool is_send_lora = false;
  26. RTC_FAST_ATTR static bool is_down = false;
  27. uint16_t adc_value[][2] =
  28. {
  29. {BAOYANG_MIN_ADC, BAOYANG_MAX_ADC},
  30. {FENGCUN_MIN_ADC, FENGCUN_MAX_ADC},
  31. {GUZHUANG_MIN_ADC, GUZHANG_MAX_ADC},
  32. {DAILIAO_MIN_ADC, DAILIAO_MAX_ADC},
  33. {TINGJI_MIN_ADC, TINGJI_MAX_ADC},
  34. {YUNXING_MIN_ADC, YUNXING_MAX_ADC},
  35. };
  36. static void press_up_cb(void *arg, void *usr_data);
  37. static void long_press_up_cb(void *arg, void *usr_data);
  38. uint16_t power_adc_value[][2] =
  39. {
  40. {0, 100},
  41. {1000, 1900},
  42. {2000, 3063},
  43. };
  44. int find_key_value(int value)
  45. {
  46. int key = 0xff;
  47. for (int i = 0; i < 6; i++)
  48. {
  49. if (
  50. (adc_value[i][1] >= value) &&
  51. (adc_value[i][0] <= value))
  52. {
  53. key = i;
  54. printf("key vaule %d\r\n", i);
  55. break;
  56. }
  57. }
  58. return key;
  59. }
  60. static void user_button_up_cb(void *arg, void *usr_data);
  61. static void power_long_press_start_cb(void *arg, void *usr_data);
  62. static void power_long_press_hold_cb(void *arg, void *usr_data);
  63. static void power_long_press_up_cb(void *arg, void *usr_data);
  64. static void power_press_up_cb(void *arg, void *usr_data);
  65. static void power_single_press_cb(void *arg, void *usr_data);
  66. static void button_down_cb(void *arg, void *usr_data);
  67. static void user_button_single_UP_cb(void *arg, void *usr_data);
  68. static void power_button_multi_press_cb(void *arg, void *usr_data);
  69. static void power_left_single_press_cb(void *arg, void *usr_data)
  70. {
  71. printf("%s\r\n", __FUNCTION__);
  72. }
  73. static void power_right_single_press_cb(void *arg, void *usr_data)
  74. {
  75. printf("%s\r\n", __FUNCTION__);
  76. }
  77. int button_idx = 0;
  78. int power_button_idx = 0;
  79. int power_button_mult_time = 0;
  80. void btn_timer_Callback(TimerHandle_t xTimer)
  81. {
  82. ESP_LOGW(LOG_TAG, "btn_timer_Callback");
  83. if (is_setting)
  84. {
  85. is_setting = false;
  86. }
  87. else if (is_reset_net)
  88. {
  89. is_reset_net = false;
  90. }
  91. is_setting = 0;
  92. // xTimerStop(btn_timer_handle,0);
  93. }
  94. static void get_rtc_time(struct tm *tmp)
  95. {
  96. struct timeval tv;
  97. gettimeofday(&tv, NULL);
  98. // 打印 RTC 时间戳
  99. printf("RTC Timestamp: %lld\n", tv.tv_sec);
  100. // 使用 localtime 函数将时间戳转换为本地时间
  101. tmp = localtime(&tv.tv_sec);
  102. // 打印本地时间
  103. printf(" get_rtc_time: %04d-%02d-%02d %02d:%02d:%02d\n",
  104. tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
  105. tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  106. }
  107. bool is_btn_timeout(void)
  108. {
  109. struct timeval now_time;
  110. gettimeofday(&now_time, NULL);
  111. ESP_LOGD(LOG_TAG, "is_send_lora= %s now_time = %lld,last = %lld,\n", is_send_lora ? "ture" : "false", now_time.tv_sec, btn_last_time.tv_sec);
  112. struct tm *tmp = localtime(&now_time.tv_sec);
  113. // ESP_LOGI(LOG_TAG,"时间: %04d-%02d-%02d %02d:%02d:%02d\n",
  114. // tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
  115. // tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  116. if (((now_time.tv_sec - btn_last_time.tv_sec) > 30) && (is_send_lora))
  117. {
  118. ESP_LOGW(LOG_TAG, "发送-----现在按键时间: %04d-%02d-%02d %02d:%02d:%02d\n",
  119. tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
  120. tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  121. is_send_lora = false;
  122. return true;
  123. }
  124. return false;
  125. }
  126. void reset_btn_last_time(void)
  127. {
  128. if (!is_send_lora)
  129. {
  130. is_send_lora = true;
  131. }
  132. gettimeofday(&btn_last_time, NULL);
  133. struct tm *tmp = localtime(&btn_last_time.tv_sec);
  134. // printf("btn_last_time: %lld\n", btn_last_time.tv_sec);
  135. ESP_LOGW(LOG_TAG, "最后按键时间: %04d-%02d-%02d %02d:%02d:%02d\n",
  136. tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
  137. tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  138. }
  139. void button_init(adc_oneshot_unit_handle_t adc_handle)
  140. {
  141. int i;
  142. printf("button_init\n");
  143. #if 1
  144. button_config_t adc_btn_cfg = {
  145. .type = BUTTON_TYPE_ADC,
  146. .long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
  147. .short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
  148. .adc_button_config = {
  149. .adc_channel = 7,
  150. .adc_handle = &adc_handle,
  151. },
  152. };
  153. // 左边6个按键初始化
  154. for (i = 0; i < KEY_NUM; i++)
  155. {
  156. adc_btn_cfg.adc_button_config.button_index = i;
  157. adc_btn_cfg.adc_button_config.min = adc_value[i][0];
  158. adc_btn_cfg.adc_button_config.max = adc_value[i][1];
  159. user_button_handle[i] = iot_button_create(&adc_btn_cfg);
  160. if (NULL == user_button_handle[i])
  161. {
  162. printf("Button create failed");
  163. }
  164. button_idx = i;
  165. iot_button_register_cb(user_button_handle[i], BUTTON_PRESS_DOWN, button_down_cb, button_idx);
  166. iot_button_register_cb(user_button_handle[i], BUTTON_PRESS_UP, user_button_up_cb, button_idx); // 松手才发按键消息
  167. // iot_button_register_cb( user_button_handle[i], BUTTON_LONG_PRESS_UP, long_press_up_cb,button_idx);
  168. // iot_button_register_cb( user_button_handle[i], BUTTON_PRESS_UP, user_button_single_click_cb,button_idx);
  169. }
  170. #endif
  171. // 电源按键
  172. btn_timer_handle = xTimerCreate(
  173. "btn_timer_handle",
  174. pdMS_TO_TICKS(10 * 1000),
  175. pdFALSE,
  176. 0,
  177. btn_timer_Callback);
  178. #if 0
  179. //右边3个按键 目前只是用一个按键 POWER
  180. button_config_t power_btn_cfg = {
  181. .type = BUTTON_TYPE_GPIO,
  182. .long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
  183. .short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
  184. .adc_button_config = {
  185. .adc_channel = 3,
  186. .adc_handle = &adc_handle,
  187. },
  188. };
  189. for(int i = 0;i < 1 ;i++)
  190. {
  191. power_btn_cfg.adc_button_config.button_index = i;
  192. power_btn_cfg.adc_button_config.min = power_adc_value[i][0] ;
  193. power_btn_cfg.adc_button_config.max = power_adc_value[i][1] ;
  194. user_powerbutton_handle[i] = iot_button_create(&power_btn_cfg);
  195. if(NULL == user_powerbutton_handle[i]) {
  196. printf( "Button create failed");
  197. }
  198. button_idx = i;
  199. iot_button_register_cb( user_powerbutton_handle[i], BUTTON_PRESS_DOWN, power_single_press_cb,button_idx);
  200. #if 0
  201. iot_button_register_cb( user_powerbutton_handle[i], BUTTON_LONG_PRESS_START, power_long_press_cb,button_idx);
  202. #else
  203. iot_button_register_cb( user_powerbutton_handle[i], BUTTON_LONG_PRESS_START, power_long_press_start_cb,button_idx);
  204. iot_button_register_cb( user_powerbutton_handle[i], BUTTON_LONG_PRESS_HOLD, power_long_press_hold_cb,button_idx);
  205. iot_button_register_cb( user_powerbutton_handle[i], BUTTON_LONG_PRESS_UP, power_long_press_up_cb,button_idx);
  206. #endif
  207. //注册按键多次按键回调
  208. button_event_config_t btn_cfg;
  209. btn_cfg.event = BUTTON_MULTIPLE_CLICK;
  210. // btn_cfg.event_data.multiple_clicks.clicks = POWER_KEY_PRSSS_COUNT_OTA;
  211. // power_button_mult_time = btn_cfg.event_data.multiple_clicks.clicks ;
  212. // iot_button_register_event_cb(user_powerbutton_handle[i], btn_cfg, power_button_multi_press_cb, power_button_mult_time);
  213. btn_cfg.event_data.multiple_clicks.clicks = POWER_KEY_PRSSS_COUNT_RESET;
  214. power_button_mult_time = btn_cfg.event_data.multiple_clicks.clicks ;
  215. iot_button_register_event_cb(user_powerbutton_handle[i], btn_cfg, power_button_multi_press_cb, power_button_mult_time);
  216. btn_cfg.event_data.multiple_clicks.clicks = POWER_KEY_PRSSS_BLE_OTA_MODE;
  217. power_button_mult_time = btn_cfg.event_data.multiple_clicks.clicks ;
  218. iot_button_register_event_cb(user_powerbutton_handle[i], btn_cfg, power_button_multi_press_cb, power_button_mult_time);
  219. // //注册按键长按按键回调
  220. // button_event_config_t btn_long_press_cfg;
  221. // btn_cfg.event = BUTTON_LONG_PRESS_START;
  222. }
  223. #else
  224. button_config_t power_btn_cfg = {
  225. .type = BUTTON_TYPE_GPIO,
  226. .long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
  227. .short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
  228. .gpio_button_config = {
  229. .gpio_num = 4,
  230. .active_level = 0,
  231. },
  232. };
  233. for (i = 0; i < 1; i++)
  234. {
  235. // power_btn_cfg.adc_button_config.button_index = i;
  236. // power_btn_cfg.adc_button_config.min = power_adc_value[i][0] ;
  237. // power_btn_cfg.adc_button_config.max = power_adc_value[i][1] ;
  238. user_powerbutton_handle[i] = iot_button_create(&power_btn_cfg);
  239. if (NULL == user_powerbutton_handle[i])
  240. {
  241. printf("Button create failed");
  242. }
  243. button_idx = i;
  244. iot_button_register_cb(user_powerbutton_handle[i], BUTTON_PRESS_DOWN, power_single_press_cb, button_idx);
  245. #if 0
  246. iot_button_register_cb( user_powerbutton_handle[i], BUTTON_LONG_PRESS_START, power_long_press_cb,button_idx);
  247. #else
  248. iot_button_register_cb(user_powerbutton_handle[i], BUTTON_LONG_PRESS_START, power_long_press_start_cb, button_idx);
  249. iot_button_register_cb(user_powerbutton_handle[i], BUTTON_LONG_PRESS_HOLD, power_long_press_hold_cb, button_idx);
  250. // iot_button_register_cb(user_powerbutton_handle[i], BUTTON_LONG_PRESS_UP, power_long_press_up_cb, button_idx);
  251. iot_button_register_cb(user_powerbutton_handle[i], BUTTON_PRESS_UP, power_press_up_cb, button_idx);
  252. #endif
  253. // 注册按键多次按键回调
  254. button_event_config_t btn_cfg;
  255. btn_cfg.event = BUTTON_MULTIPLE_CLICK;
  256. // btn_cfg.event_data.multiple_clicks.clicks = POWER_KEY_PRSSS_COUNT_OTA;
  257. // power_button_mult_time = btn_cfg.event_data.multiple_clicks.clicks ;
  258. // iot_button_register_event_cb(user_powerbutton_handle[i], btn_cfg, power_button_multi_press_cb, power_button_mult_time);
  259. btn_cfg.event_data.multiple_clicks.clicks = POWER_KEY_PRSSS_COUNT_RESET;
  260. power_button_mult_time = btn_cfg.event_data.multiple_clicks.clicks;
  261. iot_button_register_event_cb(user_powerbutton_handle[i], btn_cfg, power_button_multi_press_cb, power_button_mult_time);
  262. btn_cfg.event_data.multiple_clicks.clicks = POWER_KEY_PRSSS_DIS_RIGHT;
  263. power_button_mult_time = btn_cfg.event_data.multiple_clicks.clicks;
  264. iot_button_register_event_cb(user_powerbutton_handle[i], btn_cfg, power_button_multi_press_cb, power_button_mult_time);
  265. btn_cfg.event_data.multiple_clicks.clicks = POWER_KEY_PRSSS_BLE_OTA_MODE;
  266. power_button_mult_time = btn_cfg.event_data.multiple_clicks.clicks;
  267. iot_button_register_event_cb(user_powerbutton_handle[i], btn_cfg, power_button_multi_press_cb, power_button_mult_time);
  268. // //注册按键长按按键回调
  269. // button_event_config_t btn_long_press_cfg;
  270. // btn_cfg.event = BUTTON_LONG_PRESS_START;
  271. }
  272. #endif
  273. }
  274. void button_deinit(void)
  275. {
  276. printf("button_deinit\n");
  277. for (int i = 0; i < KEY_NUM; i++)
  278. {
  279. iot_button_delete(user_button_handle[i]);
  280. }
  281. // iot_button_delete(user_powerbutton_handle[0]);
  282. }
  283. void power_button_init(adc_oneshot_unit_handle_t adc_handle)
  284. {
  285. }
  286. void power_button_deinit(void)
  287. {
  288. for (int i = 0; i < 3; i++)
  289. iot_button_delete(user_powerbutton_handle[i]);
  290. }
  291. uint8_t button_info = 0;
  292. #include "SPIFFS.h"
  293. #if 0
  294. static void power_long_press_cb(void *arg,void *usr_data)
  295. {
  296. switch ((int)usr_data)
  297. {
  298. case 0:
  299. printf("power key long press start\r\n");
  300. button_info = POWER_ON_INTO_STATUS_CHANGE_VALUE;
  301. if(xQueueSend(button_Data_queue,&button_info,0) != true)
  302. {
  303. ESP_LOGE(LOG_TAG,"queue send is fail");
  304. return;
  305. }
  306. break;
  307. case 1:
  308. printf("power left key long press\r\n");
  309. break;
  310. }
  311. }
  312. iot_button_get_long_press_hold_cnt((button_handle_t)arg)
  313. #else
  314. static void press_up_cb(void *arg, void *usr_data)
  315. {
  316. ESP_LOGE(LOG_TAG, "BUTTON_PRESS_UP %d", (int)usr_data);
  317. }
  318. static void long_press_up_cb(void *arg, void *usr_data)
  319. {
  320. ESP_LOGE(LOG_TAG, "BUTTON_LONG_PRESS_UP %d", (int)usr_data);
  321. }
  322. static void power_long_press_start_cb(void *arg, void *usr_data)
  323. {
  324. // ESP_LOGE(LOG_TAG, "power_long_press_start_cb\n");
  325. // is_power = true;
  326. }
  327. // static void power_long_press_up_cb(void *arg, void *usr_data)
  328. // {
  329. // }
  330. static void power_press_up_cb(void *arg, void *usr_data)
  331. {
  332. is_down = false;
  333. }
  334. bool is_key_press(void)
  335. {
  336. return is_down;
  337. }
  338. void change_is_down(void)
  339. {
  340. is_down = false;
  341. }
  342. static void power_long_press_hold_cb(void *arg, void *usr_data)
  343. {
  344. // 设置的长按开始时间后开始计算hold_cnt 长按开始时间设置为1s,cnt计算时间间隔(SERIAL_TICKS)也设置为1s
  345. uint16_t hold_cnt = iot_button_get_long_press_hold_cnt((button_handle_t)arg);
  346. ESP_LOGE(LOG_TAG, " BUTTON_LONG_PRESS_HOLD[%d],count is [%d]\n", iot_button_get_ticks_time((button_handle_t)arg), hold_cnt);
  347. switch ((int)hold_cnt)
  348. {
  349. // case 1:
  350. // {
  351. // if (is_setting)
  352. // {
  353. // button_info = POWER_ON_INTO_SETTING_VALUE_LORA_0;
  354. // if (xQueueSend(button_Data_queue, &button_info, 0) != true)
  355. // {
  356. // ESP_LOGE(LOG_TAG, "queue send is fail");
  357. // return;
  358. // }
  359. // }
  360. // }
  361. case 2: // 设置模式,长按3s进入
  362. if (is_setting && is_reset_net)
  363. {
  364. ESP_LOGE(LOG_TAG, "err:OTA 和 重新配网 同时");
  365. return;
  366. }
  367. if (is_setting)
  368. {
  369. button_info = POWER_ON_INTO_OTA_VALUE;
  370. if (xQueueSend(button_Data_queue, &button_info, 0) != true)
  371. {
  372. ESP_LOGE(LOG_TAG, "queue send is fail");
  373. return;
  374. }
  375. }
  376. if (is_reset_net)
  377. {
  378. button_info = POWER_ON_INTO_RESET_VALUE;
  379. if (xQueueSend(button_Data_queue, &button_info, 0) != true)
  380. {
  381. ESP_LOGE(LOG_TAG, "queue send is fail");
  382. return;
  383. }
  384. }
  385. break;
  386. case 4: // 5s开关机
  387. if (is_setting || is_reset_net)
  388. {
  389. ESP_LOGE(LOG_TAG, "5s poweron return ");
  390. break;
  391. }
  392. button_info = POWER_ON_INTO_STATUS_CHANGE_VALUE;
  393. if (xQueueSend(button_Data_queue, &button_info, 0) != true)
  394. {
  395. ESP_LOGE(LOG_TAG, "queue send is fail");
  396. return;
  397. }
  398. break;
  399. default:
  400. // printf(" BUTTON_LONG_PRESS_HOLD[%d],count is [%d]\n", iot_button_get_ticks_time((button_handle_t)arg), hold_cnt);
  401. break;
  402. }
  403. }
  404. #endif
  405. #include "esp_sleep.h"
  406. static void power_single_press_cb(void *arg, void *usr_data)
  407. {
  408. if (Machine_info.power_status == 0)
  409. {
  410. return;
  411. }
  412. is_down = true;
  413. // ESP_LOGE(LOG_TAG, "is_down true\n");
  414. switch ((int)usr_data)
  415. {
  416. case 0:
  417. // ESP_LOGW(LOG_TAG, "power sigle press\r\n");
  418. // if (Machine_info.power_status == 1) // 开机
  419. // {
  420. button_info = POWER_ON_PRESS_VALUE;
  421. if (xQueueSend(button_Data_queue, &button_info, 0) != true)
  422. {
  423. ESP_LOGE(LOG_TAG, "queue send is fail");
  424. return;
  425. }
  426. // }
  427. // else
  428. // {
  429. // button_info = POWER_OFF_PRESS_VALUE; // 关机状态下单击按键
  430. // if (xQueueSend(button_Data_queue, &button_info, 0) != true)
  431. // {
  432. // ESP_LOGE(LOG_TAG, "queue send is fail");
  433. // return;
  434. // }
  435. // }
  436. break;
  437. case 1:
  438. printf("power left single press\r\n");
  439. break;
  440. case 2:
  441. printf("power right single press\r\n");
  442. break;
  443. }
  444. }
  445. static void button_down_cb(void *arg, void *usr_data)
  446. {
  447. ESP_LOGI(LOG_TAG, "%d true", (int)usr_data);
  448. is_down = true;
  449. }
  450. static void user_button_up_cb(void *arg, void *usr_data)
  451. {
  452. is_down = false;
  453. is_setting = false;
  454. is_reset_net = false;
  455. ESP_LOGW(LOG_TAG, " single_click_cb[%d]", iot_button_get_ticks_time((button_handle_t)arg));
  456. switch ((int)usr_data)
  457. {
  458. case BAOYANG_KEY:
  459. button_info = 6;
  460. ESP_LOGD(LOG_TAG, "bao yang");
  461. break;
  462. case FENGCUN_KEY:
  463. button_info = 5;
  464. ESP_LOGD(LOG_TAG, "feng cun");
  465. break;
  466. case GUZHUANG_KEY:
  467. button_info = 4;
  468. ESP_LOGD(LOG_TAG, "gu zhang");
  469. break;
  470. case DAILIAO_KEY:
  471. button_info = 3;
  472. ESP_LOGD(LOG_TAG, "dai liao");
  473. break;
  474. case TINGJI_KEY:
  475. button_info = 2;
  476. ESP_LOGD(LOG_TAG, "ting ji");
  477. break;
  478. case YUNXING_KEY:
  479. button_info = 1;
  480. ESP_LOGD(LOG_TAG, "yun xing");
  481. break;
  482. default:
  483. break;
  484. }
  485. #if 0
  486. if(xSemaphoreTake(button_semaphore, 0) != true)
  487. {
  488. ESP_LOGE(LOG_TAG,"button mutex is fail,not send lora queue");
  489. return;
  490. }
  491. xSemaphoreGive(button_semaphore);
  492. #endif
  493. if (Machine_info.power_status == 0) // 关机
  494. {
  495. printf("power off not refresh\r\n");
  496. return;
  497. }
  498. if (xQueueSend(button_Data_queue, &button_info, 0) != true)
  499. {
  500. ESP_LOGE(LOG_TAG, "queue send is fail");
  501. return;
  502. }
  503. }
  504. static void power_button_multi_press_cb(void *arg, void *usr_data)
  505. {
  506. if (Machine_info.power_status == 0) // 关机
  507. {
  508. printf("关机状态\r\n");
  509. return;
  510. }
  511. switch ((int)usr_data)
  512. {
  513. case POWER_KEY_PRSSS_BLE_OTA_MODE:
  514. if (!is_setting && !is_reset_net) // 当前非配置模式
  515. {
  516. is_setting = true;
  517. xTimerStart(btn_timer_handle, 0);
  518. printf("短按2次\r\n");
  519. }
  520. break;
  521. case POWER_KEY_PRSSS_DIS_RIGHT:
  522. printf("短按3次\r\n");
  523. send_button_key_queue((uint8_t)POWER_ON_INTO_DIS_RIGHT);
  524. break;
  525. case POWER_KEY_PRSSS_COUNT_RESET:
  526. if (!is_setting && !is_reset_net)
  527. {
  528. is_reset_net = true;
  529. xTimerStart(btn_timer_handle, 0);
  530. printf("短按4次\r\n");
  531. }
  532. break;
  533. }
  534. }
  535. static void user_button_single_UP_cb(void *arg, void *usr_data)
  536. {
  537. }
  538. void send_button_key_queue(uint8_t value)
  539. {
  540. button_info = value;
  541. if (xQueueSend(button_Data_queue, &button_info, 0) != true)
  542. {
  543. ESP_LOGE(LOG_TAG, "queue send is fail");
  544. return;
  545. }
  546. }