blob: 24d438dc5224467a201689d4394d591ce961b244 [file] [log] [blame]
Pavel Maltseve2603e32016-10-25 16:03:23 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
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
17#include "DefaultVehicleHal.h"
18
19namespace android {
20namespace hardware {
21namespace vehicle {
22namespace V2_0 {
23
24namespace impl {
25
Pavel Maltsevdb179c52016-10-27 15:43:06 -070026VehicleHal::VehiclePropValuePtr DefaultVehicleHal::get(
27 const VehiclePropValue& requestedPropValue, StatusCode* outStatus) {
28 *outStatus = StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -070029
30 VehiclePropValuePtr v;
Pavel Maltsevdb179c52016-10-27 15:43:06 -070031 VehicleProperty property = requestedPropValue.prop;
32 int32_t areaId = requestedPropValue.areaId;
Pavel Maltseve2603e32016-10-25 16:03:23 -070033
34 switch (property) {
35 case VehicleProperty::INFO_MAKE:
36 v = getValuePool()->obtainString("Default Car");
37 break;
38 case VehicleProperty::HVAC_FAN_SPEED:
39 int32_t value;
Pavel Maltsevdb179c52016-10-27 15:43:06 -070040 *outStatus = getHvacFanSpeed(areaId, &value);
41 if (StatusCode::OK == *outStatus) {
Pavel Maltseve2603e32016-10-25 16:03:23 -070042 v = getValuePool()->obtainInt32(value);
43 }
44 break;
45 case VehicleProperty::INFO_FUEL_CAPACITY:
46 v = getValuePool()->obtainFloat(0.75f);
47 break;
48 case VehicleProperty::DISPLAY_BRIGHTNESS:
49 v = getValuePool()->obtainInt32(brightness);
50 break;
51 default:
Pavel Maltsevdb179c52016-10-27 15:43:06 -070052 *outStatus = StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -070053 }
54
Pavel Maltsevdb179c52016-10-27 15:43:06 -070055 if (StatusCode::OK == *outStatus && v.get() != nullptr) {
Pavel Maltseve2603e32016-10-25 16:03:23 -070056 v->prop = property;
57 v->areaId = areaId;
58 v->timestamp = elapsedRealtimeNano();
59 }
60
61 return v;
62}
63
Pavel Maltsevdb179c52016-10-27 15:43:06 -070064StatusCode DefaultVehicleHal::set(const VehiclePropValue& propValue) {
Pavel Maltseve2603e32016-10-25 16:03:23 -070065 auto property = propValue.prop;
66
Pavel Maltsevdb179c52016-10-27 15:43:06 -070067 StatusCode status = StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -070068
69 switch (property) {
70 case VehicleProperty::HVAC_FAN_SPEED:
71 status = setHvacFanSpeed(propValue.areaId,
72 propValue.value.int32Values[0]);
73 break;
74 case VehicleProperty::DISPLAY_BRIGHTNESS:
75 brightness = propValue.value.int32Values[0];
76 break;
77 default:
Pavel Maltsevdb179c52016-10-27 15:43:06 -070078 status = StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -070079 }
80
81 return status;
82}
83
Pavel Maltsevdb179c52016-10-27 15:43:06 -070084StatusCode DefaultVehicleHal::getHvacFanSpeed(int32_t areaId,
Pavel Maltseve2603e32016-10-25 16:03:23 -070085 int32_t* outValue) {
Pavel Maltsevdb179c52016-10-27 15:43:06 -070086 if (areaId == toInt(VehicleAreaZone::ROW_1_LEFT)) {
Pavel Maltseve2603e32016-10-25 16:03:23 -070087 *outValue = fanSpeedRow1Left;
Pavel Maltsevdb179c52016-10-27 15:43:06 -070088 } else if (areaId == toInt(VehicleAreaZone::ROW_2_RIGHT)) {
Pavel Maltseve2603e32016-10-25 16:03:23 -070089 *outValue = fanSpeedRow1Right;
90 } else {
Pavel Maltsevdb179c52016-10-27 15:43:06 -070091 return StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -070092 }
Pavel Maltsevdb179c52016-10-27 15:43:06 -070093 return StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -070094}
95
Pavel Maltsevdb179c52016-10-27 15:43:06 -070096StatusCode DefaultVehicleHal::setHvacFanSpeed(int32_t areaId, int32_t value) {
97 if (areaId == toInt(VehicleAreaZone::ROW_1_LEFT)) {
Pavel Maltseve2603e32016-10-25 16:03:23 -070098 fanSpeedRow1Left = value;
Pavel Maltsevdb179c52016-10-27 15:43:06 -070099 } else if (areaId == toInt(VehicleAreaZone::ROW_2_RIGHT)) {
Pavel Maltseve2603e32016-10-25 16:03:23 -0700100 fanSpeedRow1Right = value;
101 } else {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700102 return StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700103 }
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700104 return StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700105}
106
107} // impl
108
109} // namespace V2_0
110} // namespace vehicle
111} // namespace hardware
112} // namespace android