blob: c56248b1c854b4381e1e41153e950910f46b68b8 [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;
84 default:
Pavel Maltsevdb179c52016-10-27 15:43:06 -070085 *outStatus = StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -070086 }
87
Pavel Maltsevdb179c52016-10-27 15:43:06 -070088 if (StatusCode::OK == *outStatus && v.get() != nullptr) {
Pavel Maltseve2603e32016-10-25 16:03:23 -070089 v->prop = property;
90 v->areaId = areaId;
91 v->timestamp = elapsedRealtimeNano();
92 }
93
94 return v;
95}
96
Pavel Maltsevdb179c52016-10-27 15:43:06 -070097StatusCode DefaultVehicleHal::set(const VehiclePropValue& propValue) {
Pavel Maltseve2603e32016-10-25 16:03:23 -070098 auto property = propValue.prop;
Pavel Maltsev30c84c32016-11-14 16:23:36 -080099 const auto& v = propValue.value;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700100
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700101 StatusCode status = StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700102
103 switch (property) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800104 case VehicleProperty::HVAC_POWER_ON:
105 mHvacPowerOn = v.int32Values[0] == 1;
106 break;
107 case VehicleProperty::HVAC_RECIRC_ON:
108 mHvacRecircOn = v.int32Values[0] == 1;
109 break;
110 case VehicleProperty::HVAC_AC_ON:
111 mHvacAcOn = v.int32Values[0] == 1;
112 break;
113 case VehicleProperty::HVAC_AUTO_ON:
114 mHvacAutoOn = v.int32Values[0] == 1;
115 break;
116 case VehicleProperty::HVAC_DEFROSTER:
117 status = setHvacDefroster(propValue.areaId, v.int32Values[0] == 1);
118 break;
119 case VehicleProperty::HVAC_FAN_DIRECTION:
120 mFanDirection =
121 static_cast<VehicleHvacFanDirection>(v.int32Values[0]);
122 break;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700123 case VehicleProperty::HVAC_FAN_SPEED:
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800124 mFanSpeed = v.int32Values[0];
125 break;
126 case VehicleProperty::HVAC_TEMPERATURE_SET:
127 status = setHvacTemperature(propValue.areaId, v.floatValues[0]);
Pavel Maltseve2603e32016-10-25 16:03:23 -0700128 break;
129 case VehicleProperty::DISPLAY_BRIGHTNESS:
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800130 mBrightness = v.int32Values[0];
Pavel Maltseve2603e32016-10-25 16:03:23 -0700131 break;
132 default:
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700133 status = StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700134 }
135
136 return status;
137}
138
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800139StatusCode DefaultVehicleHal::getHvacTemperature(int32_t areaId,
140 float* outValue) {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700141 if (areaId == toInt(VehicleAreaZone::ROW_1_LEFT)) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800142 *outValue = mRow1LeftHvacTemperatureSet;
143 } else if (areaId == toInt(VehicleAreaZone::ROW_1_RIGHT)) {
144 *outValue = mRow1RightHvacTemperatureSet;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700145 } else {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700146 return StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700147 }
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700148 return StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700149}
150
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800151StatusCode DefaultVehicleHal::setHvacTemperature(
152 int32_t areaId, float value) {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700153 if (areaId == toInt(VehicleAreaZone::ROW_1_LEFT)) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800154 mRow1LeftHvacTemperatureSet = value;
155 } else if (areaId == toInt(VehicleAreaZone::ROW_1_RIGHT)) {
156 mRow1RightHvacTemperatureSet = value;
157 } else {
158 return StatusCode::INVALID_ARG;
159 }
160 return StatusCode::OK;
161}
162
163StatusCode DefaultVehicleHal::getHvacDefroster(int32_t areaId,
164 bool* outValue) {
165 ALOGI("Getting Hvac defroster for area: 0x%x", areaId);
166
167 if (areaId == toInt(VehicleAreaWindow::FRONT_WINDSHIELD)) {
168 *outValue = mFrontDefroster;
169 } else if (areaId == toInt(VehicleAreaWindow::REAR_WINDSHIELD)) {
170 *outValue = mRearDefroster;
171 } else {
172 ALOGE("Unable to get hvac defroster for area: 0x%x", areaId);
173 return StatusCode::INVALID_ARG;
174 }
175
176 ALOGI("Getting Hvac defroster for area: 0x%x, OK", areaId);
177 return StatusCode::OK;
178}
179
180StatusCode DefaultVehicleHal::setHvacDefroster(int32_t areaId, bool value) {
181 if (areaId == toInt(VehicleAreaWindow::FRONT_WINDSHIELD)) {
182 mFrontDefroster = value;
183 } else if (areaId == toInt(VehicleAreaWindow::REAR_WINDSHIELD)) {
184 mRearDefroster = value;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700185 } else {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700186 return StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700187 }
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700188 return StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700189}
190
191} // impl
192
193} // namespace V2_0
194} // namespace vehicle
195} // namespace hardware
196} // namespace android