Skip to content

Commit

Permalink
Version 2.1.9
Browse files Browse the repository at this point in the history
- Added Hall Debug info display
- Increased History log retention
  • Loading branch information
mspider65 committed Apr 29, 2021
1 parent 06e94c0 commit 9f7e7e8
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 22 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 15
versionName "2.1.8"
versionCode 16
versionName "2.1.9"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class HallCalibrationActivity extends AppCompatActivity {

private int msgCounter;
private int step = 0;
private final byte[] dutyCycles = {25, 50, 100, (byte)(150 & 0xff)};
private final byte[] dutyCycles = {30, 70, 110, (byte)(160 & 0xff)};
private final RollingAverage[] avg = {
new RollingAverage(AVG_SIZE),
new RollingAverage(AVG_SIZE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ public class ShowDebugInfo extends AppCompatActivity {

private IntentFilter mIntentFilter = new IntentFilter();

private LinearLayout mainTimeLL, pwmTimeLL;
private TextView mainLoopTV, pwmTV;
private TextView rxcTV, rxlTV, ebikeTimeTV, motorTimeTV, pwmDownTV, pwmUpTV;
private View div1, div2;
private LinearLayout mainTimeLL, pwmTimeLL, hallErrLL;
private TextView mainLoopTV, pwmTV, hallErrTV;
private TextView rxcTV, rxlTV, ebikeTimeTV, motorTimeTV, 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();

private boolean pwmDebug = false;
private boolean mainDebug = false;
private boolean hallDebug = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -65,6 +66,15 @@ protected void onCreate(Bundle savedInstanceState) {
pwmTV.setVisibility(View.GONE);
div2.setVisibility(View.GONE);

hallErrLL = findViewById(R.id.hallErrLinearLayout);
hallErrTV = findViewById(R.id.hallErrTV);
hallStateErrTV = findViewById(R.id.hallStateErrTV);
hallSeqErrTV = findViewById(R.id.hallSeqErrTV);
div3 = findViewById(R.id.dbg_infoDV3);
hallErrLL.setVisibility(View.GONE);
hallErrTV.setVisibility(View.GONE);
div3.setVisibility(View.GONE);

mIntentFilter.addAction(TSDZBTService.TSDZ_STATUS_BROADCAST);
mIntentFilter.addAction(TSDZBTService.TSDZ_DEBUG_BROADCAST);

Expand Down Expand Up @@ -106,6 +116,12 @@ private void refreshDebug() {
pwmTV.setVisibility(View.VISIBLE);
div2.setVisibility(View.VISIBLE);
}
if (!hallDebug && (debug.debugFlags & 0x20) != 0) {
hallDebug = true;
hallErrLL.setVisibility(View.VISIBLE);
hallErrTV.setVisibility(View.VISIBLE);
div3.setVisibility(View.VISIBLE);
}

if (pwmDebug) {
int upIRQ = ((debug.debug4 & 255) << 8) + (debug.debug3 & 255);
Expand All @@ -118,6 +134,11 @@ private void refreshDebug() {
ebikeTimeTV.setText(String.format(Locale.getDefault(),"%d", debug.debug2));
motorTimeTV.setText(String.format(Locale.getDefault(),"%d", debug.debug1));
}

if (hallDebug) {
hallStateErrTV.setText(String.format(Locale.getDefault(),"%d", debug.debug5));
hallSeqErrTV.setText(String.format(Locale.getDefault(),"%d", debug.debug6));
}
}

private void refreshStatus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static class TimeInterval {
// max time interval between two log entries in a single log file. If more, a new log file is started.
private static final long MAX_LOG_PAUSE = 1000 * 60 * 20;
// log file retention is 7 days (in msec)
private static final int MAX_LOG_FILES = 20;
private static final long MAX_LOG_HISTORY = 1000 * 60 * 60 * 24 * 7;
// max single log file time is 6 hours (in msec)
private static final long MAX_FILE_HISTORY = 1000 * 60 * 60 * 6;
Expand Down Expand Up @@ -313,11 +314,12 @@ private void swapStatusFile() {
final File folder = MyApp.getInstance().getFilesDir();
final File[] files = folder.listFiles( (dir, name) ->
name.matches( STATUS_LOG_FILENAME + ".log\\.\\d+\\.\\d+$" ));
if (files != null) {
if ((files != null) && (files.length > MAX_LOG_FILES)) {
Arrays.sort(files, (object1, object2) ->
object1.getName().compareTo(object2.getName()));
long now = System.currentTimeMillis();
for (File f:files) {
for (int i = MAX_LOG_FILES; i < files.length; i++) {
File f = files[i];
String s1 = f.getName();
String[] s = s1.split("\\.");
long endTime = Long.parseLong(s[3]);
Expand Down Expand Up @@ -352,11 +354,12 @@ private void swapDebugFile() {
name.matches( DEBUG_LOG_FILENAME + ".log\\.\\d+\\.\\d+$" ));

// remove old log files
if (files != null) {
if ((files != null) && (files.length > MAX_LOG_FILES)) {
Arrays.sort(files, (object1, object2) ->
object1.getName().compareTo(object2.getName()));
long now = System.currentTimeMillis();
for (File f:files) {
for (int i = MAX_LOG_FILES; i < files.length; i++) {
File f = files[i];
String s1 = f.getName();
String[] s = s1.split("\\.");
long endTime = Long.parseLong(s[3]);
Expand Down
27 changes: 16 additions & 11 deletions app/src/main/java/spider65/ebike/tsdz2_esp32/data/TSDZ_Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,22 @@ public class TSDZ_Debug {
/*
#pragma pack(1)
typedef struct _tsdz_debug {
volatile uint8_t ui8_adc_throttle;
volatile uint8_t ui8_throttle;
volatile uint16_t ui16_adc_pedal_torque_sensor;
volatile uint8_t ui8_duty_cycle;
volatile uint16_t ui16_motor_speed_erps;
volatile uint8_t ui8_foc_angle;
volatile uint16_t ui16_pedal_torque_x100;
volatile uint16_t ui16_dummy;
volatile int16_t i16_pcb_temperaturex10;
volatile uint8_t ui8_rxc_errors;
volatile uint8_t ui8_rxl_errors;
volatile uint8_t ui8_adc_throttle;
volatile uint8_t ui8_throttle;
volatile uint16_t ui16_adc_pedal_torque_sensor;
volatile uint8_t ui8_duty_cycle;
volatile uint16_t ui16_motor_speed_erps;
volatile uint8_t ui8_foc_angle;
volatile uint16_t ui16_pedal_torque_x100;
volatile uint8_t ui8_fw_hall_cnt_offset;
volatile int16_t i16_pcb_temperaturex10;
volatile uint8_t ui8_debugFlags;
volatile uint8_t ui8_debug1;
volatile uint8_t ui8_debug2;
volatile uint8_t ui8_debug3;
volatile uint8_t ui8_debug4;
volatile uint8_t ui8_debug5;
volatile uint8_t ui8_debug6;
} struct_tsdz_debug;
*/

Expand Down
60 changes: 60 additions & 0 deletions app/src/main/res/layout/activity_show_debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,66 @@
android:layout_margin="10sp"
android:background="?android:attr/listDivider" />

<TextView
android:id="@+id/hallErrTV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2sp"
android:layout_margin="4sp"
android:gravity="center"
android:text="@string/hall_err" />

<LinearLayout
android:id="@+id/hallErrLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2sp"
android:layout_margin="5sp"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAlignment="textEnd"
android:layout_marginEnd="5sp"
android:text="@string/state_err" />

<TextView
android:id="@+id/hallStateErrTV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAlignment="textStart"
android:layout_marginStart="5sp"
android:text="@string/dash" />

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAlignment="textEnd"
android:layout_marginEnd="5sp"
android:text="@string/seq_err" />

<TextView
android:id="@+id/hallSeqErrTV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAlignment="textStart"
android:layout_marginStart="5sp"
android:text="@string/dash" />
</LinearLayout>


<View
android:id="@+id/dbg_infoDV3"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_margin="10sp"
android:background="?android:attr/listDivider" />

</LinearLayout>

<LinearLayout
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<string name="irq_time">PWM IRQ time</string>
<string name="up_irq">Up IRQ</string>
<string name="down_irq">Down IRQ</string>
<string name="hall_err">Hall Errors</string>
<string name="state_err">State Err.</string>
<string name="seq_err">Seq. Err.</string>

<string name="dash">-</string>
<string name="app_name">TSDZ2_ESP32</string>
Expand Down

0 comments on commit 9f7e7e8

Please sign in to comment.