1 /*
2 * Copyright 2008 motej
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package motejx.extensions.balanceboard;
17
18
19 /**
20 *
21 * <p>
22 * @author Kohei Matsumura
23 * @author <a href="mailto:vfritzsch@users.sourceforge.net">Volker Fritzsch</a>
24 */
25 public class BalanceBoardCalibrationData {
26
27 private int[] sensorA = new int[3];
28 private int[] sensorB = new int[3];
29 private int[] sensorC = new int[3];
30 private int[] sensorD = new int[3];
31
32 public static enum Sensor {
33 A, B, C, D;
34 }
35
36 public static enum Weight {
37 KG_0(0), KG_17(1), KG_34(2);
38
39 private final int idx;
40 private Weight(int idx) {
41 this.idx = idx;
42 }
43 }
44
45 public static final int SENSOR_A = 0;
46 public static final int SENSOR_B = 1;
47 public static final int SENSOR_C = 2;
48 public static final int SENSOR_D = 4;
49
50 public static final int WEIGHT_0_KG = 0;
51 public static final int WEIGHT_17_KG = 1;
52 public static final int WEIGHT_34_KG = 2;
53
54 public int getCalibration(Sensor sensor, Weight weight) {
55 int[] tmp = null;
56
57 switch (sensor) {
58 case A:
59 tmp = sensorA;
60 break;
61 case B:
62 tmp = sensorB;
63 break;
64 case C:
65 tmp = sensorC;
66 break;
67 case D:
68 tmp = sensorD;
69 break;
70 default:
71 throw new RuntimeException("No such sensor.");
72 }
73
74 return tmp[weight.idx];
75 }
76
77 public void setCalibration(Sensor sensor, Weight weight, int data) {
78 switch (sensor) {
79 case A:
80 sensorA[weight.idx] = data;
81 case B:
82 sensorB[weight.idx] = data;
83 case C:
84 sensorC[weight.idx] = data;
85 case D:
86 sensorD[weight.idx] = data;
87 }
88 }
89
90 // public void setCalibration(char sensor, byte[] calibrationData, int index) {
91 // System.out.println(index);
92 // switch (sensor) {
93 // case SENSOR_A:
94 // this.calibrationA.add(index, ((calibrationData[0] & 0xff) * 256)
95 // + (calibrationData[1] & 0xff));
96 // break;
97 // case SENSOR_B:
98 // this.calibrationB.add(index, ((calibrationData[0] & 0xff) * 256)
99 // + (calibrationData[1] & 0xff));
100 // break;
101 // case SENSOR_C:
102 // this.calibrationC.add(index, ((calibrationData[0] & 0xff) * 256)
103 // + (calibrationData[1] & 0xff));
104 // break;
105 // case SENSOR_D:
106 // this.calibrationD.add(index, ((calibrationData[0] & 0xff) * 256)
107 // + (calibrationData[1] & 0xff));
108 // break;
109 // default:
110 // ;
111 // }
112 // }
113 }