Subversion Repositories HomeAutomation

Rev

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

  1. /* the display object who created the menu item */
  2. PIDMenuItem.prototype.parentDisplay = null;
  3. //PIDMenuItem.prototype.sensors = null;
  4. PIDMenuItem.prototype.mode = 0;
  5. PIDMenuItem.prototype.sub_mode = 0;
  6. PIDMenuItem.prototype.tempVariable = 0;
  7. PIDMenuItem.prototype.myPIDService = null;
  8. //PIDMenuItem.prototype.currentSensorItem = 0;
  9. //PIDMenuItem.prototype.window_low = 0;
  10. //PIDMenuItem.prototype.window_high = 3; //set to nummber of rows you want to display minus 1
  11.  
  12.  
  13. function PIDMenuItem(parentDisplay, hd44789Object)
  14. {
  15.     var self = this;
  16.     this.parentDisplay = parentDisplay;
  17.     this.display = hd44789Object;
  18.    
  19.     if (!this.parentDisplay.myInitialArguments["PID"])
  20.     {
  21.         log(this.myName + ":" + this.myId + "> Failed to initialize, PID-config missing from config.\n");
  22.         return;
  23.     }
  24.    
  25.     /* Get the PWM service that we want from the ServiceManager, it takes type, service name, service id */
  26.     this.myPIDService = ServiceManager.getService("Can", "PID", this.parentDisplay.myInitialArguments["PID"]["Id"]);
  27. }
  28.  
  29. /* the display object who created the menu item */
  30. PIDMenuItem.prototype.parentDisplay = null;
  31. /* the display that we are writing to */
  32. PIDMenuItem.prototype.display = null;
  33.  
  34. /* How often the display shall update [ms]*/
  35. PIDMenuItem.prototype.UpdateTime = 5000;
  36.  
  37. /* what PIDMenuItem is left of this item, if used */
  38. PIDMenuItem.prototype.LeftItem = null;
  39. /* what PIDMenuItem is right of this item, if used */
  40. PIDMenuItem.prototype.RightItem = null;
  41. /* what PIDMenuItem is after of this item, if used */
  42. PIDMenuItem.prototype.PressEnterItem = null;
  43.  
  44. /*
  45. Standard events can be:
  46. left, right, enter, back, up, down....
  47. */
  48. PIDMenuItem.prototype.processEvent = function (event)
  49. {
  50.     switch (this.mode)
  51.     {
  52.     case 0:
  53.         switch (event)
  54.         {
  55.         case "right":
  56.             this.parentDisplay.changeToRight();
  57.             break;
  58.         case "left":
  59.             this.parentDisplay.changeToLeft();
  60.             break;
  61.         case "enter":
  62.             this.mode = 1;
  63.             this.sub_mode = 0;
  64.             this.display.clearScreen();
  65.             break;
  66.         }
  67.         break;
  68.     case 1:
  69.         switch (event)
  70.         {
  71.         case "right":
  72.             this.sub_mode++;
  73.             if (this.sub_mode > 2) {
  74.                 this.sub_mode = 0;
  75.             }
  76.             break;
  77.         case "left":
  78.             if (this.sub_mode == 0) {
  79.                 this.sub_mode = 2;
  80.             }
  81.             this.sub_mode--;
  82.             break;
  83.         case "enter":
  84.             switch (this.sub_mode)
  85.             {
  86.             case 0:
  87.                 this.mode = 2;
  88.                 this.sub_mode = 0;
  89.                 this.tempVariable = this.myPIDService.Reference;
  90.                 break;
  91.             case 1:
  92.                 this.mode = 3;
  93.                 this.sub_mode = 0;
  94.                 break;
  95.             case 2:
  96.                 this.mode = 0;
  97.                 this.sub_mode = 0;
  98.                 break;
  99.             }
  100.             this.display.clearScreen();
  101.             break;
  102.         }
  103.         break;
  104.     case 2:
  105.         switch (event)
  106.         {
  107.         case "right":
  108.             if (this.sub_mode == 3) {
  109.                 this.tempVariable = this.tempVariable + 0.5;
  110.             } else {
  111.                 this.sub_mode++;
  112.                 if (this.sub_mode > 3) {
  113.                     this.sub_mode = 0;
  114.                 }
  115.             }
  116.             break;
  117.         case "left":
  118.             if (this.sub_mode == 3) {
  119.                 this.tempVariable = this.tempVariable - 0.5;
  120.             } else {
  121.                 if (this.sub_mode == 0) {
  122.                     this.sub_mode = 3;
  123.                 }
  124.                 this.sub_mode--;
  125.             }
  126.             break;
  127.         case "enter":
  128.             switch (this.sub_mode)
  129.             {
  130.             case 0:
  131.                 this.sub_mode = 3;
  132.                 break;
  133.             case 1:
  134.                 //spara
  135.                 this.myPIDService.setValue(this.tempVariable);
  136.                 this.mode = 0;
  137.                 this.sub_mode = 0;
  138.                 break;
  139.             case 2:
  140.                 this.mode = 0;
  141.                 this.sub_mode = 0;
  142.                 break;
  143.             case 3:
  144.                 this.sub_mode = 0;
  145.                 break;
  146.             }
  147.             break;
  148.         }
  149.         break;
  150.     case 3:
  151.         switch (event)
  152.         {
  153.         case "right":
  154.             break;
  155.         case "left":
  156.             break;
  157.         case "enter":
  158.             this.mode = 0;
  159.             this.sub_mode = 0;
  160.             break;
  161.         }
  162.         break;
  163.     }
  164. }
  165.  
  166. PIDMenuItem.prototype.onEnter = function ()
  167. {
  168.     this.mode = 0;
  169.     this.display.clearScreen();
  170. }
  171. PIDMenuItem.prototype.update = function ()
  172. {
  173.     //this.display.clearScreen();
  174.     switch (this.mode)
  175.     {
  176.     case 1:
  177.         switch (this.sub_mode)
  178.         {
  179.         case 0:
  180.             this.display.printText(0, 3,"> Set Temperature");
  181.             break;
  182.         case 1:
  183.             this.display.printText(0, 3,"> Settings");
  184.             break;
  185.         case 2:
  186.             this.display.printText(0, 3,"> Tillbaka");
  187.             break;
  188.         }
  189.     case 0:
  190.         this.display.printText(0, 0,"Reference:     "+this.myPIDService.Reference.toFixed(1).toString()+"¤C");
  191.         this.display.printText(0, 1,"Measurment:    "+this.myPIDService.Reference.toFixed(1).toString()+"¤C");
  192.         this.display.printText(0, 2,"Out: "+this.myPIDService.PWM.toFixed(1).toString()+"%   Sum: "+this.myPIDService.sum.toFixed(1).toString());
  193.         break;
  194.     case 2:
  195.         this.display.printText(0, 0,"Set temperature:");
  196.         switch (this.sub_mode)
  197.         {
  198.         case 0:
  199.             this.display.printText(0, 1,"   > "+this.tempVariable.toFixed(1).toString()+"¤C");
  200.             this.display.printText(0, 3,"  Spara     Ångra");
  201.             break;
  202.         case 1:
  203.             this.display.printText(0, 1,"     "+this.tempVariable.toFixed(1).toString()+"¤C")
  204.             this.display.printText(0, 3,"> Spara     Ångra");
  205.             break;
  206.         case 2:
  207.             this.display.printText(0, 1,"     "+this.tempVariable.toFixed(1).toString()+"¤C")
  208.             this.display.printText(0, 3,"  Spara   > Ångra");
  209.             break;
  210.         case 3:
  211.             this.display.printText(0, 1,"  <> "+this.tempVariable.toFixed(1).toString()+"¤C")
  212.             this.display.printText(0, 3,"  Spara     Ångra");
  213.             break;
  214.         }
  215.         break;
  216.     case 3:
  217.         this.display.printText(0, 0,"  Settings");
  218.         break;
  219.     }
  220. }
  221.  
  222. PIDMenuItem.prototype.onExit = function ()
  223. {
  224.     this.mode = 0;
  225.     this.sub_mode = 0;
  226. }
  227.  
  228.  
  229.