I am trying to implement a function in my application where a vibrator can pulsate. The user can change 3 things: vibration power, pulse duration and time between pulses using the sliders.
I was thinking of some code like:
for(i=0; i<(pulse length * whatever)+(pulse gap * whatever); i+=1){
pattern[i]=pulse length*i;
patern[i+1]=pulse gap;
However, when I use this code (when it runs correctly, this is just a quick example), this leads to a crash of the application. In addition, when I change the strength of the vibration (which works), I have to restart the service to change the strength. The way I change strength is the change in time during which the vibrator turns on and off in the template.
This is the code I use to determine how the phone should vibrate (the code here is slightly different from what I would prefer):
if (rb == 3){
z.vibrate(constant, 0);
} else if (rb == 2){
smooth[0]=0;
for (int i=1; i<100; i+=2){
double angle = (2.0 * Math.PI * i) / 100;
smooth[i] = (long) (Math.sin(angle)*127);
smooth[i+1]=10;
}
z.vibrate(smooth, 0);
} else if (rb == 1){
sharp[0]=0;
for(int i=0; i<10; i+=2){
sharp[i] = s*pl;
sharp[i+1] = s+pg;
}
z.vibrate(sharp, 0);
}
} else {
z.cancel();
}
- - , , , .