speed command buttons
This commit is contained in:
@@ -22,6 +22,7 @@ dependencies {
|
|||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
implementation 'com.android.support:appcompat-v7:28.0.0'
|
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||||
|
implementation 'com.google.android:flexbox:1.0.0'
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||||
|
|||||||
@@ -38,9 +38,6 @@ package us.keiran.suitleds;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.media.Ringtone;
|
|
||||||
import android.media.RingtoneManager;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -48,12 +45,10 @@ package us.keiran.suitleds;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -77,7 +72,8 @@ public class MainActivity extends Activity implements RadioGroup.OnCheckedChange
|
|||||||
private BluetoothAdapter mBtAdapter = null;
|
private BluetoothAdapter mBtAdapter = null;
|
||||||
private ListView messageListView;
|
private ListView messageListView;
|
||||||
private ArrayAdapter<String> listAdapter;
|
private ArrayAdapter<String> listAdapter;
|
||||||
private Button btnConnectDisconnect, btnSend, btnRainbow;
|
private Button btnConnectDisconnect, btnSend, btnRainbow, btnFastest, btnFast, btnMed, btnSlow, btnSlowest;
|
||||||
|
private Button disableButtons[];
|
||||||
private EditText edtMessage;
|
private EditText edtMessage;
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -99,6 +95,22 @@ public class MainActivity extends Activity implements RadioGroup.OnCheckedChange
|
|||||||
btnConnectDisconnect=(Button) findViewById(R.id.btn_select);
|
btnConnectDisconnect=(Button) findViewById(R.id.btn_select);
|
||||||
btnSend=(Button) findViewById(R.id.sendButton);
|
btnSend=(Button) findViewById(R.id.sendButton);
|
||||||
btnRainbow=findViewById(R.id.rainbowButton);
|
btnRainbow=findViewById(R.id.rainbowButton);
|
||||||
|
btnFastest=findViewById(R.id.speedFastest);
|
||||||
|
btnFast=findViewById((R.id.speedFast));
|
||||||
|
btnMed=findViewById((R.id.speedMed));
|
||||||
|
btnSlow=findViewById((R.id.speedSlow));
|
||||||
|
btnSlowest=findViewById(R.id.speedSlowest);
|
||||||
|
disableButtons = new Button[7];
|
||||||
|
disableButtons[0] = btnSend;
|
||||||
|
disableButtons[1] = btnRainbow;
|
||||||
|
disableButtons[2] = btnFastest;
|
||||||
|
disableButtons[3] = btnFast;
|
||||||
|
disableButtons[4] = btnMed;
|
||||||
|
disableButtons[5] = btnSlow;
|
||||||
|
disableButtons[6] = btnSlowest;
|
||||||
|
for (Button btn: disableButtons){
|
||||||
|
btn.setEnabled(false);
|
||||||
|
}
|
||||||
edtMessage = (EditText) findViewById(R.id.sendText);
|
edtMessage = (EditText) findViewById(R.id.sendText);
|
||||||
service_init();
|
service_init();
|
||||||
|
|
||||||
@@ -158,25 +170,55 @@ public class MainActivity extends Activity implements RadioGroup.OnCheckedChange
|
|||||||
btnRainbow.setOnClickListener(new View.OnClickListener() {
|
btnRainbow.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
byte[] value;
|
sendCmd("pr");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
btnFastest.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
sendCmd("s0");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
btnFast.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
sendCmd("s20");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
btnMed.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
sendCmd("s50");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
btnSlow.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
sendCmd("s100");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
btnSlowest.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
sendCmd("s200");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Set initial UI state
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendCmd(String cmdStr){
|
||||||
try {
|
try {
|
||||||
//send data to service
|
byte[] value = cmdStr.getBytes("UTF-8");
|
||||||
value = "pr".getBytes("UTF-8");
|
|
||||||
mService.sendDataWithCRC(value);
|
mService.sendDataWithCRC(value);
|
||||||
//Update the log with time stamp
|
|
||||||
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
|
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
|
||||||
listAdapter.add("["+currentDateTimeString+"] TX: "+ "pr");
|
listAdapter.add("["+currentDateTimeString+"] TX: "+ cmdStr);
|
||||||
messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
|
messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set initial UI state
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//UART service connected/disconnected
|
//UART service connected/disconnected
|
||||||
@@ -219,11 +261,11 @@ public class MainActivity extends Activity implements RadioGroup.OnCheckedChange
|
|||||||
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
|
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
|
||||||
Log.d(TAG, "UART_CONNECT_MSG");
|
Log.d(TAG, "UART_CONNECT_MSG");
|
||||||
btnConnectDisconnect.setText("Disconnect");
|
btnConnectDisconnect.setText("Disconnect");
|
||||||
edtMessage.setEnabled(true);
|
for (Button btn: disableButtons){
|
||||||
btnSend.setEnabled(true);
|
btn.setEnabled(true);
|
||||||
btnRainbow.setEnabled(true);
|
}
|
||||||
((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName()+ " - ready");
|
((TextView) findViewById(R.id.deviceName)).setText(mDevice.getName()+ " - ready");
|
||||||
listAdapter.add("["+currentDateTimeString+"] Connected to: "+ mDevice.getName());
|
listAdapter.add("["+currentDateTimeString+"] Connected: "+ mDevice.getName());
|
||||||
messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
|
messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
|
||||||
mState = UART_PROFILE_CONNECTED;
|
mState = UART_PROFILE_CONNECTED;
|
||||||
}
|
}
|
||||||
@@ -237,11 +279,11 @@ public class MainActivity extends Activity implements RadioGroup.OnCheckedChange
|
|||||||
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
|
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
|
||||||
Log.d(TAG, "UART_DISCONNECT_MSG");
|
Log.d(TAG, "UART_DISCONNECT_MSG");
|
||||||
btnConnectDisconnect.setText("Connect");
|
btnConnectDisconnect.setText("Connect");
|
||||||
edtMessage.setEnabled(false);
|
for (Button btn: disableButtons){
|
||||||
btnSend.setEnabled(false);
|
btn.setEnabled(false);
|
||||||
btnRainbow.setEnabled(false);
|
}
|
||||||
((TextView) findViewById(R.id.deviceName)).setText("Not Connected");
|
((TextView) findViewById(R.id.deviceName)).setText("Not Connected");
|
||||||
listAdapter.add("["+currentDateTimeString+"] Disconnected from: "+ mDevice.getName());
|
listAdapter.add("["+currentDateTimeString+"] Disconnected: "+ mDevice.getName());
|
||||||
mState = UART_PROFILE_DISCONNECTED;
|
mState = UART_PROFILE_DISCONNECTED;
|
||||||
mService.close();
|
mService.close();
|
||||||
//setUiState();
|
//setUiState();
|
||||||
|
|||||||
@@ -18,6 +18,78 @@
|
|||||||
android:text="Connect" />
|
android:text="Connect" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Patterns"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
|
||||||
|
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/patternRow"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/rainbowButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Rainbow" />
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Speed"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
|
||||||
|
|
||||||
|
<com.google.android.flexbox.FlexboxLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/speedRow"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:flexWrap="wrap"
|
||||||
|
app:alignItems="stretch"
|
||||||
|
app:alignContent="stretch">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/speedFastest"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Fastest" />
|
||||||
|
<Button
|
||||||
|
android:id="@+id/speedFast"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Fast" />
|
||||||
|
<Button
|
||||||
|
android:id="@+id/speedMed"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Med" />
|
||||||
|
<Button
|
||||||
|
android:id="@+id/speedSlow"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Slow" />
|
||||||
|
<Button
|
||||||
|
android:id="@+id/speedSlowest"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Slowest" />
|
||||||
|
</com.google.android.flexbox.FlexboxLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Log"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/linearLayout3"
|
android:id="@+id/linearLayout3"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -40,7 +112,6 @@
|
|||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_toLeftOf="@+id/sendButton"
|
android:layout_toLeftOf="@+id/sendButton"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:enabled="false"
|
|
||||||
android:fontFamily="1"
|
android:fontFamily="1"
|
||||||
android:lines="1"
|
android:lines="1"
|
||||||
android:maxLength="20"
|
android:maxLength="20"
|
||||||
@@ -53,8 +124,8 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_above="@+id/sendButton"
|
android:layout_above="@+id/sendButton"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentTop="true" >
|
android:layout_alignParentTop="true"
|
||||||
</ListView>
|
android:background="@android:drawable/screen_background_light"></ListView>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/sendButton"
|
android:id="@+id/sendButton"
|
||||||
@@ -62,26 +133,11 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:enabled="false"
|
|
||||||
android:text="Send" />
|
android:text="Send" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/patternRow"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="10dp"
|
|
||||||
android:layout_marginBottom="10dp">
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/rainbowButton"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Rainbow" />
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/deviceRow"
|
android:id="@+id/deviceRow"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
Reference in New Issue
Block a user