forked from Blendman974/faceclaw
Add a wake-lock when the G2 screen is on
This commit is contained in:
1 parent
6632ada3c3
commit
116e8891e7
4 files changed
+45
No files matched your search
@@ -24,6 +24,7 @@
|
|||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE"/>
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE"/>
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="com.tns.NativeScriptApplication"
|
android:name="com.tns.NativeScriptApplication"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.content.Context;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -34,7 +35,10 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
|||||||
private static final BleProtocol.ImageTileOptions DASHBOARD_TILE =
|
private static final BleProtocol.ImageTileOptions DASHBOARD_TILE =
|
||||||
new BleProtocol.ImageTileOptions("img00", 10, 0, 0, 576, 288);
|
new BleProtocol.ImageTileOptions("img00", 10, 0, 0, 576, 288);
|
||||||
|
|
||||||
|
private static final String G2_SCREEN_WAKE_LOCK_TAG = "Faceclaw:G2Screen";
|
||||||
|
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
|
private final PowerManager powerManager;
|
||||||
private final FaceclawBleManager bleManager;
|
private final FaceclawBleManager bleManager;
|
||||||
private final InterruptibleSleep interruptibleSleep = new InterruptibleSleep();
|
private final InterruptibleSleep interruptibleSleep = new InterruptibleSleep();
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
@@ -87,6 +91,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
|||||||
private int headsetCharging = -1;
|
private int headsetCharging = -1;
|
||||||
private boolean audioCaptureActive;
|
private boolean audioCaptureActive;
|
||||||
private volatile FaceclawAudioPacketListener audioPacketListener;
|
private volatile FaceclawAudioPacketListener audioPacketListener;
|
||||||
|
private PowerManager.WakeLock g2ScreenWakeLock;
|
||||||
|
|
||||||
private String displayedFingerprint = "";
|
private String displayedFingerprint = "";
|
||||||
private byte[] displayedBmp = new byte[0];
|
private byte[] displayedBmp = new byte[0];
|
||||||
@@ -104,6 +109,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
|||||||
|
|
||||||
public FaceclawBleCommunicator(Context context, String rightAddress, String leftAddress, String ringAddress) {
|
public FaceclawBleCommunicator(Context context, String rightAddress, String leftAddress, String ringAddress) {
|
||||||
this.appContext = context.getApplicationContext();
|
this.appContext = context.getApplicationContext();
|
||||||
|
this.powerManager = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE);
|
||||||
this.bleManager = new FaceclawBleManager(appContext);
|
this.bleManager = new FaceclawBleManager(appContext);
|
||||||
this.bleManager.setListener(this);
|
this.bleManager.setListener(this);
|
||||||
this.rightAddress = requireAddress("rightAddress", rightAddress);
|
this.rightAddress = requireAddress("rightAddress", rightAddress);
|
||||||
@@ -160,6 +166,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
|||||||
bleManager.disconnect(ringAddress);
|
bleManager.disconnect(ringAddress);
|
||||||
}
|
}
|
||||||
bleManager.close();
|
bleManager.close();
|
||||||
|
releaseG2ScreenWakeLock();
|
||||||
setStateDisplay("disconnected", "Disconnected.");
|
setStateDisplay("disconnected", "Disconnected.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,6 +174,10 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
|||||||
disconnect();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setG2ScreenOn(boolean screenOn) {
|
||||||
|
mainHandler.post(() -> updateG2ScreenWakeLock(screenOn));
|
||||||
|
}
|
||||||
|
|
||||||
public boolean startG2AudioCapture(FaceclawAudioPacketListener listener) {
|
public boolean startG2AudioCapture(FaceclawAudioPacketListener listener) {
|
||||||
if (listener == null) {
|
if (listener == null) {
|
||||||
throw new IllegalArgumentException("listener is required");
|
throw new IllegalArgumentException("listener is required");
|
||||||
@@ -1526,6 +1537,28 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateG2ScreenWakeLock(boolean screenOn) {
|
||||||
|
if (screenOn) {
|
||||||
|
if (g2ScreenWakeLock == null) {
|
||||||
|
g2ScreenWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, G2_SCREEN_WAKE_LOCK_TAG);
|
||||||
|
g2ScreenWakeLock.setReferenceCounted(false);
|
||||||
|
}
|
||||||
|
if (!g2ScreenWakeLock.isHeld()) {
|
||||||
|
g2ScreenWakeLock.acquire();
|
||||||
|
logLine("G2 screen wake lock acquired");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
releaseG2ScreenWakeLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void releaseG2ScreenWakeLock() {
|
||||||
|
if (g2ScreenWakeLock != null && g2ScreenWakeLock.isHeld()) {
|
||||||
|
g2ScreenWakeLock.release();
|
||||||
|
logLine("G2 screen wake lock released");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void logLine(String line) {
|
private void logLine(String line) {
|
||||||
Log.i(TAG, line);
|
Log.i(TAG, line);
|
||||||
final FaceclawBleCommunicatorListener current = listener;
|
final FaceclawBleCommunicatorListener current = listener;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { voiceControlBridge } from "../native/voice-control";
|
|||||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
|
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
|
||||||
import {
|
import {
|
||||||
applyDashboardScreenTimeout,
|
applyDashboardScreenTimeout,
|
||||||
|
dashboardState,
|
||||||
drawDashboard,
|
drawDashboard,
|
||||||
noteDashboardPhoneTextInput,
|
noteDashboardPhoneTextInput,
|
||||||
openAndroidNotificationFromSleep,
|
openAndroidNotificationFromSleep,
|
||||||
@@ -561,9 +562,15 @@ class DashboardController {
|
|||||||
this.updateDisplayPreviewFromImage(image);
|
this.updateDisplayPreviewFromImage(image);
|
||||||
}
|
}
|
||||||
if (this.communicator) {
|
if (this.communicator) {
|
||||||
|
if (dashboardState.screenOn) {
|
||||||
|
await this.communicator.setG2ScreenOn(true);
|
||||||
|
}
|
||||||
console.log("submitDashboardImage");
|
console.log("submitDashboardImage");
|
||||||
await this.communicator.submitDashboardImage(image.to8bppBuffer(), image.width, image.height, fingerprint, paintMs);
|
await this.communicator.submitDashboardImage(image.to8bppBuffer(), image.width, image.height, fingerprint, paintMs);
|
||||||
await this.communicator.waitForNextFrameMetrics(FRAME_TRANSMIT_BACKPRESSURE_TIMEOUT_MS);
|
await this.communicator.waitForNextFrameMetrics(FRAME_TRANSMIT_BACKPRESSURE_TIMEOUT_MS);
|
||||||
|
if (!dashboardState.screenOn) {
|
||||||
|
await this.communicator.setG2ScreenOn(false);
|
||||||
|
}
|
||||||
if (updatePreviewAfterTransmit) {
|
if (updatePreviewAfterTransmit) {
|
||||||
await this.updateConnectedDisplayPreviewFromImage(image);
|
await this.updateConnectedDisplayPreviewFromImage(image);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,6 +225,10 @@ export class FaceclawCommunicatorBridge {
|
|||||||
await this.enqueueJavaCall(() => this.communicator.start());
|
await this.enqueueJavaCall(() => this.communicator.start());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setG2ScreenOn(screenOn: boolean): Promise<void> {
|
||||||
|
await this.enqueueJavaCall(() => this.communicator.setG2ScreenOn(Boolean(screenOn)));
|
||||||
|
}
|
||||||
|
|
||||||
async submitDashboardImage(image8bpp: Uint8Array, width: number, height: number, fingerprint: string, paintMs = -1): Promise<void> {
|
async submitDashboardImage(image8bpp: Uint8Array, width: number, height: number, fingerprint: string, paintMs = -1): Promise<void> {
|
||||||
const snapshot = new Uint8Array(image8bpp);
|
const snapshot = new Uint8Array(image8bpp);
|
||||||
await this.enqueueJavaCall(() => {
|
await this.enqueueJavaCall(() => {
|
||||||
|
|||||||
Reference in new issue
Block a user