diff --git a/docs/protocols/协议简述-添加扫描时光色.docx b/docs/protocols/协议简述-添加扫描时光色.docx new file mode 100644 index 0000000..196f989 Binary files /dev/null and b/docs/protocols/协议简述-添加扫描时光色.docx differ diff --git a/miniprogram/i18n/locales/autoScan.js b/miniprogram/i18n/locales/autoScan.js index 95c7609..638b9ff 100644 --- a/miniprogram/i18n/locales/autoScan.js +++ b/miniprogram/i18n/locales/autoScan.js @@ -17,6 +17,7 @@ module.exports = { doneStatusPost: ' 帧),正在启动治疗...', notWorn: '面膜未佩戴好,请重新佩戴后再试', timeout: '检测超时,未收到数据,请重试', + deviceFault: '设备异常,扫描已停止,请重启设备后再试', cmdFailed: '检测命令发送失败' }, en: { @@ -35,6 +36,7 @@ module.exports = { doneStatusPost: ' frames), starting treatment...', notWorn: 'The mask is not worn properly. Please re-fit and try again', timeout: 'Scan timed out with no data. Please try again', + deviceFault: 'Device error — scan stopped. Please restart the device and try again', cmdFailed: 'Failed to send scan command' } } diff --git a/miniprogram/i18n/locales/common.js b/miniprogram/i18n/locales/common.js index 23228d0..ed378f9 100644 --- a/miniprogram/i18n/locales/common.js +++ b/miniprogram/i18n/locales/common.js @@ -18,12 +18,14 @@ module.exports = { saveFailed: '保存失败', networkError: '网络异常,请重试', deviceNotConnected: '设备未连接', + // 区域 = IO 纵列布局:left=IO1(0x01) top=IO2(0x02中上) middle=IO3(0x04中) + // bottom=IO4(0x08中下) right=IO5(0x10)。key 名沿用,语义以掩码为准。 regions: { - right: '右区', left: '左区', - top: '上区', + top: '中上区', middle: '中区', - bottom: '下区' + bottom: '中下区', + right: '右区' }, wavelengths: { red: '红光', @@ -51,11 +53,11 @@ module.exports = { networkError: 'Network error, please retry', deviceNotConnected: 'Device not connected', regions: { - right: 'Right', left: 'Left', - top: 'Top', + top: 'Upper Center', middle: 'Center', - bottom: 'Bottom' + bottom: 'Lower Center', + right: 'Right' }, wavelengths: { red: 'Red', diff --git a/miniprogram/i18n/locales/report.js b/miniprogram/i18n/locales/report.js index 1d57fdc..692cf12 100644 --- a/miniprogram/i18n/locales/report.js +++ b/miniprogram/i18n/locales/report.js @@ -5,6 +5,9 @@ module.exports = { subtitle: '基于多光谱反射的肤质倾向参考', scannedAt: '扫描时间', overallTitle: '整体倾向', + faceTitle: '分区光疗方案', + faceTapHint: '点击分区可查看该光的功效介绍', + allNormalHint: '未发现明显问题区域,可进行日常舒缓养护', regionTitle: '分区分析', recommendTitle: '推荐护理', noProblem: '未见明显倾向', @@ -19,12 +22,11 @@ module.exports = { pigment: '色素 / 暗黄', deep: '深层循环 / 疲劳' }, - regionNames: { - right: '右脸', - left: '左脸', - top: '额头', - middle: '鼻区', - bottom: '下巴' + modeNames: { + red: '嫩肤焕亮', + ir: '深层焕活', + uv: '净痘控油', + yellow: '匀净提亮' } }, en: { @@ -32,6 +34,9 @@ module.exports = { subtitle: 'Skin-tendency reference from multispectral reflection', scannedAt: 'Scanned at', overallTitle: 'Overall Tendency', + faceTitle: 'Zone Care Map', + faceTapHint: 'Tap a zone to learn about its light', + allNormalHint: 'No notable concerns found — a gentle daily care session works well', regionTitle: 'Zone Analysis', recommendTitle: 'Recommended Care', noProblem: 'No notable tendency', @@ -46,12 +51,11 @@ module.exports = { pigment: 'Pigment / Sallowness', deep: 'Deep circulation / Fatigue' }, - regionNames: { - right: 'Right cheek', - left: 'Left cheek', - top: 'Forehead', - middle: 'Nose', - bottom: 'Chin' + modeNames: { + red: 'Glow & Firm', + ir: 'Deep Revive', + uv: 'Clear & Balance', + yellow: 'Even & Brighten' } } } diff --git a/miniprogram/i18n/locales/treating.js b/miniprogram/i18n/locales/treating.js index 4d7f233..e5149ef 100644 --- a/miniprogram/i18n/locales/treating.js +++ b/miniprogram/i18n/locales/treating.js @@ -7,8 +7,6 @@ module.exports = { smartMode: '✨ 智能模式', normalMode: '🔄 普通模式', allRegions: '全区域', - regionTopLeft: '左上区', - regionTopRight: '右上区', relax1: '请放松心情', relax2: '享受美好时光', stopBtn: '停止使用', @@ -35,8 +33,6 @@ module.exports = { smartMode: '✨ Smart Mode', normalMode: '🔄 Normal Mode', allRegions: 'All regions', - regionTopLeft: 'Top-left', - regionTopRight: 'Top-right', relax1: 'Relax and unwind', relax2: 'Enjoy your moment', stopBtn: 'Stop', diff --git a/miniprogram/pages/auto-scan/auto-scan.js b/miniprogram/pages/auto-scan/auto-scan.js index cf17e52..8a114f4 100644 --- a/miniprogram/pages/auto-scan/auto-scan.js +++ b/miniprogram/pages/auto-scan/auto-scan.js @@ -51,7 +51,8 @@ Page({ return } - self._pdSum = [0, 0, 0, 0, 0, 0, 0] + // 按扫描光色分桶累加(FFE4 Byte17 高三位,新协议)。旧固件无标识 → 全部归 red 桶。 + self._buckets = {} self._frameCount = 0 self._completed = false self._collecting = false @@ -81,6 +82,15 @@ Page({ self._lastRunState = data.run_state } + // 设备故障(Byte18=0xFF):立即中止,不等 3 分钟超时 + if (data.run_state === 0xFF) { + console.error('[SCAN] 设备故障,中止扫描') + self._completed = true + self._cleanup() + self.setData({ phase: 'ready', error: i18n.t('autoScan.deviceFault') }) + return + } + if (data.run_state === 1) { self._seenRunState1 = true } @@ -110,10 +120,17 @@ Page({ if (self._completed || !self._collecting) return if (!data || !data.pd || data.pd.length < 7) return - self._frameCount++ - for (var i = 0; i < 7; i++) { - self._pdSum[i] += data.pd[i] + var wave = data.scan_wave || 'red' // 旧固件帧无光色标识,按单波长红光兼容 + var bucket = self._buckets[wave] + if (!bucket) { + bucket = { sum: [0, 0, 0, 0, 0, 0, 0], n: 0 } + self._buckets[wave] = bucket } + bucket.n++ + for (var i = 0; i < 7; i++) { + bucket.sum[i] += data.pd[i] + } + self._frameCount++ self.setData({ frameCount: self._frameCount, vbat: data.vbat || self.data.vbat, @@ -155,28 +172,35 @@ Page({ this._completed = true this._cleanup() - var avg = [] - var count = this._frameCount || 1 - for (var i = 0; i < 7; i++) { - avg.push(Math.round(this._pdSum[i] / count)) + // 每个光色桶各自求平均 → waves: { red:[7], ir:[7], uv:[7], yellow:[7] }(有几色算几色) + var waves = {} + var firstAvg = [] + for (var wave in this._buckets) { + if (!this._buckets.hasOwnProperty(wave)) continue + var b = this._buckets[wave] + if (!b.n) continue + var avg = [] + for (var i = 0; i < 7; i++) avg.push(Math.round(b.sum[i] / b.n)) + waves[wave] = avg + if (!firstAvg.length) firstAvg = avg } - this.setData({ phase: 'done', pdAvg: avg, frameCount: count }) - getApp().globalData.lastScanPdAvg = avg - console.log('[SCAN] PD平均值:', avg, '帧数:', count) + this.setData({ phase: 'done', pdAvg: firstAvg, frameCount: this._frameCount }) + getApp().globalData.lastScanPdAvg = firstAvg + console.log('[SCAN] 分桶结果:', JSON.stringify(Object.keys(waves).map(function (k) { return k })), '总帧数:', this._frameCount) - this._buildAndGoReport(avg) + this._buildAndGoReport(waves) }, // Scan finished -> run the (placeholder) diagnosis, store + persist a report, and // navigate to the report page so the user sees their skin tendencies and chooses // care. This replaces the previous auto-start-treatment behavior. // - // NOTE: today only single-wavelength red PD is collected, and the thresholds + - // PD->region mapping in services/diagnosis.js are placeholders pending calibration. - // Report + persistence work end to end regardless; the numbers get real after - // 4-wavelength scan collection and calibration land. - _buildAndGoReport: function (avg) { + // NOTE: thresholds + PD->region mapping in services/diagnosis.js are placeholders + // pending hardware confirmation / calibration (tunable via server diagnosis_config). + // Old firmware sends no wave marker -> everything lands in the red bucket and the + // pipeline degrades to single-wavelength gracefully. + _buildAndGoReport: function (waves) { var self = this var app = getApp() var mask = self.data.regions || 0x1F @@ -185,7 +209,7 @@ Page({ var scannedAt = Date.now() function proceed(config) { - var scanData = diagnosis.fromRedScan(avg, mask, deviceId, scannedAt) + var scanData = diagnosis.buildScanData(waves, mask, deviceId, scannedAt) var report = diagnosis.analyze(scanData, config || diagnosis.DEFAULT_CONFIG) app.globalData.lastScanReport = report @@ -205,7 +229,9 @@ Page({ } api.getDiagnosisConfig().then(function (cfg) { - proceed(cfg && cfg.levels ? cfg : diagnosis.DEFAULT_CONFIG) + // 非空对象即采用——缺失字段由 analyze 逐项回退 DEFAULT;只发部分字段(如仅调 pd_region_map)也生效 + var usable = cfg && typeof cfg === 'object' && Object.keys(cfg).length > 0 + proceed(usable ? cfg : diagnosis.DEFAULT_CONFIG) }).catch(function () { proceed(diagnosis.DEFAULT_CONFIG) }) diff --git a/miniprogram/pages/light-info/light-info.js b/miniprogram/pages/light-info/light-info.js index bb98c3e..c2f570c 100644 --- a/miniprogram/pages/light-info/light-info.js +++ b/miniprogram/pages/light-info/light-info.js @@ -15,9 +15,12 @@ Page({ modeColors: ['#E8503A', '#7C4DFF', '#F5B841', '#8B2E3C', '#F08AA8'] }, - onLoad: function () { + onLoad: function (options) { var app = getApp() - this.setData({ statusBarHeight: app.globalData.statusBarHeight }) + // 报告页分区跳转带 ?wave=red|ir|uv|yellow,高亮对应光卡片('ir' 对应本页 key 'infrared') + var focus = (options && options.wave) || '' + if (focus === 'ir') focus = 'infrared' + this.setData({ statusBarHeight: app.globalData.statusBarHeight, focusWave: focus }) }, onShow: function () { diff --git a/miniprogram/pages/light-info/light-info.wxml b/miniprogram/pages/light-info/light-info.wxml index bb33004..3872d70 100644 --- a/miniprogram/pages/light-info/light-info.wxml +++ b/miniprogram/pages/light-info/light-info.wxml @@ -8,7 +8,7 @@ {{i18n.lightInfo.lightsSectionTitle}} - + diff --git a/miniprogram/pages/light-info/light-info.wxss b/miniprogram/pages/light-info/light-info.wxss index af9b6f7..121f9fc 100644 --- a/miniprogram/pages/light-info/light-info.wxss +++ b/miniprogram/pages/light-info/light-info.wxss @@ -123,3 +123,9 @@ line-height: 1.6; text-align: center; } + +/* 从扫描报告分区跳转时高亮对应光 */ +.light-card-focus { + border: 2rpx solid rgba(60, 60, 60, 0.35); + box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.10); +} diff --git a/miniprogram/pages/manual-treatment/manual-treatment.js b/miniprogram/pages/manual-treatment/manual-treatment.js index 6a7176d..ae250ce 100644 --- a/miniprogram/pages/manual-treatment/manual-treatment.js +++ b/miniprogram/pages/manual-treatment/manual-treatment.js @@ -23,13 +23,13 @@ Page({ ], selectedFunctionId: 'rejuvenate', selectedWavelength: 2, - // region mask mapping identical to treatment-setup: 右=0x01 左=0x02 上=0x04 中=0x08 下=0x10 + // 掩码 = IO 纵列布局(与 treatment-setup 一致):左=0x01 中上=0x02 中=0x04 中下=0x08 右=0x10 regions: [ - { key: 'right', mask: 0x01, checked: true }, - { key: 'left', mask: 0x02, checked: true }, - { key: 'top', mask: 0x04, checked: true }, - { key: 'middle', mask: 0x08, checked: true }, - { key: 'bottom', mask: 0x10, checked: true } + { key: 'left', mask: 0x01, checked: true }, + { key: 'top', mask: 0x02, checked: true }, + { key: 'middle', mask: 0x04, checked: true }, + { key: 'bottom', mask: 0x08, checked: true }, + { key: 'right', mask: 0x10, checked: true } ], // safety: a single session must NOT exceed 10 minutes (hardware caps at 10). durations: [5, 10], diff --git a/miniprogram/pages/scan-report/scan-report.js b/miniprogram/pages/scan-report/scan-report.js index c6a50cf..4a08973 100644 --- a/miniprogram/pages/scan-report/scan-report.js +++ b/miniprogram/pages/scan-report/scan-report.js @@ -3,7 +3,8 @@ var ble = require('../../services/ble') var diagnosis = require('../../services/diagnosis') var i18n = require('../../i18n/index') -var WAVE_CODE_KEY = { 1: 'infrared', 2: 'red', 3: 'uv', 4: 'yellow' } +// diagnosis 的 wave key ('ir') 与 common.wavelengths 的 key ('infrared') 不同名,需映射 +var WAVE_COMMON_KEY = { red: 'red', ir: 'infrared', uv: 'uv', yellow: 'yellow' } function pad2(n) { return (n < 10 ? '0' : '') + n } @@ -24,6 +25,7 @@ Page({ overallList: [], regionList: [], recommendList: [], + faceZones: [], starting: false, error: '' }, @@ -111,9 +113,16 @@ Page({ return { label: d.problems[o.type] || o.type, level: o.level, levelLabel: levelLabel(o.level) } }) + function regionName(key) { + return (common.regions && common.regions[key]) || key + } + function modeName(waveKey) { + return (d.modeNames && d.modeNames[waveKey]) || '' + } + var regionList = (report.regions || []).map(function (r) { return { - name: d.regionNames[r.region] || r.region, + name: regionName(r.region), level: r.level, levelLabel: levelLabel(r.level), problemLabel: r.top_problem ? (d.problems[r.top_problem] || r.top_problem) : d.noProblem, @@ -121,22 +130,34 @@ Page({ } }) - var defs = diagnosis.REGION_DEFS + // 推荐护理:现在 recommend_plan 每区一条(可不同色),一条 BLE 命令可全部下发 var recommendList = (report.recommend_plan || []).map(function (p) { - var names = [] - for (var i = 0; i < defs.length; i++) { - if (p.mask & defs[i].mask) names.push(d.regionNames[defs[i].key] || defs[i].key) - } - var waveKey = WAVE_CODE_KEY[p.wavelength] return { - label: d.problems[p.label_key] || '', - wavelengthLabel: (waveKey && common.wavelengths[waveKey]) || '', - regionsLabel: names.join('、'), - wavelength: p.wavelength, + modeLabel: modeName(p.wave), + wavelengthLabel: common.wavelengths[WAVE_COMMON_KEY[p.wave]] || '', + regionsLabel: regionName(p.region), + levelLabel: levelLabel(p.level), mask: p.mask } }) + // 面罩示意图数据(固定 5 区,未扫描/无问题的区置灰) + var byKey = {} + ;(report.regions || []).forEach(function (r) { byKey[r.region] = r }) + var faceZones = diagnosis.REGION_DEFS.map(function (def) { + var r = byKey[def.key] + var hasProblem = !!(r && r.top_problem && r.wave) + return { + key: def.key, + waveKey: hasProblem ? r.wave : null, + name: regionName(def.key), + hasProblem: hasProblem, + modeLabel: hasProblem ? modeName(r.wave) : '', + levelLabel: hasProblem ? levelLabel(r.level) : '', + colorClass: hasProblem ? 'zone-' + r.wave : 'zone-none' + } + }) + this._report = report this.setData({ loading: false, @@ -146,26 +167,37 @@ Page({ overallList: overallList, regionList: regionList, recommendList: recommendList, + faceZones: faceZones, error: '' }) }, + onTapZone: function (e) { + var wave = e.currentTarget.dataset.wave + wx.navigateTo({ url: '/pages/light-info/light-info' + (wave ? '?wave=' + wave : '') }) + }, + onStartRecommend: function () { var self = this var report = self._report || {} + var plan = report.recommend_plan || [] if (!ble.isConnected()) { self.setData({ error: i18n.t('common.deviceNotConnected') }) return } - var plan = (report.recommend_plan && report.recommend_plan[0]) || null - var mask = plan ? plan.mask : (report.recommend_mask || 0x1F) - var wl = plan ? plan.wavelength : 2 - if (!mask) mask = 0x1F + if (!plan.length) return + + // 一条 33B 命令携带全部分区差异化方案(每区各自的光色,亮度来自 diagnosis config,默认 204=80%) + var mask = report.recommend_mask || 0 + var wl = plan[0].wavelength || 2 // treating 页展示用(多色场景显示首个) self.setData({ starting: true, error: '' }) ble.setParams({ - region_mask: mask, wavelength: wl, brightness: 140, - duration_ms: 600000, mode: 1, control: 0x02 + plan: plan.map(function (p) { + return { mask: p.mask, wave: p.wave, brightness: p.brightness } + }), + duration_ms: 600000, + control: 0x02 }).then(function () { return ble.startTreatment(mask) }).then(function () { diff --git a/miniprogram/pages/scan-report/scan-report.wxml b/miniprogram/pages/scan-report/scan-report.wxml index 46fe595..71ef53a 100644 --- a/miniprogram/pages/scan-report/scan-report.wxml +++ b/miniprogram/pages/scan-report/scan-report.wxml @@ -30,6 +30,64 @@ {{i18n.report.noProblem}} + + + {{i18n.report.faceTitle}} + + + + {{faceZones[0].name}} + {{faceZones[0].modeLabel}} + {{faceZones[0].levelLabel}} + + + + + {{faceZones[1].name}} + {{faceZones[1].modeLabel}} + {{faceZones[1].levelLabel}} + + + {{faceZones[2].name}} + {{faceZones[2].modeLabel}} + {{faceZones[2].levelLabel}} + + + {{faceZones[3].name}} + {{faceZones[3].modeLabel}} + {{faceZones[3].levelLabel}} + + + + + {{faceZones[4].name}} + {{faceZones[4].modeLabel}} + {{faceZones[4].levelLabel}} + + + + + + + {{i18n.report.modeNames.red}} + + + + {{i18n.report.modeNames.ir}} + + + + {{i18n.report.modeNames.uv}} + + + + {{i18n.report.modeNames.yellow}} + + + {{i18n.report.faceTapHint}} + {{i18n.report.allNormalHint}} + + {{i18n.report.regionTitle}} @@ -48,7 +106,7 @@ - {{item.label}} + {{item.modeLabel}} {{item.wavelengthLabel}} · {{item.regionsLabel}} diff --git a/miniprogram/pages/scan-report/scan-report.wxss b/miniprogram/pages/scan-report/scan-report.wxss index 25323cb..3090feb 100644 --- a/miniprogram/pages/scan-report/scan-report.wxss +++ b/miniprogram/pages/scan-report/scan-report.wxss @@ -60,6 +60,73 @@ .empty-hint { color: #999; font-size: 26rpx; } +.face-map { + display: flex; + height: 480rpx; + gap: 8rpx; + padding: 12rpx; + box-sizing: border-box; + background: #FAFAFA; + border-radius: 32rpx; +} +.face-col { display: flex; flex-direction: column; flex: 1; gap: 8rpx; } +.face-col-mid { flex: 1.15; } +.face-zone { + flex: 1; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + border-radius: 20rpx; + border: 2rpx solid transparent; + padding: 8rpx; + box-sizing: border-box; + transition: transform 0.1s ease; +} +.face-col-side .face-zone { border-radius: 28rpx; } +.face-zone:active { transform: scale(0.96); } +.face-zone-name { font-size: 26rpx; font-weight: 600; } +.face-zone-mode { font-size: 22rpx; margin-top: 6rpx; } +.face-zone-level { font-size: 20rpx; margin-top: 2rpx; opacity: 0.85; } + +.zone-red { + background: rgba(232, 93, 93, 0.14); + border-color: rgba(232, 93, 93, 0.4); + color: #B23C3C; +} +.zone-ir { + background: rgba(192, 107, 74, 0.14); + border-color: rgba(192, 107, 74, 0.4); + color: #8C4A2E; +} +.zone-uv { + background: rgba(142, 107, 216, 0.14); + border-color: rgba(142, 107, 216, 0.4); + color: #5F3FAE; +} +.zone-yellow { + background: rgba(232, 185, 61, 0.18); + border-color: rgba(232, 185, 61, 0.45); + color: #8A6A10; +} +.zone-none { + background: #F0F0F0; + border-color: #E5E5E5; + color: #999; +} + +.face-legend { display: flex; flex-wrap: wrap; margin-top: 20rpx; } +.legend-item { display: flex; align-items: center; margin: 0 20rpx 10rpx 0; } +.legend-dot { width: 16rpx; height: 16rpx; border-radius: 50%; margin-right: 8rpx; } +.legend-dot.zone-red { background: #E85D5D; border: none; } +.legend-dot.zone-ir { background: #C06B4A; border: none; } +.legend-dot.zone-uv { background: #8E6BD8; border: none; } +.legend-dot.zone-yellow { background: #E8B93D; border: none; } +.legend-label { font-size: 22rpx; color: #666; } + +.face-tap-hint { font-size: 22rpx; color: #bbb; margin-top: 14rpx; text-align: center; } +.face-all-normal-hint { font-size: 24rpx; color: #6BBF59; text-align: center; margin-top: 12rpx; } + .region-row { display: flex; align-items: center; diff --git a/miniprogram/pages/treating/treating.js b/miniprogram/pages/treating/treating.js index 85e811a..a3256a0 100644 --- a/miniprogram/pages/treating/treating.js +++ b/miniprogram/pages/treating/treating.js @@ -23,16 +23,15 @@ Page({ }, _getRegionText: function (regionMask) { + // 掩码 = IO 纵列布局:0x01左 0x02中上 0x04中 0x08中下 0x10右 var REGION_MAP = { - 1: 'common.regions.right', - 2: 'common.regions.left', - 4: 'common.regions.top', - 8: 'common.regions.middle', - 16: 'common.regions.bottom', - 32: 'treating.regionTopLeft', - 64: 'treating.regionTopRight' + 1: 'common.regions.left', + 2: 'common.regions.top', + 4: 'common.regions.middle', + 8: 'common.regions.bottom', + 16: 'common.regions.right' } - if (regionMask === 0x7F) return i18n.t('treating.allRegions') + if (regionMask === 0x1F) return i18n.t('treating.allRegions') var names = [] for (var bit in REGION_MAP) { if (regionMask & parseInt(bit)) names.push(i18n.t(REGION_MAP[bit])) @@ -48,7 +47,7 @@ Page({ var app = getApp() this.setData({ statusBarHeight: app.globalData.statusBarHeight }) this._deviceId = ble.getDeviceId() || (app.globalData.currentDevice && app.globalData.currentDevice.device_id) || '' - var regions = parseInt(options.regions) || 0x7F + var regions = parseInt(options.regions) || 0x1F this.setData({ regions: regions, wavelength: parseInt(options.wavelength) || 2, diff --git a/miniprogram/pages/treatment-setup/treatment-setup.js b/miniprogram/pages/treatment-setup/treatment-setup.js index 5716c0e..7308862 100644 --- a/miniprogram/pages/treatment-setup/treatment-setup.js +++ b/miniprogram/pages/treatment-setup/treatment-setup.js @@ -34,7 +34,8 @@ Page({ var app = getApp() this.setData({ statusBarHeight: app.globalData.statusBarHeight }) i18n.bind(this) - var regionKeys = ['right', 'left', 'top', 'middle', 'bottom'] + // 顺序对应 data.regions 的掩码 0x01..0x10(IO1..IO5 = 左/中上/中/中下/右) + var regionKeys = ['left', 'top', 'middle', 'bottom', 'right'] var regions = this.data.regions regions.forEach(function (r, i) { r.name = i18n.t('common.regions.' + regionKeys[i]) diff --git a/miniprogram/services/ble/connection.js b/miniprogram/services/ble/connection.js index fb4a267..df79b96 100644 --- a/miniprogram/services/ble/connection.js +++ b/miniprogram/services/ble/connection.js @@ -99,7 +99,7 @@ function handleValueChange(res) { console.warn('[BLE] ADC checksum mismatch, dropping') return } - emit('adc', { pd: parsed.pd, vbat: vbatMv, battery: batteryPct, fitting: parsed.fitting, run_state: parsed.run_state }) + emit('adc', { pd: parsed.pd, vbat: vbatMv, battery: batteryPct, fitting: parsed.fitting, scan_wave: parsed.scan_wave, run_state: parsed.run_state, is_fault: parsed.is_fault }) emit('battery', { battery: batteryPct, vbat: vbatMv }) emit('fitting', { fitting: parsed.fitting }) emit('run_state', { run_state: parsed.run_state }) diff --git a/miniprogram/services/ble/protocol.js b/miniprogram/services/ble/protocol.js index 4e78107..829be9e 100644 --- a/miniprogram/services/ble/protocol.js +++ b/miniprogram/services/ble/protocol.js @@ -57,18 +57,23 @@ var TREAT_MODE = { SMART: 1 } +// 区域 = IO 纵列布局(果果 2026-07 定案):左=IO1(0x01),中上=IO2(0x02),中=IO3(0x04), +// 中下=IO4(0x08),右=IO5(0x10)。旧命名(左脸颊/额头/鼻部…)来自过时文档,与实物不符,已废弃。 var REGION = { - LEFT_CHEEK: 0x01, - RIGHT_CHEEK: 0x02, - FOREHEAD: 0x04, - CHIN: 0x08, - NOSE: 0x10, - LEFT_EYE: 0x20, - RIGHT_EYE: 0x40, - FULL_FACE: 0x7F + LEFT: 0x01, + TOP: 0x02, + MIDDLE: 0x04, + BOTTOM: 0x08, + RIGHT: 0x10, + FULL_FACE: 0x1F } -var REGION_NAMES = ['left_cheek', 'right_cheek', 'forehead', 'chin', 'nose', 'left_eye', 'right_eye'] +var REGION_NAMES = ['left', 'top', 'middle', 'bottom', 'right'] + +// FFE4 Byte17 高三位 = 扫描时光色指示(协议简述-添加扫描时光色.docx 2026-07): +// 001=红光 010=红外 011=紫外(蓝) 100=暖黄。注意与下发命令的 WAVELENGTH 编码 +// (IR=1,R=2,UV=3,Y=4) 不同——1/2 正好是红与红外互换,绝不能复用那套常量。 +var SCAN_WAVE_KEY = { 1: 'red', 2: 'ir', 3: 'uv', 4: 'yellow' } var DEVICE_ERR = { 0x00: 'SUCCESS', @@ -167,37 +172,64 @@ var CONTROL = { TREAT: 0x02 } +// 每 IO 6 字节,颜色格顺序 [红][红外][紫外][暖黄](厂商原表,新版协议简述再次确认)。 +// 两种调用方式: +// 单色广播(旧):{ region_mask, wavelength(编码), brightness, ... } +// 分区差异化(新):{ plan: [{ mask, wave:'red'|'ir'|'uv'|'yellow', brightness }], hold_time, control } +// —— 同一条命令里不同区可用不同颜色不同亮度(协议本身就支持 5 IO × 4 色独立)。 +var WAVE_BYTE_OFFSET = { red: 0, ir: 1, uv: 2, yellow: 3 } + +// 安全包线(builder 层硬上限,纵深防御——即使服务端 diagnosis_config 误配也不可突破): +// 治疗亮度 ≤204(80%),单次时长 ≤600s(10min)。固件侧安全机制大多未实现,此处是最后防线。 +var MAX_TREAT_BRIGHTNESS = 204 +var MAX_HOLD_SECONDS = 600 + function buildVendorCommand(options) { options = options || {} - var regionMask = options.region_mask || REGION.FULL_FACE - var wavelength = options.wavelength || WAVELENGTH.R - var brightness = clampByte(options.brightness === undefined ? 200 : options.brightness) var gain = clampUInt16(options.current_gain === undefined ? 0 : options.current_gain) var durationMs = options.duration_ms || 600000 var holdSeconds = clampUInt16(options.hold_time === undefined ? Math.round(durationMs / 1000) : options.hold_time) var control = options.control !== undefined ? options.control : CONTROL.TREAT - var regions = [ - REGION.LEFT_CHEEK, - REGION.RIGHT_CHEEK, - REGION.FOREHEAD, - REGION.CHIN, - REGION.NOSE - ] + if (holdSeconds > MAX_HOLD_SECONDS) holdSeconds = MAX_HOLD_SECONDS + var isTreat = control === CONTROL.TREAT + function clampTreat(b) { + b = clampByte(b) + return isTreat && b > MAX_TREAT_BRIGHTNESS ? MAX_TREAT_BRIGHTNESS : b + } + var ioMasks = [REGION.LEFT, REGION.TOP, REGION.MIDDLE, REGION.BOTTOM, REGION.RIGHT] // IO1..IO5 var bytes = [] + var i, j - for (var i = 0; i < regions.length; i++) { - var enabled = (regionMask & regions[i]) !== 0 - var red = 0 - var infrared = 0 - var uv = 0 - var warmYellow = 0 - if (enabled) { - if (wavelength === WAVELENGTH.R) red = brightness - if (wavelength === WAVELENGTH.IR) infrared = brightness - if (wavelength === WAVELENGTH.UV) uv = brightness - if (wavelength === WAVELENGTH.Y) warmYellow = brightness + if (options.plan && options.plan.length) { + for (i = 0; i < ioMasks.length; i++) { + var slot = [0, 0, 0, 0] + for (j = 0; j < options.plan.length; j++) { + var p = options.plan[j] + if ((p.mask & ioMasks[i]) === 0) continue + var off = WAVE_BYTE_OFFSET[p.wave] + if (off === undefined) continue + slot[off] = clampTreat(p.brightness === undefined ? 200 : p.brightness) + } + bytes.push(slot[0], slot[1], slot[2], slot[3], (gain >> 8) & 0xFF, gain & 0xFF) + } + } else { + var regionMask = options.region_mask || REGION.FULL_FACE + var wavelength = options.wavelength || WAVELENGTH.R + var brightness = clampTreat(options.brightness === undefined ? 200 : options.brightness) + for (i = 0; i < ioMasks.length; i++) { + var enabled = (regionMask & ioMasks[i]) !== 0 + var red = 0 + var infrared = 0 + var uv = 0 + var warmYellow = 0 + if (enabled) { + if (wavelength === WAVELENGTH.R) red = brightness + if (wavelength === WAVELENGTH.IR) infrared = brightness + if (wavelength === WAVELENGTH.UV) uv = brightness + if (wavelength === WAVELENGTH.Y) warmYellow = brightness + } + bytes.push(red, infrared, uv, warmYellow, (gain >> 8) & 0xFF, gain & 0xFF) } - bytes.push(red, infrared, uv, warmYellow, (gain >> 8) & 0xFF, gain & 0xFF) } bytes.push((holdSeconds >> 8) & 0xFF, holdSeconds & 0xFF) @@ -217,13 +249,18 @@ function parseVendorStatus(buffer) { for (var p = 0; p < 7; p++) { pds19.push(bytes[p * 2] | (bytes[p * 2 + 1] << 8)) } + // Byte17 复用:低位=贴合状态(0/1),高三位=扫描时光色指示(0 表示无标识/非扫描态或旧固件)。 + // Byte18 运行状态:0=IDLE 1=检测 2=治疗 0xFF=故障。 + var scanWaveCode = (bytes[16] >> 5) & 0x07 return { type: 'adc', is_heartbeat: false, pd: pds19, vbat: bytes[14] | (bytes[15] << 8), - fitting: bytes[16], + fitting: bytes[16] & 0x1F, + scan_wave: SCAN_WAVE_KEY[scanWaveCode] || null, run_state: bytes[17], + is_fault: bytes[17] === 0xFF, checksum_ok: checksum19 === bytes[18], raw_hex: bytesToHex(bytes) } @@ -326,11 +363,13 @@ function parseException(payload) { // --- display helpers --- +// 掩码 = IO 纵列布局(与 REGION 常量一致)。注意:此处为硬编码中文(历史遗留, +// history/treatment-done 在用);新页面请改用 i18n common.regions.* 取标签。 function getRegionName(mask) { var names = [] var bits = [ - [0x01, '右区'], [0x02, '左区'], [0x04, '上区'], - [0x08, '中区'], [0x10, '下区'], [0x20, '左上区'], [0x40, '右上区'] + [0x01, '左区'], [0x02, '中上区'], [0x04, '中区'], + [0x08, '中下区'], [0x10, '右区'] ] for (var i = 0; i < bits.length; i++) { if (mask & bits[i][0]) names.push(bits[i][1]) @@ -362,6 +401,7 @@ module.exports = { TREAT_MODE: TREAT_MODE, REGION: REGION, REGION_NAMES: REGION_NAMES, + SCAN_WAVE_KEY: SCAN_WAVE_KEY, CONTROL: CONTROL, DEVICE_ERR: DEVICE_ERR, diff --git a/miniprogram/services/diagnosis.js b/miniprogram/services/diagnosis.js index 48c4a50..038088e 100644 --- a/miniprogram/services/diagnosis.js +++ b/miniprogram/services/diagnosis.js @@ -1,130 +1,165 @@ -// Skin-tendency diagnosis — FRAMEWORK / placeholder implementation. +// Skin-tendency diagnosis — 按《扫描+护理完整流程.docx》7.1/7.2/7.3 + +// 《协议简述-添加扫描时光色.docx》+ 果果 2026-07 定案实现。 // -// STATUS: the diagnosis 依据 is NOT yet calibrated (客户也认为"还只是概念"). -// This module defines the full data pipeline so the report UI + storage work end -// to end today, but the thresholds and the PD->region mapping are PLACEHOLDERS to -// be replaced after real-device calibration. It degrades gracefully when only -// partial scan data (currently single-wavelength red) is available. +// 核心链路:28 组 PD(4 波长×7 路) → 按 PD_REGION_MAP 聚合成 5 区 → +// 每波长算 5 区平均当基准 → 吸收度 NR = 本区/基准 − 1 → +// 每区取 4 个 NR 的最大者(argmax),超过阈值 TH 才判定问题 → 该波长即该区治疗光色。 // -// Two things here need hardware/calibration confirmation before this is "real": -// 1) PD_REGION_MAP — which of the 7 PDs feed which facial region (docs disagree). -// 2) levels thresholds — normalized-absorption cutoffs per severity level. -// Both can be overridden at runtime by the server-side diagnosis_config, so tuning -// after calibration does NOT require an app release. +// 极性(已由固件批注版文档坐实,新版协议简述再次确认"0x0FFF表示最低光照"): +// PD ADC 值越大 = 反射光越弱 = 皮肤吸收越多。故 NR = zone/avg − 1(吸收多→NR 高)。 +// config.polarity = 'direct' 可切回"值大=光强"的旧假设(备用开关,标定时救急)。 +// +// 仍未确认(走 config 热调,勿写死): +// 1) PD_REGION_MAP —— 7 路 PD 与 5 区的物理对应,所有文档从未给出,当前为推测值。 +// 2) 3 路 PD 区的聚合 —— 文档 7.1 自相矛盾(几何平均 vs 取最小),按更细的几何平均+3σ剔异常实现。 +// 所有阈值/亮度/映射均可被服务端 diagnosis_config 覆盖,标定后免发版调参。 -// Problem type -> recommended care wavelength (IR=1, R=2, UV=3, Y=4). +// 问题类型 -> 治疗波长编码(下发命令用:IR=1, R=2, UV=3, Y=4)。 var PROBLEM_WAVELENGTH = { aging: 2, acne: 3, pigment: 4, deep: 1 } -// Scanned wavelength code -> the problem it reveals (inverse of the above). -var WAVELENGTH_PROBLEM = { 1: 'deep', 2: 'aging', 3: 'acne', 4: 'pigment' } -// Dictionary wave-key -> wavelength code. +// 波长 key -> 揭示的问题类型。 +var WAVE_PROBLEM = { red: 'aging', uv: 'acne', yellow: 'pigment', ir: 'deep' } +// 波长 key -> 下发命令编码。 var WAVE_KEY_CODE = { red: 2, uv: 3, yellow: 4, ir: 1 } -// 5 regions in the app's neutral convention (right/left/top/middle/bottom), -// matching treatment-setup.js masks. +// 5 区 = IO 纵列布局(果果定案):左=IO1 中上=IO2 中=IO3 中下=IO4 右=IO5。 var REGION_DEFS = [ - { key: 'right', mask: 0x01 }, - { key: 'left', mask: 0x02 }, - { key: 'top', mask: 0x04 }, - { key: 'middle', mask: 0x08 }, - { key: 'bottom', mask: 0x10 } + { key: 'left', mask: 0x01 }, + { key: 'top', mask: 0x02 }, + { key: 'middle', mask: 0x04 }, + { key: 'bottom', mask: 0x08 }, + { key: 'right', mask: 0x10 } ] -// PLACEHOLDER PD->region map. Flow doc: 7 PDs = 1 special region (3 PDs) + 4 regions -// (1 PD each). The exact assignment is UNCONFIRMED — replace after hardware confirms -// the PD physical layout. Each region lists the PD index(es) that feed its signal. -var PD_REGION_MAP = { - right: [0], left: [1], top: [2], middle: [3, 5, 6], bottom: [4] -} - -var MAX_ADC = 4095 - var DEFAULT_CONFIG = { calibrated: false, - levels: { low: 0.15, mid: 0.35, high: 0.55 }, + polarity: 'inverted', // inverted=值大吸收多(已确认) | direct=旧假设备用 + th: 0.10, // 判定阈值(文档建议初始值,需临床标定) + severity: { low: 0.05, mid: 0.15, high: 0.30 }, // 轻/中/重分级,仅报告展示 + brightness: 204, // 治疗强度 80%(果果定案),仅用于推荐方案下发 + // 推测映射:中区含 3 路 PD(文档"1 特殊区 3 路+4 普通区各 1 路"),待固件确认后改 config。 + pd_region_map: { left: [0], top: [1], middle: [2, 3, 4], bottom: [5], right: [6] }, problem_wavelength: PROBLEM_WAVELENGTH } -function _avg(arr) { - if (!arr || !arr.length) return 0 - var s = 0 - for (var i = 0; i < arr.length; i++) s += arr[i] - return s / arr.length +function _median(arr) { + var s = arr.slice().sort(function (a, b) { return a - b }) + var m = Math.floor(s.length / 2) + return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2 } -// Normalized absorption in [0,1]: the more the light is absorbed (lower reflected PD -// relative to the底噪 baseline), the stronger the tendency signal. -function _absorption(pdValue, baseline) { - if (!baseline || baseline <= 0) return 0 - var a = (baseline - pdValue) / baseline - if (a < 0) a = 0 - if (a > 1) a = 1 - return a +// 区域有效值:1 路直接用;≥3 路按 7.1 节"几何平均 + 剔奇异值"(防黑痣/毛发单点失真)。 +// 剔异常用 MAD(中位数绝对偏差)而非文档字面的 3σ:n=3 时单个离群点会把标准差同步撑大, +// 3σ 判据永不触发(审计实证 [900,9000,905] 不剔);MAD 阈值 4.45×MAD ≈ 3σ 等效(3×1.4826)。 +function _aggregate(vals) { + if (!vals.length) return 0 + if (vals.length === 1) return vals[0] + var kept = vals + if (vals.length >= 3) { + var med = _median(vals) + var devs = vals.map(function (v) { return Math.abs(v - med) }) + var mad = _median(devs) + var thr = 4.45 * mad + var filtered = vals.filter(function (v) { return Math.abs(v - med) <= thr }) + if (filtered.length >= 2) kept = filtered + } + var logSum = 0 + for (var i = 0; i < kept.length; i++) { + if (kept[i] <= 0) return 0 // 有无效 0 值时该区数据不可信 + logSum += Math.log(kept[i]) + } + return Math.exp(logSum / kept.length) } -function _levelOf(score, levels) { - if (score >= levels.high) return 3 - if (score >= levels.mid) return 2 - if (score >= levels.low) return 1 +function _severityLevel(nr, severity) { + if (nr > severity.high) return 3 + if (nr > severity.mid) return 2 + if (nr > severity.low) return 1 return 0 } // scanData: { // device_id, scanned_at, -// region_mask, // which regions were scanned (default 0x1F) -// noise: [7], // per-PD 底噪 baseline (optional; defaults MAX_ADC) -// waves: { red:[7], uv:[7], yellow:[7], ir:[7] } // any subset; each = 7 PD values +// region_mask, // 本次扫描选中的区域(默认 0x1F) +// waves: { red:[7], ir:[7], uv:[7], yellow:[7] } // 任意子集;每项 = 7 路 PD ADC // } function analyze(scanData, config) { config = config || DEFAULT_CONFIG - var levels = config.levels || DEFAULT_CONFIG.levels + var th = config.th !== undefined ? config.th : DEFAULT_CONFIG.th + var severity = config.severity || DEFAULT_CONFIG.severity + var brightness = config.brightness || DEFAULT_CONFIG.brightness + var pdMap = config.pd_region_map || DEFAULT_CONFIG.pd_region_map var problemWave = config.problem_wavelength || PROBLEM_WAVELENGTH + var inverted = config.polarity !== 'direct' scanData = scanData || {} var waves = scanData.waves || {} - var noise = scanData.noise var scannedMask = scanData.region_mask || 0x1F + // 1) 聚合:每波长 × 每选中区 → 区域有效值 + var zone = {} // zone[waveKey][regionKey] = 有效值 + var included = [] // 参与本次扫描的区域定义 + var r, def + for (r = 0; r < REGION_DEFS.length; r++) { + if ((scannedMask & REGION_DEFS[r].mask) !== 0) included.push(REGION_DEFS[r]) + } + for (var wk in waves) { + if (!waves.hasOwnProperty(wk) || !WAVE_PROBLEM[wk]) continue + var pdArr = waves[wk] + if (!pdArr || !pdArr.length) continue + zone[wk] = {} + for (r = 0; r < included.length; r++) { + def = included[r] + var idxs = pdMap[def.key] || [] + var vals = [] + for (var k = 0; k < idxs.length; k++) { + var v = pdArr[idxs[k]] + if (v !== undefined && v !== null && v > 0) vals.push(v) + } + if (vals.length) zone[wk][def.key] = _aggregate(vals) + } + } + + // 2) 每波长的基准 = 该波长下各区有效值的平均(7.1:Avg_PD_X_AllZones) + var avg = {} + for (wk in zone) { + if (!zone.hasOwnProperty(wk)) continue + var sum = 0 + var n = 0 + for (r = 0; r < included.length; r++) { + var zv = zone[wk][included[r].key] + if (zv !== undefined) { sum += zv; n++ } + } + if (n > 0) avg[wk] = sum / n + } + + // 3) 吸收度 NR + 每区 argmax 判定 var regions = [] var overallAcc = {} - - for (var r = 0; r < REGION_DEFS.length; r++) { - var def = REGION_DEFS[r] - if ((scannedMask & def.mask) === 0) continue - var pdIdx = PD_REGION_MAP[def.key] || [] - var problems = [] - - for (var wk in waves) { - if (!waves.hasOwnProperty(wk)) continue - var code = WAVE_KEY_CODE[wk] - var problemType = WAVELENGTH_PROBLEM[code] - if (!problemType) continue - - var pdVals = [] - var baseVals = [] - for (var k = 0; k < pdIdx.length; k++) { - var idx = pdIdx[k] - if (waves[wk][idx] !== undefined) pdVals.push(waves[wk][idx]) - baseVals.push(noise && noise[idx] !== undefined ? noise[idx] : MAX_ADC) - } - if (!pdVals.length) continue - - var score = _absorption(_avg(pdVals), _avg(baseVals)) - var level = _levelOf(score, levels) - if (level > 0) { - problems.push({ type: problemType, level: level, score: Math.round(score * 100) / 100 }) - if (!overallAcc[problemType] || level > overallAcc[problemType]) { - overallAcc[problemType] = level - } - } + for (r = 0; r < included.length; r++) { + def = included[r] + var nrs = [] // 该区所有可算波长的 {wave, nr} + for (wk in zone) { + if (!zone.hasOwnProperty(wk)) continue + if (zone[wk][def.key] === undefined || !avg[wk]) continue + var ratio = zone[wk][def.key] / avg[wk] + var nr = inverted ? (ratio - 1) : (1 - ratio) + nrs.push({ wave: wk, nr: Math.round(nr * 1000) / 1000 }) + } + nrs.sort(function (a, b) { return b.nr - a.nr }) + var top = nrs.length ? nrs[0] : null + var hasProblem = !!(top && top.nr > th) + var problemType = hasProblem ? WAVE_PROBLEM[top.wave] : null + var level = hasProblem ? Math.max(1, _severityLevel(top.nr, severity)) : 0 + if (problemType && (!overallAcc[problemType] || level > overallAcc[problemType])) { + overallAcc[problemType] = level } - - problems.sort(function (a, b) { return (b.level - a.level) || (b.score - a.score) }) - var top = problems.length ? problems[0] : null regions.push({ region: def.key, mask: def.mask, - top_problem: top ? top.type : null, - level: top ? top.level : 0, - problems: problems + top_problem: problemType, + wave: hasProblem ? top.wave : null, + level: level, + score: top ? top.nr : 0, + nrs: nrs // 全量吸收度,供标定期回看 }) } @@ -134,23 +169,22 @@ function analyze(scanData, config) { } overall.sort(function (a, b) { return b.level - a.level }) - // Recommendation: care each region-with-a-top-problem using that problem's wavelength. - // One BLE command carries one wavelength, so plan entries are grouped by wavelength. - var planByWave = {} - var recommendMask = 0 - for (var i = 0; i < regions.length; i++) { - var reg = regions[i] - if (!reg.top_problem) continue - var wl = problemWave[reg.top_problem] - if (!wl) continue - planByWave[wl] = (planByWave[wl] || 0) | reg.mask - recommendMask |= reg.mask - } + // 4) 推荐方案:每个问题区一条(区独立、可不同色),一条 BLE 命令即可全部下发。 var recommendPlan = [] - for (var w in planByWave) { - if (!planByWave.hasOwnProperty(w)) continue - var code2 = parseInt(w, 10) - recommendPlan.push({ wavelength: code2, mask: planByWave[w], label_key: WAVELENGTH_PROBLEM[code2] }) + var recommendMask = 0 + for (r = 0; r < regions.length; r++) { + var reg = regions[r] + if (!reg.top_problem || !reg.wave) continue + recommendPlan.push({ + region: reg.region, + mask: reg.mask, + wave: reg.wave, + wavelength: WAVE_KEY_CODE[reg.wave], + label_key: reg.top_problem, + level: reg.level, + brightness: brightness + }) + recommendMask |= reg.mask } return { @@ -165,30 +199,30 @@ function analyze(scanData, config) { } } -// Adapt the current (single-wavelength red) auto-scan result into scanData, so the -// pipeline works today. pdAvg = 7 averaged PD values under red light. -function fromRedScan(pdAvg, regionMask, deviceId, scannedAt, noise) { +// 把 auto-scan 按波长分桶后的平均值组装成 scanData。 +// buckets: { red:[7], ir:[7], uv:[7], yellow:[7] } 任意子集(旧固件无波长标识时只有 red)。 +function buildScanData(buckets, regionMask, deviceId, scannedAt) { return { device_id: deviceId || null, scanned_at: scannedAt || 0, region_mask: regionMask || 0x1F, - noise: noise || null, - waves: { red: (pdAvg || []).slice(0, 7) } + waves: buckets || {} } } -// Deterministic mock report for UI development / demo when there is no device data. +// 无设备数据时的演示报告(开发者工具 mock)。 +// 数值按已确认极性编造:值大=吸收多 → 左区红光偏高(光老化)、中区紫外偏高(痘痘油脂)。 function mockReport() { return analyze({ device_id: 'MOCK', scanned_at: 0, region_mask: 0x1F, - noise: [4000, 4000, 4000, 4000, 4000, 4000, 4000], waves: { - red: [3500, 3600, 1900, 3400, 3450, 3500, 3500], - uv: [3700, 3750, 3600, 1700, 3700, 1800, 1900], - yellow: [3500, 3550, 3400, 3450, 2300, 3500, 3520], - ir: [3600, 3600, 3550, 3580, 3560, 3600, 3600] + // 左 中上 中(3路) 中下 右 + red: [1350, 920, 900, 910, 905, 890, 940], + uv: [2050, 2020, 2600, 2560, 2620, 1990, 2080], + yellow: [1500, 1520, 1490, 1505, 1495, 1530, 1510], + ir: [1800, 1790, 1805, 1795, 1800, 1815, 1790] } }, DEFAULT_CONFIG) } @@ -196,9 +230,10 @@ function mockReport() { module.exports = { DEFAULT_CONFIG: DEFAULT_CONFIG, PROBLEM_WAVELENGTH: PROBLEM_WAVELENGTH, - WAVELENGTH_PROBLEM: WAVELENGTH_PROBLEM, + WAVE_PROBLEM: WAVE_PROBLEM, + WAVE_KEY_CODE: WAVE_KEY_CODE, REGION_DEFS: REGION_DEFS, analyze: analyze, - fromRedScan: fromRedScan, + buildScanData: buildScanData, mockReport: mockReport } diff --git a/server/sql/schema.sql b/server/sql/schema.sql index 1ada10b..5e9f5b1 100644 --- a/server/sql/schema.sql +++ b/server/sql/schema.sql @@ -204,4 +204,4 @@ INSERT IGNORE INTO system_settings (setting_key, setting_value) VALUES ('enable_binding', 'true'), ('enable_free_mode', 'true'), ('maintenance_mode', 'false'), -('diagnosis_config', '{"calibrated": false, "note": "占位阈值,待真机标定后调整", "levels": {"low": 0.15, "mid": 0.35, "high": 0.55}, "problem_wavelength": {"aging": 2, "acne": 3, "pigment": 4, "deep": 1}}'); +('diagnosis_config', '{"calibrated": false, "note": "阈值/PD映射为待标定初始值(文档建议值+推测映射);polarity=inverted 已由固件确认(PD值大=吸收多);pd_region_map 待固件给出 PD1~7 实际排布后修正", "polarity": "inverted", "th": 0.10, "severity": {"low": 0.05, "mid": 0.15, "high": 0.30}, "brightness": 204, "pd_region_map": {"left": [0], "top": [1], "middle": [2, 3, 4], "bottom": [5], "right": [6]}, "problem_wavelength": {"aging": 2, "acne": 3, "pigment": 4, "deep": 1}}');