In the end, passing it a callback function that returned the value worked, something like this:
function querySensorThenTrigger(callback_func)
querySensor()
tmr.alarm(0, 100, tmr.ALARM_SINGLE, function(callback_func)
val = querySensor()
callback_func(val)
end)
end
and to use:
querySensorThenTrigger(function()
print(val)
end)
marcelstoer wrote:mickles wrote:Anyone have any neat ideas on how to hold off returning a value until the sensor conversion is complete?
I'm not sure I fully understand but I have the feeling you're looking at this from the "wrong" perspective. Lua/NodeMCU is asynchronous and event-driven (reactive if you like buzz words). So, rather than "holding off returning until X" you need to define a callback function to "execute after X happened".
Something like the following may be more promising:Code: Select allfunction querySensorThenTrigger(callback_func)
querySensor()
tmr.alarm(0, 100, tmr.ALARM_SINGLE, function(callback_func)
querySensor()
callback_func()
end)
end