BowlerKernel
DyIOChannelMode.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.dyio;
16 
17 import java.util.Collection;
18 import java.util.EnumSet;
19 import java.util.HashMap;
20 import java.util.Map;
21 
22 import com.neuronrobotics.sdk.common.ISendable;
23 // TODO: Auto-generated Javadoc
29 public enum DyIOChannelMode implements ISendable {
30 
32  NO_CHANGE (0x00, "No Change"),
33 
35  OFF (0x01, "Off"),
36 
38  DIGITAL_IN (0x02, "Digital In"),
39 
41  DIGITAL_OUT (0x03, "Digital Out"),
42 
44  ANALOG_IN (0x04, "Analog In"),
45 
47  ANALOG_OUT (0x05, "Analog Out"),
48 
50  PWM_OUT (0x06, "PWM Out"),
51 
53  SERVO_OUT (0x07, "Servo Out"),
54 
56  USART_TX (0x08, "USART Tx"),
57 
59  USART_RX (0x09, "USART Rx"),
60 
62  SPI_MOSI (0x0A, "SPI MoSi"),
63 
65  SPI_MISO (0x0B, "SPI MiSo"),
66 
68  SPI_CLOCK (0x0C, "SPI Clock"),
69 
71  SPI_SELECT (0x0D, "SPI Select"),
72 
74  COUNT_IN_INT (0x0E, "Counter In Int"),
75 
77  COUNT_IN_DIR (0x0F, "Counter In Dir"),
78 
80  COUNT_IN_HOME (0x10, "Counter In Home"),
81 
83  COUNT_OUT_INT (0x11, "Counter Out Int"),
84 
86  COUNT_OUT_DIR (0x12, "Counter Out Dir"),
87 
89  COUNT_OUT_HOME(0x13, "Counter Out Home"),
90 
92  DC_MOTOR_VEL (0x14, "DC Motor Velocity"),
93 
95  DC_MOTOR_DIR (0x15, "DC Motor Direction"),
96 
98  PPM_IN (0x16, "PPM Reader"),
100  DEBUG_TX (0x17, "DEBUG_TX"),
101 
103  DEBUG_RX (0x18, "DEBUG_RX");
104 
106  private static final Map<Byte,DyIOChannelMode> lookup = new HashMap<Byte,DyIOChannelMode>();
107 
109  private byte value;
110 
112  private String readableName;
113 
114  static {
115  for(DyIOChannelMode cm : EnumSet.allOf(DyIOChannelMode.class)) {
116  lookup.put(cm.getValue(), cm);
117  }
118  }
119 
126  private DyIOChannelMode(int val, String name) {
127  value = (byte) val;
128  readableName = name;
129  }
130 
136  public static Collection<DyIOChannelMode> getModes() {
137  return lookup.values();
138  }
139 
145  public byte getValue() {
146  return value;
147  }
148 
155  public static DyIOChannelMode get(byte code) {
156  if(lookup.get(code)==null)
157  lookup.put(code, NO_CHANGE);
158  return lookup.get(code);
159  }
160 
167  public static DyIOChannelMode getFromSlug(String slug) {
168  for (DyIOChannelMode cm : EnumSet.allOf(DyIOChannelMode.class)) {
169  if(cm.toSlug().toLowerCase().contentEquals(slug.toLowerCase()))
170  return cm;
171  }
172  throw new RuntimeException("No mode availible for slug: "+slug);
173  }
174 
175  /* (non-Javadoc)
176  * @see java.lang.Enum#toString()
177  */
178  public String toString() {
179  return readableName;
180  }
181 
187  public String toSlug() {
188  return toString().replace(" ", "-").toLowerCase();
189  }
190 
191  /* (non-Javadoc)
192  * @see com.neuronrobotics.sdk.common.ISendable#getBytes()
193  */
194 
195  public byte[] getBytes() {
196  byte [] b = {getValue()};
197  return b;
198  }
199 }
static DyIOChannelMode getFromSlug(String slug)
static Collection< DyIOChannelMode > getModes()
static DyIOChannelMode get(byte code)