Add ability to power back on. Only expose 'power cycle' in the UI.

This commit is contained in:
James Sanford 2012-10-12 18:42:27 -07:00
parent c3af8c61f5
commit 1f9812a371
4 changed files with 38 additions and 10 deletions

View File

@ -10,6 +10,6 @@
android:title="@string/emulation_speed" />
<item android:id="@+id/warm_reset"
android:title="@string/warm_reset" />
<item android:id="@+id/power_off"
android:title="@string/power_off" />
<item android:id="@+id/power_cycle"
android:title="@string/power_cycle" />
</menu>

View File

@ -29,5 +29,5 @@
<string name="input_controls_show">Show Controls</string>
<string name="emulation_speed">Emulation Speed</string>
<string name="warm_reset">Warm Reset</string>
<string name="power_off">Power Off</string>
<string name="power_cycle">Power Cycle</string>
</resources>

View File

@ -108,8 +108,9 @@ public class KegsMain extends Activity implements KegsKeyboard.StickyReset {
} else if (item_id == R.id.warm_reset) {
mKegsView.doWarmReset();
return true;
} else if (item_id == R.id.power_off) {
} else if (item_id == R.id.power_cycle) {
mKegsView.doPowerOff();
mKegsView.allowPowerOn();
return true;
}
return false;

View File

@ -38,6 +38,7 @@ class KegsView extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mSurfaceHolder;
private Context mContext;
private final ReentrantLock mPauseLock = new ReentrantLock();
private final ReentrantLock mPowerWait = new ReentrantLock();
public KegsThread(SurfaceHolder surfaceHolder, Context context) {
mSurfaceHolder = surfaceHolder;
@ -85,7 +86,11 @@ class KegsView extends SurfaceView implements SurfaceHolder.Callback {
@Override
public void run() {
mainLoop(mBitmap, mEventQueue);
while(true) {
mPowerWait.lock();
mPowerWait.unlock();
mainLoop(mBitmap, mEventQueue);
}
// For TESTING:
// while (true) {
// try {
@ -123,6 +128,25 @@ class KegsView extends SurfaceView implements SurfaceHolder.Callback {
public boolean nowPaused() {
return mPauseLock.hasQueuedThreads();
}
public void doPowerOff() {
// Tell the native thread loop to wait before powering on again.
mPowerWait.lock();
// Special event, see android_driver.c:x_key_special()
mEventQueue.add(new Event.KeyKegsEvent(120 + 0x80, true));
}
public void allowPowerOn() {
// Intended to be called from the UI thread.
// As the native thread is allowed to loop by default,
// this is only useful after using doPowerOff().
if (mPowerWait.isHeldByCurrentThread()) {
mPowerWait.unlock();
}
}
}
private KegsThread thread;
@ -147,11 +171,6 @@ class KegsView extends SurfaceView implements SurfaceHolder.Callback {
mEventQueue.add(new Event.KeyKegsEvent(speed + 0x80, true));
}
public void doPowerOff() {
// Special event, see android_driver.c:x_key_special()
mEventQueue.add(new Event.KeyKegsEvent(120 + 0x80, true));
}
public void doWarmReset() {
// Press keys down.
mEventQueue.add(new Event.KeyKegsEvent(KegsKeyboard.KEY_OPEN_APPLE, false));
@ -163,6 +182,14 @@ class KegsView extends SurfaceView implements SurfaceHolder.Callback {
mEventQueue.add(new Event.KeyKegsEvent(KegsKeyboard.KEY_OPEN_APPLE, true));
}
public void doPowerOff() {
thread.doPowerOff();
}
public void allowPowerOn() {
thread.allowPowerOn();
}
public KegsThread getThread() {
return thread;
}