好不容易调试好了,不过小车运动明显有延迟啊,不知道是不是可以修改线程睡眠那里的时间,不过改了还是会出现按键无反应,有时候一按会连续运动,即使按键弹起。我把最后部分代码贴出来,烦请高手指点一下,谢谢!
private Runnable mRunnable = new Runnable()
{
public void run()
{
while(true)
{
if(Send_CMD_Status==0)
{
try
{
Thread.sleep(50);
//Thread.sleep(1);
} catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
continue;
}
if(Send_CMD_Status>0) Send_CMD_Status--;
if(Cam_Reset_Status==2)
{
Cam_Reset_Status = 1;
CmdBuffer[1] = (byte)0x01;
CmdBuffer[2] = (byte)0x02;
Cam_UpDown = 0x7B;
CmdBuffer[3] = (byte)Cam_UpDown;
}
else if(Cam_Reset_Status==1)
{
Cam_Reset_Status = 0;
CmdBuffer[1] = (byte)0x01;
CmdBuffer[2] = (byte)0x01;
Cam_LeftRight = 0x5A;
CmdBuffer[3] = (byte)Cam_LeftRight;
}
else
{
Cam_Reset_Status = 0;
}
try
{
//连接服务器
mSocketClient = new Socket(CtrlIp,Integer.parseInt(CtrlPort));
//取得输入、输出流
//mBufferedReaderClient = new BufferedReader(new InputStreamReader(mSocketClient.getInputStream()));
//mPrintWriterClient = new PrintWriter(mSocketClient.getOutputStream(), true);
mSocketClient.getOutputStream().write(CmdBuffer);
//mSocketClient.getOutputStream().write(CmdBuffer);
mSocketClient.close();
// Thread.sleep(100);
Thread.sleep(10);
}
catch (Exception ex)
{
mSocketClient = null;
}
}
}
};
|