Skip to content

Commit 9dc0aba

Browse files
committed
Allow detecting isMoving within onMotionStart cb
Set the flag indicating motion state before calling the onMotion callback functions. Otherwise, `node->isMoving()` unexpectedly returns false from within the callback. Resolves #25
1 parent 99c51f9 commit 9dc0aba

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/TheThingsNode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ void TheThingsNode::loop()
164164
if (!this->motionStarted)
165165
{
166166
this->motionStartedAt = millis();
167+
this->motionStarted = true;
167168
if (this->motionEnabled && this->motionStartCallback)
168169
{
169170
this->motionStartCallback();
170171
}
171-
this->motionStarted = true;
172172
}
173173
TTN_MOTION_START = false;
174174
}
@@ -177,11 +177,11 @@ void TheThingsNode::loop()
177177
{
178178
if (this->motionStarted)
179179
{
180+
this->motionStarted = false;
180181
if (this->motionEnabled && this->motionStopCallback)
181182
{
182183
this->motionStopCallback(millis() - this->motionStartedAt);
183184
}
184-
this->motionStarted = false;
185185
}
186186
TTN_MOTION_STOP = false;
187187
}

0 commit comments

Comments
 (0)