Skip to content

Commit

Permalink
fix(xo-arduino): make possible to send char literals in tweak-byte nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
brusherru committed Sep 17, 2020
1 parent 7340241 commit 864269a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/xod-arduino/src/formatTweakMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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:
Expand Down

0 comments on commit 864269a

Please sign in to comment.