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 package com.android.car.hvac.controllers; 17 18 import android.car.hardware.hvac.CarHvacManager; 19 import android.util.SparseIntArray; 20 21 import com.android.car.hvac.HvacController; 22 import com.android.car.hvac.ui.FanDirectionButtons; 23 24 /** 25 * A controller to handle changes in the fan direction. Also maps fan directions specified 26 * in the {@link FanDirectionButtons} to the {@link CarHvacManager}{@code #FAN_DIRECTION_*} 27 * constants in the vehicle hardware. 28 */ 29 public class FanDirectionButtonsController { 30 private final static int FAN_DIRECTION_COUNT = 4; 31 32 private final FanDirectionButtons mFanDirectionButtons; 33 private final HvacController mHvacController; 34 private final SparseIntArray mFanDirectionMap = new SparseIntArray(FAN_DIRECTION_COUNT); 35 36 public FanDirectionButtonsController(FanDirectionButtons speedBar, HvacController controller) { 37 mFanDirectionButtons = speedBar; 38 mHvacController = controller; 39 initialize(); 40 } 41 42 private void initialize() { 43 // Note Car specific values are being used here, as not all cars have the floor 44 // and defroster fan direction. 45 mFanDirectionMap.put(FanDirectionButtons.FAN_DIRECTION_FACE, 46 CarHvacManager.FAN_DIRECTION_FACE); 47 mFanDirectionMap.put(FanDirectionButtons.FAN_DIRECTION_FACE_FLOOR, 48 (CarHvacManager.FAN_DIRECTION_FACE | CarHvacManager.FAN_DIRECTION_FLOOR)); 49 mFanDirectionMap.put(FanDirectionButtons.FAN_DIRECTION_FLOOR, 50 CarHvacManager.FAN_DIRECTION_FLOOR); 51 mFanDirectionMap.put(FanDirectionButtons.FAN_DIRECTION_FLOOR_DEFROSTER, 52 (CarHvacManager.FAN_DIRECTION_DEFROST | CarHvacManager.FAN_DIRECTION_FLOOR)); 53 mFanDirectionButtons.setFanDirectionClickListener(mListener); 54 } 55 56 private final FanDirectionButtons.FanDirectionClickListener mListener 57 = new FanDirectionButtons.FanDirectionClickListener() { 58 @Override 59 public void onFanDirectionClicked(@FanDirectionButtons.FanDirection int direction) { 60 mHvacController.setFanDirection(mFanDirectionMap.get(direction)); 61 } 62 }; 63 } 64