poe-svelte-ui-lib 3.13.0 → 3.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,7 +33,6 @@
33
33
  const hints = $derived(hintsSetting("WidgetFOC", persistKey))
34
34
  const rootStyle = $derived(accentStyle(accent))
35
35
 
36
- /* Свёрнутость: выбор пользователя переживает перезагрузку (persistKey) */
37
36
  const guiCollapsed = untrack(() => collapsed)
38
37
  collapsed = readPersistedCollapsed(
39
38
  untrack(() => persistKey),
@@ -41,7 +40,6 @@
41
40
  )
42
41
  $effect(() => writePersistedCollapsed(persistKey, collapsed, guiCollapsed))
43
42
 
44
- /* Живое состояние: пока виджет раскрыт, раз в refreshMs он просит перечитать группу */
45
43
  $effect(() => {
46
44
  if (collapsed || !refreshMs || !onRefresh) return
47
45
  const timer = setInterval(() => onRefresh?.(), refreshMs)
@@ -50,7 +48,6 @@
50
48
 
51
49
  const finite = (v: unknown) => (v === undefined || v === null || v === "" || !Number.isFinite(Number(v)) ? undefined : Number(v))
52
50
 
53
- /* Флаги оси (Flg): 0x01 включён, 0x02 выход в угол, 0x04 калибровка нуля, 0x08 поток уставок прервался, 0x10 ноль известен, 0x20 занят процедурой */
54
51
  const flags = $derived(finite(value.Flg))
55
52
  const flag = (bit: number) => flags !== undefined && (flags & bit) !== 0
56
53
  const enabled = $derived(flag(0x01))
@@ -67,85 +64,77 @@
67
64
  ],
68
65
  )
69
66
 
70
- /* Настройки по разделам: ключ, единица (ключ перевода widget.foc.unit.*), выбор - варианты 0..n-1, только чтение */
71
67
  type Field = { key: string; unit?: string; options?: string[]; readonly?: boolean; step?: number; torqueModes?: number[] }
