1a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik/*
2a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik * Copyright (C) 2017 The Android Open Source Project
3a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik *
4a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik * Licensed under the Apache License, Version 2.0 (the "License");
5a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik * you may not use this file except in compliance with the License.
6a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik * You may obtain a copy of the License at
7a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik *
8a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik *      http://www.apache.org/licenses/LICENSE-2.0
9a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik *
10a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik * Unless required by applicable law or agreed to in writing, software
11a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik * distributed under the License is distributed on an "AS IS" BASIS,
12a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik * See the License for the specific language governing permissions and
14a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik * limitations under the License.
15a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik */
16a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik
17a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paikpackage android.support.car.hardware;
18a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik
197bd39e929390e754c96e2792efe0deac7b3841e6Anthony Chenimport static androidx.annotation.RestrictTo.Scope.GROUP_ID;
207bd39e929390e754c96e2792efe0deac7b3841e6Anthony Chen
21a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paikimport android.os.Bundle;
22a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik
237bd39e929390e754c96e2792efe0deac7b3841e6Anthony Chenimport androidx.annotation.RestrictTo;
24a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik
25a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik/**
26a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik * A CarSensorConfig object corresponds to a single sensor type coming from the car.
27a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik * @hide
28a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik */
29a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paikpublic class CarSensorConfig {
30a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    /** List of property specific mapped elements in bundle for WHEEL_TICK_DISTANCE sensor*/
31a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    /** @hide */
32a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    public final static String WHEEL_TICK_DISTANCE_SUPPORTED_WHEELS =
33cc2cf056d652c3037dee3b60ea7fb5284756f82bSteve Paik        "android.car.wheelTickDistanceSupportedWheels";
34a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    /** @hide */
35a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    public final static String WHEEL_TICK_DISTANCE_FRONT_LEFT_UM_PER_TICK =
36a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        "android.car.wheelTickDistanceFrontLeftUmPerTick";
37a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    /** @hide */
38a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    public final static String WHEEL_TICK_DISTANCE_FRONT_RIGHT_UM_PER_TICK =
39a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        "android.car.wheelTickDistanceFrontRightUmPerTick";
40a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    /** @hide */
41a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    public final static String WHEEL_TICK_DISTANCE_REAR_RIGHT_UM_PER_TICK =
42a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        "android.car.wheelTickDistanceRearRightUmPerTick";
43a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    /** @hide */
44a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    public final static String WHEEL_TICK_DISTANCE_REAR_LEFT_UM_PER_TICK =
45a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        "android.car.wheelTickDistanceRearLeftUmPerTick";
46a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik
47a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    /** Config data stored in Bundle */
48a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    private final Bundle mConfig;
49a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    private final int mType;
50a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik
51a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    private final static int RAW_BUNDLE_SIZE = 4;
52a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    private final static int WHEEL_TICK_DISTANCE_BUNDLE_SIZE = 6;
53a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik
54a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    /**
55a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik     * Constructs a {@link CarSensorConfig}. Handled by CarSensorManager implementations.
56a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik     * App developers need not worry about constructing these objects.
57a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik     * @hide
58a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik     */
59a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    @RestrictTo(GROUP_ID)
60a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    public CarSensorConfig(int type, Bundle in) {
61a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        mType = type;
62a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        mConfig = in.deepCopy();
63a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    }
64a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik
65a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    private void checkType(int type) {
66a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        if (mType == type) {
67a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik            return;
68a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        }
69a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        throw new UnsupportedOperationException(String.format(
70a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik            "Invalid sensor type: expected %d, got %d", type, mType));
71a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    }
72a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik
73a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    /** @hide */
74a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    public int getInt(String key) {
75a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        if (mConfig.containsKey(key)) {
76a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik            return mConfig.getInt(key);
77a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        } else {
78a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik            throw new IllegalArgumentException("SensorType " + mType +
79a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik                " does not contain key: " + key);
80a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        }
81a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    }
82a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik
83a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    /** @hide */
84a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    public int getType() {
85a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        return mType;
86a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    }
87a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik
88a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    /** @hide */
89a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    @Override
90a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    public String toString() {
91a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        StringBuilder sb = new StringBuilder();
92a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        sb.append(getClass().getName() + "[");
93a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        sb.append("mConfig: " + mConfig.toString());
94a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        sb.append("mType: " + mType);
95a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        sb.append("]");
96a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik        return sb.toString();
97a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik    }
98a2819901c1b4f56e4950dd5cb6bf6c9e8042cf4cSteve Paik}
99