Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 19 | namespace android { |
| 20 | namespace hardware { |
| 21 | namespace vehicle { |
| 22 | namespace V2_0 { |
| 23 | |
| 24 | namespace impl { |
| 25 | |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 26 | VehicleHal::VehiclePropValuePtr DefaultVehicleHal::get( |
| 27 | const VehiclePropValue& requestedPropValue, StatusCode* outStatus) { |
| 28 | *outStatus = StatusCode::OK; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 29 | |
| 30 | VehiclePropValuePtr v; |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 31 | VehicleProperty property = requestedPropValue.prop; |
| 32 | int32_t areaId = requestedPropValue.areaId; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 33 | |
| 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 Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 40 | *outStatus = getHvacFanSpeed(areaId, &value); |
| 41 | if (StatusCode::OK == *outStatus) { |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 42 | 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 Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 52 | *outStatus = StatusCode::INVALID_ARG; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 55 | if (StatusCode::OK == *outStatus && v.get() != nullptr) { |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 56 | v->prop = property; |
| 57 | v->areaId = areaId; |
| 58 | v->timestamp = elapsedRealtimeNano(); |
| 59 | } |
| 60 | |
| 61 | return v; |
| 62 | } |
| 63 | |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 64 | StatusCode DefaultVehicleHal::set(const VehiclePropValue& propValue) { |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 65 | auto property = propValue.prop; |
| 66 | |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 67 | StatusCode status = StatusCode::OK; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 68 | |
| 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 Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 78 | status = StatusCode::INVALID_ARG; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | return status; |
| 82 | } |
| 83 | |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 84 | StatusCode DefaultVehicleHal::getHvacFanSpeed(int32_t areaId, |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 85 | int32_t* outValue) { |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 86 | if (areaId == toInt(VehicleAreaZone::ROW_1_LEFT)) { |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 87 | *outValue = fanSpeedRow1Left; |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 88 | } else if (areaId == toInt(VehicleAreaZone::ROW_2_RIGHT)) { |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 89 | *outValue = fanSpeedRow1Right; |
| 90 | } else { |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 91 | return StatusCode::INVALID_ARG; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 92 | } |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 93 | return StatusCode::OK; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 96 | StatusCode DefaultVehicleHal::setHvacFanSpeed(int32_t areaId, int32_t value) { |
| 97 | if (areaId == toInt(VehicleAreaZone::ROW_1_LEFT)) { |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 98 | fanSpeedRow1Left = value; |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 99 | } else if (areaId == toInt(VehicleAreaZone::ROW_2_RIGHT)) { |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 100 | fanSpeedRow1Right = value; |
| 101 | } else { |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 102 | return StatusCode::INVALID_ARG; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 103 | } |
Pavel Maltsev | db179c5 | 2016-10-27 15:43:06 -0700 | [diff] [blame^] | 104 | return StatusCode::OK; |
Pavel Maltsev | e2603e3 | 2016-10-25 16:03:23 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | } // impl |
| 108 | |
| 109 | } // namespace V2_0 |
| 110 | } // namespace vehicle |
| 111 | } // namespace hardware |
| 112 | } // namespace android |