This function will wait until an event is raised with an optional timeout.
An event is a notification that something has happened in the accelerometer interface.
There are two types of events:
1. | Events triggered by the application (solicited event). |
2. | Events triggered by the Accelerometer (unsolicited event). |
The events are queued until appropriate action is taken as described in this table:
Event#
|
Event
|
Solicited
|
Action
|
1
|
Events has been lost due to too many events in queue.
|
No
|
|
2
|
Logging is stopped due to acceleration.
|
No
|
|
3
|
Logging is stopped due to shock.
|
No
|
|
4
|
Logging is stopped due to buffer is full or stopped by application
|
Yes
|
|
5
|
Logging has reached warning level.
|
No
|
Optional: Save logging buffer.
|
6
|
Logging buffer is full.
|
No
|
Optional: Save logging buffer.
|
7
|
Acceleration surpassing requested limits detected.
|
No
|
Call accAccelerationEvent.
|
8
|
Shock surpassing the requested limits detected.
|
No
|
Call accShockEvent.
|
accWaitEvent notifies the application of the oldest queued event.
This means that if the appropriate action is not taken, accWaitEvent will continue to report the same event.
Note: waiting for an event by using this function will block the calling thread.
Input:
Timeout : INT (-1,0..32000, default -1)
Timeout period in milliseconds to wait.
0
|
- Disable timeout. The function will return immediately.
|
-1
|
- Wait forever. The function will only return when data is received.
|
Output:
None.
Returns: INT
8
|
- Shock surpassing the requested limits detected.
|
7
|
- Acceleration surpassing requested limits detected.
|
6
|
- Logging buffer is full.
|
5
|
- Logging has reached warning level.
|
4
|
- Logging is stopped due to buffer is full or stopped by application.
|
3
|
- Logging is stopped due to shock.
|
2
|
- Logging is stopped due to acceleration.
|
1
|
- Events have been lost due to too many events in queue.
|
0
|
- Timeout.
|
-1
|
- General error.
|
-2
|
- Accelerometer interface is not open.
|
-3
|
- Invalid timeout.
|
Declaration:
FUNCTION accWaitEvent : INT;
VAR_INPUT
timeout : INT;
END_VAR;
Example:
INCLUDE rtcu.inc
THREAD_BLOCK accMonitor;
VAR
event : INT := 0;
END_VAR;
WHILE event <> -1 DO
event := accWaitEvent(timeout := -1);
CASE event OF
1: DebugMsg(message := "Events has been lost due to too many events in queue");
2: DebugMsg(message := "Logging is stopped due to acceleration event");
3: DebugMsg(message := "Logging is stopped due to shock event");
4: SendAccLog();
5: DumpAccLog();
6: DumpAccLog();
DebugMsg(message := "Logging buffer is full, data could be lost");
7: ReadAccEvent();
8: ReadShockEvent();
ELSE
DebugFmt(message := "accWaitEvent - event=\1", v1 := event);
END_CASE;
END_WHILE;
END_THREAD_BLOCK;
|