forked from Blendman974/faceclaw
Add brightness setting
This commit is contained in:
1 parent
afc05d6a19
commit
7455775390
7 files changed
+116
-3
No files matched your search
@@ -288,6 +288,28 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
interruptibleSleep.interrupt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the lens brightness. Fire-and-forget, like the IMU control: the
|
||||
* message is queued ahead of other traffic and any not-yet-sent brightness
|
||||
* message is superseded. When autoAdjust is true the ambient-light sensor
|
||||
* drives brightness and brightnessLevel is ignored; otherwise
|
||||
* brightnessLevel (0-100) is applied directly.
|
||||
*/
|
||||
public void setBrightness(boolean autoAdjust, int brightnessLevel) {
|
||||
synchronized (lock) {
|
||||
if (!running || !sessionReady) {
|
||||
logLine("skip brightness set; session not ready");
|
||||
return;
|
||||
}
|
||||
clearMessagesOfKindLocked("brightness-control");
|
||||
OutboundMessage message = messageBuilder.setBrightness(autoAdjust, brightnessLevel);
|
||||
message.onTimeout = () -> logLine("brightness control ack timeout");
|
||||
pendingMessages.addFirst(message);
|
||||
logLine("queue brightness " + (autoAdjust ? "auto" : "level=" + brightnessLevel));
|
||||
}
|
||||
interruptibleSleep.interrupt();
|
||||
}
|
||||
|
||||
public void addImuListener(FaceclawImuListener listener) {
|
||||
if (listener != null) {
|
||||
imuListeners.add(listener);
|
||||
|
||||
@@ -271,6 +271,28 @@ public class BleProtocol {
|
||||
return wrapEvenHub(CMD_OPEN_IMU, magic, 22, concat(inner));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the lens brightness: G2SettingPackage{commandId=1 (DeviceReceiveInfo),
|
||||
* deviceReceiveInfoFromApp(3){deviceReceiveBrightness(1){autoAdjust(1),
|
||||
* brightnessLevel(2)}}} on sid 0x09. brightnessLevel is 0-100 (nonlinear;
|
||||
* 0 is dim-but-visible, not off). When autoAdjust is set the ambient-light
|
||||
* sensor drives brightness, so the level field is omitted; otherwise the
|
||||
* level is always encoded (explicit zero included) so brightnessLevel=0
|
||||
* reaches the wire.
|
||||
*/
|
||||
public static byte[] buildSetBrightness(int magic, boolean autoAdjust, int brightnessLevel) {
|
||||
List<byte[]> brightness = new ArrayList<>();
|
||||
brightness.add(encodeVarintField(1, autoAdjust ? 1 : 0));
|
||||
if (!autoAdjust) {
|
||||
brightness.add(encodeVarintField(2, brightnessLevel));
|
||||
}
|
||||
return concat(CollectionUtils.listOf(
|
||||
encodeVarintField(1, 1),
|
||||
encodeVarintField(2, magic),
|
||||
encodeMessageField(3, encodeMessageField(1, concat(brightness)))
|
||||
));
|
||||
}
|
||||
|
||||
public static byte[] buildSettingsQuery(int magic) {
|
||||
byte[] request = encodeVarintField(1, 1);
|
||||
return concat(CollectionUtils.listOf(
|
||||
|
||||
@@ -122,6 +122,21 @@ public class MessageBuilder {
|
||||
);
|
||||
}
|
||||
|
||||
public OutboundMessage setBrightness(boolean autoAdjust, int brightnessLevel) {
|
||||
int magic = magicPool.allocate();
|
||||
return new OutboundMessage(
|
||||
"brightness-control",
|
||||
autoAdjust ? "brightness auto" : "brightness level=" + brightnessLevel,
|
||||
BleProtocol.SID_UI_SETTING,
|
||||
BleProtocol.FLAG_REQUEST,
|
||||
magic,
|
||||
BleProtocol.buildSetBrightness(magic, autoAdjust, brightnessLevel),
|
||||
ACK_TIMEOUT_MS,
|
||||
-1,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
public OutboundMessage createLayout(BleProtocol.ImageTileOptions... tiles) {
|
||||
int magic = magicPool.allocate();
|
||||
return new OutboundMessage(
|
||||
|
||||
Reference in new issue
Block a user