1 /* 2 * Copyright (c) 2024-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef POWERMGR_PROXIMITY_CONTROLLER_BASE_H 17 #define POWERMGR_PROXIMITY_CONTROLLER_BASE_H 18 19 #ifdef HAS_SENSORS_SENSOR_PART 20 #include <mutex> 21 #endif 22 #include "sensor_agent.h" 23 #include "power_state_machine_info.h" 24 #include "iproximity_controller.h" 25 26 namespace OHOS { 27 namespace PowerMgr { 28 class ProximityControllerBase : public IProximityController { 29 public: 30 typedef void (*SensorCallbackFunc)(SensorEvent *event); 31 ProximityControllerBase() = default; 32 ProximityControllerBase(const std::string& name, SensorCallbackFunc callback); 33 virtual ~ProximityControllerBase(); 34 bool InitProximitySensorUser(); 35 void Enable() override; 36 void Disable() override; OnClose()37 void OnClose() override {} OnAway()38 void OnAway() override {} 39 static const int32_t PROXIMITY_CLOSE_SCALAR = 0; 40 static const int32_t PROXIMITY_AWAY_SCALAR = 5; 41 static const uint32_t SAMPLING_RATE = 100000000; 42 private: 43 SensorCallbackFunc callback_ = nullptr; 44 std::string name_ {}; 45 SensorUser user_ {}; 46 }; 47 } // namespace PowerMgr 48 } // namespace OHOS 49 #endif // POWERMGR_PROXIMITY_CONTROLLER_BASE_H