1

我正在尝试使用 Timer 作为延迟功能。当我尝试使用 Timer.de() 删除之前设置的时间时,但仍然以某种方式触发了某些事情,并且我在代码下方收到了错误。

如何在while循环中实现延迟功能。

我尝试了延迟白色,如下所示。我正在使用 esp32。

        let i = 0;
        let sensorData = 0;
        while(i<100){
            let Tid=Timer.set(500,0,function(){
                sensorData = sensorData + this.CalculateResistance();
            },null);
            Timer.del(Tid);
            sensorData = sensorData/100;
            sensorData = sensorData/MQ_GasSensor.SensorParameters.ClearAirRatio;
        }
        return sensorData;     
    },```

somehow it triggers watchdog.
here is the error.
[Jul 19 01:44:42.683] E (30764) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
[Jul 19 01:44:42.694]  - mgos (CPU 0/1), backtrace: 0x4000c3f8 0x400f7f35 0x400f7ff4 0x400fb73a 0x400fca1b 0x400fca73 0x400f31e3 0x400f3214 0x400e28a5 0x400e2c08 0x400e67eb 0x40083b04
[Jul 19 01:44:42.708] 
[Jul 19 01:44:42.708] E (30764) task_wdt: Tasks currently running:
[Jul 19 01:44:42.713] E (30764) task_wdt: CPU 0: mgos
[Jul 19 01:44:42.717] E (30764) task_wdt: Aborting.
[Jul 19 01:44:42.720] abort() was called at PC 0x400d1350 on core 0
[Jul 19 01:44:42.724] 
[Jul 19 01:44:42.725] Backtrace: 0x4008f0db 0x4008f25d 0x400d1350 0x40081686 0x4000c3f5 0x400f7f35 0x400f7ff4 0x400fb73a 0x400fca1b 0x400fca73 0x400f31e3 0x400f3214 0x400e28a5 0x400e2c08 0x400e67eb 0x40083b04
[Jul 19 01:44:42.741] 
[Jul 19 01:44:42.741] --- BEGIN CORE DUMP ---
[Jul 19 01:44:42.743] mos: catching core dump
[Jul 19 01:44:45.599] .............[Jul 19 01:45:22.289] mos: core dump aborted
[Jul 19 01:45:22.289] 
[Jul 19 01:45:22.289] rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[Jul 19 01:45:22.294] configsip: 0, SPIWP:0xee
[Jul 19 01:45:22.296] clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[Jul 19 01:45:22.302] mode:DIO, clock div:1
[Jul 19 01:45:22.304] load:0x3fff0018,len:4
[Jul 19 01:45:22.306] load:0x3fff001c,len:6188
[Jul 19 01:45:22.309] load:0x40078000,len:9588
[Jul 19 01:45:22.311] load:0x40080400,len:6968
[Jul 19 01:45:22.313] entry 0x40080740
4

0 回答 0