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 | |
| 26 | VehicleHal::VehiclePropValuePtr DefaultVehicleHal::get(VehicleProperty property, |
| 27 | int32_t areaId, |
| 28 | status_t* outStatus) { |
| 29 | *outStatus = OK; |
| 30 | |
| 31 | VehiclePropValuePtr v; |
| 32 | |
| 33 | switch (property) { |
| 34 | case VehicleProperty::INFO_MAKE: |
| 35 | v = getValuePool()->obtainString("Default Car"); |
| 36 | break; |
| 37 | case VehicleProperty::HVAC_FAN_SPEED: |
| 38 | int32_t value; |
| 39 | if ((*outStatus = getHvacFanSpeed(areaId, &value)) == OK) { |
| 40 | v = getValuePool()->obtainInt32(value); |
| 41 | } |
| 42 | break; |
| 43 | case VehicleProperty::INFO_FUEL_CAPACITY: |
| 44 | v = getValuePool()->obtainFloat(0.75f); |
| 45 | break; |
| 46 | case VehicleProperty::DISPLAY_BRIGHTNESS: |
| 47 | v = getValuePool()->obtainInt32(brightness); |
| 48 | break; |
| 49 | default: |
| 50 | *outStatus = BAD_VALUE; |
| 51 | } |
| 52 | |
| 53 | if (*outStatus == OK && v.get() != nullptr) { |
| 54 | v->prop = property; |
| 55 | v->areaId = areaId; |
| 56 | v->timestamp = elapsedRealtimeNano(); |
| 57 | } |
| 58 | |
| 59 | return v; |
| 60 | } |
| 61 | |
| 62 | status_t DefaultVehicleHal::set(const VehiclePropValue& propValue) { |
| 63 | auto property = propValue.prop; |
| 64 | |
| 65 | status_t status = OK; |
| 66 | |
| 67 | switch (property) { |
| 68 | case VehicleProperty::HVAC_FAN_SPEED: |
| 69 | status = setHvacFanSpeed(propValue.areaId, |
| 70 | propValue.value.int32Values[0]); |
| 71 | break; |
| 72 | case VehicleProperty::DISPLAY_BRIGHTNESS: |
| 73 | brightness = propValue.value.int32Values[0]; |
| 74 | break; |
| 75 | default: |
| 76 | status = BAD_VALUE; |
| 77 | } |
| 78 | |
| 79 | return status; |
| 80 | } |
| 81 | |
| 82 | status_t DefaultVehicleHal::getHvacFanSpeed(int32_t areaId, |
| 83 | int32_t* outValue) { |
| 84 | if (areaId == val(VehicleAreaZone::ROW_1_LEFT)) { |
| 85 | *outValue = fanSpeedRow1Left; |
| 86 | } else if (areaId == val(VehicleAreaZone::ROW_2_RIGHT)) { |
| 87 | *outValue = fanSpeedRow1Right; |
| 88 | } else { |
| 89 | return BAD_VALUE; |
| 90 | } |
| 91 | return OK; |
| 92 | } |
| 93 | |
| 94 | status_t DefaultVehicleHal::setHvacFanSpeed(int32_t areaId, int32_t value) { |
| 95 | if (areaId == val(VehicleAreaZone::ROW_1_LEFT)) { |
| 96 | fanSpeedRow1Left = value; |
| 97 | } else if (areaId == val(VehicleAreaZone::ROW_2_RIGHT)) { |
| 98 | fanSpeedRow1Right = value; |
| 99 | } else { |
| 100 | return BAD_VALUE; |
| 101 | } |
| 102 | return OK; |
| 103 | } |
| 104 | |
| 105 | } // impl |
| 106 | |
| 107 | } // namespace V2_0 |
| 108 | } // namespace vehicle |
| 109 | } // namespace hardware |
| 110 | } // namespace android |