speed command buttons

This commit is contained in:
2019-03-16 21:45:24 -04:00
parent c0c46972de
commit d2441a6847
3 changed files with 145 additions and 46 deletions

View File

@@ -22,6 +22,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android:flexbox:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

View File

@@ -38,9 +38,6 @@ package us.keiran.suitleds;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.res.Configuration;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -48,12 +45,10 @@ package us.keiran.suitleds;
import android.os.Message;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
@@ -77,7 +72,8 @@ public class MainActivity extends Activity implements RadioGroup.OnCheckedChange
private BluetoothAdapter mBtAdapter = null;
private ListView messageListView;
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;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -99,6 +95,22 @@ public class MainActivity extends Activity implements RadioGroup.OnCheckedChange
btnConnectDisconnect=(Button) findViewById(R.id.btn_select);
btnSend=(Button) findViewById(R.id.sendButton);
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);
service_init();
@@ -158,27 +170,57 @@ public class MainActivity extends Activity implements RadioGroup.OnCheckedChange
btnRainbow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
byte[] value;
try {
//send data to service
value = "pr".getBytes("UTF-8");
mService.sendDataWithCRC(value);
//Update the log with time stamp
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
listAdapter.add("["+currentDateTimeString+"] TX: "+ "pr");
messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
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 {
byte[] value = cmdStr.getBytes("UTF-8");
mService.sendDataWithCRC(value);
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
listAdapter.add("["+currentDateTimeString+"] TX: "+ cmdStr);
messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//UART service connected/disconnected
private ServiceConnection mServiceConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder rawBinder) {
@@ -219,11 +261,11 @@ public class MainActivity extends Activity implements RadioGroup.OnCheckedChange
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
Log.d(TAG, "UART_CONNECT_MSG");
btnConnectDisconnect.setText("Disconnect");
edtMessage.setEnabled(true);
btnSend.setEnabled(true);
btnRainbow.setEnabled(true);
for (Button btn: disableButtons){
btn.setEnabled(true);
}
((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);
mState = UART_PROFILE_CONNECTED;
}
@@ -237,11 +279,11 @@ public class MainActivity extends Activity implements RadioGroup.OnCheckedChange
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
Log.d(TAG, "UART_DISCONNECT_MSG");
btnConnectDisconnect.setText("Connect");
edtMessage.setEnabled(false);
btnSend.setEnabled(false);
btnRainbow.setEnabled(false);
for (Button btn: disableButtons){
btn.setEnabled(false);
}
((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;
mService.close();
//setUiState();

View File

@@ -18,6 +18,78 @@
android:text="Connect" />
</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
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
@@ -40,7 +112,6 @@
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/sendButton"
android:ems="10"
android:enabled="false"
android:fontFamily="1"
android:lines="1"
android:maxLength="20"
@@ -53,8 +124,8 @@
android:layout_height="wrap_content"
android:layout_above="@+id/sendButton"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
android:layout_alignParentTop="true"
android:background="@android:drawable/screen_background_light"></ListView>
<Button
android:id="@+id/sendButton"
@@ -62,26 +133,11 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:enabled="false"
android:text="Send" />
</RelativeLayout>
</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
android:id="@+id/deviceRow"
android:layout_width="match_parent"