1 /* 2 * Copyright (c) 2022-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 #ifdef DEVICE_STATUS_SENSOR_ENABLE 20 #include <cmath> 21 #include <cstdio> 22 #include <iostream> 23 24 #include "devicestatus_common.h" 25 #include "devicestatus_data_define.h" 26 #include "devicestatus_msdp_interface.h" 27 #include "sensor_data_callback.h" 28 #include "stationary_data.h" 29 30 namespace OHOS { 31 namespace Msdp { 32 namespace DeviceStatus { 33 class AlgoBase { 34 public: AlgoBase()35 AlgoBase() {}; 36 virtual ~AlgoBase() = default; 37 38 virtual bool Init(Type type) = 0; 39 void Unsubscribe(int32_t sensorTypeId); 40 void RegisterCallback(const std::shared_ptr<IMsdp::MsdpAlgoCallback> callback); 41 42 protected: 43 enum { 44 UNKNOWN = -1, 45 STILL, 46 UNSTILL, 47 HORIZONTAL, 48 NON_HORIZONTAL, 49 VERTICAL, 50 NON_VERTICAL 51 }; 52 struct { 53 float x { 0.0 }; 54 float y { 0.0 }; 55 float z { 0.0 }; 56 double resultantAcc { 0.0 }; 57 double pitch { 0.0 }; 58 double roll { 0.0 }; 59 } algoPara_ {}; 60 int32_t state_ { UNKNOWN }; 61 int32_t counter_ { COUNTER_THRESHOLD }; 62 Data reportInfo_ { TYPE_INVALID, 63 VALUE_INVALID, 64 STATUS_INVALID, 65 ACTION_INVALID, 66 0.0 }; 67 68 virtual bool StartAlgorithm(int32_t sensorTypeId, AccelData* sensorData) = 0; 69 bool SetData(int32_t sensorTypeId, AccelData* sensorData); 70 virtual void ExecuteOperation() = 0; 71 void UpdateStateAndReport(OnChangedValue value, int32_t state, Type type); 72 73 SensorCallback algoCallback_ { nullptr }; 74 std::shared_ptr<IMsdp::MsdpAlgoCallback> callback_ { nullptr }; 75 }; 76 } // namespace DeviceStatus 77 } // namespace Msdp 78 } // namespace OHOS 79 #endif // DEVICE_STATUS_SENSOR_ENABLE 80 #endif // ALGO_BASE_H 81 82