我的工作,它检测手抖动(通过加速度计)的 Andr oid 应用程序,它调制基于振动强度的振动频率。
我能够通过标准偏差获得震颤强度(代码如下):
public void regressionCalc() {
//Calculating sum values
double sumZ;
double meanZ;
sumZ = 0;
final TextView accZText = (TextView) findViewById(R.id.accelText);
accZText.setText("");
for (int r = 0; r < recArray.length; r++) {
sumZ = sumZ + recArray[r];
}
meanZ = sumZ/recArray.length;
//Calculating standard deviation
double sumXu2; //this represents E((x-xbar)^2)
sumXu2 = 0;
for (int x = 0; x < recArray.length; x++) {
sumXu2 += ((recArray[x]-meanZ)*(recArray[x]-meanZ));
}
double SD;
SD = Math.sqrt(sumXu2/(recArray.length-1));
tremorIntensity = SD;
accZText.setText(String.format("%.2f", tremorIntensity) + "");
accZText.setTextSize(80);
}
但我不知道如何处理振动。我的意思是,我希望手机振动强度根据回归值降低或增加。
有人能告诉我正确的方法吗?提前感谢。
答案在我的评论 * 显示如何使设备嗡嗡声根据模式:
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long[] pattern = {0, 100, 1000, 300, 200, 100, 500, 200, 100};
v.vibrate(pattern, -1);
由于您已经有了一个摇动强度值,剩下的问题只是使用您的强度值生成pattern
的值。
在硬件级别上,蜂鸣器只是打开或关闭,因此决定对pattern
的哪种更改最佳模拟更改强度是一个反复试验的问题。它可能很简单,使每个on
值与tremorIntensity
成比例:
long[] pattern = {0, tremorItensity * factor, 100}
*Here it is.
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(19条)