72
- const SECTIONS: { key: string; fields: Field[] }[] = [
73
- {
74
- key: "motor",
75
- fields: [
76
- { key: "M_Type", options: ["bldc", "stepper"] },
77
- { key: "M_PP", step: 1 },
78
- { key: "M_R", unit: "ohm", step: 0.01 },
79
- { key: "M_L", unit: "h", step: 0.0001 },
80
- { key: "M_KV", unit: "kv", step: 1 },
81
- { key: "M_Dir", readonly: true },
82
- ],
83
- },
84
- {
85
- key: "limits",
86
- fields: [
87
- { key: "M_VL", unit: "volt", step: 0.1 },
88
- { key: "M_CL", unit: "amp", step: 0.01, torqueModes: [1, 2, 3] },
89
- { key: "M_VLL", unit: "dps", step: 1 },
90
- { key: "M_CTO", unit: "ms", step: 10 },
91
- { key: "M_Torq", options: ["voltage", "estCurrent", "dcCurrent", "focCurrent"] },
92
- { key: "M_Mod", options: ["spwm", "svm", "trap120", "trap150"] },
93
- ],
94
- },
95
- {
96
- key: "current",
97
- fields: [
98
- ...["C_Kp", "C_Ki", "C_Kd"].map((key) => ({ key, step: 0.001, torqueModes: [2, 3] })),
99
- { key: "C_Lim", unit: "volt", readonly: true },
100
- { key: "C_Ramp", unit: "vps", step: 0.001, torqueModes: [2, 3] },
101
- ],
102
- },
103
- {
104
- key: "velocity",
105
- fields: [...["V_Kp", "V_Ki", "V_Kd"].map((key) => ({ key, step: 0.0001 })), { key: "V_Lim", readonly: true }, { key: "V_Ramp", step: 0.0001 }],
106
- },
107
- {
108
- key: "angle",
109
- fields: [
110
- { key: "A_Kp", step: 0.1 },
111
- { key: "A_Lim", unit: "dps", step: 1 },
112
- ],
113
- },
114
- {
115
- key: "sensor",
116
- fields: [
117
- { key: "S_Gain", unit: "vpa", step: 0.001 },
118
- { key: "S_OffA", unit: "volt", readonly: true },
119
- { key: "S_OffB", unit: "volt", readonly: true },
120
- { key: "S_OffC", unit: "volt", readonly: true },
121
- { key: "S_VTf", unit: "sec", step: 0.001 },
122
- { key: "S_CTf", unit: "sec", step: 0.0001 },
123
- ],
124
- },
68
+
69
+ const motorFields: Field[] = [
70
+ { key: "M_Type", options: ["bldc", "stepper"] },
71
+ { key: "M_PP", step: 1 },
72
+ { key: "M_R", unit: "ohm", step: 0.01 },
73
+ { key: "M_L", unit: "h", step: 0.0001 },
74
+ { key: "M_KV", unit: "kv", step: 1 },
75
+ { key: "M_Dir", readonly: true },
76
+ ]
77
+
78
+ const limitsFields: Field[] = [
79
+ { key: "M_VL", unit: "volt", step: 0.1 },
80
+ { key: "M_CL", unit: "amp", step: 0.01, torqueModes: [1, 2, 3] },
81
+ { key: "M_VLL", unit: "dps", step: 1 },
82
+ { key: "M_CTO", unit: "ms", step: 10 },
83
+ { key: "M_Torq", options: ["voltage", "estCurrent", "dcCurrent", "focCurrent"] },
84
+ { key: "M_Mod", options: ["spwm", "svm", "trap120", "trap150"] },
85
+ ]
86
+
87
+ const currentFields: Field[] = [
88
+ { key: "C_Kp", step: 0.001, torqueModes: [2, 3] },
89
+ { key: "C_Ki", step: 0.001, torqueModes: [2, 3] },
90
+ { key: "C_Kd", step: 0.001, torqueModes: [2, 3] },
91
+ { key: "C_Lim", unit: "volt", step: 0.1, torqueModes: [2, 3] },
92
+ { key: "C_Ramp", unit: "vps", step: 0.001, torqueModes: [2, 3] },
93
+ ]
94
+
95
+ const velocityFields: Field[] = [
96
+ { key: "V_Kp", step: 0.0001 },
97
+ { key: "V_Ki", step: 0.0001 },
98
+ { key: "V_Kd", step: 0.0001 },
99
+ { key: "V_Lim", readonly: true },
100
+ { key: "V_Ramp", step: 0.0001 },
101
+ ]
102
+
103
+ const angleFields: Field[] = [
104
+ { key: "A_Kp", step: 0.1 },
105
+ { key: "A_Lim", unit: "dps", step: 1 },
106
+ { key: "A_Ramp", unit: "dps2", step: 1 },
125
107
  ]
108
+
109
+ const sensorFields: Field[] = [
110
+ { key: "S_Gain", unit: "vpa", step: 0.001 },
111
+ { key: "S_OffA", unit: "volt", readonly: true },
112
+ { key: "S_OffB", unit: "volt", readonly: true },
113
+ { key: "S_OffC", unit: "volt", readonly: true },
114
+ { key: "S_VTf", unit: "sec", step: 0.001 },
115
+ { key: "S_CTf", unit: "sec", step: 0.0001 },
116
+ ]
117
+
118
+ const allFields = [...motorFields, ...limitsFields, ...currentFields, ...velocityFields, ...angleFields, ...sensorFields]
119
+
126
120
  let open = $state<Record<string, boolean>>({})
127
121
  let edits = $state<Record<string, number>>({})
128
122
  const read = (key: string) => finite(value[key as keyof typeof value])
123
+
129
124
  const polePairs = $derived(read("M_PP") ?? 0)
130
125
  const zeroTravel = $derived(
131
126
  Number.isInteger(polePairs) && polePairs > 0
132
127
  ? $T("widget.foc.zero.travel", { degrees: (270 / polePairs).toLocaleString($Language, { maximumFractionDigits: 1 }) })
133
128
  : $T("widget.foc.zero.travel.unknown"),
134
129
  )
130
+
135
131
  const torqueMode = $derived(edits.M_Torq ?? read("M_Torq"))
136
132
  const motorType = $derived(edits.M_Type ?? read("M_Type"))
137
133
  const usesCurrentLoop = $derived(torqueMode === undefined || torqueMode === 2 || torqueMode === 3)
134
+
138
135
  const available = (f: Field) => (f.key === "M_Mod" ? motorType !== 1 : !f.torqueModes || torqueMode === undefined || f.torqueModes.includes(torqueMode))
139
136
  const shown = (f: Field) => (available(f) ? edits[f.key] : undefined) ?? read(f.key)
140
- const changedFields = $derived(
141
- SECTIONS.flatMap(({ fields }) => fields).filter((f) => !f.readonly && available(f) && edits[f.key] !== undefined && edits[f.key] !== read(f.key)),
142
- )
143
- const dirty = $derived(Object.keys(edits).some((key) => edits[key] !== read(key)))
144
- const save = () => {
145
- if (!onSave || busy || !changedFields.length) return
146
- onSave(Object.fromEntries(changedFields.map(({ key }) => [key, edits[key]])))
147
- edits = {}
148
- }
137
+
149
138
  const fieldName = (f: Field) => {
150
139
  const reportedMode = read("M_Torq")
151
140
  const unit =
@@ -161,14 +150,29 @@
161
150
  return `${$T(`widget.foc.field.${f.key}`)}${unit ? `, ${$T(`widget.foc.unit.${unit}`)}` : ""}`
162
151
  }
163
152
  const optionText = (f: Field, v: number | undefined) => (v === undefined ? "-" : f.options ? $T(`widget.foc.opt.${f.options[v] ?? v}`) : String(v))
164
- const sectionSummary = (s: { fields: Field[] }) =>
165
- s.fields
153
+
154
+ const summaryOf = (fields: Field[]) =>
155
+ fields
166
156
  .filter(available)
167
157
  .slice(0, 4)
168
158
  .map((f) => `${f.key} ${optionText(f, shown(f))}`)
169
159
  .join(" · ")
170
160
 
171
- /* Автонастройка: полоса TuneHz правится рядом с кнопкой */
161
+ const dirty = $derived(Object.keys(edits).some((key) => edits[key] !== read(key)))
162
+ const changedEntries = $derived(
163
+ Object.entries(edits)
164
+ .filter(([k, v]) => v !== read(k))
165
+ .filter(([k]) => {
166
+ const f = allFields.find((x) => x.key === k)
167
+ return !!f && !f.readonly && available(f)
168
+ }),
169
+ )
170
+ const save = () => {
171
+ if (!onSave || busy || !changedEntries.length) return
172
+ onSave(Object.fromEntries(changedEntries))
173
+ edits = {}
174
+ }
175
+
172
176
  let tuneHz = $state<number | undefined>(undefined)
173
177
  const tuneShown = $derived(tuneHz ?? read("TuneHz") ?? 40)
174
178
  let tuneWait = $state(false)
@@ -184,18 +188,19 @@
184
188
  onRefresh?.()
185
189
  }, 2500)
