Start the timer when on first sbubscription, stop when there is no one left

master
denes 6 years ago
parent ccecfc1743
commit b1c960117e

@ -70,19 +70,12 @@ bool MovesenseExerciseService::startModule()
{ {
mModuleState = WB_RES::ModuleStateValues::STARTED; mModuleState = WB_RES::ModuleStateValues::STARTED;
// Start LED timer. true = trigger repeatedly
mTimer = ResourceClient::startTimer(BLINK_PERIOD_MS, true);
return true; return true;
} }
void MovesenseExerciseService::stopModule() void MovesenseExerciseService::stopModule()
{ {
mModuleState = WB_RES::ModuleStateValues::STOPPED; mModuleState = WB_RES::ModuleStateValues::STOPPED;
// Stop LED timer
ResourceClient::stopTimer(mTimer);
mTimer = whiteboard::ID_INVALID_TIMER;
} }
void MovesenseExerciseService::onUnsubscribeResult(whiteboard::RequestId requestId, void MovesenseExerciseService::onUnsubscribeResult(whiteboard::RequestId requestId,
@ -131,6 +124,10 @@ whiteboard::Result MovesenseExerciseService::startRunning(whiteboard::RequestId&
DEBUGLOG("asyncSubscribe threw error: %u", result); DEBUGLOG("asyncSubscribe threw error: %u", result);
return whiteboard::HTTP_CODE_BAD_REQUEST; return whiteboard::HTTP_CODE_BAD_REQUEST;
} }
// Start LED timer. true = trigger repeatedly
mTimer = ResourceClient::startTimer(BLINK_PERIOD_MS, true);
isRunning = true; isRunning = true;
return whiteboard::HTTP_CODE_OK; return whiteboard::HTTP_CODE_OK;
@ -157,6 +154,11 @@ whiteboard::Result MovesenseExerciseService::stopRunning()
{ {
DEBUGLOG("asyncUnsubscribe threw error: %u", result); DEBUGLOG("asyncUnsubscribe threw error: %u", result);
} }
// Stop LED timer
ResourceClient::stopTimer(mTimer);
mTimer = whiteboard::ID_INVALID_TIMER;
isRunning = false; isRunning = false;
releaseResource(mMeasAccResourceId); releaseResource(mMeasAccResourceId);
@ -203,7 +205,9 @@ void MovesenseExerciseService::onSubscribe(const whiteboard::Request& request,
{ {
case WB_RES::LOCAL::EXERCISE_SUMVECTOR_DENES::ID: 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::RequestId remoteRequestId;
whiteboard::Result result = startRunning(remoteRequestId); whiteboard::Result result = startRunning(remoteRequestId);
@ -256,6 +260,8 @@ void MovesenseExerciseService::onClientUnavailable(whiteboard::ClientId clientId
void MovesenseExerciseService::onTimer(whiteboard::TimerId timerId) void MovesenseExerciseService::onTimer(whiteboard::TimerId timerId)
{ {
DEBUGLOG("MovesenseExerciseService::onTimer()");
if (timerId != mTimer) if (timerId != mTimer)
{ {
return; return;

Loading…
Cancel
Save