안드로이드 개발 질문/답변
(글 수 45,052)
밑에소스처럼 버튼을 동시 터치하거나 터치하면 nxt가 움직여야 되는데....바퀴가 한쪽으로만 움직이고 덜덜덜 거리네요...
case문안에 if문이 의심스럽지만...뭐가 잘못됐나요???...염치없지만 질문 올려봅니다 ㅜㅜ
public boolean onTouch(View v, MotionEvent event) {
//Log.i("NXT", "onTouch event: " + Integer.toString(event.getAction()));
int action = event.getAction();
//if ((action == MotionEvent.ACTION_DOWN) || (action == MotionEvent.ACTION_MOVE)) {
switch(action & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_DOWN: {
if(action == MotionEvent.ACTION_UP){
byte power = (byte) mPower;
if (mReverse) {
power *= -1;
}
byte l = (byte) (power*lmod);
byte r = (byte) (power*rmod);
byte s = (byte) (power*smod);
if (!mReverseLR) {
mNXTTalker.motors(l,r,s, mRegulateSpeed, mSynchronizeMotors);
} else {
mNXTTalker.motors(l,r,s, mRegulateSpeed, mSynchronizeMotors);
}
} else if ((action == MotionEvent.ACTION_UP) || (action == MotionEvent.ACTION_CANCEL)) {
mNXTTalker.motors((byte) 0, (byte) 0,(byte) 0, mRegulateSpeed, mSynchronizeMotors);
}
return true;
}
case MotionEvent.ACTION_POINTER_DOWN:{
if(action == MotionEvent.ACTION_POINTER_DOWN){
byte power = (byte) mPower;
if (mReverse) {
power *= -1;
}
byte l = (byte) (power*lmod);
byte r = (byte) (power*rmod);
byte s = (byte) (power*smod);
if (!mReverseLR) {
mNXTTalker.motors(l,r,s, mRegulateSpeed, mSynchronizeMotors);
} else {
mNXTTalker.motors(l,r,s, mRegulateSpeed, mSynchronizeMotors);
}
} else if ((action == MotionEvent.ACTION_POINTER_UP) || (action == MotionEvent.ACTION_CANCEL)) {
mNXTTalker.motors((byte) 0, (byte) 0,(byte) 0, mRegulateSpeed, mSynchronizeMotors);
}
return true;
}
}
return true;
}
}
case문안에 if문이 의심스럽지만...뭐가 잘못됐나요???...염치없지만 질문 올려봅니다 ㅜㅜ
public boolean onTouch(View v, MotionEvent event) {
//Log.i("NXT", "onTouch event: " + Integer.toString(event.getAction()));
int action = event.getAction();
//if ((action == MotionEvent.ACTION_DOWN) || (action == MotionEvent.ACTION_MOVE)) {
switch(action & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_DOWN: {
if(action == MotionEvent.ACTION_UP){
byte power = (byte) mPower;
if (mReverse) {
power *= -1;
}
byte l = (byte) (power*lmod);
byte r = (byte) (power*rmod);
byte s = (byte) (power*smod);
if (!mReverseLR) {
mNXTTalker.motors(l,r,s, mRegulateSpeed, mSynchronizeMotors);
} else {
mNXTTalker.motors(l,r,s, mRegulateSpeed, mSynchronizeMotors);
}
} else if ((action == MotionEvent.ACTION_UP) || (action == MotionEvent.ACTION_CANCEL)) {
mNXTTalker.motors((byte) 0, (byte) 0,(byte) 0, mRegulateSpeed, mSynchronizeMotors);
}
return true;
}
case MotionEvent.ACTION_POINTER_DOWN:{
if(action == MotionEvent.ACTION_POINTER_DOWN){
byte power = (byte) mPower;
if (mReverse) {
power *= -1;
}
byte l = (byte) (power*lmod);
byte r = (byte) (power*rmod);
byte s = (byte) (power*smod);
if (!mReverseLR) {
mNXTTalker.motors(l,r,s, mRegulateSpeed, mSynchronizeMotors);
} else {
mNXTTalker.motors(l,r,s, mRegulateSpeed, mSynchronizeMotors);
}
} else if ((action == MotionEvent.ACTION_POINTER_UP) || (action == MotionEvent.ACTION_CANCEL)) {
mNXTTalker.motors((byte) 0, (byte) 0,(byte) 0, mRegulateSpeed, mSynchronizeMotors);
}
return true;
}
}
return true;
}
}