Commit 0ee097e4 authored by martin hou's avatar martin hou

fix: 增加按键测试指令

parent 9a27099e
...@@ -330,6 +330,9 @@ declare class Jensen { ...@@ -330,6 +330,9 @@ declare class Jensen {
// 获取WebUSB超时时间 // 获取WebUSB超时时间
getWebUSBTimeout: (seconds?: number) => Promise<{ timeout: number }>; getWebUSBTimeout: (seconds?: number) => Promise<{ timeout: number }>;
// 发送按键消息
sendKeyCode: (mode: number, keyCode: number, seconds?: number) => Promise<ReturnStruct['common']>;
dump: (void); dump: (void);
} }
......
...@@ -31,7 +31,10 @@ export function Home() { ...@@ -31,7 +31,10 @@ export function Home() {
const liveTimeoutRef = useRef<number | null>(null); const liveTimeoutRef = useRef<number | null>(null);
const sendTimeoutRef = useRef<number | null>(null); const sendTimeoutRef = useRef<number | null>(null);
const liveIntervalRef = useRef<number>(liveDelay); const liveIntervalRef = useRef<number>(liveDelay);
const [mute, setMute] = useState<boolean>(false);
const muteRef = useRef<boolean>(false); // 保存最新的静音状态供定时回调使用
useEffect(() => { liveIntervalRef.current = liveDelay; }, [liveDelay]); useEffect(() => { liveIntervalRef.current = liveDelay; }, [liveDelay]);
useEffect(() => { muteRef.current = mute; }, [mute]);
mgr.onconnectionstatechanged((state, dinfo) => { mgr.onconnectionstatechanged((state, dinfo) => {
console.log('onconnectionstatechanged', state, dinfo); console.log('onconnectionstatechanged', state, dinfo);
...@@ -535,10 +538,10 @@ export function Home() { ...@@ -535,10 +538,10 @@ export function Home() {
const scheduleLiveTick = async () => { const scheduleLiveTick = async () => {
let jensen = getJensen(); let jensen = getJensen();
if (jensen == null) return; if (jensen == null) return;
let live = await jensen.getRealtime(1, false, 1); let live = await jensen.getRealtime(1, muteRef.current, 1);
// 若无数据直接调度下一次 // 若无数据直接调度下一次
if (live?.data == null) return; if (live?.data == null) return;
setLiveStates('live: ' + live.data.length + ' rest: ' + live.rest + ' muted: ' + live.muted); setLiveStates('live: ' + live.data.length + ' rest: ' + live.rest + ' muted: ' + live.muted + ' == ' + muteRef.current);
// 仅计算,不保留引用;如需录音导出再使用 blocksRef.current.push(live.data.slice(8)) // 仅计算,不保留引用;如需录音导出再使用 blocksRef.current.push(live.data.slice(8))
// blocksRef.current.push(live.data.slice(8)); // blocksRef.current.push(live.data.slice(8));
const [rms1, rms2, mono16k] = rms(live.data); const [rms1, rms2, mono16k] = rms(live.data);
...@@ -706,6 +709,21 @@ export function Home() { ...@@ -706,6 +709,21 @@ export function Home() {
URL.revokeObjectURL(url); URL.revokeObjectURL(url);
} }
const muteControl = async () => {
setMute((prev) => {
const next = !prev;
muteRef.current = next; // 立即同步给定时回调
return next;
});
}
const sendKey = async (mode: number, keyCode: number) => {
let jensen = getJensen();
if (jensen == null) return;
let rst = await jensen.sendKeyCode(mode, keyCode, 5);
Logger.info('jensen', 'live', 'Send Key: ' + JSON.stringify(rst));
}
return ( return (
<> <>
<div className="btn-container" style={{ display: 'flex', flexDirection: 'row', gap: '16px', padding: '16px', alignItems: 'center', flexWrap: 'wrap' }}> <div className="btn-container" style={{ display: 'flex', flexDirection: 'row', gap: '16px', padding: '16px', alignItems: 'center', flexWrap: 'wrap' }}>
...@@ -738,6 +756,10 @@ export function Home() { ...@@ -738,6 +756,10 @@ export function Home() {
<button onClick={getSettings}>Get Settings</button> <button onClick={getSettings}>Get Settings</button>
<button onClick={startLive}>Start Live</button> <button onClick={startLive}>Start Live</button>
<button onClick={stopLive}>Stop Live</button> <button onClick={stopLive}>Stop Live</button>
<button onClick={muteControl}>{mute ? 'Muted' : 'Unmuted'}</button>
<button onClick={() => sendKey(0x01, 0x04)}>Mute (Click)</button>
<button onClick={() => sendKey(0x02, 0x03)}>Record (Long Click)</button>
<button onClick={() => sendKey(0x03, 0x05)}>Playback (Dbl Press)</button>
<span style={{ marginLeft: '8px' }}>Interval(ms): </span> <span style={{ marginLeft: '8px' }}>Interval(ms): </span>
<input <input
type="number" type="number"
......
...@@ -31,6 +31,7 @@ const GET_BATTERY_STATUS = 0x1004; ...@@ -31,6 +31,7 @@ const GET_BATTERY_STATUS = 0x1004;
const REALTIME_READ_SETTING = 0x20; const REALTIME_READ_SETTING = 0x20;
const REALTIME_CONTROL = 0x21; const REALTIME_CONTROL = 0x21;
const REALTIME_TRANSFER = 0x22; const REALTIME_TRANSFER = 0x22;
const SEND_KEY_CODE = 0x1c;
const BLUETOOTH_SCAN = 0x1001; const BLUETOOTH_SCAN = 0x1001;
const BLUETOOTH_CMD = 0x1002; const BLUETOOTH_CMD = 0x1002;
...@@ -816,6 +817,11 @@ Jensen.prototype.getWebUSBTimeout = async function (seconds) ...@@ -816,6 +817,11 @@ Jensen.prototype.getWebUSBTimeout = async function (seconds)
return this.send(new Command(READ_WEBUSB_TIMEOUT), seconds); return this.send(new Command(READ_WEBUSB_TIMEOUT), seconds);
}; };
Jensen.prototype.sendKeyCode = async function (mode, keyCode, seconds)
{
return this.send(new Command(SEND_KEY_CODE).body([mode & 0xff, keyCode & 0xff]), seconds);
};
Jensen.prototype.listFiles = async function () { Jensen.prototype.listFiles = async function () {
let tag = 'filelist-' + this.serialNumber; let tag = 'filelist-' + this.serialNumber;
if (this[tag] != null) return null; if (this[tag] != null) return null;
...@@ -1339,12 +1345,12 @@ Jensen.prototype.pauseRealtime = async function (seconds) { ...@@ -1339,12 +1345,12 @@ Jensen.prototype.pauseRealtime = async function (seconds) {
Jensen.prototype.stopRealtime = async function (seconds) { Jensen.prototype.stopRealtime = async function (seconds) {
return this.send(new Command(REALTIME_CONTROL).body([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), seconds); return this.send(new Command(REALTIME_CONTROL).body([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), seconds);
}; };
Jensen.prototype.getRealtime = async function (frames, mute, seconds) { Jensen.prototype.getRealtime = async function (frames, seconds) {
let a = (frames >> 24) & 0xff; let a = (frames >> 24) & 0xff;
let b = (frames >> 16) & 0xff; let b = (frames >> 16) & 0xff;
let c = (frames >> 8) & 0xff; let c = (frames >> 8) & 0xff;
let d = (frames >> 0) & 0xff; let d = (frames >> 0) & 0xff;
return this.send(new Command(REALTIME_TRANSFER).body([a, b, c, d, 0x00, 0x00, 0x00, mute ? 0x01 : 0x00]), seconds); return this.send(new Command(REALTIME_TRANSFER).body([a, b, c, d]), seconds);
}; };
Jensen.prototype.requestToneUpdate = async function(signature, size, seconds) { Jensen.prototype.requestToneUpdate = async function(signature, size, seconds) {
let data = []; let data = [];
...@@ -1647,6 +1653,7 @@ Jensen.registerHandler(GET_FILE_BLOCK, commonMessageParser); ...@@ -1647,6 +1653,7 @@ Jensen.registerHandler(GET_FILE_BLOCK, commonMessageParser);
Jensen.registerHandler(TEST_SN_WRITE, commonMessageParser); Jensen.registerHandler(TEST_SN_WRITE, commonMessageParser);
Jensen.registerHandler(SCHEDULE_INFO, commonMessageParser); Jensen.registerHandler(SCHEDULE_INFO, commonMessageParser);
Jensen.registerHandler(BLUETOOTH_CMD, commonMessageParser); Jensen.registerHandler(BLUETOOTH_CMD, commonMessageParser);
Jensen.registerHandler(SEND_KEY_CODE, commonMessageParser);
Jensen.registerHandler(REQUEST_TONE_UPDATE, (msg) => { Jensen.registerHandler(REQUEST_TONE_UPDATE, (msg) => {
let rst = msg.body[0]; let rst = msg.body[0];
let txt = 'success'; let txt = 'success';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment