feat(new tools): 4-20 mA, 0-10 V and analog scaling converters (#596)

Add an Automation category with three tools for PLC programmers and
instrumentation technicians, built on a shared AnalogSignalConverter
component and a tested src/utils/analog-signal.ts module:

- 4-20 mA converter: current <-> engineering value, 4-20 / 0-20 mA, with the
  NAMUR NE 43 loop diagnostic (failure, undefined zone, under/over-range)
- 0-10 V converter: 0-10, 2-10, 0-5, 1-5 and ±10 V, warns below the live
  zero (broken wire)
- Analog scaling calculator: raw PLC values (Siemens 0-27648 / ±27648,
  Schneider 0-10000, 12/15/16 bits) <-> engineering value, with the rounded
  raw value

Three-column layout: input, parameters and output, each side with a gauge and
a coloured status. A swap button inverts the conversion direction and keeps
the operating point. Also shows the y = gain × x + offset formula for the PLC
and a 0-25-50-75-100 % reference table. Ranges are validated (min < max).

English and French translations.
This commit is contained in:
AlgoVeria authored and GitHub committed 2026-11-08 18:45:54 +01:00
1 parent e7758934a8
commit b5eace85db
15 files changed
+1137

No files matched your search

@@ -0,0 +1,39 @@
import { expect, test } from '@playwright/test';
test.describe('Tool - Analog scaling calculator', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/analog-scaling-calculator');
});
test('Has correct title', async ({ page }) => {
await expect(page).toHaveTitle('Analog scaling calculator - IT Tools');
});
test('Scales a Siemens raw value', async ({ page }) => {
await page.getByTestId('converter-input').locator('input').fill('20736');
await page.getByTestId('converter-input').locator('input').press('Enter');
await expect(page.getByTestId('converter-output')).toHaveText('75 %');
await expect(page.getByTestId('formula').locator('input')).toHaveValue('value = 0.003616898148 × signal');
});
test('Gives the rounded raw value in the other direction', async ({ page }) => {
await page.getByTestId('swap-direction').click();
await page.getByTestId('converter-input').locator('input').fill('33.3');
await page.getByTestId('converter-input').locator('input').press('Enter');
await expect(page.getByTestId('converter-output')).toHaveText('9206.784');
await expect(page.getByTestId('converter-output-rounded')).toContainText('9207');
});
test('Rejects a range whose min is not lower than its max', async ({ page }) => {
const min = page.getByTestId('engineering-min').locator('input');
await min.fill('200');
await min.press('Enter');
await expect(page.getByText('The engineering min must be lower than the engineering max.')).toBeVisible();
await expect(page.getByTestId('converter-output')).toHaveText('—');
await expect(page.getByTestId('output-gauge')).toHaveCount(0);
await min.fill('-50');
await min.press('Enter');
await expect(page.getByTestId('converter-output')).not.toHaveText('—');
});
});
@@ -0,0 +1,25 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n';
import AnalogSignalConverter from '@/components/AnalogSignalConverter.vue';
const { t } = useI18n();
const presets = computed(() => [
{ label: t('tools.analog-scaling-calculator.texts.preset-siemens-unipolar'), min: 0, max: 27648 },
{ label: t('tools.analog-scaling-calculator.texts.preset-siemens-bipolar'), min: -27648, max: 27648 },
{ label: t('tools.analog-scaling-calculator.texts.preset-schneider'), min: 0, max: 10000 },
{ label: t('tools.analog-scaling-calculator.texts.preset-12-bits'), min: 0, max: 4095 },
{ label: t('tools.analog-scaling-calculator.texts.preset-15-bits'), min: 0, max: 32767 },
{ label: t('tools.analog-scaling-calculator.texts.preset-16-bits'), min: 0, max: 65535 },
]);
</script>
<template>
<AnalogSignalConverter
storage-key="analog-scaling-calculator"
:signal-label="t('tools.analog-scaling-calculator.texts.signal-label')"
:presets="presets"
:default-engineering="{ min: 0, max: 100, unit: '%' }"
integer-signal
/>
</template>
@@ -0,0 +1,25 @@
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
export const tool = defineTool({
name: t('tools.analog-scaling-calculator.title'),
path: '/analog-scaling-calculator',
description: t('tools.analog-scaling-calculator.description'),
keywords: [
'analog',
'scaling',
'raw',
'plc',
'siemens',
'27648',
'schneider',
'norm_x',
'scale_x',
'engineering',
'unit',
],
component: () => import('./analog-scaling-calculator.vue'),
icon: defineAsyncComponent(() => import('@vicons/tabler/es/AdjustmentsHorizontal')),
createdAt: new Date('2026-11-03'),
category: 'Automation',
});
@@ -0,0 +1,37 @@
import { expect, test } from '@playwright/test';
test.describe('Tool - 4-20 mA converter', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/current-loop-4-20ma-converter');
});
test('Has correct title', async ({ page }) => {
await expect(page).toHaveTitle('4-20 mA converter - IT Tools');
});
test('Converts a current into an engineering value', async ({ page }) => {
await page.getByTestId('converter-input').locator('input').fill('8');
await page.getByTestId('converter-input').locator('input').press('Enter');
await expect(page.getByTestId('converter-output')).toHaveText('2.5 bar');
await expect(page.getByTestId('input-status')).toContainText('In range');
});
test('Swaps the direction and keeps the operating point', async ({ page }) => {
await page.getByTestId('converter-input').locator('input').fill('16');
await page.getByTestId('converter-input').locator('input').press('Enter');
await expect(page.getByTestId('converter-output')).toHaveText('7.5 bar');
await page.getByTestId('swap-direction').click();
await expect(page.getByTestId('converter-input').locator('input')).toHaveValue('7.5');
await expect(page.getByTestId('converter-output')).toHaveText('16 mA');
await expect(page.getByTestId('formula').locator('input')).toHaveValue('signal = 1.6 × value + 4');
await page.getByTestId('swap-direction').click();
});
test('Reports a NAMUR NE 43 loop failure', async ({ page }) => {
await page.getByTestId('converter-input').locator('input').fill('2');
await page.getByTestId('converter-input').locator('input').press('Enter');
await expect(page.getByTestId('input-status')).toContainText('Low failure');
});
});
@@ -0,0 +1,22 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n';
import AnalogSignalConverter from '@/components/AnalogSignalConverter.vue';
const { t } = useI18n();
const presets = [
{ label: '4-20 mA', min: 4, max: 20 },
{ label: '0-20 mA', min: 0, max: 20 },
];
</script>
<template>
<AnalogSignalConverter
storage-key="current-loop-4-20ma-converter"
:signal-label="t('tools.current-loop-4-20ma-converter.texts.signal-label')"
signal-unit="mA"
:presets="presets"
:default-engineering="{ min: 0, max: 10, unit: 'bar' }"
current-loop-diagnostic
/>
</template>
@@ -0,0 +1,26 @@
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
export const tool = defineTool({
name: t('tools.current-loop-4-20ma-converter.title'),
path: '/current-loop-4-20ma-converter',
description: t('tools.current-loop-4-20ma-converter.description'),
keywords: [
'4-20',
'ma',
'milliampere',
'current',
'loop',
'analog',
'sensor',
'transmitter',
'namur',
'ne43',
'plc',
'scaling',
],
component: () => import('./current-loop-4-20ma-converter.vue'),
icon: defineAsyncComponent(() => import('@vicons/tabler/es/Gauge')),
createdAt: new Date('2026-11-03'),
category: 'Automation',
});
@@ -0,0 +1,13 @@
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
export const tool = defineTool({
name: t('tools.voltage-0-10v-converter.title'),
path: '/voltage-0-10v-converter',
description: t('tools.voltage-0-10v-converter.description'),
keywords: ['0-10', 'volt', 'voltage', 'analog', 'sensor', '1-5', '2-10', 'plc', 'scaling'],
component: () => import('./voltage-0-10v-converter.vue'),
icon: defineAsyncComponent(() => import('@vicons/tabler/es/Bolt')),
createdAt: new Date('2026-11-03'),
category: 'Automation',
});
@@ -0,0 +1,25 @@
import { expect, test } from '@playwright/test';
test.describe('Tool - 0-10 V converter', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/voltage-0-10v-converter');
});
test('Has correct title', async ({ page }) => {
await expect(page).toHaveTitle('0-10 V converter - IT Tools');
});
test('Converts a voltage into an engineering value', async ({ page }) => {
await page.getByTestId('converter-input').locator('input').fill('2.5');
await page.getByTestId('converter-input').locator('input').press('Enter');
await expect(page.getByTestId('converter-output')).toHaveText('25 %');
});
test('Warns below the live zero of a 2-10 V signal', async ({ page }) => {
await page.getByTestId('signal-min').locator('input').fill('2');
await page.getByTestId('signal-min').locator('input').press('Enter');
await page.getByTestId('converter-input').locator('input').fill('1');
await page.getByTestId('converter-input').locator('input').press('Enter');
await expect(page.getByTestId('input-status')).toContainText('live zero');
});
});
@@ -0,0 +1,24 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n';
import AnalogSignalConverter from '@/components/AnalogSignalConverter.vue';
const { t } = useI18n();
const presets = [
{ label: '0-10 V', min: 0, max: 10 },
{ label: '2-10 V', min: 2, max: 10 },
{ label: '0-5 V', min: 0, max: 5 },
{ label: '1-5 V', min: 1, max: 5 },
{ label: '±10 V', min: -10, max: 10 },
];
</script>
<template>
<AnalogSignalConverter
storage-key="voltage-0-10v-converter"
:signal-label="t('tools.voltage-0-10v-converter.texts.signal-label')"
signal-unit="V"
:presets="presets"
:default-engineering="{ min: 0, max: 100, unit: '%' }"
/>
</template>