Skip to content

Commit 6172938

Browse files
Merge pull request #26 from rgm3/motion-callback-ismoving
Set motion flag before callback
2 parents 99c51f9 + 41b9b4e commit 6172938

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

docs/TheThingsNode.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,10 @@ void onMotionStop(void(*callback)(unsigned long duration));
255255
- `unsigned long duration`: Time since the motion began, in ms.
256256

257257
### Method: isMoving
258-
Returns `true` if the device is currently moving. Requires the sensor to be enabled via `onMotionStart()`, `onMotionStop()` or `setMotion()`.
258+
Returns `true` if the device is currently moving. Requires the sensor to be enabled via `onMotionStart()`, `onMotionStop()` or `configMotion()`.
259259

260260
### Method: getAcceleration
261-
Returns the acceleration measured by the motion sensor in [units of g-force](https://en.wikipedia.org/wiki/G-force). Each of the values x, y and z falls in the range -2g to +2g. This function is useful to determine the orientation of the sensor relative to the earth, as gravity causes a 1g acceleration towards the centre of the earth. Requires the sensor to be enabled via `onMotionStart()`, `onMotionStop()` or `setMotion()`.
261+
Returns the acceleration measured by the motion sensor in [units of g-force](https://en.wikipedia.org/wiki/G-force). Each of the values x, y and z falls in the range -2g to +2g. This function is useful to determine the orientation of the sensor relative to the earth, as gravity causes a 1g acceleration towards the centre of the earth. Requires the sensor to be enabled via `onMotionStart()`, `onMotionStop()` or `configMotion()`.
262262

263263
```c
264264
void getAcceleration(float *x, float *y, float *z);

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)