Subversion Repositories HomeAutomation

Rev

Rev 1351 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. function HD44789(type, name, id)
  3. {
  4.     this.CanService(type, name, id);
  5. }
  6.  
  7. extend(HD44789, CanService);
  8.  
  9. HD44789.prototype.myWidth = null;
  10. HD44789.prototype.myHeight = null;
  11. HD44789.prototype.myBacklightStrength = null;
  12.  
  13. HD44789.prototype.canMessageHandler = function(canMessage)
  14. {
  15.     if (canMessage.getDirectionFlag() == "From_Owner")
  16.     {
  17.         switch (canMessage.getCommandName())
  18.         {
  19.         case "LCD_Clear":
  20.         break;
  21.        
  22.         case "LCD_Cursor":
  23.         break;
  24.        
  25.         case "LCD_Text":
  26.         break;
  27.        
  28.         case "LCD_TextAt":
  29.         break;
  30.        
  31.         case "LCD_Size":
  32.         this.myWidth = canMessage.getData("Width");
  33.         this.myHeight = canMessage.getData("Height");
  34.         log(this.myName + ":" + this.myId + "> Reported size: " + this.myWidth + "x" + this.myHeight + "\n");
  35.         break;
  36.        
  37.         case "LCD_Backlight":
  38.         this.myBacklight = canMessage.getData("Strength");
  39.         log(this.myName + ":" + this.myId + "> Reported backlight strength: " + this.myBacklight + "\n");
  40.         break;
  41.         }
  42.     }
  43.    
  44.     this.CanService.prototype.canMessageHandler.call(this, canMessage);
  45. }
  46.  
  47. HD44789.prototype.onlineHandler = function()
  48. {
  49.     this.CanService.prototype.onlineHandler.call(this);
  50.  
  51.     // Request size of LCD
  52.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_Size");
  53.     sendMessage(canMessage);
  54.    
  55.     // Request backlight strength
  56.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_Backlight");
  57.     sendMessage(canMessage);
  58. }
  59.  
  60. HD44789.prototype.printText = function(x, y, text)
  61. {
  62.     text = text.replace(/Å/, String.fromCharCode(1));
  63.     text = text.replace(/å/, String.fromCharCode(0));
  64.     text = text.replace(/Ä/, String.fromCharCode(2));
  65.     text = text.replace(/ä/, String.fromCharCode(225));
  66.     text = text.replace(/Ö/, String.fromCharCode(3));
  67.     text = text.replace(/ö/, String.fromCharCode(239));
  68.     text = text.replace(/¤/, String.fromCharCode(223));
  69.  
  70.     while (text.length > 0)
  71.     {
  72.         var text6 = text.substr(0, 6);
  73.  
  74.         var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_TextAt");
  75.         canMessage.setData("X", x);
  76.         canMessage.setData("Y", y);
  77.         canMessage.setData("Text", text6);
  78.         sendMessage(canMessage);
  79.        
  80.         x += text6.length;
  81.         text = text.slice(text6.length);
  82.     }
  83. }
  84.  
  85. HD44789.prototype.clearScreen = function()
  86. {
  87.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_Clear");
  88.     sendMessage(canMessage);
  89. }
  90.  
  91. HD44789.prototype.setBacklight = function(strength)
  92. {
  93.     var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "LCD_Backlight");
  94.     canMessage.setData("Strength", strength);
  95.     sendMessage(canMessage);
  96. }
  97.  
  98. HD44789.prototype.getBacklight = function()
  99. {
  100.     return this.myBacklight;
  101. }
  102.  
  103. HD44789.prototype.getWidth = function()
  104. {
  105.     return this.myWidth;
  106. }
  107.  
  108. HD44789.prototype.getHeight = function()
  109. {
  110.     return this.myHeight;
  111. }
  112.