diff --git a/MovesenseExerciseService.cpp b/MovesenseExerciseService.cpp index 02266fd..5d4fea3 100644 --- a/MovesenseExerciseService.cpp +++ b/MovesenseExerciseService.cpp @@ -70,19 +70,12 @@ bool MovesenseExerciseService::startModule() { mModuleState = WB_RES::ModuleStateValues::STARTED; - // Start LED timer. true = trigger repeatedly - mTimer = ResourceClient::startTimer(BLINK_PERIOD_MS, true); - return true; } void MovesenseExerciseService::stopModule() { mModuleState = WB_RES::ModuleStateValues::STOPPED; - - // Stop LED timer - ResourceClient::stopTimer(mTimer); - mTimer = whiteboard::ID_INVALID_TIMER; } void MovesenseExerciseService::onUnsubscribeResult(whiteboard::RequestId requestId, @@ -131,6 +124,10 @@ whiteboard::Result MovesenseExerciseService::startRunning(whiteboard::RequestId& DEBUGLOG("asyncSubscribe threw error: %u", result); return whiteboard::HTTP_CODE_BAD_REQUEST; } + + // Start LED timer. true = trigger repeatedly + mTimer = ResourceClient::startTimer(BLINK_PERIOD_MS, true); + isRunning = true; return whiteboard::HTTP_CODE_OK; @@ -157,6 +154,11 @@ whiteboard::Result MovesenseExerciseService::stopRunning() { DEBUGLOG("asyncUnsubscribe threw error: %u", result); } + + // Stop LED timer + ResourceClient::stopTimer(mTimer); + mTimer = whiteboard::ID_INVALID_TIMER; + isRunning = false; releaseResource(mMeasAccResourceId); @@ -203,7 +205,9 @@ void MovesenseExerciseService::onSubscribe(const whiteboard::Request& request, { case WB_RES::LOCAL::EXERCISE_SUMVECTOR_DENES::ID: { - // Someone subscribed to our service. Start collecting data and notifying when our service changes state (every 10 seconds) + // Someone subscribed to our service. Start collecting data + // and publish calculated sumvector average (every 1 second) + whiteboard::RequestId remoteRequestId; whiteboard::Result result = startRunning(remoteRequestId); @@ -256,6 +260,8 @@ void MovesenseExerciseService::onClientUnavailable(whiteboard::ClientId clientId void MovesenseExerciseService::onTimer(whiteboard::TimerId timerId) { + DEBUGLOG("MovesenseExerciseService::onTimer()"); + if (timerId != mTimer) { return;