I am trying to send some strings on my android device using bluetooth to my arduino so I am wondering if my logic is correct for my code.
The part I am stuck on how to implement if all arguements are OK then it should send String temp = "t"; continously every 5 seconds.
but is rest of my logic correct and will it work as intended?
public class SendOut implements Runnable{
private boolean sStop = false;
private Thread I;
String temp = "t";
public SendOut(){
I = new Thread(this, "Output Thread");
I.start();
}
public boolean isRunning(){
return I.isAlive();
}
//button down to send data to arduino
butDown.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(targetTemp != RoomTemp)
{
temp = '1';
break;
}
else
{
temp = '0';
break;
}
}
});
//button Up to send data to arduino
butUp.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(targetTemp != RoomTemp)
{
temp = '1';
break;
}
else
{
temp = '0'
break;
}
}
});
public void onToggleClicked(View AC) {
// Is the toggle on?
boolean off = ((ToggleButton) view).isChecked();
if (on)
{
temp = 'acON';
break;
}
else
{
temp = 'acOff';
break;
}
}
public void onToggleClicked(View heat) {
// Is the toggle on?
boolean off = ((ToggleButton) view).isChecked();
if (on)
{
temp = 'heatON';
break;
}
else
{
temp = 'heatOff';
break;
}
}
@Override
public void run() {
// TODO Auto-generated method stub
try {
while(true){
mBTSocket.getOutputStream().write(temp.getBytes());
Thread.sleep(5000);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void stop() {
// TODO Auto-generated method stub
sStop = true;
}
}