private void sendValues(float[] armAngles) { int start = 0; int end = armAngles.length; int step = armAngles.length / 2; while (start < end) { if (end - start < step) { step = end - start; } byte[] data = new byte[step * 2]; for (int i = 0; i < step; i++) { int idx = start + i; float angle = (float) ArmAngleUtil.radToDig(armAngles[idx]) + mArmSetting.getAngleOffset(idx); float rate = (angle - mArmSetting.getServoMin(idx)) / (mArmSetting.getServoMax(idx) - mArmSetting.getServoMin(idx)); rate = Math.max(Math.min(1, rate), 0); int value = (int) (0xFFFF * rate); if (mArmSetting.getServoInvert(idx)) { value = 0xffff - value; } data[i * 2] = (byte) ((value >> 8) & 0xFF); data[i * 2 + 1] = (byte) (value & 0xFF); } try { if (mAdkService != null) { mAdkService.sendCommand((byte) 0x03, (byte) (0x01 + (start * 2)), data); } } catch (RemoteException e) { Log.d("Debug", "RemoteException"); // finish(); } start += step; } }
@Override public void onServiceConnected(ComponentName name, IBinder service) { mAdkService = IAdkService.Stub.asInterface(service); try { mAdkService.connectDevice(); } catch (RemoteException e) { Log.d("Debug", e.toString(), e); } }