diff --git a/app/build.gradle b/app/build.gradle index d381cb0..542eeb9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "spider65.ebike.tsdz2_esp32" minSdkVersion 23 targetSdkVersion 28 - versionCode 16 - versionName "2.1.9" + versionCode 17 + versionName "2.1.10" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/spider65/ebike/tsdz2_esp32/activities/ShowDebugInfo.java b/app/src/main/java/spider65/ebike/tsdz2_esp32/activities/ShowDebugInfo.java index 156ecba..f4773eb 100644 --- a/app/src/main/java/spider65/ebike/tsdz2_esp32/activities/ShowDebugInfo.java +++ b/app/src/main/java/spider65/ebike/tsdz2_esp32/activities/ShowDebugInfo.java @@ -25,11 +25,11 @@ public class ShowDebugInfo extends AppCompatActivity { - private IntentFilter mIntentFilter = new IntentFilter(); + private final IntentFilter mIntentFilter = new IntentFilter(); private LinearLayout mainTimeLL, pwmTimeLL, hallErrLL; private TextView mainLoopTV, pwmTV, hallErrTV; - private TextView rxcTV, rxlTV, ebikeTimeTV, motorTimeTV, pwmDownTV, pwmUpTV, hallStateErrTV, hallSeqErrTV; + private TextView rxcTV, rxlTV, ebikeTimeTV, pwmDownTV, pwmUpTV, hallStateErrTV, hallSeqErrTV; private View div1, div2, div3; private final TSDZ_Status status = new TSDZ_Status(); private final TSDZ_Debug debug = new TSDZ_Debug(); @@ -51,7 +51,6 @@ protected void onCreate(Bundle savedInstanceState) { mainTimeLL = findViewById(R.id.mainTimeLinearLayout); mainLoopTV = findViewById(R.id.mainTimeTV); ebikeTimeTV = findViewById(R.id.mainLoopTimeTV); - motorTimeTV = findViewById(R.id.motorLoopTimeTV); div1 = findViewById(R.id.dbg_infoDV1); mainTimeLL.setVisibility(View.GONE); mainLoopTV.setVisibility(View.GONE); @@ -132,7 +131,6 @@ private void refreshDebug() { if (mainDebug) { ebikeTimeTV.setText(String.format(Locale.getDefault(),"%d", debug.debug2)); - motorTimeTV.setText(String.format(Locale.getDefault(),"%d", debug.debug1)); } if (hallDebug) { @@ -148,7 +146,7 @@ private void refreshStatus() { private byte[] lastStatusData, lastDebugData; - private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() { + private final BroadcastReceiver mMessageReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction() == null) return; diff --git a/app/src/main/java/spider65/ebike/tsdz2_esp32/activities/SystemSetupActivity.java b/app/src/main/java/spider65/ebike/tsdz2_esp32/activities/SystemSetupActivity.java index bb2e306..7c35f84 100644 --- a/app/src/main/java/spider65/ebike/tsdz2_esp32/activities/SystemSetupActivity.java +++ b/app/src/main/java/spider65/ebike/tsdz2_esp32/activities/SystemSetupActivity.java @@ -26,8 +26,8 @@ public class SystemSetupActivity extends AppCompatActivity { private static final String TAG = "MotorSetupActivity"; - private static final int DEFAULT_36V_INDUCTANCE = 80; - private static final int DEFAULT_48V_INDUCTANCE = 142; + private static final int DEFAULT_36V_FOC_MULTI = 24; + private static final int DEFAULT_48V_FOC_MULTI = 32; private TSDZ_Config cfg = new TSDZ_Config(); private IntentFilter mIntentFilter = new IntentFilter(); @@ -77,11 +77,11 @@ public void onOkCancelClick(View view) { public void onClickInductance(View view) { switch (view.getId()) { - case R.id.inductance36BT: - binding.inductanceET.setText(String.valueOf(DEFAULT_36V_INDUCTANCE)); + case R.id.focMultip36BT: + binding.focMultipET.setText(String.valueOf(DEFAULT_36V_FOC_MULTI)); break; - case R.id.inductance48BT: - binding.inductanceET.setText(String.valueOf(DEFAULT_48V_INDUCTANCE)); + case R.id.focMultip48BT: + binding.focMultipET.setText(String.valueOf(DEFAULT_48V_FOC_MULTI)); break; } } @@ -104,11 +104,14 @@ public void onCheckedChanged(View view, boolean checked) { private void saveCfg() { Integer val; boolean checked; - if ((val = checkRange(binding.inductanceET, 0, 150)) == null) { - showDialog(getString(R.string.motor_inductance), getString(R.string.range_error, 0, 150)); + if ((val = checkRange(binding.focMultipET, 0, 50)) == null) { + showDialog(getString(R.string.foc_multiplicator), getString(R.string.range_error, 0, 50)); return; } - cfg.ui8_motor_inductance_x1048576 = val; + cfg.ui8_foc_angle_multiplicator = val; + + checked = binding.fieldWeakeningCB.isChecked(); + cfg.fieldWeakeningEnabled = checked; if ((val = checkRange(binding.accelerationET, 0, 100)) == null) { showDialog(getString(R.string.acceleration), getString(R.string.range_error, 0, 100)); diff --git a/app/src/main/java/spider65/ebike/tsdz2_esp32/data/TSDZ_Config.java b/app/src/main/java/spider65/ebike/tsdz2_esp32/data/TSDZ_Config.java index 723d747..c638fa7 100644 --- a/app/src/main/java/spider65/ebike/tsdz2_esp32/data/TSDZ_Config.java +++ b/app/src/main/java/spider65/ebike/tsdz2_esp32/data/TSDZ_Config.java @@ -35,7 +35,7 @@ public int getValue() { } } - public int ui8_motor_inductance_x1048576; + public int ui8_foc_angle_multiplicator; public int ui8_motor_temperature_min_value_to_limit; public int ui8_motor_temperature_max_value_to_limit; public int ui8_motor_acceleration; @@ -74,6 +74,8 @@ public int getValue() { public int ui16_torque_offset_ADC; public int[] ui8_hall_ref_angles = new int[6]; public int[] ui8_hall_counter_offset = new int[6]; + public boolean fieldWeakeningEnabled; + /* #pragma pack(1) @@ -112,7 +114,7 @@ public int getValue() { volatile uint8_t ui8_torque_assist_level[4]; volatile uint8_t ui8_eMTB_assist_sensitivity[4]; volatile uint8_t ui8_walk_assist_level[4]; - volatile uint8_t ui8_torque_offset_fix; + volatile uint8_t ui8_flags; volatile uint16_t ui16_torque_offset_value; volatile uint8_t ui8_hall_ref_angles[6]; volatile uint8_t ui8_hall_offsets[6]; @@ -124,7 +126,7 @@ public boolean setData(byte[] data) { Log.e(TAG, "setData: wrong data size" + data.length); return false; } - ui8_motor_inductance_x1048576 = (data[0] & 255); + ui8_foc_angle_multiplicator = (data[0] & 255); ui8_motor_temperature_min_value_to_limit = (data[1] & 255); ui8_motor_temperature_max_value_to_limit = (data[2] & 255); ui8_motor_acceleration = (data[3] & 255); @@ -169,7 +171,8 @@ public boolean setData(byte[] data) { ui8_eMTB_assist_level[i] = (data[45+i] & 255); for (int i=0;i<4;i++) ui8_walk_assist_level[i] = (data[49+i] & 255); - torque_offset_fix = (data[53] & 255 ) != 0; // ui8_torque_offset_fix + torque_offset_fix = (data[53] & 0x01 ) != 0; + fieldWeakeningEnabled = (data[53] & 0x02) != 0; ui16_torque_offset_ADC = (data[54] & 255) + ((data[55] & 255) << 8); for (int i=0;i<6;i++) ui8_hall_ref_angles[i] = (data[56+i] & 255); @@ -180,7 +183,7 @@ public boolean setData(byte[] data) { public byte[] toByteArray() { byte[] data = new byte[CFG_SIZE]; - data[0] = (byte)(ui8_motor_inductance_x1048576 & 0xff); + data[0] = (byte)(ui8_foc_angle_multiplicator & 0xff); data[1] = (byte)ui8_motor_temperature_min_value_to_limit; data[2] = (byte)ui8_motor_temperature_max_value_to_limit; data[3] = (byte)ui8_motor_acceleration; @@ -224,7 +227,9 @@ public byte[] toByteArray() { data[45+i] = (byte)ui8_eMTB_assist_level[i]; for (int i=0;i<4;i++) data[49+i] = (byte)ui8_walk_assist_level[i]; - data[53] = (byte)(torque_offset_fix? 1:0); + data[53] = 0; + data[53] |= (byte)(torque_offset_fix? 1:0); + data[53] |= (byte)(fieldWeakeningEnabled? 2:0); data[54] = (byte)ui16_torque_offset_ADC; data[55] = (byte)(ui16_torque_offset_ADC >>> 8); for (int i=0;i<6;i++) diff --git a/app/src/main/res/layout/activity_show_debug.xml b/app/src/main/res/layout/activity_show_debug.xml index 91a9dc8..aa602da 100644 --- a/app/src/main/res/layout/activity_show_debug.xml +++ b/app/src/main/res/layout/activity_show_debug.xml @@ -126,22 +126,6 @@ android:layout_marginStart="5sp" android:text="@string/dash" /> - - - + android:text="@{String.valueOf(cfg.ui8_foc_angle_multiplicator)}" />