Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var ZonePro = function() {
  2.     var self = {
  3.         system      : "",
  4.         model       : "",
  5.         feedback    : "",
  6.         debug       : 1,
  7.         zone1       : ["01","05","00","10"],
  8.         zone2       : ["01","05","01","11"],
  9.         zone3       : ["01","05","02","12"],
  10.         zone4       : ["01","05","03","13"],
  11.     };
  12.  
  13.     self.setup = function(system, feedback) {
  14.             self.log("Creating " + system + " " + feedback );
  15.             self.system = system;
  16.             self.feedback = feedback;
  17.     };
  18.  
  19.     self.initialize = function() {
  20.         self.log("init");
  21.         CF.watch(CF.FeedbackMatchedEvent, self.system, self.feedback, self.ProcessFeedback);
  22.         self.sendHeartbeat();
  23.     };
  24.  
  25.     ///////////////////////////////
  26.     // VOLUME FUNCTIONS          //
  27.     ///////////////////////////////
  28.     self.setVolume = function(zone, volume) {
  29.         switch (zone) {
  30.             case 1:
  31.             self.setZoneVolume(self.zone1, volume);
  32.             break;
  33.             case 2:
  34.             self.setZoneVolume(self.zone2, volume);
  35.             break;
  36.             case 3:
  37.             self.setZoneVolume(self.zone3, volume);
  38.             self.setZoneVolume(self.zone4, volume);
  39.             break;
  40.  
  41.         }
  42.  
  43.     };
  44.     self.setZoneVolume = function(zone, volume) {
  45.         var commandarray = ["F0","64","00","01","00","00","00","1C","00","33"];
  46.         var fillarray    = ["00","30"];
  47.         var endarray     = ["01","00","00","00","00","01","00","01","03","00"];
  48.         commandarray = commandarray.concat(zone, fillarray, zone, endarray);
  49.         commandarray.push((parseInt(volume) * 2 + 181).toString(16));
  50.         commandarray.push(self.checksum(commandarray));
  51.         self.log(commandarray);
  52.         self.sendCommand(self.hexify(commandarray));
  53.     };
  54.  
  55.  
  56.  
  57.     ///////////////////////////////
  58.     // MUTE FUNCTIONS            //
  59.     ///////////////////////////////
  60.     self.muteOn = function() {
  61.         self.log("Mute");
  62.         self.muteZoneOn(1, "01");
  63.         self.muteZoneOn(2, "01");
  64.         self.muteZoneOn(3, "01");
  65.         self.muteZoneOn(4, "01");
  66.     };
  67.     self.muteOff = function() {
  68.         self.log("UnMute");
  69.         self.muteZoneOn(1, "00");
  70.         self.muteZoneOn(2, "00");
  71.         self.muteZoneOn(3, "00");
  72.         self.muteZoneOn(4, "00");
  73.     };
  74.     self.muteZoneOn = function(zone, mute) {
  75.         var commandarray = ["F0","64","00","01","00","00","00","1B","00","33"];
  76.         var fillarray    = ["00","30"];
  77.         var endarray     = ["01","00","00","00","00","01","00","02","01"];
  78.         var target = "";
  79.         switch (zone) {
  80.             case 1:
  81.             target = self.zone1;
  82.             break;
  83.             case 2:
  84.             target = self.zone2;
  85.             break;
  86.             case 3:
  87.             target = self.zone3;
  88.             break;
  89.             case 4:
  90.             target = self.zone4;
  91.             break;
  92.         }
  93.         commandarray = commandarray.concat(target, fillarray, target, endarray);
  94.         commandarray.push(mute);
  95.         commandarray.push(self.checksum(commandarray));
  96.         self.sendCommand(self.hexify(commandarray));
  97.     };
  98.  
  99.  
  100.  
  101.  
  102.     ///////////////////////////////
  103.     // FEEDBACK                  //
  104.     ///////////////////////////////
  105.     self.ProcessFeedback = function(feedbackname, feedbackstring) {
  106.         return;
  107. // hahahaha
  108.  
  109. // hahahahahahahahahahah
  110.  
  111. // yea right
  112.     };
  113.  
  114.  
  115.     ///////////////////////////////
  116.     // INTERNAL HELPER FUNCTIONS //
  117.     ///////////////////////////////
  118.     self.sendHeartbeat = function() {
  119.         // Heartbeat F0 8C
  120.         self.log("heartbeat");
  121.         self.sendCommand("\xF0\x8C");
  122.     };
  123.  
  124.     self.hexify = function( array ) {
  125.         var string = "";
  126.         for ( var i = 0; i < array.length; i++) {
  127.             string = string + String.fromCharCode(parseInt(array[i],16));
  128.         }
  129.         return string;
  130.     };
  131.  
  132.     self.checksum = function(dbx) {
  133.         var ccit = ["5E","BC","E2","61","3F","DD","83","C2","9C","7E","20","A3","FD","1F","41","9D","C3","21","7F","FC","A2","40","1E","5F","01","E3","BD","3E","60","82","DC","23","7D","9F","C1","42","1C","FE","A0","E1","BF","5D","03","80","DE","3C","62","BE","E0","02","5C","DF","81","63","3D","7C","22","C0","9E","1D","43","A1","FF","46","18","FA","A4","27","79","9B","C5","84","DA","38","66","E5","BB","59","07","DB","85","67","39","BA","E4","06","58","19","47","A5","FB","78","26","C4","9A","65","3B","D9","87","04","5A","B8","E6","A7","F9","1B","45","C6","98","7A","24","F8","A6","44","1A","99","C7","25","7B","3A","64","86","D8","5B","05","E7","B9","8C","D2","30","6E","ED","B3","51","0F","4E","10","F2","AC","2F","71","93","CD","11","4F","AD","F3","70","2E","CC","92","D3","8D","6F","31","B2","EC","0E","50","AF","F1","13","4D","CE","90","72","2C","6D","33","D1","8F","0C","52","B0","EE","32","6C","8E","D0","53","0D","EF","B1","F0","AE","4C","12","91","CF","2D","73","CA","94","76","28","AB","F5","17","49","08","56","B4","EA","69","37","D5","8B","57","09","EB","B5","36","68","8A","D4","95","CB","29","77","F4","AA","48","16","E9","B7","55","0B","88","D6","34","6A","2B","75","97","C9","4A","14","F6","A8","74","2A","C8","96","15","4B","A9","F7","B6","E8","0A","54","D7","89","6B","35"];
  134.         var bcc = "FF";
  135.         for (var i = 1; i < dbx.length; i++ ) {
  136.             var dbx1 = parseInt(dbx[i],16);
  137.             var bcc1 = parseInt(bcc,16);
  138.             var bcc = ccit[(bcc1^dbx1)-1];
  139.         }
  140.         return bcc;
  141.     };
  142.  
  143.     self.sendCommand = function (command) {
  144.         CF.send("Moxa_ZonePro", command + "\n");
  145.     };
  146.  
  147.     // Only allow logging calls when CF is in debug mode - better performance in release mode this way
  148.     self.log = function(msg) {
  149.         if (CF.debug && self.debug) {
  150.             CF.log("ZonePro: " + msg);
  151.         }
  152.     };
  153.  
  154.     return self;
  155. };
  156.  
  157. CF.modules.push({
  158.     name: "DBX ZonePro",
  159.     object: ZonePro,
  160.     version: 1.0
  161. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement