Skip to content

Commit

Permalink
- New BT interface:
Browse files Browse the repository at this point in the history
   + MTU size change
   + Real time data sent in only only 1 characteristic
- Chart update with new values and zoom levels
- Added Torqe Setup activity (Torque Smooth)
N.B.:
Remove the ESP32_TSDZ2 device from the paried devices after installation of the new version!
  • Loading branch information
mspider65 committed Mar 28, 2022
1 parent c199900 commit 29f4e7e
Show file tree
Hide file tree
Showing 27 changed files with 1,278 additions and 949 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 23
targetSdkVersion 28
versionCode 18
versionName "2.1.11"
versionName "2.1.12"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
android:name=".activities.SystemSetupActivity"
android:label="@string/title_activity_system_setup"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.TorqueSetupActivity"
android:label="@string/title_activity_torque_setup"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.BatterySetupActivity"
android:label="@string/title_activity_battery_setup"
Expand Down
161 changes: 84 additions & 77 deletions app/src/main/java/spider65/ebike/tsdz2_esp32/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import spider65.ebike.tsdz2_esp32.activities.MotorTestActivity;
import spider65.ebike.tsdz2_esp32.activities.ShowDebugInfo;
import spider65.ebike.tsdz2_esp32.activities.TSDZCfgActivity;
import spider65.ebike.tsdz2_esp32.data.TSDZ_Debug;
import spider65.ebike.tsdz2_esp32.data.TSDZ_Status;
import spider65.ebike.tsdz2_esp32.ota.Esp32_Ota;
import spider65.ebike.tsdz2_esp32.ota.Stm8_Ota;
Expand All @@ -56,7 +55,6 @@

import static java.util.Arrays.copyOfRange;
import static spider65.ebike.tsdz2_esp32.TSDZConst.CMD_GET_APP_VERSION;
import static spider65.ebike.tsdz2_esp32.TSDZConst.DEBUG_ADV_SIZE;
import static spider65.ebike.tsdz2_esp32.TSDZConst.STATUS_ADV_SIZE;
import static spider65.ebike.tsdz2_esp32.activities.BluetoothSetupActivity.KEY_DEVICE_MAC;

Expand All @@ -65,7 +63,7 @@ public class MainActivity extends AppCompatActivity implements View.OnTouchListe

private static final String TAG = "MainActivity";

private static final String KEY_SCREEN_ON = "SCREEN_ON";
public static final String KEY_SCREEN_ON = "SCREEN_ON";

private TextView mTitle;
private boolean serviceRunning;
Expand All @@ -78,11 +76,9 @@ public class MainActivity extends AppCompatActivity implements View.OnTouchListe
IntentFilter mIntentFilter = new IntentFilter();

private ViewPager viewPager;
private final byte[] lastStatusData = new byte[STATUS_ADV_SIZE];
private final byte[] lastDebugData = new byte[DEBUG_ADV_SIZE];
private byte[] lastStatusData = new byte[STATUS_ADV_SIZE];

private final TSDZ_Status status = new TSDZ_Status();
private final TSDZ_Debug debug = new TSDZ_Debug();

private TextView modeLevelTV;
private TextView statusTV;
Expand Down Expand Up @@ -114,7 +110,7 @@ protected void onCreate(Bundle savedInstanceState) {
else
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

mainPagerAdapter = new MainPagerAdapter(this, getSupportFragmentManager(), status, debug);
mainPagerAdapter = new MainPagerAdapter(this, getSupportFragmentManager(), status);
viewPager = findViewById(R.id.view_pager);
viewPager.setAdapter(mainPagerAdapter);
viewPager.setOnTouchListener(this);
Expand Down Expand Up @@ -261,7 +257,6 @@ public boolean onSwipe(Direction direction) {
mIntentFilter.addAction(TSDZBTService.CONNECTION_LOST_BROADCAST);
mIntentFilter.addAction(TSDZBTService.TSDZ_COMMAND_BROADCAST);
mIntentFilter.addAction(TSDZBTService.TSDZ_STATUS_BROADCAST);
mIntentFilter.addAction(TSDZBTService.TSDZ_DEBUG_BROADCAST);

checkBT();
updateUIStatus();
Expand Down Expand Up @@ -468,65 +463,88 @@ private boolean checkDevice() {
return false;
}


private boolean s_brake;
private short s_status = 0;
private boolean s_controllerCommError;
private boolean s_lcdCommError;
private boolean s_streetMode;
private TSDZ_Status.RidingMode s_ridingMode = TSDZ_Status.RidingMode.OFF_MODE;
private short s_assistLevel = 0;

private void refreshView() {
if (status.brake)
brakeIV.setVisibility(View.VISIBLE);
else
brakeIV.setVisibility(View.INVISIBLE);

// Motor Status are in the bits 0-5
if (status.status != 0) {
statusTV.setVisibility(View.VISIBLE);
statusTV.setText(String.valueOf(status.status));
} else
statusTV.setVisibility(View.INVISIBLE);

// Communication Status are in the bits 6-7
if ((status.controllerCommError || status.lcdCommError) && !commError) {
commError = true;
updateStatusIcons();
} else if ((!status.controllerCommError && !status.lcdCommError) && commError) {
commError = false;
updateStatusIcons();
if (status.brake != s_brake) {
s_brake = status.brake;
if (status.brake)
brakeIV.setVisibility(View.VISIBLE);
else
brakeIV.setVisibility(View.INVISIBLE);
}

if (status.streetMode)
streetModeIV.setImageResource(R.mipmap.street_icon_on);
else
streetModeIV.setImageResource(R.mipmap.street_icon_off);
if (status.status != s_status) {
s_status = status.status;
if (status.status != 0) {
statusTV.setVisibility(View.VISIBLE);
statusTV.setText(String.valueOf(status.status));
} else
statusTV.setVisibility(View.INVISIBLE);
}

switch (status.ridingMode) {
case OFF_MODE:
modeLevelTV.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.off_mode_icon, 0, 0, 0);
modeLevelTV.setText("0");
break;
case eMTB_ASSIST_MODE:
modeLevelTV.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.emtb_mode_icon, 0, 0, 0);
modeLevelTV.setText(String.valueOf(status.assistLevel));
break;
case WALK_ASSIST_MODE:
modeLevelTV.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.walk_mode_icon, 0, 0, 0);
modeLevelTV.setText(String.valueOf(status.assistLevel));
break;
case POWER_ASSIST_MODE:
modeLevelTV.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.power_mode_icon, 0, 0, 0);
modeLevelTV.setText(String.valueOf(status.assistLevel));
break;
case TORQUE_ASSIST_MODE:
modeLevelTV.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.torque_mode_icon, 0, 0, 0);
modeLevelTV.setText(String.valueOf(status.assistLevel));
break;
case CADENCE_ASSIST_MODE:
modeLevelTV.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.cadence_mode_icon, 0, 0, 0);
modeLevelTV.setText(String.valueOf(status.assistLevel));
break;
case CRUISE_MODE:
modeLevelTV.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.cruise_mode_icon, 0, 0, 0);
modeLevelTV.setText(String.valueOf(status.assistLevel));
break;
if ((status.controllerCommError != s_controllerCommError) || (status.lcdCommError != s_lcdCommError)) {
s_controllerCommError = status.controllerCommError;
s_lcdCommError = status.lcdCommError;
if ((status.controllerCommError || status.lcdCommError) && !commError) {
commError = true;
updateStatusIcons();
} else if ((!status.controllerCommError && !status.lcdCommError) && commError) {
commError = false;
updateStatusIcons();
}
}

if (status.streetMode != s_streetMode) {
s_streetMode = status.streetMode;
if (status.streetMode)
streetModeIV.setImageResource(R.mipmap.street_icon_on);
else
streetModeIV.setImageResource(R.mipmap.street_icon_off);
}
}

