From 7a62a68e6d79a81144bb624309a3a5764801286d Mon Sep 17 00:00:00 2001 From: xianii Date: Tue, 9 Jan 2024 17:40:20 +0800 Subject: [PATCH 1/6] signal pin setup --- src/routes/+page.svelte | 12 +- src/routes/chartData.svelte | 48 ++---- src/routes/controller.svelte | 219 +++++------------------- src/routes/controllers/discharge.svelte | 56 ++++++ src/routes/controllers/system.svelte | 100 +++++++++++ src/routes/controllers/work.svelte | 113 ++++++++++++ src/routes/dataHandler.js | 35 +++- src/routes/info.svelte | 25 +++ src/routes/webhid.svelte | 31 ++-- 9 files changed, 411 insertions(+), 228 deletions(-) create mode 100644 src/routes/controllers/discharge.svelte create mode 100644 src/routes/controllers/system.svelte create mode 100644 src/routes/controllers/work.svelte create mode 100644 src/routes/info.svelte diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 3b9b3d0..37bf690 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,6 +1,7 @@ -
-
-
-
-
- -
-
- -
-
+
+
+
+
-
-
- 空闲 | 放电 | 充电 - 信号引脚配置 -
-
- 阻抗估计 - 点火延迟 - 点火压降 -
-
- 点火时间 - 平均功率 - 能量释放 -
+
+
diff --git a/src/routes/controller.svelte b/src/routes/controller.svelte index b336fca..7482018 100644 --- a/src/routes/controller.svelte +++ b/src/routes/controller.svelte @@ -1,6 +1,12 @@ +
+ {#each [{ label: '点火测试', value: '1' }, { label: '放电测试', value: '2' }, { label: '系统功能', value: '3' }] as item} + + {/each} +
+
-
-
- 单次点火测试 -
- 点火时长 {workDuration}ms - - -
- -
-
- 连续点火测试 -
- 点火时长 {workDuration}ms - - -
-
- 点火间隔 {workIntervar}ms - - -
- -
-
- 点火时序测试 -
- 点火扫描区间 {workDurationScanStart}ms-{workDurationScanEnd}ms - - -
-
- 点火间隔 {workIntervar}ms - - -
- -
-
- 系统功能 -
- 波形数据 - - - - - -
-
- 测试接口 - - - - -
-
+
+ {#if ctrlPanelMode == '1'} + + {/if} + {#if ctrlPanelMode == '2'} + + {/if} + {#if ctrlPanelMode == '3'} + + {/if}
diff --git a/src/routes/controllers/discharge.svelte b/src/routes/controllers/discharge.svelte new file mode 100644 index 0000000..d8653e6 --- /dev/null +++ b/src/routes/controllers/discharge.svelte @@ -0,0 +1,56 @@ + + +
+ 放电测试 +
+ 点火时长 + {workDuration}ms + + +
+
+ 点火间隔 + {workIntervar}ms + + +
+ +
diff --git a/src/routes/controllers/system.svelte b/src/routes/controllers/system.svelte new file mode 100644 index 0000000..e14e9b4 --- /dev/null +++ b/src/routes/controllers/system.svelte @@ -0,0 +1,100 @@ + + +
+ 信号引脚设置 + +
+ 信号引脚模式 +
+ {#each [{ name: '无效', value: 0 }, { name: '输入', value: 1 }, { name: '输出', value: 2 }] as item} + + {/each} +
+
+ +
+ 有效电平 +
+ {#each [{ name: '低电平', value: 0 }, { name: '高电平', value: 1 }] as item} + + {/each} +
+
+
+ +
+ +
+ 系统功能 +
+ 波形数据 + + + + + +
+
+ 测试接口 + + +
+
diff --git a/src/routes/controllers/work.svelte b/src/routes/controllers/work.svelte new file mode 100644 index 0000000..fab6d37 --- /dev/null +++ b/src/routes/controllers/work.svelte @@ -0,0 +1,113 @@ + + +
+ 单次点火测试 +
+ 点火时长 + {workDuration}ms + + +
+ +
+ +
+
+ 点火时序测试 +
+ 点火扫描区间 + {workDurationScanStart}ms + - + {workDurationScanEnd}ms + + +
+
+ 点火间隔 + {workIntervar}ms + + +
+ +
diff --git a/src/routes/dataHandler.js b/src/routes/dataHandler.js index 35ab024..84f6b7f 100644 --- a/src/routes/dataHandler.js +++ b/src/routes/dataHandler.js @@ -37,7 +37,7 @@ let voltPostProc = (adc) => { } let currentPostProc = (adc) => { let mA = -4.07 * adc + 12610 - if (mA < 50 && mA > -50) { + if (mA < 70 && mA > -70) { mA = 0 } return mA / 1000 @@ -93,6 +93,31 @@ let powerDataSet = { return self.v.toFixed(1) + self.postfix }, } +let delayDataSet = { + name: "点火延迟", + head: 0x72, + postfix: "ms", + v: 0, + print: (self) => { + return (self.v / 1000).toFixed(2) + self.postfix + }, +} +let worktimeDataSet = { + name: "燃烧时间", + head: 0x74, + postfix: "ms", + v: 0, + print: (self) => { + return (self.v / 1000).toFixed(2) + self.postfix + }, +} +let timestampDataSet = { + name: "时间戳", + head: 0x7f, + postfix: "us", + v: 0, +} + export let dataTypesArray = new Array( temperatureDataSet, battDataSet, @@ -100,7 +125,10 @@ export let dataTypesArray = new Array( peakDataSet, powerDataSet, freqDataSet, - ratioDataSet + ratioDataSet, + delayDataSet, + worktimeDataSet, + timestampDataSet ) export const dataTypes = new Map([ [0x00, temperatureDataSet], @@ -110,6 +138,9 @@ export const dataTypes = new Map([ [0x13, battDataSet], [0x18, ratioDataSet], [0xf0, powerDataSet], + [0x72, delayDataSet], + [0x74, worktimeDataSet], + [0x7f, timestampDataSet], ]) export function dataUpdate(datas) { datas.forEach((element) => { diff --git a/src/routes/info.svelte b/src/routes/info.svelte new file mode 100644 index 0000000..5c5adaa --- /dev/null +++ b/src/routes/info.svelte @@ -0,0 +1,25 @@ + + +
+
+ 空闲 +
+ +
+
+ {#each [{ name: '阻抗估计', value: 1.04, unit: 'Ω' }, { name: '点火延迟', value: 22, unit: 'ms' }, { name: '点火压降', value: 335, unit: 'mV' }, { name: '点火时间', value: 2.35, unit: 's' }, { name: '平均功率', value: 8.09, unit: 'W' }, { name: '能量释放', value: 11.253, unit: 'mAh' }] as item} +
+ {item.name} + {item.value} + {item.unit} +
+ {/each} +
+
+
diff --git a/src/routes/webhid.svelte b/src/routes/webhid.svelte index ed12470..4cf050b 100644 --- a/src/routes/webhid.svelte +++ b/src/routes/webhid.svelte @@ -58,17 +58,17 @@ return -1; } console.log('device list', device_list); - let dev = device_list.find((d) => d.vendorId === vid); - if (!dev) { + let hidDevice = device_list.find((d) => d.vendorId === vid); + if (!hidDevice) { console.log('ERROR: No valid devices found'); return -2; } - if (!dev.opened) { - await dev.open(); + if (!hidDevice.opened) { + await hidDevice.open(); } - dev.oninputreport = reportPaser; - console.log('device opened:', dev); - return dev; + hidDevice.oninputreport = reportPaser; + console.log('device opened:', hidDevice); + return hidDevice; } async function openDeviceListById(vendorId) { let devs = await navigator.hid.requestDevice({ @@ -79,13 +79,13 @@ return -1; } console.log('valid devices:', devs); - let dev = devs[0]; - if (!dev.opened) { - await dev.open(); + let hidDevice = devs[0]; + if (!hidDevice.opened) { + await hidDevice.open(); } - dev.oninputreport = reportPaser; - console.log('device opened:', dev); - return dev; + hidDevice.oninputreport = reportPaser; + console.log('device opened:', hidDevice); + return hidDevice; } function dataPaser(data) { @@ -101,6 +101,10 @@ if (data[4] != (data[2] ^ data[3])) { return; } + // function buf2hex(buffer) { + // return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join(' '); + // } + // console.log("hid", buf2hex(data.buffer)); let validDataType = (dt) => { if (dataTypes.has(dt)) { return dataTypes.get(dt); @@ -127,7 +131,6 @@ dataValue = dataType.postProc(dataValue); } dataType.v = dataValue; - return { name: dataType.name, head: dataType.head, v: dataType.v }; }; let output = []; From 31e2a2e902f88d1cecc324f36beb7964d92663e8 Mon Sep 17 00:00:00 2001 From: xianii Date: Mon, 22 Jan 2024 16:07:38 +0800 Subject: [PATCH 2/6] info panel update --- src/routes/+page.svelte | 2 +- src/routes/controllers/discharge.svelte | 2 +- src/routes/controllers/work.svelte | 2 +- src/routes/info.svelte | 69 +++++++++++++++++++++++-- 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 37bf690..e343c05 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -22,7 +22,7 @@
- +
diff --git a/src/routes/controllers/discharge.svelte b/src/routes/controllers/discharge.svelte index d8653e6..05a8cef 100644 --- a/src/routes/controllers/discharge.svelte +++ b/src/routes/controllers/discharge.svelte @@ -51,6 +51,6 @@ />
⚠️ 开始 ⚠️
diff --git a/src/routes/controllers/work.svelte b/src/routes/controllers/work.svelte index fab6d37..1928e28 100644 --- a/src/routes/controllers/work.svelte +++ b/src/routes/controllers/work.svelte @@ -108,6 +108,6 @@ ⚠️ 扫描 ⚠️
diff --git a/src/routes/info.svelte b/src/routes/info.svelte index 5c5adaa..da5ea93 100644 --- a/src/routes/info.svelte +++ b/src/routes/info.svelte @@ -1,19 +1,82 @@
- 空闲 + {state}
- {#each [{ name: '阻抗估计', value: 1.04, unit: 'Ω' }, { name: '点火延迟', value: 22, unit: 'ms' }, { name: '点火压降', value: 335, unit: 'mV' }, { name: '点火时间', value: 2.35, unit: 's' }, { name: '平均功率', value: 8.09, unit: 'W' }, { name: '能量释放', value: 11.253, unit: 'mAh' }] as item} + {#each datas as item}
- {item.name} + {item.name} {item.value} From 86a43299714704dde093f39cfd016cee650e5348 Mon Sep 17 00:00:00 2001 From: xianii Date: Mon, 22 Jan 2024 16:07:54 +0800 Subject: [PATCH 3/6] add filter for realtime data --- src/routes/realtimeData.svelte | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/routes/realtimeData.svelte b/src/routes/realtimeData.svelte index c0a99a5..de0dc5f 100644 --- a/src/routes/realtimeData.svelte +++ b/src/routes/realtimeData.svelte @@ -1,13 +1,17 @@
-
+
{#if dataTypesArrayU} {#each dataTypesArrayU as item} - {#if item.head != 0x00} + {#if filter.includes(item.head)}
{item.name}
Date: Mon, 22 Jan 2024 16:08:19 +0800 Subject: [PATCH 4/6] remove temperature in nav --- src/routes/nav.svelte | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/routes/nav.svelte b/src/routes/nav.svelte index 649b16c..dd53687 100644 --- a/src/routes/nav.svelte +++ b/src/routes/nav.svelte @@ -9,24 +9,8 @@ export let device; export let dataTypesArrayU; - const temperature_badge_themes = ['badge-info', 'badge-success', 'badge-warning', 'badge-error']; - const temperature_badge_levels_high = [24, 45, 60, 100]; - const temperature_badge_levels_low = [0, 22, 42, 58]; - let temperature_badge_level = 1; - $: temperature_badge_theme = temperature_badge_themes[temperature_badge_level]; - function onHidNewDataMsg(event) { dispatch('message', event.detail); - event.detail.forEach((data) => { - if (data.head == 0x00) { - if (data.v > temperature_badge_levels_high[temperature_badge_level]) { - temperature_badge_level += 1; - } - if (data.v < temperature_badge_levels_low[temperature_badge_level]) { - temperature_badge_level -= 1; - } - } - }); } @@ -40,15 +24,6 @@
{#if device && device.opened}
已连接
- {#if dataTypesArrayU} - {#each dataTypesArrayU as item} - {#if item.head == 0x00} -
- {#if item.print}{item.print(item)}{:else}{item.v}{/if} -
- {/if} - {/each} - {/if} {:else}
未连接
{/if} From aeb27c6b22c875a1ef6ae212fe1bf31571fddc59 Mon Sep 17 00:00:00 2001 From: xianii Date: Mon, 22 Jan 2024 16:09:20 +0800 Subject: [PATCH 5/6] add current output data source --- src/routes/chartData.svelte | 29 ++++++++++++++-------- src/routes/dataHandler.js | 48 +++++++++++++++++++++++-------------- 2 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/routes/chartData.svelte b/src/routes/chartData.svelte index 794026b..7c2a6a3 100644 --- a/src/routes/chartData.svelte +++ b/src/routes/chartData.svelte @@ -36,8 +36,8 @@ datasets: [ { head: 0x13, - label: '电池', - borderColor: '#8feb34', + label: '电压输入', + borderColor: '#025f9e', yAxisID: 'mv', tension: 0.4, pointStyle: false, @@ -45,8 +45,8 @@ }, { head: 0x11, - label: '峰值', - borderColor: '#eb6e34', + label: '电压输出', + borderColor: '#f77d02', yAxisID: 'mv', tension: 0.4, pointStyle: false, @@ -54,16 +54,25 @@ }, { head: 0x12, - label: '电流', - borderColor: '#eb346a', - yAxisID: 'mA', + label: '电流输入', + borderColor: '#74029e', + yAxisID: 'A', + tension: 0.4, + pointStyle: false, + data: [] + }, + { + head: 0x14, + label: '电流输出', + borderColor: '#d40000', + yAxisID: 'A', tension: 0.4, pointStyle: false, data: [] }, { head: 0xf0, - label: '功率', + label: '功率输出', borderColor: '#ebebeb', yAxisID: 'Watt', tension: 0.4, @@ -109,14 +118,14 @@ display: true, position: 'right', suggestedMin: -2.0, - suggestedMax: 10 + suggestedMax: 6 }, mv: { type: 'linear', display: true, position: 'left', suggestedMin: 0.0, - suggestedMax: 4.2, + suggestedMax: 5.0, grid: { color: ['#777777FF', '#77777780'] } diff --git a/src/routes/dataHandler.js b/src/routes/dataHandler.js index 84f6b7f..fdef20c 100644 --- a/src/routes/dataHandler.js +++ b/src/routes/dataHandler.js @@ -36,14 +36,14 @@ let voltPostProc = (adc) => { return mv / 1000 } let currentPostProc = (adc) => { - let mA = -4.07 * adc + 12610 - if (mA < 70 && mA > -70) { + let mA = 4.07 * adc - 12610 + if (mA < 140 && mA > -80) { mA = 0 } return mA / 1000 } -let peakDataSet = { - name: "输出峰值", +let voltOutDataSet = { + name: "输出电压", head: 0x11, postfix: "V", v: 0, @@ -52,8 +52,8 @@ let peakDataSet = { return self.v.toFixed(2) + self.postfix }, } -let currentDataSet = { - name: "输出电流", +let currentInDataSet = { + name: "输入电流", head: 0x12, postfix: "A", v: 0, @@ -62,8 +62,8 @@ let currentDataSet = { return self.v.toFixed(2) + self.postfix }, } -let battDataSet = { - name: "电池电压", +let voltInDataSet = { + name: "输入电压", head: 0x13, postfix: "V", v: 0, @@ -72,6 +72,16 @@ let battDataSet = { return self.v.toFixed(2) + self.postfix }, } +let currentOutDataSet = { + name: "输出电流", + head: 0x14, + postfix: "A", + v: 0, + postProc: currentPostProc, + print: (self) => { + return self.v.toFixed(2) + self.postfix + }, +} let ratioDataSet = { name: "输出占空比", head: 0x18, @@ -85,7 +95,7 @@ let ratioDataSet = { }, } let powerDataSet = { - name: "输出功率", + name: "峰值功率", head: 0xf0, postfix: "W", v: 0, @@ -99,7 +109,7 @@ let delayDataSet = { postfix: "ms", v: 0, print: (self) => { - return (self.v / 1000).toFixed(2) + self.postfix + return (self.v / 1000).toFixed(1) + self.postfix }, } let worktimeDataSet = { @@ -108,7 +118,7 @@ let worktimeDataSet = { postfix: "ms", v: 0, print: (self) => { - return (self.v / 1000).toFixed(2) + self.postfix + return (self.v / 1000).toFixed(0) + self.postfix }, } let timestampDataSet = { @@ -120,9 +130,10 @@ let timestampDataSet = { export let dataTypesArray = new Array( temperatureDataSet, - battDataSet, - currentDataSet, - peakDataSet, + voltInDataSet, + currentInDataSet, + voltOutDataSet, + currentOutDataSet, powerDataSet, freqDataSet, ratioDataSet, @@ -133,9 +144,10 @@ export let dataTypesArray = new Array( export const dataTypes = new Map([ [0x00, temperatureDataSet], [0x10, freqDataSet], - [0x11, peakDataSet], - [0x12, currentDataSet], - [0x13, battDataSet], + [0x11, voltOutDataSet], + [0x12, currentInDataSet], + [0x13, voltInDataSet], + [0x14, currentOutDataSet], [0x18, ratioDataSet], [0xf0, powerDataSet], [0x72, delayDataSet], @@ -148,7 +160,7 @@ export function dataUpdate(datas) { dataTypes.get(element.head).v = element.v } }) - powerDataSet.v = peakDataSet.v * currentDataSet.v + powerDataSet.v = voltOutDataSet.v * currentInDataSet.v if (freqDataSet.v > 0.0 && freqDataSet.v < 100.0) { powerDataSet.v = (powerDataSet.v * freqDataSet.v) / 100 } From e017d59bcfce04625dec784564d958c8cf8bb443 Mon Sep 17 00:00:00 2001 From: xianii Date: Tue, 23 Jul 2024 16:05:02 +0800 Subject: [PATCH 6/6] Create gh-pages.yml --- .github/workflows/gh-pages.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/gh-pages.yml diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml new file mode 100644 index 0000000..d54f7a4 --- /dev/null +++ b/.github/workflows/gh-pages.yml @@ -0,0 +1,29 @@ +name: Deploy to GitHub Pages + +on: + push: + branches: [main] + workflow_dispatch: + +permissions: + contents: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install and Build + run: | + yarn install + yarn build + + - name: Deploy to GitHub Pages + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages + folder: build + clean: true + clean-exclude: .nojekyll + single-commit: true