whitecatboard / Lua-RTOS-ESP32

Lua RTOS for ESP32
Other
1.19k stars 221 forks source link

Timer fires only once (reopen) #253

Closed Mynogs closed 5 years ago

Mynogs commented 5 years ago

@jolivepetrus Sorry I missed your question! The value of sim.simStepS is 0.1 This means calculate a simulation step ever 100ms.

Mynogs commented 5 years ago

@jolivepetrus I found the reason: The time value must be a integer value, so I use math.floor().

do
  print('Start p+ simulation ' .. (sim.stepRateS * 1000) .. 'ms cycle time')
  local t = tmr.attach(
    tmr.TMR0,
    math.floor(sim.stepRateS * 1000000),
    function()
      block.step()
      collectgarbage()
      sim.step = sim.step + 1
      sim.stepT0 = sim.stepT0 + 1
      sim.timeS = sim.timeS + sim.stepRateS
    end
  )
  t:start()
end

Now my question is: Is zero a valid timer value? If not an error whould be helpful.

jolivepetrus commented 5 years ago

@Mynogs,

Should be solved in https://github.com/whitecatboard/Lua-RTOS-ESP32/commit/7eb7045fc7bf91dc763ef5bcfe5f1ea2648f75cb.