MCPcopy Create free account
hub / github.com/circircir-circle/human_exist_device / loop

Function loop

ESP32_LD2410/src/main.cpp:486–604  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

484int i = 0;
485
486void loop()
487{
488 char msg[100];
489 char title[100];
490 delay(100);
491 int invalid_frames = 0;
492 // V1.0.3 加入条件判断: 只有当自动重启后, 或者蓝牙已关闭的情况, 才引入自动重启机制
493 if ((bootCount > 1) || (resr_count_down <= 0)) {
494 // V1.0.2 发现设备有几率失联的问题, 因此当检测到断网或者连不上mqtt时, 自动重启
495// Serial.println("check network");
496 if ((WiFi.status() != WL_CONNECTED) || (mqttclient.loop() == false))
497 {
498 Serial.println("network have encounted critical errors");
499 esp_deep_sleep_start();
500 }
501 }
502 if (resr_count_down < 0)
503 {
504 xTimerStop(xTimer_rest, 0);
505 Serial.println("stop the timer to wait ble");
506 Serial.println("esp32 will be restarted");
507 esp_deep_sleep_start();
508 }
509 invalid_frames = 0;
510 while (1)
511 {
512 Serial1.read(read_buf, 45);
513// Serial.printf("read_buf: ");
514// for (int i = 0; i < 45; i++)
515// {
516// Serial.printf("0x%02x ", read_buf[i]);
517// }
518// Serial.println(" ");
519 if ((read_buf[0] == 0xF4) && (read_buf[1] == 0xF3) && (read_buf[2] == 0xF2) && (read_buf[3] == 0xF1))
520 {
521 // 如果工程模式打开失败, 收到的还是正常模式的数据, 则再次尝试打开工程模式
522 if ((read_buf[19] == 0xF8) && (read_buf[20] == 0xF7) && (read_buf[21] == 0xF6) && (read_buf[22] == 0xF5))
523 {
524 open_LD2410_engineering_mode();
525 }
526// Serial.println("it's valid frame");
527 ladar_status = 1;
528 break;
529 }
530 //V1.2.0 此处加入延时, 防止长时间读不到雷达的数据, 导致触发看门狗
531 delay(10);
532 //V1.2.0 如果连续读100次都读不到雷达的数据, 则跳出循环, 并且在mqtt中报告雷达工作不正常
533 if (invalid_frames++ > 100)
534 {
535 ladar_status = 0;
536 break;
537 }
538// Serial.println("warning: it's unvalid frame, read again");
539 }
540 proc_LD2410_data();
541 // Reading potentiometer value
542 if (ldr_cnt++ > ldr_period * 10)
543 {

Callers

nothing calls this directly

Calls 3

proc_LD2410_dataFunction · 0.85
setValueMethod · 0.80

Tested by

no test coverage detected