blob: 4e27bdcc6c6cfedf40af7c4f7963765da30fe68b [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
Yifan Hongf9d30342016-11-30 13:45:34 -080019#define LOG_TAG "default_vehicle"
20#include <android/log.h>
21
Pavel Maltseve2603e32016-10-25 16:03:23 -070022namespace android {
23namespace hardware {
24namespace vehicle {
25namespace V2_0 {
26
27namespace impl {
28
Pavel Maltsevdb179c52016-10-27 15:43:06 -070029VehicleHal::VehiclePropValuePtr DefaultVehicleHal::get(
30 const VehiclePropValue& requestedPropValue, StatusCode* outStatus) {
31 *outStatus = StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -070032
33 VehiclePropValuePtr v;
Pavel Maltsevdb179c52016-10-27 15:43:06 -070034 VehicleProperty property = requestedPropValue.prop;
35 int32_t areaId = requestedPropValue.areaId;
Pavel Maltsev30c84c32016-11-14 16:23:36 -080036 auto& pool = *getValuePool();
Pavel Maltseve2603e32016-10-25 16:03:23 -070037
38 switch (property) {
39 case VehicleProperty::INFO_MAKE:
Pavel Maltsev30c84c32016-11-14 16:23:36 -080040 v = pool.obtainString("Default Car");
Pavel Maltseve2603e32016-10-25 16:03:23 -070041 break;
42 case VehicleProperty::HVAC_FAN_SPEED:
Pavel Maltsev30c84c32016-11-14 16:23:36 -080043 v = pool.obtainInt32(mFanSpeed);
44 break;
45 case VehicleProperty::HVAC_POWER_ON:
46 v = pool.obtainBoolean(mHvacPowerOn);
47 break;
48 case VehicleProperty::HVAC_RECIRC_ON:
49 v = pool.obtainBoolean(mHvacRecircOn);
50 break;
51 case VehicleProperty::HVAC_AC_ON:
52 v = pool.obtainBoolean(mHvacAcOn);
53 break;
54 case VehicleProperty::HVAC_AUTO_ON:
55 v = pool.obtainBoolean(mHvacAutoOn);
56 break;
57 case VehicleProperty::HVAC_FAN_DIRECTION:
58 v = pool.obtainInt32(toInt(mFanDirection));
59 break;
60 case VehicleProperty::HVAC_DEFROSTER:
61 bool defroster;
62 *outStatus = getHvacDefroster(areaId, &defroster);
Pavel Maltsevdb179c52016-10-27 15:43:06 -070063 if (StatusCode::OK == *outStatus) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -080064 v = pool.obtainBoolean(defroster);
65 }
66 break;
67 case VehicleProperty::HVAC_TEMPERATURE_SET:
68 float value;
69 *outStatus = getHvacTemperature(requestedPropValue.areaId,
70 &value);
71 if (StatusCode::OK == *outStatus) {
72 v = pool.obtainFloat(value);
Pavel Maltseve2603e32016-10-25 16:03:23 -070073 }
74 break;
75 case VehicleProperty::INFO_FUEL_CAPACITY:
Pavel Maltsev30c84c32016-11-14 16:23:36 -080076 v = pool.obtainFloat(0.75f);
Pavel Maltseve2603e32016-10-25 16:03:23 -070077 break;
78 case VehicleProperty::DISPLAY_BRIGHTNESS:
Pavel Maltsev30c84c32016-11-14 16:23:36 -080079 v = pool.obtainInt32(mBrightness);
80 break;
81 case VehicleProperty::NIGHT_MODE:
82 v = pool.obtainBoolean(false);
83 break;
84 case VehicleProperty::GEAR_SELECTION:
85 v = pool.obtainInt32(toInt(VehicleGear::GEAR_PARK));
Pavel Maltseve2603e32016-10-25 16:03:23 -070086 break;
Pavel Maltsevb5e51092016-11-22 11:01:03 -080087 case VehicleProperty::DRIVING_STATUS:
88 v = pool.obtainInt32(toInt(VehicleDrivingStatus::UNRESTRICTED));
89 break;
Pavel Maltseve2603e32016-10-25 16:03:23 -070090 default:
Pavel Maltsevdb179c52016-10-27 15:43:06 -070091 *outStatus = StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -070092 }
93
Pavel Maltsevdb179c52016-10-27 15:43:06 -070094 if (StatusCode::OK == *outStatus && v.get() != nullptr) {
Pavel Maltseve2603e32016-10-25 16:03:23 -070095 v->prop = property;
96 v->areaId = areaId;
97 v->timestamp = elapsedRealtimeNano();
98 }
99
100 return v;
101}
102
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700103StatusCode DefaultVehicleHal::set(const VehiclePropValue& propValue) {
Pavel Maltseve2603e32016-10-25 16:03:23 -0700104 auto property = propValue.prop;
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800105 const auto& v = propValue.value;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700106
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700107 StatusCode status = StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700108
109 switch (property) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800110 case VehicleProperty::HVAC_POWER_ON:
111 mHvacPowerOn = v.int32Values[0] == 1;
112 break;
113 case VehicleProperty::HVAC_RECIRC_ON:
114 mHvacRecircOn = v.int32Values[0] == 1;
115 break;
116 case VehicleProperty::HVAC_AC_ON:
117 mHvacAcOn = v.int32Values[0] == 1;
118 break;
119 case VehicleProperty::HVAC_AUTO_ON:
120 mHvacAutoOn = v.int32Values[0] == 1;
121 break;
122 case VehicleProperty::HVAC_DEFROSTER:
123 status = setHvacDefroster(propValue.areaId, v.int32Values[0] == 1);
124 break;
125 case VehicleProperty::HVAC_FAN_DIRECTION:
126 mFanDirection =
127 static_cast<VehicleHvacFanDirection>(v.int32Values[0]);
128 break;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700129 case VehicleProperty::HVAC_FAN_SPEED:
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800130 mFanSpeed = v.int32Values[0];
131 break;
132 case VehicleProperty::HVAC_TEMPERATURE_SET:
133 status = setHvacTemperature(propValue.areaId, v.floatValues[0]);
Pavel Maltseve2603e32016-10-25 16:03:23 -0700134 break;
135 case VehicleProperty::DISPLAY_BRIGHTNESS:
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800136 mBrightness = v.int32Values[0];
Pavel Maltseve2603e32016-10-25 16:03:23 -0700137 break;
138 default:
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700139 status = StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700140 }
141
142 return status;
143}
144
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800145StatusCode DefaultVehicleHal::getHvacTemperature(int32_t areaId,
146 float* outValue) {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700147 if (areaId == toInt(VehicleAreaZone::ROW_1_LEFT)) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800148 *outValue = mRow1LeftHvacTemperatureSet;
149 } else if (areaId == toInt(VehicleAreaZone::ROW_1_RIGHT)) {
150 *outValue = mRow1RightHvacTemperatureSet;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700151 } else {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700152 return StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700153 }
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700154 return StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700155}
156
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800157StatusCode DefaultVehicleHal::setHvacTemperature(
158 int32_t areaId, float value) {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700159 if (areaId == toInt(VehicleAreaZone::ROW_1_LEFT)) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800160 mRow1LeftHvacTemperatureSet = value;
161 } else if (areaId == toInt(VehicleAreaZone::ROW_1_RIGHT)) {
162 mRow1RightHvacTemperatureSet = value;
163 } else {
164 return StatusCode::INVALID_ARG;
165 }
166 return StatusCode::OK;
167}
168
169StatusCode DefaultVehicleHal::getHvacDefroster(int32_t areaId,
170 bool* outValue) {
171 ALOGI("Getting Hvac defroster for area: 0x%x", areaId);
172
173 if (areaId == toInt(VehicleAreaWindow::FRONT_WINDSHIELD)) {
174 *outValue = mFrontDefroster;
175 } else if (areaId == toInt(VehicleAreaWindow::REAR_WINDSHIELD)) {
176 *outValue = mRearDefroster;
177 } else {
178 ALOGE("Unable to get hvac defroster for area: 0x%x", areaId);
179 return StatusCode::INVALID_ARG;
180 }
181
182 ALOGI("Getting Hvac defroster for area: 0x%x, OK", areaId);
183 return StatusCode::OK;
184}
185
186StatusCode DefaultVehicleHal::setHvacDefroster(int32_t areaId, bool value) {
187 if (areaId == toInt(VehicleAreaWindow::FRONT_WINDSHIELD)) {
188 mFrontDefroster = value;
189 } else if (areaId == toInt(VehicleAreaWindow::REAR_WINDSHIELD)) {
190 mRearDefroster = value;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700191 } else {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700192 return StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700193 }
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700194 return StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700195}
196
197} // impl
198
199} // namespace V2_0
200} // namespace vehicle
201} // namespace hardware
202} // namespace android