Advertisement
Guest User

Untitled

a guest
May 16th, 2015
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. module.exports = function(helper) {
  2. var binaryToPulse, protocolInfo, pulsesToBinaryMapping;
  3. pulsesToBinaryMapping = {
  4. '10': '1',
  5. '01': '0',
  6. '11': '1',
  7. '02': '',
  8. '12': ''
  9. };
  10. binaryToPulse = {
  11. '0': '01',
  12. '1': '10'
  13. };
  14. return protocolInfo = {
  15. name: 'led5',
  16. type: 'command',
  17. values: {
  18. id: {
  19. type: "number"
  20. },
  21. command: {
  22. type: "string"
  23. }
  24. },
  25. brands: ["LED RGB Controller"],
  26. pulseLengths: [350, 720, 4650],
  27. pulseCount: 66,
  28. decodePulses: function(pulses) {
  29. var binary, command, type, red, green, blue, commandcode, result;
  30. binary = helper.map(pulses, pulsesToBinaryMapping);
  31. commandcode = binary.slice(16, 32);
  32. type=commandcode.slice(0, 1);
  33. switch (type) {
  34. case "1":
  35. switch (commandcode) {
  36. case "1000010101111010":
  37. command = "on";
  38. break;
  39. case "1000010001111011":
  40. command = "off";
  41. break;
  42. case "1000011001111001":
  43. command = "bright+";
  44. break;
  45. case "1000011101111000":
  46. command = "bright-";
  47. break;
  48. case "1000000101111110":
  49. command = "less";
  50. break;
  51. case "1000001001111101":
  52. command = "more";
  53. break;
  54. default:
  55. command = "code:" + commandcode;
  56. }
  57. break;
  58. case "0":
  59. blue = commandcode.slice(1, 6);
  60. green = commandcode.slice(6, 11);
  61. red = commandcode.slice(11, 16);
  62. //command = "rgbcode: " + red + " " + green + " " + blue + " " + commandcode + " " + parseInt(red, 2) + " " + parseInt(green, 2) + " " + parseInt(blue, 2);
  63. command = "rgbcode: " + parseInt(red, 2) + " " + parseInt(green, 2) + " " + parseInt(blue, 2);
  64. break
  65. }
  66. return result = {
  67. id: helper.binaryToNumber(binary, 0, 15),
  68. command: command
  69. };
  70. },
  71. encodeMessage: function(message) {
  72. var commandcode, id;
  73. id = helper.map(helper.numberToBinary(message.id, 16), binaryToPulse);
  74. switch (message.command) {
  75. case "on":
  76. commandcode = "1000010101111010";
  77. break;
  78. case "off":
  79. commandcode = "1000010001111011";
  80. break;
  81. case "bright+":
  82. commandcode = "1000011001111001";
  83. break;
  84. case "bright-":
  85. commandcode = "1000011101111000";
  86. break;
  87. case "less":
  88. commandcode = "1000000101111110";
  89. break;
  90. case "more":
  91. commandcode = "1000001001111101";
  92. break;
  93. default:
  94. if (message.command.slice(0, 5) === "code:") {
  95. commandcode = message.command.slice(5);
  96. }
  97. }
  98. commandcode = helper.map(commandcode, binaryToPulse);
  99. return "" + id + commandcode + "12";
  100. }
  101. };
  102. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement