-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDDIR_Handler_MotionSensor.java
57 lines (41 loc) · 1.89 KB
/
DDIR_Handler_MotionSensor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import javax.realtime.PeriodicParameters;
import javax.realtime.PeriodicTimer;
import javax.realtime.PriorityParameters;
import javax.realtime.PriorityScheduler;
import javax.realtime.Timer;
import javax.realtime.RelativeTime;
import javax.safetycritical.StorageConfigurationParameters;
import javax.realtime.*;
import javax.safetycritical.*;
// Implementaion of a periodic event handler
public class DDIR_Handler_MotionSensor extends PeriodicEventHandler {
static boolean RM_flag = false ;
double S_value=0.0;
public DDIR_Handler_MotionSensor() {
super(new PriorityParameters(PriorityScheduler.instance()
.getNormPriority()), new PeriodicParameters(null,
new RelativeTime(30000, 0)), new StorageConfigurationParameters(
32768, 4096, 4096), 65536, "DDIR_Handler_MotionSensor");
}
public void handleEvent() {
try{
if( RM_flag == false && S_value > 0.5 ){ // different activities have diffrent threshold so for medium we have 0.5
for(int i=1; i< (int)Math.ceil((120-60)/DDIR_PMMission.Slop);i++){
DDIR_PMMission.PaceInterval = (int)Math.ceil(60000/(60 + DDIR_PMMission.Slop*i));
RealtimeThread.sleep(new RelativeTime(DDIR_PMMission.reactionTime/(int)Math.ceil((120-60)/DDIR_PMMission.Slop),0)); //sleep
System.out.println("Update Pacing Interval :" + DDIR_PMMission.PaceInterval);
}
RM_flag = true;
}else if(RM_flag == true && S_value <= 0.5){
for(int i=1; i< Math.ceil((120-60)/DDIR_PMMission.Slop);i++){
DDIR_PMMission.PaceInterval = (int)Math.ceil(60000/(120 - DDIR_PMMission.Slop*i));
RealtimeThread.sleep(new RelativeTime((int)Math.ceil(DDIR_PMMission.recoveryTime/Math.ceil((120-60)/DDIR_PMMission.Slop)),0)); //sleep
System.out.println("Update Pacing Interval :" + DDIR_PMMission.PaceInterval);
}
RM_flag = false;
}
}catch (InterruptedException ie){
System.out.println(ie.getMessage());
}
}
}// end class