Skip to content

Commit

Permalink
Configurable motor inductance
Browse files Browse the repository at this point in the history
  • Loading branch information
mspider65 committed Aug 13, 2020
1 parent ea63e65 commit 1b76ce3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "spider65.ebike.tsdz2_esp32"
minSdkVersion 23
targetSdkVersion 28
versionCode 7
versionName "2.1.0"
versionCode 8
versionName "2.1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public void onOkCancelClick(View view) {
}
}

public void onClickInductance(View view) {
switch (view.getId()) {
case R.id.inductance36BT:
binding.inductanceET.setText("80");
break;
case R.id.inductance48BT:
binding.inductanceET.setText("142");
break;
}
}
// invalidate all to hide/show the checkbox dependant fields
public void onCheckedChanged(View view, boolean checked) {
switch (view.getId()) {
Expand All @@ -89,8 +99,11 @@ public void onCheckedChanged(View view, boolean checked) {
private void saveCfg() {
Integer val;
boolean checked;

cfg.ui8_motor_type = binding.motorTypeSP.getSelectedItemPosition();
if ((val = checkRange(binding.inductanceET, 0, 150)) == null) {
showDialog(getString(R.string.motor_inductance), getString(R.string.range_error, 0, 150));
return;
}
cfg.ui8_motor_inductance_x1048576 = val;

if ((val = checkRange(binding.accelerationET, 0, 100)) == null) {
showDialog(getString(R.string.acceleration), getString(R.string.range_error, 0, 100));
Expand Down Expand Up @@ -197,7 +210,6 @@ public void onReceive(Context context, Intent intent) {
case TSDZBTService.TSDZ_CFG_READ_BROADCAST:
if (cfg.setData(intent.getByteArrayExtra(TSDZBTService.VALUE_EXTRA))) {
binding.setCfg(cfg);
binding.motorTypeSP.setSelection(cfg.ui8_motor_type);
binding.lightConfigSP.setSelection(cfg.ui8_lights_configuration);
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public int getValue() {
}
}

public int ui8_motor_type;
public int ui8_motor_inductance_x1048576;
public int ui8_motor_temperature_min_value_to_limit;
public int ui8_motor_temperature_max_value_to_limit;
public int ui8_motor_acceleration;
Expand Down Expand Up @@ -119,7 +119,7 @@ public boolean setData(byte[] data) {
Log.e(TAG, "setData: wrong data size");
return false;
}
ui8_motor_type = (data[0] & 255);
ui8_motor_inductance_x1048576 = (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);
Expand Down Expand Up @@ -170,7 +170,7 @@ public boolean setData(byte[] data) {

public byte[] toByteArray() {
byte[] data = new byte[CFG_SIZE];
data[0] = (byte)(ui8_motor_type & 0xff);
data[0] = (byte)(ui8_motor_inductance_x1048576 & 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;
Expand Down
29 changes: 24 additions & 5 deletions app/src/main/res/layout/activity_system_setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,36 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/motor_type"
android:text="@string/motor_inductance"
android:layout_gravity="center_vertical" />

<Spinner
android:id="@+id/motorTypeSP"
<EditText
android:id="@+id/inductanceET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="5dp"
android:entries="@array/motor_types"
android:minWidth="100dp"/>
android:layout_weight="2"
android:ems="2"
android:inputType="number"
android:text="@{String.valueOf(cfg.ui8_motor_inductance_x1048576)}" />

<Button
android:id="@+id/inductance36BT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:onClick="@{handler::onClickInductance}"
android:text="36V" />

<Button
android:id="@+id/inductance48BT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:onClick="@{handler::onClickInductance}"
android:text="48V" />

</LinearLayout>

<LinearLayout
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<string name="title_activity_system_setup">System Setup</string>
<string name="motor">Motor</string>
<string name="motor_type">Motor Type</string>
<string name="motor_inductance">Motor Inductance</string>
<string name="acceleration">Acceleration</string>
<string name="max_current">Max current (A)</string>
<string name="max_power">Max Power (W)</string>
Expand Down

0 comments on commit 1b76ce3

Please sign in to comment.