Subversion Repositories HomeAutomation

Rev

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

  1. //    <command id="69" name="Rotary_Switch" type="physical" module="" description="Command to transmit a rotary encoder switch status">
  2. //      <variables>
  3. //        <variable name="SwitchId" type="uint" start_bit="0" bit_length="8" unit="" description=""/>
  4. //        <variable name="Direction" type="uint" start_bit="8" bit_length="8" unit="" description=""/>
  5. //        <variable name="Steps" type="uint" start_bit="16" bit_length="8" unit="" description=""/>
  6. //        <variable name="Position" type="uint" start_bit="24" bit_length="8" unit="" description=""/>
  7. //      </variables>
  8. //    </command>
  9.  
  10. //    <command id="70" name="Button" type="physical" module="" description="">
  11. //      <variables>
  12. //        <variable name="SwitchId" type="uint" start_bit="0" bit_length="8" unit="" description=""/>
  13. //        <variable name="Status" type="enum" start_bit="8" bit_length="8" unit="" description="">
  14. //          <value id="1" name="Pressed"/>
  15. //          <value id="0" name="Released"/>
  16. //        </variable>
  17. //      </variables>
  18. //    </command>
  19.  
  20. function Rotary(type, name, id)
  21. {
  22.     this.CanService(type, name, id);
  23.     this.myLastDirection = new Array();
  24.     this.myLastSteps = new Array();
  25.     this.myLastPosition = new Array();
  26. }
  27.  
  28. extend(Rotary, CanService);
  29.  
  30. Rotary.prototype.myLastDirection = null;
  31. Rotary.prototype.myLastSteps = null;
  32. Rotary.prototype.myLastPosition = null;
  33. Rotary.prototype.myLastButtonStatus = "Released";
  34.  
  35.  
  36. Rotary.prototype.canMessageHandler = function(canMessage)
  37. {
  38.     if (canMessage.getDirectionFlag() == "From_Owner")
  39.     {
  40.         switch (canMessage.getCommandName())
  41.         {
  42.         case "Rotary_Switch":
  43.         log(this.myName + ":" + this.myId + "> New direction: " + canMessage.getData("Direction") + ", steps: " + canMessage.getData("Steps") + "\n");
  44.         this.myLastDirection[canMessage.getData("SwitchId")] = canMessage.getData("Direction");
  45.         this.myLastSteps[canMessage.getData("SwitchId")] = canMessage.getData("Steps");
  46.         this.myLastPosition[canMessage.getData("SwitchId")] = canMessage.getData("Position");
  47.         this.callEvent("newValue", canMessage.getData("SwitchId"));
  48.         break;
  49.        
  50.         case "Button":
  51.         log(this.myName + ":" + this.myId + "> New button status: " + canMessage.getData("Status") + "\n");
  52.         this.myLastButtonStatus[canMessage.getData("SwitchId")] = canMessage.getData("Status");
  53.         this.callEvent("newValue", canMessage.getData("SwitchId"));
  54.         break;
  55.         }
  56.     }
  57.    
  58.     this.CanService.prototype.canMessageHandler.call(this, canMessage);
  59. }
  60.  
  61. Rotary.prototype.getDirection = function(switchId)
  62. {
  63.     return this.myLastDirection[switchId];
  64. }
  65.  
  66. Rotary.prototype.getPosition = function(switchId)
  67. {
  68.     return this.myLastPosition[switchId];
  69. }
  70.  
  71. Rotary.prototype.getSteps = function(switchId)
  72. {
  73.     return this.myLastSteps[switchId];
  74. }
  75.  
  76. Rotary.prototype.getButtonStatus = function(switchId)
  77. {
  78.     return this.myLastButtonStatus[switchId];
  79. }