Subversion Repositories HomeAutomation

Rev

Rev 1353 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. function KS0108(type, name, id)
  3. {
  4.     this.CanService(type, name, id);
  5. }
  6.  
  7. extend(KS0108, CanService);
  8.  
  9. KS0108.prototype.myBacklightStrength = null;
  10.  
  11. KS0108.prototype.canMessageHandler = function(canMessage)
  12. {
  13.     if (canMessage.getDirectionFlag() == "From_Owner")
  14.     {
  15.         switch (canMessage.getCommandName())
  16.         {
  17.         case "LCD_Clear":
  18.         break;
  19.        
  20.         case "LCD_Cursor":
  21.         break;
  22.        
  23.         case "LCD_Text":
  24.         break;
  25.        
  26.         case "LCD_TextAt":
  27.         break;
  28.        
  29.         case "LCD_Backlight":
  30.         this.myBacklight = canMessage.getData("Strength");
  31.         //log(this.myName + ":" + this.myId + "> Reported backlight strength: " + this.myBacklight + "\n");
  32.         break;
  33.         }
  34.     }
  35.    
  36.     this.CanService.prototype.canMessageHandler.call(this, canMessage);
  37. }
  38.  
  39. KS0108.prototype.onlineHandler = function()
  40. {
  41.     this.CanService.prototype.onlineHandler.call(this);
  42.    
  43.     // Request backlight strength
  44.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_Backlight");
  45.     sendMessage(canMessage);
  46. }
  47.  
  48. KS0108.prototype.printText = function(x, y, text, inverted, transparent)
  49. {
  50.     text = text.replace(/å/, String.fromCharCode(128));
  51.     text = text.replace(/Å/, String.fromCharCode(129));
  52.     text = text.replace(/ä/, String.fromCharCode(130));
  53.     text = text.replace(/Ä/, String.fromCharCode(131));
  54.     text = text.replace(/ö/, String.fromCharCode(132));
  55.     text = text.replace(/Ö/, String.fromCharCode(133));
  56.     text = text.replace(/¤/, String.fromCharCode(134));
  57.     while (text.length > 0)
  58.     {
  59.         var text6 = text.substr(0, 6);
  60.  
  61.         var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_TextAt");
  62.         canMessage.setData("Inverted", inverted);
  63.         canMessage.setData("Transparent", transparent);
  64.         canMessage.setData("X", x);
  65.         canMessage.setData("Y", y);
  66.         canMessage.setData("Text", text6);
  67.         sendMessage(canMessage);
  68.        
  69.         x += text6.length;
  70.         text = text.slice(text6.length);
  71.     }
  72. }
  73.  
  74. KS0108.prototype.clearScreen = function(inverted)
  75. {
  76.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_Clear");
  77.     canMessage.setData("Inverted", inverted);
  78.     sendMessage(canMessage);
  79. }
  80.  
  81. KS0108.prototype.setBacklight = function(strength)
  82. {
  83.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_Backlight");
  84.     canMessage.setData("Strength", strength);
  85.     sendMessage(canMessage);
  86. }
  87.  
  88. KS0108.prototype.getBacklight = function()
  89. {
  90.     return this.myBacklight;
  91. }
  92.  
  93. KS0108.prototype.drawLine = function(xStart, yStart , xEnd, yEnd, inverted)
  94. {
  95.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_DrawLine");
  96.     canMessage.setData("Inverted", inverted);
  97.     canMessage.setData("X1", xStart);
  98.     canMessage.setData("Y1", yStart);
  99.     canMessage.setData("X2", xEnd);
  100.     canMessage.setData("Y2", yEnd);
  101.     sendMessage(canMessage);
  102. }
  103.  
  104. KS0108.prototype.drawCircle = function(xCentre, yCentre , radius , inverted)
  105. {
  106.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_DrawCircle");
  107.     canMessage.setData("Inverted", inverted);
  108.     canMessage.setData("Xcentre", xCentre);
  109.     canMessage.setData("Ycentre", yCentre);
  110.     canMessage.setData("Radius", radius);
  111.     sendMessage(canMessage);
  112. }
  113.  
  114. KS0108.prototype.invertRect = function(x, y , width, height)
  115. {
  116.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_InvertRect")
  117.     canMessage.setData("X", x);
  118.     canMessage.setData("Y", y);
  119.     canMessage.setData("Width", width);
  120.     canMessage.setData("Height", height);
  121.     sendMessage(canMessage);
  122. }
  123.  
  124. KS0108.prototype.DrawRect = function(x, y , width, height, inverted, fill, radius)
  125. {
  126.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_DrawRect")
  127.     canMessage.setData("X", x);
  128.     canMessage.setData("Y", y);
  129.     canMessage.setData("Width", width);
  130.     canMessage.setData("Height", height);
  131.     canMessage.setData("Inverted", inverted);
  132.     canMessage.setData("Fill", fill);
  133.     canMessage.setData("Radius", radius);
  134.     sendMessage(canMessage);
  135. }
  136.