MOGA support

This commit is contained in:
Stefanos Kornilios Mitsis Poiitidis 2013-12-29 00:14:45 +01:00
parent f5d29677b3
commit f7a39783f6
10 changed files with 225 additions and 182 deletions

0
newdc/sdl/main.cpp → core/sdl/main.cpp Executable file → Normal file
View File

Binary file not shown.

View File

@ -37,6 +37,8 @@ public class GL2JNIActivity extends Activity {
GL2JNIView mView;
PopupWindow popUp;
LayoutParams params;
MOGAInput moga = new MOGAInput();
int map[];
View addbut(int x, OnClickListener ocl) {
@ -116,6 +118,7 @@ public class GL2JNIActivity extends Activity {
@Override
protected void onCreate(Bundle icicle) {
moga.onCreate(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
createPopup();
@ -237,8 +240,6 @@ public class GL2JNIActivity extends Activity {
return true;
}
int rv = 0xFFFF;
private static final int key_CONT_B = 0x0002;
private static final int key_CONT_A = 0x0004;
private static final int key_CONT_START = 0x0008;
@ -251,7 +252,7 @@ public class GL2JNIActivity extends Activity {
// TODO: Controller mapping in options. Trunk has Ouya layout. This is a DS3
// layout.
;/*
/*
* map[]= new int[] { OuyaController.BUTTON_Y, key_CONT_B,
* OuyaController.BUTTON_U, key_CONT_A, OuyaController.BUTTON_O, key_CONT_X,
* OuyaController.BUTTON_A, key_CONT_Y,
@ -288,17 +289,15 @@ public class GL2JNIActivity extends Activity {
for (int i = 0; i < map.length; i += 2) {
if (map[i + 0] == kc) {
if (down)
this.rv &= ~map[i + 1];
GL2JNIView.kcode_raw &= ~map[i + 1];
else
this.rv |= map[i + 1];
GL2JNIView.kcode_raw |= map[i + 1];
rav = true;
break;
}
}
GL2JNIView.kcode_raw = rv;
return rav;
}
@ -332,6 +331,13 @@ public class GL2JNIActivity extends Activity {
protected void onPause() {
super.onPause();
mView.onPause();
moga.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
moga.onDestroy();
}
@Override
@ -357,5 +363,6 @@ public class GL2JNIActivity extends Activity {
protected void onResume() {
super.onResume();
mView.onResume();
moga.onResume();
}
}

View File

@ -0,0 +1,211 @@
package com.reicast.emulator;
/******************************************************************************/
import java.util.Map.Entry;
import java.util.TreeMap;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.util.Log;
import com.bda.controller.Controller;
import com.bda.controller.ControllerListener;
import com.bda.controller.KeyEvent;
import com.bda.controller.MotionEvent;
import com.bda.controller.StateEvent;
/******************************************************************************/
/*
*/
public class MOGAInput
{
static final int DELAY = 1000 / 50; // 50 Hz
static final int ACTION_CONNECTED = Controller.ACTION_CONNECTED;
static final int ACTION_DISCONNECTED = Controller.ACTION_DISCONNECTED;
static final int ACTION_VERSION_MOGA = Controller.ACTION_VERSION_MOGA;
static final int ACTION_VERSION_MOGAPRO = Controller.ACTION_VERSION_MOGAPRO;
Controller mController = null;
private static final int key_CONT_B = 0x0002;
private static final int key_CONT_A = 0x0004;
private static final int key_CONT_START = 0x0008;
private static final int key_CONT_DPAD_UP = 0x0010;
private static final int key_CONT_DPAD_DOWN = 0x0020;
private static final int key_CONT_DPAD_LEFT = 0x0040;
private static final int key_CONT_DPAD_RIGHT = 0x0080;
private static final int key_CONT_Y = 0x0200;
private static final int key_CONT_X = 0x0400;
int[] map = new int[] {
KeyEvent.KEYCODE_BUTTON_B, key_CONT_B,
KeyEvent.KEYCODE_BUTTON_A, key_CONT_A,
KeyEvent.KEYCODE_BUTTON_X, key_CONT_X,
KeyEvent.KEYCODE_BUTTON_Y, key_CONT_Y,
KeyEvent.KEYCODE_DPAD_UP, key_CONT_DPAD_UP,
KeyEvent.KEYCODE_DPAD_DOWN, key_CONT_DPAD_DOWN,
KeyEvent.KEYCODE_DPAD_LEFT, key_CONT_DPAD_LEFT,
KeyEvent.KEYCODE_DPAD_RIGHT, key_CONT_DPAD_RIGHT,
KeyEvent.KEYCODE_BUTTON_START, key_CONT_START,
};
public MOGAInput()
{
/*
mStates.put(StateEvent.STATE_CONNECTION, new ExampleInteger("STATE_CONNECTION......"));
mStates.put(StateEvent.STATE_POWER_LOW, new ExampleInteger("STATE_POWER_LOW......"));
mStates.put(StateEvent.STATE_CURRENT_PRODUCT_VERSION, new ExampleInteger("STATE_CURRENT_PRODUCT_VERSION"));
mStates.put(StateEvent.STATE_SUPPORTED_PRODUCT_VERSION, new ExampleInteger("STATE_SUPPORTED_PRODUCT_VERSION"));
mKeys.put(KeyEvent.KEYCODE_DPAD_UP, new ExampleInteger("KEYCODE_DPAD_UP......"));
mKeys.put(KeyEvent.KEYCODE_DPAD_DOWN, new ExampleInteger("KEYCODE_DPAD_DOWN......"));
mKeys.put(KeyEvent.KEYCODE_DPAD_LEFT, new ExampleInteger("KEYCODE_DPAD_LEFT......"));
mKeys.put(KeyEvent.KEYCODE_DPAD_RIGHT, new ExampleInteger("KEYCODE_DPAD_RIGHT......"));
mKeys.put(KeyEvent.KEYCODE_BUTTON_A, new ExampleInteger("KEYCODE_BUTTON_A......"));
mKeys.put(KeyEvent.KEYCODE_BUTTON_B, new ExampleInteger("KEYCODE_BUTTON_B......"));
mKeys.put(KeyEvent.KEYCODE_BUTTON_X, new ExampleInteger("KEYCODE_BUTTON_X......"));
mKeys.put(KeyEvent.KEYCODE_BUTTON_Y, new ExampleInteger("KEYCODE_BUTTON_Y......"));
mKeys.put(KeyEvent.KEYCODE_BUTTON_L1, new ExampleInteger("KEYCODE_BUTTON_L1......"));
mKeys.put(KeyEvent.KEYCODE_BUTTON_R1, new ExampleInteger("KEYCODE_BUTTON_R1......"));
mKeys.put(KeyEvent.KEYCODE_BUTTON_L2, new ExampleInteger("KEYCODE_BUTTON_L2......"));
mKeys.put(KeyEvent.KEYCODE_BUTTON_R2, new ExampleInteger("KEYCODE_BUTTON_R2......"));
mKeys.put(KeyEvent.KEYCODE_BUTTON_THUMBL, new ExampleInteger("KEYCODE_BUTTON_THUMBL......"));
mKeys.put(KeyEvent.KEYCODE_BUTTON_THUMBR, new ExampleInteger("KEYCODE_BUTTON_THUMBR......"));
mKeys.put(KeyEvent.KEYCODE_BUTTON_START, new ExampleInteger("KEYCODE_BUTTON_START......"));
mKeys.put(KeyEvent.KEYCODE_BUTTON_SELECT, new ExampleInteger("KEYCODE_BUTTON_SELECT......"));
mMotions.put(MotionEvent.AXIS_X, new ExampleFloat("AXIS_X........."));
mMotions.put(MotionEvent.AXIS_Y, new ExampleFloat("AXIS_Y........."));
mMotions.put(MotionEvent.AXIS_Z, new ExampleFloat("AXIS_Z........."));
mMotions.put(MotionEvent.AXIS_RZ, new ExampleFloat("AXIS_RZ......."));
mMotions.put(MotionEvent.AXIS_LTRIGGER, new ExampleFloat("AXIS_LTRIGGER........."));
mMotions.put(MotionEvent.AXIS_RTRIGGER, new ExampleFloat("AXIS_RTRIGGER........."));
*/
}
protected void onCreate(Activity act)
{
mController = Controller.getInstance(act);
mController.init();
mController.setListener(new ExampleControllerListener(), new Handler());
Log.w("INPUT", "Create");
}
protected void onDestroy()
{
Log.w("INPUT", "Desotry");
mController.exit();
}
protected void onPause()
{
Log.w("INPUT", "PAUSe");
mController.onPause();
}
protected void onResume()
{
Log.w("INPUT", "RESUMe");
mController.onResume();
/*
for(final Entry<Integer, ExampleInteger> entry : mStates.entrySet())
{
final int key = entry.getKey();
final ExampleInteger value = entry.getValue();
value.mValue = mController.getState(key);
}
for(final Entry<Integer, ExampleInteger> entry : mKeys.entrySet())
{
final int key = entry.getKey();
final ExampleInteger value = entry.getValue();
value.mValue = mController.getKeyCode(key);
}
for(final Entry<Integer, ExampleFloat> entry : mMotions.entrySet())
{
final int key = entry.getKey();
final ExampleFloat value = entry.getValue();
value.mValue = mController.getAxisValue(key);
}
*/
}
class ExampleControllerListener implements ControllerListener
{
public void onKeyEvent(KeyEvent event)
{
Log.w("KEYINPUT", event.toString());
for (int i = 0; i < map.length; i += 2) {
if (map[i + 0] == event.getKeyCode()) {
if (event.getAction() == 0) //FIXME to const
GL2JNIView.kcode_raw &= ~map[i + 1];
else
GL2JNIView.kcode_raw |= map[i + 1];
break;
}
}
/*
final ExampleInteger value = mKeys.get(event.getKeyCode());
if(value != null)
{
value.mValue = event.getAction();
}*/
}
public void onMotionEvent(MotionEvent event)
{
Log.w("MOINPUT", event.toString());
float LS_X = event.getAxisValue(MotionEvent.AXIS_X);
float LS_Y = event.getAxisValue(MotionEvent.AXIS_Y);
float L2 = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
float R2 = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
GL2JNIView.lt = (int) (L2 * 255);
GL2JNIView.rt = (int) (R2 * 255);
GL2JNIView.jx = (int) (LS_X * 126);
GL2JNIView.jy = (int) (LS_Y * 126);
/*
for(final Entry<Integer, ExampleFloat> entry : mMotions.entrySet())
{
final int key = entry.getKey();
final ExampleFloat value = entry.getValue();
value.mValue = event.getAxisValue(key);
}*/
}
public void onStateEvent(StateEvent event)
{
Log.w("SINPUT", event.toString());
/*
final ExampleInteger value = mStates.get(event.getState());
if(value != null)
{
value.mValue = event.getAction();
}*/
}
}
}

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>libnewdc</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newdc"
android:versionCode="1"
android:versionName="1.0">
</manifest>

View File

@ -1,92 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="libnewdc" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

View File

@ -1,20 +0,0 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@ -1,15 +0,0 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
android.library=true
# Project target.
target=android-15