Provide more visual feedback when calibrating joystick variants

This commit is contained in:
Aaron Culliney 2019-06-09 16:58:53 -07:00
parent e643b1c855
commit 7eacfb4564
3 changed files with 78 additions and 4 deletions

View File

@ -12,9 +12,11 @@
package org.deadc0de.apple2ix;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import org.deadc0de.apple2ix.basic.R;
@ -22,16 +24,19 @@ import java.util.ArrayList;
public class Apple2JoystickCalibration implements Apple2MenuView {
private final static String TAG = "Apple2JoystickCalibration";
private final static String TAG = "apple2ix-js-calibrate";
public final static int JOYSTICK_DIVIDER_NUM_CHOICES = Apple2Preferences.DECENT_AMOUNT_OF_CHOICES;
public final static String PREF_SCREEN_DIVISION = "screenDivider";
private static native long nativePollJoystick();
private Apple2Activity mActivity = null;
private View mSettingsView = null;
private ArrayList<Apple2MenuView> mViewStack = null;
private boolean mTouchMenuEnabled = false;
private int mSavedTouchDevice = Apple2SettingsMenu.TouchDeviceVariant.NONE.ordinal();
private Thread joystickPollerThread = null;
public Apple2JoystickCalibration(Apple2Activity activity, ArrayList<Apple2MenuView> viewStack, Apple2SettingsMenu.TouchDeviceVariant variant) {
mActivity = activity;
@ -43,7 +48,7 @@ public class Apple2JoystickCalibration implements Apple2MenuView {
setup(variant);
}
private void setup(Apple2SettingsMenu.TouchDeviceVariant variant) {
private void setup(final Apple2SettingsMenu.TouchDeviceVariant variant) {
LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mSettingsView = inflater.inflate(R.layout.activity_calibrate_joystick, null, false);
@ -72,6 +77,42 @@ public class Apple2JoystickCalibration implements Apple2MenuView {
float val = Apple2Preferences.getFloatJSONPref(Apple2Preferences.PREF_DOMAIN_JOYSTICK, PREF_SCREEN_DIVISION, (JOYSTICK_DIVIDER_NUM_CHOICES >> 1) / (float) JOYSTICK_DIVIDER_NUM_CHOICES);
sb.setProgress((int) (val * JOYSTICK_DIVIDER_NUM_CHOICES));
final TextView axisCoords = (TextView) mSettingsView.findViewById(R.id.axisCoords);
joystickPollerThread = new Thread() {
@Override
public void run() {
Log.i(TAG, "Starting joystick poll thread...");
try {
while (true) {
long cxy = nativePollJoystick();
String t = "";
if (variant == Apple2SettingsMenu.TouchDeviceVariant.JOYSTICK) {
final int x = ((int) (cxy & 0xFF00) >> 8) - 128;
final int y = ((int) (cxy & 0x00FF) >> 0) - 128;
t = "X:" + x + " Y:" + y;
} else {
char c = (char) ((cxy & 0xFF0000) >> 16);
t = "Key:" + c;
}
final String axisText = t;
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
axisCoords.setText(axisText);
}
});
Thread.sleep(100);
}
} catch (Exception e) {
Log.i(TAG, "Stopping joystick poll thread...");
}
}
};
joystickPollerThread.start();
mTouchMenuEnabled = (boolean) Apple2Preferences.getJSONPref(Apple2KeyboardSettingsMenu.SETTINGS.TOUCH_MENU_ENABLED);
Apple2Preferences.setJSONPref(Apple2KeyboardSettingsMenu.SETTINGS.TOUCH_MENU_ENABLED, false);
mSavedTouchDevice = (int) Apple2Preferences.getJSONPref(Apple2SettingsMenu.SETTINGS.CURRENT_INPUT);
@ -96,6 +137,7 @@ public class Apple2JoystickCalibration implements Apple2MenuView {
}
public void dismiss() {
joystickPollerThread.interrupt();
for (Apple2MenuView apple2MenuView : mViewStack) {
if (apple2MenuView != this) {
mActivity.pushApple2View(apple2MenuView);

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:layout_marginStart="0dp"
android:layout_marginRight="0dp"
@ -20,4 +20,19 @@
android:layout_alignParentStart="true"
android:layout_marginLeft="0dp"
android:layout_marginStart="0dp" />
<TextView
android:id="@+id/axisCoords"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/seekBar"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="@dimen/preference_margin_left"
android:layout_marginLeft="@dimen/preference_margin_left"
android:layout_marginTop="@dimen/preference_margin_top"
android:background="@color/white"
android:text="X:255 Y:255"
android:textColor="@color/black" />
</RelativeLayout>

View File

@ -615,3 +615,20 @@ void Java_org_deadc0de_apple2ix_Apple2Preferences_nativePrefsSync(JNIEnv *env, j
}
}
jlong Java_org_deadc0de_apple2ix_Apple2JoystickCalibration_nativePollJoystick(JNIEnv *env, jclass cls) {
jlong cxy = 0;
uint8_t c = apple_ii_64k[0][0xC000];
if (c | 0x80) {
c = keys_apple2ASCII(c, NULL);
} else {
c = ' ';
}
cxy |= (c << 16);
cxy |= ((joy_x & 0xFF) << 8);
cxy |= ((joy_y & 0xFF) << 0);
return cxy;
}