186
190
  }
191
+
192
+ const hasCurrentSensor = $derived(value.IA !== undefined && value.IB !== undefined && value.IC !== undefined)
187
193
  </script>
188
194
 
189
195
  {#snippet fieldCell(title: string, samples: string[], inset: string, content: Snippet)}
190
196
  <div class="max-w-full min-w-0 flex-[1_1_max-content]">
191
- <!-- Ширина строки зависит от подписи и текста поля, без стандартной ширины input браузера -->
192
197
  <div class="pointer-events-none invisible h-0 overflow-hidden whitespace-nowrap" aria-hidden="true">
193
198
  <div class="text-[12px] font-semibold">{title}</div>
194
199
  {#each samples as sample (sample)}
195
200
  <div class="text-[14px]" style:padding-inline={inset}>{sample}</div>
196
201
  {/each}
197
202
  </div>
198
- <div class="[contain:inline-size]">
203
+ <div class="contain-[inline-size]">
199
204
  {@render content()}
200
205
  </div>
201
206
  </div>
@@ -216,6 +221,59 @@
216
221
  {/snippet}
217
222
  {/snippet}
218
223
 
224
+ {#snippet selectField(f: Field)}
225
+ {@const options = f.options!.map((o, i) => ({ id: `${f.key}-${o}`, name: $T(`widget.foc.opt.${o}`), value: i }))}
226
+ {@render fieldCell(
227
+ fieldName(f),
228
+ options.map(({ name }) => name),
229
+ "1.5rem",
230
+ select,
231
+ )}
232
+ {#snippet select()}
233
+ <UI.Select
234
+ type="buttons"
235
+ label={{ name: fieldName(f) }}
236
+ {options}
237
+ value={shown(f)}
238
+ disabled={!onSave || busy}
239
+ onUpdate={(v) => (edits = { ...edits, [f.key]: Number(v) })}
240
+ />
241
+ {/snippet}
242
+ {/snippet}
243
+
244
+ {#snippet field(f: Field)}
245
+ {#if available(f)}
246
+ {#if f.options}
247
+ {@render selectField(f)}
248
+ {:else}
249
+ {@render numberField(f)}
250
+ {/if}
251
+ {/if}
252
+ {/snippet}
253
+
254
+ {#snippet section(key: string, fields: Field[], children?: Snippet)}
255
+ <div class="flex flex-col rounded-[10px] border border-(--hairline-color) bg-(--back-color)">
256
+ <div class="px-3 py-2" use:hint={{ text: $T(`widget.foc.hint.${key}`), enabled: $hints }}>
257
+ <SectionHead
258
+ title={$T(`widget.foc.section.${key}`)}
259
+ summary={summaryOf(fields)}
260
+ open={!!open[key]}
261
+ onToggle={() => (open = { ...open, [key]: !open[key] })}
262
+ />
263
+ </div>
264
+ {#if open[key]}
265
+ <div class="flex flex-wrap items-end gap-x-3 gap-y-2 border-t border-(--hairline-color) p-3">
266
+ {#each fields as f (f.key)}
267
+ {@render field(f)}
268
+ {/each}
269
+ {#if children}
270
+ {@render children()}
271
+ {/if}
272
+ </div>
273
+ {/if}
274
+ </div>
275
+ {/snippet}
276
+
219
277
  <div
220
278
  class={twMerge("@container relative flex w-full flex-col gap-4 rounded-2xl border border-(--hairline-color) bg-(--container-color) p-4", wrapperClass)}
221
279
  style={rootStyle}
@@ -236,6 +294,33 @@
236
294
  </span>
237
295
  {/each}
238
296
  </div>
297
+ {#if onTune}
298
+ {@const tuneLabel = `${$T("widget.foc.field.TuneHz")}, ${$T("widget.foc.unit.hz")}`}
299
+ <div class="flex flex-wrap items-center gap-2" use:hint={{ text: $T("widget.foc.hint.tune"), enabled: $hints }}>
300
+ <div class="flex-shrink-0">
301
+ {@render fieldCell(tuneLabel, [String(tuneShown)], "1.5rem", bandwidth)}
302
+ </div>
303
+ {#snippet bandwidth()}
304
+ <UI.Input
305
+ wrapperClass="w-24"
306
+ type="number"
307
+ label={{ name: tuneLabel }}
308
+ value={tuneShown}
309
+ number={{ minNum: 5, maxNum: 60, step: 1 }}
310
+ disabled={busy || tuneWait}
311
+ onUpdate={(v) => (tuneHz = Number(v))}
312
+ />
313
+ {/snippet}
314
+ <UI.Button
315
+ wrapperClass="w-40"
316
+ variant="primary"
317
+ content={{ name: $T("widget.foc.tune") }}
318
+ disabled={!enabled || busy || tuneWait}
319
+ confirm={$T("widget.foc.tune.confirm")}
320
+ onClick={tune}
321
+ />
322
+ </div>
323
+ {/if}
239
324
  {#if onEnable}
240
325
  <div use:hint={{ text: $T("widget.foc.hint.enable"), enabled: $hints }}>
241
326
  <UI.Button
@@ -256,90 +341,41 @@
256
341
  <SensorReadout label="Uq" value={value.Uq} digits={2} unit={$T("widget.foc.unit.volt")} />
257
342
  </div>
258
343
 
259
- {#if onTune}
260
- {@const tuneLabel = `${$T("widget.foc.field.TuneHz")}, ${$T("widget.foc.unit.hz")}`}
261
- <div class="flex flex-wrap items-end justify-end gap-2">
262
- <div class="flex max-w-full flex-wrap items-end gap-2" use:hint={{ text: $T("widget.foc.hint.tune"), enabled: $hints }}>
263
- {@render fieldCell(tuneLabel, [String(tuneShown)], "1.5rem", bandwidth)}
264
- {#snippet bandwidth()}
265
- <UI.Input
266
- type="number"
267
- label={{ name: tuneLabel }}
268
- value={tuneShown}
269
- number={{ minNum: 5, maxNum: 60, step: 1 }}
270
- disabled={busy || tuneWait}
271
- onUpdate={(v) => (tuneHz = Number(v))}
272
- />
273
- {/snippet}
274
- <UI.Button
275
- wrapperClass="w-44"
276
- variant="primary"
277
- content={{ name: $T("widget.foc.tune") }}
278
- disabled={!enabled || busy || tuneWait}
279
- confirm={$T("widget.foc.tune.confirm")}
280
- onClick={tune}
281
- />
282
- </div>
344
+ {#if hasCurrentSensor}
345
+ <div class="grid grid-cols-3 gap-1.5" use:hint={{ text: $T("widget.foc.hint.phaseCurrents"), enabled: $hints }}>
346
+ <SensorReadout label="IA" value={value.IA} digits={3} unit={$T("widget.foc.unit.amp")} />
347
+ <SensorReadout label="IB" value={value.IB} digits={3} unit={$T("widget.foc.unit.amp")} />
348
+ <SensorReadout label="IC" value={value.IC} digits={3} unit={$T("widget.foc.unit.amp")} />
283
349
  </div>
284
350
  {/if}
285
351
 
286
- {#each SECTIONS.filter(({ key }) => key !== "current" || usesCurrentLoop) as section (section.key)}
287
- <div class="flex flex-col rounded-[10px] border border-(--hairline-color) bg-(--back-color)">
288
- <div class="px-3 py-2" use:hint={{ text: $T(`widget.foc.hint.${section.key}`), enabled: $hints }}>
289
- <SectionHead
290
- title={$T(`widget.foc.section.${section.key}`)}
291
- summary={sectionSummary(section)}
292
- open={!!open[section.key]}
293
- onToggle={() => (open = { ...open, [section.key]: !open[section.key] })}
294
- />
295
- </div>
296
- {#if open[section.key]}
297
- <div class="flex flex-wrap items-end gap-x-3 gap-y-2 border-t border-(--hairline-color) p-3">
298
- {#each section.fields.filter(available) as f (f.key)}
299
- {#if f.options}
300
- {@const options = f.options.map((o, i) => ({ id: `${f.key}-${o}`, name: $T(`widget.foc.opt.${o}`), value: i }))}
301
- {@render fieldCell(
302
- fieldName(f),
303
- options.map(({ name }) => name),
304
- "1.5rem",
305
- select,
306
- )}
307
- {#snippet select()}
308
- <UI.Select
309
- type="buttons"
310
- label={{ name: fieldName(f) }}
311
- {options}
312
- value={shown(f)}
313
- disabled={!onSave || busy}
314
- onUpdate={(v) => (edits = { ...edits, [f.key]: Number(v) })}
315
- />
316
- {/snippet}
317
- {:else}
318
- {@render numberField(f)}
319
- {/if}
320
- {/each}
321
- {#if section.key === "motor"}
322
- <div class="flex max-w-full min-w-0 flex-[0_1_max-content] flex-wrap items-end gap-x-3 gap-y-2">
323
- {@render numberField({ key: "ZEA", unit: "edeg", readonly: true })}
324
- {#if onZero}
325
- <div use:hint={{ text: $T("widget.foc.hint.zero"), enabled: $hints }}>
326
- <UI.Button
327
- wrapperClass="w-auto"
328
- componentClass="px-3 whitespace-nowrap"
329
- variant="primary"
330
- content={{ name: $T("widget.foc.zero") }}
331
- disabled={!enabled || busy}
332
- confirm={`${$T("widget.foc.zero.confirm")}\n\n${zeroTravel}`}
333
- onClick={onZero}
334
- />
335
- </div>
336
- {/if}
337
- </div>
338
- {/if}
352
+ {#snippet motorExtra()}
353
+ <div class="flex max-w-full min-w-0 flex-[0_1_max-content] flex-wrap items-end gap-x-3 gap-y-2">
354
+ {@render numberField({ key: "ZEA", unit: "edeg", readonly: true })}
355
+ {#if onZero}
356
+ <div use:hint={{ text: $T("widget.foc.hint.zero"), enabled: $hints }}>
357
+ <UI.Button
358
+ wrapperClass="w-auto"
359
+ componentClass="px-3 whitespace-nowrap"
360
+ variant="primary"
361
+ content={{ name: $T("widget.foc.zero") }}
362
+ disabled={!enabled || busy}
363
+ confirm={`${$T("widget.foc.zero.confirm")}\n\n${zeroTravel}`}
364
+ onClick={onZero}
365
+ />
339
366
  </div>
340
367
  {/if}
341
368
  </div>
342
- {/each}
369
+ {/snippet}
370
+
371
+ {@render section("motor", motorFields, motorExtra)}
372
+ {@render section("limits", limitsFields)}
373
+ {#if usesCurrentLoop}
374
+ {@render section("current", currentFields)}
375
+ {/if}
376
+ {@render section("velocity", velocityFields)}
377
+ {@render section("angle", angleFields)}
378
+ {@render section("sensor", sensorFields)}
343
379
 
344
380
  {#if onSave}
345
381
  <div class="flex flex-col items-center gap-2">
@@ -372,7 +408,7 @@
372
408
  componentClass="px-2 whitespace-nowrap"
373
409
  variant="primary"
374
410
  content={{ name: $T("widget.common.save") }}
375
- disabled={!changedFields.length || busy}
411
+ disabled={!changedEntries.length || busy}
376
412
  onClick={save}
377
413
  />
378
414
  </div>
package/dist/gui.d.ts CHANGED
@@ -167,6 +167,9 @@ export declare const WIDGET_FIELDS: {
167
167
  Iq: number;
168
168
  Uq: number;
169
169
  Flg: number;
170
+ IA: number;
171
+ IB: number;
172
+ IC: number;
170
173
  M_Type: number;
171
174
  M_PP: number;
172
175
  M_R: number;
package/dist/gui.js CHANGED
@@ -171,13 +171,16 @@ export const WIDGET_FIELDS = {
171
171
  Iq: num,
172
172
  Uq: num,
173
173
  Flg: num,
174
+ IA: num /* токи фаз, только при наличии датчика тока */,
175
+ IB: num,
176
+ IC: num,
174
177
  M_Type: num,
175
178
  M_PP: num,
176
179
  M_R: num,
177
180
  M_L: num,
178
181
  M_KV: num,
179
- M_Dir: num,
180
- ZEA: num,
182
+ M_Dir: num /* readonly в прошивке */,
183
+ ZEA: num /* readonly в прошивке */,
181
184
  M_VL: num,
182
185
  M_CL: num,
183
186
  M_VLL: num,
@@ -198,13 +201,13 @@ export const WIDGET_FIELDS = {
198
201
  A_Lim: num,
199
202
  A_Ramp: num,
200
203
  S_Gain: num,
201
- S_OffA: num,
202
- S_OffB: num,
203
- S_OffC: num,
204
+ S_OffA: num /* readonly в прошивке */,
205
+ S_OffB: num /* readonly в прошивке */,
206
+ S_OffC: num /* readonly в прошивке */,
204
207
  S_VTf: num,
205
208
  S_CTf: num,
206
- TuneHz: num,
207
- Run: num,
209
+ TuneHz: num /* range 5..100 */,
210
+ Run: num /* 0/1, триггер автонастройки */,
208
211
  },
209
212
  /* База оси любого привода (группа HOME, компонент homing прошивки): способ, состояние и края - только чтение; Off, Speed, Marg и ключи способа сохраняются */
210
213
  WidgetHoming: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-svelte-ui-lib",
3
- "version": "3.13.0",
3
+ "version": "3.13.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Oleg-Perevyshin/ElementsUI.git"