if ((status.ridingMode != s_ridingMode) || (status.assistLevel != s_assistLevel)) {
s_ridingMode = status.ridingMode;
s_assistLevel = status.assistLevel;
switch (status.ridingMode) {
case OFF_MODE:
modeLevelTV.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.off_mode_icon, 0, 0, 0);
modeLevelTV.setText("0");
break;
case eMTB_ASSIST_MODE:
modeLevelTV.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.emtb_mode_icon, 0, 0, 0);
modeLevelTV.setText(String.valueOf(status.assistLevel));
break;
case WALK_ASSIST_MODE:
modeLevelTV.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.walk_mode_icon, 0, 0, 0);
modeLevelTV.setText(String.valueOf(status.assistLevel));
break;
case POWER_ASSIST_MODE:
modeLevelTV.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.power_mode_icon, 0, 0, 0);
modeLevelTV.setText(String.valueOf(status.assistLevel));
break;
case TORQUE_ASSIST_MODE:
modeLevelTV.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.torque_mode_icon, 0, 0, 0);
modeLevelTV.setText(String.valueOf(status.assistLevel));
break;
case CADENCE_ASSIST_MODE:
modeLevelTV.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.cadence_mode_icon, 0, 0, 0);
modeLevelTV.setText(String.valueOf(status.assistLevel));
break;
case CRUISE_MODE:
modeLevelTV.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.cruise_mode_icon, 0, 0, 0);
modeLevelTV.setText(String.valueOf(status.assistLevel));
break;
}
}
}

private void updateStatusIcons() {
switch (btStatus) {
Expand Down Expand Up @@ -610,7 +628,7 @@ private void showVersions(byte[] data) {
builder.show();
}

private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
private final BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//Log.d(TAG, "onReceive " + intent.getAction());
Expand Down Expand Up @@ -666,22 +684,11 @@ public void onReceive(Context context, Intent intent) {
data = intent.getByteArrayExtra(TSDZBTService.VALUE_EXTRA);
if (!Arrays.equals(lastStatusData, data)) {
if (status.setData(data)) {
System.arraycopy(data, 0, lastStatusData, 0, STATUS_ADV_SIZE);
// refresh Bottom data, and Status Fragmnt if visibile
lastStatusData = data;
refreshView();
if (viewPager.getCurrentItem() == 0)
mainPagerAdapter.getMyFragment(viewPager.getCurrentItem()).refreshView();
}
}
break;
case TSDZBTService.TSDZ_DEBUG_BROADCAST:
data = intent.getByteArrayExtra(TSDZBTService.VALUE_EXTRA);
if (!Arrays.equals(lastDebugData, data)) {
// refresh Debug Fragment if visibile
if (debug.setData(data)) {
System.arraycopy(data, 0, lastDebugData, 0, DEBUG_ADV_SIZE);
if (viewPager.getCurrentItem() == 1)
mainPagerAdapter.getMyFragment(viewPager.getCurrentItem()).refreshView();
//mainPagerAdapter.getMyFragment(viewPager.getCurrentItem()).refreshView(status);
mainPagerAdapter.getMyFragment(0).refreshView(status);
mainPagerAdapter.getMyFragment(1).refreshView(status);
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import spider65.ebike.tsdz2_esp32.data.TSDZ_Debug;
import spider65.ebike.tsdz2_esp32.data.TSDZ_Status;
import spider65.ebike.tsdz2_esp32.fragments.FragmentDebug;
import spider65.ebike.tsdz2_esp32.fragments.FragmentStatus;
Expand All @@ -22,10 +21,10 @@ public class MainPagerAdapter extends FragmentPagerAdapter {
private static final Fragment[] TAB_FRAGMENTS = new Fragment[2];
private final Context mContext;

MainPagerAdapter(Context context, FragmentManager fm, TSDZ_Status status, TSDZ_Debug debug) {
MainPagerAdapter(Context context, FragmentManager fm, TSDZ_Status status) {
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
TAB_FRAGMENTS[0] = FragmentStatus.newInstance(status);
TAB_FRAGMENTS[1] = FragmentDebug.newInstance(debug);
TAB_FRAGMENTS[1] = FragmentDebug.newInstance(status);
mContext = context;
}

Expand Down
Loading

0 comments on commit 29f4e7e

Please sign in to comment.