There are problems with a pulsating vibrator

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();
}

- - , , , .

+3
1

, , , ArrayIndexOutOfBounds.

, long, .

long[] OutOfBounds = new long[];
OutOfBounds[0] = 100;
// this is an error, it trying to access something that does not exist.

long[] legit = new long[3];
legit[0] = 0;
legit[1] = 500;
legit[2] = 1000;
// legit[3] = 0; Again, this will give you an error. 

vibrate() - . :

v.vibrate(legit, 0);
// vibrate() combines both legit[0] + legit[2] for the 'off' time

long tooLegit = new long[100];
tooLegit[0] = 1000;
tooLegit[1] = 500;
tooLegit[10] = 100;
tooLegit[11] = 2000;
v.vibrate(tooLegit, 0);
// vibrate() skips over the values you didn't define, ie long[2] = 0, long[3] = 0, etc

, .

0

All Articles