crownstone / crownstone-microapp

Crownstone microapp. Contains several examples and library to communicate with bluenet.
Apache License 2.0
2 stars 6 forks source link

Fix delay bug after refactor #10

Closed martijnvandermarel closed 2 years ago

martijnvandermarel commented 2 years ago

The delay function had a bug where the true delay was a factor 10 higher than the delay passed as the argument. The cause of this is that the microapp is not called every bluenet tick. Instead, in the MicroappController::tickMicroapp() function (https://github.com/crownstone/bluenet/blob/master/source/src/microapp/cs_MicroappController.cpp#L302) the microapp is only called every MICROAPP_LOOP_FREQUENCY ticks (default value for MICROAPP_LOOP_FREQUENCY is 10, as defined in the shared cs_MicroappStructs.h)

The solution is simple: delay_ms argument is divided by MICROAPP_LOOP_FREQUENCY in the delay() function on the microapp side.

mrquincle commented 2 years ago

Ah, check. I thought I had changed that indeed (which is why I introduced MICROAPP_LOOP_FREQUENCY). Good catch.