Subversion Repositories HomeAutomation

Rev

Blame | 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 RotaryHex(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.     this.myLastButtonStatus = new Array();
  27. }
  28.  
  29. extend(RotaryHex, CanService);
  30.  
  31. RotaryHex.prototype.myLastDirection = null;
  32. RotaryHex.prototype.myLastSteps = null;
  33. RotaryHex.prototype.myLastPosition = null;
  34. RotaryHex.prototype.myLastButtonStatus = "Released";
  35.  
  36.  
  37. RotaryHex.prototype.canMessageHandler = function(canMessage)
  38. {
  39.     if (canMessage.getDirectionFlag() == "From_Owner")
  40.     {
  41.         switch (canMessage.getCommandName())
  42.         {
  43.         case "Rotary_Switch":
  44.         //log(this.myName + ":" + this.myId + "> New direction: " + canMessage.getData("Direction") + ", steps: " + canMessage.getData("Steps") + ", position: " + canMessage.getData("Position") + "\n");
  45.         this.myLastDirection[canMessage.getData("SwitchId")] = canMessage.getData("Direction");
  46.         this.myLastSteps[canMessage.getData("SwitchId")] = canMessage.getData("Steps");
  47.         this.myLastPosition[canMessage.getData("SwitchId")] = canMessage.getData("Position");
  48.         this.callEvent("newPosition", canMessage.getData("SwitchId"));
  49.         break;
  50.        
  51.         case "Button":
  52.         //log(this.myName + ":" + this.myId + "> New button status: " + canMessage.getData("Status") + "\n");
  53.         this.myLastButtonStatus[canMessage.getData("SwitchId")] = canMessage.getData("Status");
  54.         this.callEvent("newBtnStatus", canMessage.getData("SwitchId"));
  55.         break;
  56.         }
  57.     }
  58.    
  59.     this.CanService.prototype.canMessageHandler.call(this, canMessage);
  60. }
  61.  
  62. RotaryHex.prototype.getDirection = function(switchId)
  63. {
  64.     return this.myLastDirection[switchId];
  65. }
  66.  
  67. RotaryHex.prototype.getPosition = function(switchId)
  68. {
  69.     return this.myLastPosition[switchId];
  70. }
  71.  
  72. RotaryHex.prototype.getSteps = function(switchId)
  73. {
  74.     return this.myLastSteps[switchId];
  75. }
  76.  
  77. RotaryHex.prototype.getButtonStatus = function(switchId)
  78. {
  79.     return this.myLastButtonStatus[switchId];
  80. }
  81.