blob: 5054cfe603db61a5d8442e3ae5efc88b8d658415 [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 Maltsev30c84c32016-11-14 16:23:36 -080033 auto& pool = *getValuePool();
Pavel Maltseve2603e32016-10-25 16:03:23 -070034
35 switch (property) {
36 case VehicleProperty::INFO_MAKE:
Pavel Maltsev30c84c32016-11-14 16:23:36 -080037 v = pool.obtainString("Default Car");
Pavel Maltseve2603e32016-10-25 16:03:23 -070038 break;
39 case VehicleProperty::HVAC_FAN_SPEED:
Pavel Maltsev30c84c32016-11-14 16:23:36 -080040 v = pool.obtainInt32(mFanSpeed);
41 break;
42 case VehicleProperty::HVAC_POWER_ON:
43 v = pool.obtainBoolean(mHvacPowerOn);
44 break;
45 case VehicleProperty::HVAC_RECIRC_ON:
46 v = pool.obtainBoolean(mHvacRecircOn);
47 break;
48 case VehicleProperty::HVAC_AC_ON:
49 v = pool.obtainBoolean(mHvacAcOn);
50 break;
51 case VehicleProperty::HVAC_AUTO_ON:
52 v = pool.obtainBoolean(mHvacAutoOn);
53 break;
54 case VehicleProperty::HVAC_FAN_DIRECTION:
55 v = pool.obtainInt32(toInt(mFanDirection));
56 break;
57 case VehicleProperty::HVAC_DEFROSTER:
58 bool defroster;
59 *outStatus = getHvacDefroster(areaId, &defroster);
Pavel Maltsevdb179c52016-10-27 15:43:06 -070060 if (StatusCode::OK == *outStatus) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -080061 v = pool.obtainBoolean(defroster);
62 }
63 break;
64 case VehicleProperty::HVAC_TEMPERATURE_SET:
65 float value;
66 *outStatus = getHvacTemperature(requestedPropValue.areaId,
67 &value);
68 if (StatusCode::OK == *outStatus) {
69 v = pool.obtainFloat(value);
Pavel Maltseve2603e32016-10-25 16:03:23 -070070 }
71 break;
72 case VehicleProperty::INFO_FUEL_CAPACITY:
Pavel Maltsev30c84c32016-11-14 16:23:36 -080073 v = pool.obtainFloat(0.75f);
Pavel Maltseve2603e32016-10-25 16:03:23 -070074 break;
75 case VehicleProperty::DISPLAY_BRIGHTNESS:
Pavel Maltsev30c84c32016-11-14 16:23:36 -080076 v = pool.obtainInt32(mBrightness);
77 break;
78 case VehicleProperty::NIGHT_MODE:
79 v = pool.obtainBoolean(false);
80 break;
81 case VehicleProperty::GEAR_SELECTION:
82 v = pool.obtainInt32(toInt(VehicleGear::GEAR_PARK));
Pavel Maltseve2603e32016-10-25 16:03:23 -070083 break;
Pavel Maltsevb5e51092016-11-22 11:01:03 -080084 case VehicleProperty::DRIVING_STATUS:
85 v = pool.obtainInt32(toInt(VehicleDrivingStatus::UNRESTRICTED));
86 break;
Pavel Maltseve2603e32016-10-25 16:03:23 -070087 default:
Pavel Maltsevdb179c52016-10-27 15:43:06 -070088 *outStatus = StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -070089 }
90
Pavel Maltsevdb179c52016-10-27 15:43:06 -070091 if (StatusCode::OK == *outStatus && v.get() != nullptr) {
Pavel Maltseve2603e32016-10-25 16:03:23 -070092 v->prop = property;
93 v->areaId = areaId;
94 v->timestamp = elapsedRealtimeNano();
95 }
96
97 return v;
98}
99
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700100StatusCode DefaultVehicleHal::set(const VehiclePropValue& propValue) {
Pavel Maltseve2603e32016-10-25 16:03:23 -0700101 auto property = propValue.prop;
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800102 const auto& v = propValue.value;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700103
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700104 StatusCode status = StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700105
106 switch (property) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800107 case VehicleProperty::HVAC_POWER_ON:
108 mHvacPowerOn = v.int32Values[0] == 1;
109 break;
110 case VehicleProperty::HVAC_RECIRC_ON:
111 mHvacRecircOn = v.int32Values[0] == 1;
112 break;
113 case VehicleProperty::HVAC_AC_ON:
114 mHvacAcOn = v.int32Values[0] == 1;
115 break;
116 case VehicleProperty::HVAC_AUTO_ON:
117 mHvacAutoOn = v.int32Values[0] == 1;
118 break;
119 case VehicleProperty::HVAC_DEFROSTER:
120 status = setHvacDefroster(propValue.areaId, v.int32Values[0] == 1);
121 break;
122 case VehicleProperty::HVAC_FAN_DIRECTION:
123 mFanDirection =
124 static_cast<VehicleHvacFanDirection>(v.int32Values[0]);
125 break;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700126 case VehicleProperty::HVAC_FAN_SPEED:
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800127 mFanSpeed = v.int32Values[0];
128 break;
129 case VehicleProperty::HVAC_TEMPERATURE_SET:
130 status = setHvacTemperature(propValue.areaId, v.floatValues[0]);
Pavel Maltseve2603e32016-10-25 16:03:23 -0700131 break;
132 case VehicleProperty::DISPLAY_BRIGHTNESS:
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800133 mBrightness = v.int32Values[0];
Pavel Maltseve2603e32016-10-25 16:03:23 -0700134 break;
135 default:
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700136 status = StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700137 }
138
139 return status;
140}
141
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800142StatusCode DefaultVehicleHal::getHvacTemperature(int32_t areaId,
143 float* outValue) {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700144 if (areaId == toInt(VehicleAreaZone::ROW_1_LEFT)) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800145 *outValue = mRow1LeftHvacTemperatureSet;
146 } else if (areaId == toInt(VehicleAreaZone::ROW_1_RIGHT)) {
147 *outValue = mRow1RightHvacTemperatureSet;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700148 } else {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700149 return StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700150 }
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700151 return StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700152}
153
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800154StatusCode DefaultVehicleHal::setHvacTemperature(
155 int32_t areaId, float value) {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700156 if (areaId == toInt(VehicleAreaZone::ROW_1_LEFT)) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800157 mRow1LeftHvacTemperatureSet = value;
158 } else if (areaId == toInt(VehicleAreaZone::ROW_1_RIGHT)) {
159 mRow1RightHvacTemperatureSet = value;
160 } else {
161 return StatusCode::INVALID_ARG;
162 }
163 return StatusCode::OK;
164}
165
166StatusCode DefaultVehicleHal::getHvacDefroster(int32_t areaId,
167 bool* outValue) {
168 ALOGI("Getting Hvac defroster for area: 0x%x", areaId);
169
170 if (areaId == toInt(VehicleAreaWindow::FRONT_WINDSHIELD)) {
171 *outValue = mFrontDefroster;
172 } else if (areaId == toInt(VehicleAreaWindow::REAR_WINDSHIELD)) {
173 *outValue = mRearDefroster;
174 } else {
175 ALOGE("Unable to get hvac defroster for area: 0x%x", areaId);
176 return StatusCode::INVALID_ARG;
177 }
178
179 ALOGI("Getting Hvac defroster for area: 0x%x, OK", areaId);
180 return StatusCode::OK;
181}
182
183StatusCode DefaultVehicleHal::setHvacDefroster(int32_t areaId, bool value) {
184 if (areaId == toInt(VehicleAreaWindow::FRONT_WINDSHIELD)) {
185 mFrontDefroster = value;
186 } else if (areaId == toInt(VehicleAreaWindow::REAR_WINDSHIELD)) {
187 mRearDefroster = value;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700188 } else {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700189 return StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700190 }
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700191 return StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700192}
193
194} // impl
195
196} // namespace V2_0
197} // namespace vehicle
198} // namespace hardware
199} // namespace android