1 /* 2 * Copyright (c) 2023 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 ALGO_BASE_H 17 #define ALGO_BASE_H 18 19 #include <cmath> 20 #include <cstdio> 21 #include <iostream> 22 23 #include "devicestatus_common.h" 24 #include "devicestatus_data_define.h" 25 #include "devicestatus_data_utils.h" 26 #include "devicestatus_msdp_interface.h" 27 #include "sensor_data_callback.h" 28 29 namespace OHOS { 30 namespace Msdp { 31 class AlgoBase { 32 public: 33 AlgoBase() = default; 34 virtual ~AlgoBase() = default; 35 36 virtual bool Init(DevicestatusDataUtils::DevicestatusType type) = 0; 37 void Unsubscribe(int32_t sensorTypeId); 38 void RegisterCallback(std::shared_ptr<DevicestatusMsdpInterface::MsdpAlgorithmCallback> callback); 39 void UnregisterCallback(); 40 protected: 41 virtual bool StartAlgorithm(int32_t sensorTypeId, AccelData* sensorData) = 0; 42 bool GetData(int32_t sensorTypeId, AccelData* sensorData); 43 virtual void ExecuteOperation() = 0; 44 void UpdateStateAndReport(DevicestatusDataUtils::DevicestatusValue value, 45 int32_t state, DevicestatusDataUtils::DevicestatusType type); 46 47 enum { 48 UNKNOWN = -1, 49 STILL, 50 NON_STILL, 51 RELATIVE_STILL, 52 NON_RELATIVE_STILL, 53 HORIZONTAL, 54 NON_HORIZONTAL, 55 VERTICAL, 56 NON_VERTICAL 57 }; 58 int32_t state_ = UNKNOWN; 59 int32_t counter_ = COUNTER_THRESHOLD; 60 DevicestatusDataUtils::AlgoData algoPara_ {}; 61 DevicestatusDataUtils::DevicestatusData reportInfo_; 62 SensorCallback algoCallback_ { nullptr }; 63 std::shared_ptr<DevicestatusMsdpInterface::MsdpAlgorithmCallback> callback_ { nullptr }; 64 }; 65 } // namespace Msdp 66 } // namespace OHOS 67 #endif // ALGO_BASE_H 68