(merge PR) docs: map block

This commit is contained in:
Loren Norman 2025-08-07 15:01:04 -04:00 committed by GitHub
commit 4b2b8705f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,27 +5,25 @@ export default {
name: "Map",
colour: 120,
description: "Scale a value from one range of numbers to another",
connections: {
mode: "value",
output: "number",
},
template: `
Map
Value: %VALUE
From: %FROM_RANGE
To: %TO_RANGE
`,
inputs: {
VALUE: {
description: "The number to scale from the original range to the target range.",
check: "expression",
bytecodeProperty: "value",
shadow: 'io_math_number'
},
FROM_RANGE: {
description: "The original range that the input value comes from (e.g., sensor readings from 0 to 1023).",
check: 'range',
bytecodeProperty: "from",
shadow: {
@ -42,8 +40,8 @@ export default {
}
}
},
TO_RANGE: {
description: "The target range to scale the value to (e.g., convert to 0.0-1.0 for percentages).",
check: 'range',
bytecodeProperty: "to",
shadow: {
@ -61,7 +59,6 @@ export default {
}
},
},
generators: {
json: (block, generator) => {
const
@ -69,11 +66,9 @@ export default {
from = JSON.parse(generator.valueToCode(block, 'FROM_RANGE', 0)),
to = JSON.parse(generator.valueToCode(block, 'TO_RANGE', 0)),
payload = { mapValue: { value, from, to }}
return [ JSON.stringify(payload), 0 ]
}
},
regenerators: {
json: (blockObject, helpers) => {
const
@ -111,7 +106,6 @@ export default {
}
}),
}
return { type: 'math_map', inputs }
}
}