dryingPresets.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Resolving an AMS tray's material to a row in the drying preset table.
  2. //
  3. // The table itself lives with the UI that renders it; only the lookup is here,
  4. // so it can be exercised without dragging a page module into the test.
  5. export type DryingPreset = { n3f: number; n3s: number; n3f_hours: number; n3s_hours: number };
  6. // Materials whose AMS spelling differs from the preset table's key. Bambu
  7. // labels nylon "PA" while its own composites spell the family out, so PA6 and
  8. // PAHT would otherwise miss a table that has a perfectly good PA row.
  9. const DRYING_MATERIAL_ALIASES: Record<string, string> = {
  10. 'NYLON': 'PA',
  11. 'PA6': 'PA',
  12. 'PAHT': 'PA',
  13. };
  14. /**
  15. * Pick the preset key for a tray's material.
  16. *
  17. * The answer is always a key the table actually has, which is the whole point:
  18. * the drying popover seeds both the temperature and the filament name the start
  19. * command carries from this, and the dropdown silently falls back to its first
  20. * option when handed a value that isn't in its list. Seeding it with a raw
  21. * `tray_type` therefore displayed "PLA" while sending the raw string -- an
  22. * AMS-HT holding Support for PLA/PETG (`tray_type` "PLA-S") showed PLA in the
  23. * dropdown and told the printer PLA-S (#2774).
  24. *
  25. * `tray_type` carries plenty of spellings the table doesn't list: support
  26. * materials (PLA-S) and composites (PETG-CF, PLA-CF, ABS-GF, PAHT-CF) all dry
  27. * as their base material, so the suffix is dropped before giving up. Anything
  28. * still unrecognised lands on PLA, deliberately the coolest row -- under-drying
  29. * an exotic filament wastes a cycle, where defaulting to PA's 85 degrees would
  30. * deform a PLA spool.
  31. */
  32. export function resolveDryingPresetKey(
  33. trayType: string | null | undefined,
  34. presets: Record<string, DryingPreset>,
  35. ): string {
  36. const raw = (trayType || '').split(' ')[0].toUpperCase();
  37. for (const candidate of [raw, raw.split('-')[0]]) {
  38. const key = DRYING_MATERIAL_ALIASES[candidate] ?? candidate;
  39. if (presets[key]) return key;
  40. }
  41. return 'PLA';
  42. }