From 864269ae0c056e06384373c0c3eddf12571f7cfd Mon Sep 17 00:00:00 2001 From: Kirill Shumilov Date: Thu, 17 Sep 2020 16:34:03 +0300 Subject: [PATCH] fix(xo-arduino): make possible to send char literals in tweak-byte nodes --- .../xod-arduino/src/formatTweakMessage.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/xod-arduino/src/formatTweakMessage.js b/packages/xod-arduino/src/formatTweakMessage.js index bbb6fdc61..186e0b981 100644 --- a/packages/xod-arduino/src/formatTweakMessage.js +++ b/packages/xod-arduino/src/formatTweakMessage.js @@ -7,6 +7,24 @@ import { def } from './types'; import { byteLiteralToDecimal } from './templates'; +// Convert char literals to decimal byte literals +// E.G. `'a'` -> `97d` +const charLiteralToByteLiteral = R.when( + XP.isLikeCharLiteral, + R.compose( + R.concat(R.__, 'd'), + R.toString, + a => a.charCodeAt(0), + R.nth(1), + R.match(XP.charLiteralRegExp) + ) +); + +const formatByteLiteral = R.compose( + byteLiteralToDecimal, + charLiteralToByteLiteral +); + export default def( 'formatTweakMessage :: PatchPath -> NodeId -> DataValue -> String', (nodeType, nodeId, value) => { @@ -17,7 +35,7 @@ export default def( case XP.PIN_TYPE.BOOLEAN: return `${prefix}:${value === 'True' ? '1' : '0'}\r\n`; case XP.PIN_TYPE.BYTE: - return `${prefix}:${byteLiteralToDecimal(value)}\r\n`; + return `${prefix}:${formatByteLiteral(value)}\r\n`; case XP.PIN_TYPE.PULSE: return `${prefix}\r\n`; case XP.PIN_TYPE.STRING: