BowlerKernel
PIDLimitEventType.java
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright 2010 Neuron Robotics, LLC
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  ******************************************************************************/
15 package com.neuronrobotics.sdk.pid;
16 
17 import java.util.ArrayList;
18 import java.util.EnumSet;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22 
23 // TODO: Auto-generated Javadoc
24 
28 public enum PIDLimitEventType {
29 
33  NO_LIMIT(0x00),
35  LOWERLIMIT(0x01),
36 
38  INDEXEVENT(0x02),
39 
41  UPPERLIMIT(0x04),
42 
44  OVERCURRENT(0x08),
52  HOME_EVENT(0x20)
53  ;
54  ;
55 
57  private static final Map<Byte,PIDLimitEventType> lookup = new HashMap<Byte,PIDLimitEventType>();
58 
59  static {
60  for(PIDLimitEventType cm : EnumSet.allOf(PIDLimitEventType.class)) {
61  lookup.put(cm.getValue(), cm);
62  }
63  }
64 
66  private byte value;
67 
73  private PIDLimitEventType(int val) {
74  value = (byte) val;
75  }
76 
82  public byte getValue() {
83  return value;
84  }
85 
92  public static PIDLimitEventType get(byte code) {
93 
94  return lookup.get(code);
95  }
96 
103  public static List<PIDLimitEventType> getAllLimitMasks(byte code) {
104  ArrayList<PIDLimitEventType> ret = new ArrayList<PIDLimitEventType>();
105 
106  for(PIDLimitEventType s:PIDLimitEventType.values()){
107  if((s.value&code)>0){
108  ret.add(s);
109  }
110  }
111  return ret;
112  }
113 
119  /* (non-Javadoc)
120  * @see com.neuronrobotics.sdk.common.ISendable#getBytes()
121  */
122  public byte[] getBytes() {
123  byte [] b = {getValue()};
124  return b;
125  }
126 
127 }
static List< PIDLimitEventType > getAllLimitMasks(byte code)
static PIDLimitEventType get(byte code)