Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = function(helper) {
- var binaryToPulse, protocolInfo, pulsesToBinaryMapping;
- pulsesToBinaryMapping = {
- '10': '1',
- '01': '0',
- '11': '1',
- '02': '',
- '12': ''
- };
- binaryToPulse = {
- '0': '01',
- '1': '10'
- };
- return protocolInfo = {
- name: 'led5',
- type: 'command',
- values: {
- id: {
- type: "number"
- },
- command: {
- type: "string"
- }
- },
- brands: ["LED RGB Controller"],
- pulseLengths: [350, 720, 4650],
- pulseCount: 66,
- decodePulses: function(pulses) {
- var binary, command, type, red, green, blue, commandcode, result;
- binary = helper.map(pulses, pulsesToBinaryMapping);
- commandcode = binary.slice(16, 32);
- type=commandcode.slice(0, 1);
- switch (type) {
- case "1":
- switch (commandcode) {
- case "1000010101111010":
- command = "on";
- break;
- case "1000010001111011":
- command = "off";
- break;
- case "1000011001111001":
- command = "bright+";
- break;
- case "1000011101111000":
- command = "bright-";
- break;
- case "1000000101111110":
- command = "less";
- break;
- case "1000001001111101":
- command = "more";
- break;
- default:
- command = "code:" + commandcode;
- }
- break;
- case "0":
- blue = commandcode.slice(1, 6);
- green = commandcode.slice(6, 11);
- red = commandcode.slice(11, 16);
- //command = "rgbcode: " + red + " " + green + " " + blue + " " + commandcode + " " + parseInt(red, 2) + " " + parseInt(green, 2) + " " + parseInt(blue, 2);
- command = "rgbcode: " + parseInt(red, 2) + " " + parseInt(green, 2) + " " + parseInt(blue, 2);
- break
- }
- return result = {
- id: helper.binaryToNumber(binary, 0, 15),
- command: command
- };
- },
- encodeMessage: function(message) {
- var commandcode, id;
- id = helper.map(helper.numberToBinary(message.id, 16), binaryToPulse);
- switch (message.command) {
- case "on":
- commandcode = "1000010101111010";
- break;
- case "off":
- commandcode = "1000010001111011";
- break;
- case "bright+":
- commandcode = "1000011001111001";
- break;
- case "bright-":
- commandcode = "1000011101111000";
- break;
- case "less":
- commandcode = "1000000101111110";
- break;
- case "more":
- commandcode = "1000001001111101";
- break;
- default:
- if (message.command.slice(0, 5) === "code:") {
- commandcode = message.command.slice(5);
- }
- }
- commandcode = helper.map(commandcode, binaryToPulse);
- return "" + id + commandcode + "12";
- }
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement