App 2.22.1: gear badge shows only P; Logs list the raw gear codes
The badge said "D" for every gear that was not P, so N and R read as D. EVHardware now passes on the raw gear code; the badge shows P for 1, no letter for codes not yet mapped, "—" when unread. The Logs tab lists each change of the code with time and speed, to match R, N and D on the car. Emulator only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package com.evsuite.abrp;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Every change of the car's raw gear code with the time and speed, the last {@link #MAX_LINES},
|
||||
* shown on the Logs tab. It is how the codes for R, N and D get matched to the lever: shift
|
||||
* through them and read which code each one gave. Kept in preferences so the list survives
|
||||
* the app being closed in between. Written only when the code changes.
|
||||
*/
|
||||
final class GearLog {
|
||||
|
||||
static final int MAX_LINES = 12;
|
||||
private static final String PREFS = "gear_log";
|
||||
private static final String KEY = "lines";
|
||||
|
||||
/** The last code seen in this process; MIN_VALUE before the first reading. */
|
||||
private static int last = Integer.MIN_VALUE;
|
||||
|
||||
private GearLog() {}
|
||||
|
||||
/** Called with every reading; records a line when the code differs from the last one. */
|
||||
static void note(Context context, Integer raw, Float speedKmh) {
|
||||
int code = raw == null ? -1 : raw;
|
||||
synchronized (GearLog.class) {
|
||||
if (context == null || code == last) return;
|
||||
last = code;
|
||||
String line = new SimpleDateFormat("dd.MM. HH:mm:ss", Locale.US).format(new Date())
|
||||
+ " code " + (raw == null ? "unread" : String.valueOf(raw))
|
||||
+ (raw != null && raw == Gear.PARK ? " (P)" : "")
|
||||
+ " at " + (speedKmh == null ? "—" : String.format(Locale.US, "%.0f km/h", speedKmh));
|
||||
SharedPreferences prefs = context.getApplicationContext()
|
||||
.getSharedPreferences(PREFS, Context.MODE_PRIVATE);
|
||||
List<String> lines = UpdateLog.append(split(prefs.getString(KEY, null)), line, MAX_LINES);
|
||||
prefs.edit().putString(KEY, String.join("\n", lines)).apply();
|
||||
}
|
||||
}
|
||||
|
||||
/** The code now, null when unread or not read yet. */
|
||||
static synchronized Integer current() {
|
||||
return last < 0 ? null : last;
|
||||
}
|
||||
|
||||
/** Newest first. */
|
||||
static List<String> lines(Context context) {
|
||||
SharedPreferences prefs = context.getApplicationContext()
|
||||
.getSharedPreferences(PREFS, Context.MODE_PRIVATE);
|
||||
return split(prefs.getString(KEY, null));
|
||||
}
|
||||
|
||||
private static List<String> split(String stored) {
|
||||
if (stored == null || stored.isEmpty()) return new ArrayList<>();
|
||||
return new ArrayList<>(Arrays.asList(stored.split("\n")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user