Handle long presses: push-to-talk, with a tap-like fallback
On a real G2 a touch held slightly too long is reported as a long press (sysEvent type 9, then type 10 on release; source 1 right temple, 3 left), not as a tap, and was ignored. A long press now does what a tap does. If it started a recording and is held at least 700 ms, releasing it sends (push-to-talk); released sooner, it behaves like a tap and the recording continues until the next tap or press. Tests: 219 unit/integration; simulator 7 scenarios (long_press / long_press_release through the automation API). Not reviewed, not deployed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -43,6 +43,7 @@ function makeController(dev: FakeDevice): Controller {
|
||||
submitAttempts: 3,
|
||||
submitRetryMs: 30,
|
||||
micStallMs: 300,
|
||||
holdToTalkMs: 150,
|
||||
makeClient: (baseUrl, token) =>
|
||||
new BridgeClient({
|
||||
baseUrl,
|
||||
@@ -608,3 +609,75 @@ describe('CODY-009: exactly one conversation is created, whatever the timing', (
|
||||
expect(h.hermes.executions).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('long press (a real G2 reported a slow tap as a long press)', () => {
|
||||
it('push-to-talk: hold starts recording, speaking while held, releasing sends', async () => {
|
||||
await pairedController();
|
||||
h.stt.next({ text: 'held question' });
|
||||
device.longPress();
|
||||
await until('listening with mic open', () => phase() === 'listening' && device.micOpen);
|
||||
expect(device.frame.status).toContain('● REC');
|
||||
device.speak(0.5);
|
||||
await new Promise((r) => setTimeout(r, 200)); // held longer than the push-to-talk threshold
|
||||
device.longPressRelease();
|
||||
await until('answer', () => phase() === 'answer');
|
||||
expect(h.hermes.lastRun()!.input).toBe('held question');
|
||||
expect(device.micOpen).toBe(false);
|
||||
expect(h.hermes.executions).toBe(1);
|
||||
});
|
||||
|
||||
it('a press released quickly behaves like a tap: recording continues until the next tap', async () => {
|
||||
await pairedController();
|
||||
device.longPress();
|
||||
await until('listening', () => phase() === 'listening' && device.micOpen);
|
||||
device.longPressRelease(); // released at once: not push-to-talk
|
||||
await new Promise((r) => setTimeout(r, 250));
|
||||
expect(phase()).toBe('listening');
|
||||
expect(device.micOpen).toBe(true);
|
||||
expect(h.stt.calls).toBe(0);
|
||||
device.speak(0.4);
|
||||
device.tap();
|
||||
await until('answer', () => phase() === 'answer');
|
||||
expect(h.hermes.executions).toBe(1);
|
||||
});
|
||||
|
||||
it('a long press while already recording sends, and its release does nothing more', async () => {
|
||||
await pairedController();
|
||||
device.tap();
|
||||
await until('listening', () => phase() === 'listening' && device.micOpen);
|
||||
device.speak(0.4);
|
||||
device.longPress();
|
||||
await until('answer', () => phase() === 'answer');
|
||||
await new Promise((r) => setTimeout(r, 200));
|
||||
device.longPressRelease();
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
expect(phase()).toBe('answer'); // the late release did not start a new recording
|
||||
expect(device.micOpens).toBe(1);
|
||||
expect(h.hermes.executions).toBe(1);
|
||||
});
|
||||
|
||||
it('a release with no press, or after a cancel, is ignored', async () => {
|
||||
await pairedController();
|
||||
device.longPressRelease();
|
||||
expect(phase()).toBe('ready');
|
||||
device.longPress();
|
||||
await until('listening', () => phase() === 'listening' && device.micOpen);
|
||||
await new Promise((r) => setTimeout(r, 200));
|
||||
device.doubleTap(); // cancel while still holding
|
||||
expect(phase()).toBe('cancelled');
|
||||
device.longPressRelease();
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
expect(phase()).toBe('cancelled');
|
||||
expect(h.stt.calls).toBe(0);
|
||||
expect(h.hermes.executions).toBe(0);
|
||||
});
|
||||
|
||||
it('a long press on an answer starts a follow-up, like a tap', async () => {
|
||||
await pairedController();
|
||||
controller.askText('first');
|
||||
await until('answer', () => phase() === 'answer');
|
||||
device.longPress();
|
||||
await until('listening', () => phase() === 'listening' && device.micOpen);
|
||||
expect(snapshot.state.conversationId).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -191,13 +191,17 @@ describe('start-up when a callable Even host appears during the wait', () => {
|
||||
await wait(20);
|
||||
const afterTap = diagnostics()['Glasses input']!;
|
||||
expect(afterTap).toContain('1 gesture/lifecycle event(s)');
|
||||
expect(afterTap).not.toContain('ignored;');
|
||||
expect(afterTap).toContain('sysEvent(type=none,source=1) -> tap');
|
||||
// The tap really drove the app: unpaired, so the state stays put, but it was delivered.
|
||||
push('sysEvent', { eventType: 9, eventSource: 1 }); // long press: outside the contract
|
||||
push('sysEvent', { eventType: 9, eventSource: 1 }); // long press: recognised
|
||||
await wait(20);
|
||||
expect(diagnostics()['Glasses input']).toContain('sysEvent(type=9,source=1) -> long_press');
|
||||
push('sysEvent', { eventType: 8, imuData: { x: 1, y: 2, z: 3 } }); // IMU: outside the contract
|
||||
await wait(20);
|
||||
const afterLongPress = diagnostics()['Glasses input']!;
|
||||
expect(afterLongPress).toContain('1 ignored');
|
||||
expect(afterLongPress).toContain('sysEvent(type=9,source=1) -> ignored');
|
||||
expect(afterLongPress).toContain('sysEvent(type=8) -> ignored');
|
||||
push('audioEvent', { audioPcm: [1, 2, 3, 4] });
|
||||
await wait(20);
|
||||
push('sysEvent', { eventType: 3 });
|
||||
|
||||
Reference in New Issue
Block a user