diff --git a/frameworks/native/miscdevice/src/light_client.cpp b/frameworks/native/miscdevice/src/light_client.cpp index 026eb8f724cbf12615a429c627f452614d70bdca..8884bf08139ba62c6c97e33445e4138b75735cec 100755 --- a/frameworks/native/miscdevice/src/light_client.cpp +++ b/frameworks/native/miscdevice/src/light_client.cpp @@ -62,7 +62,8 @@ int32_t LightClient::InitLightClient() retry++; } HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_EXCEPTION", - HiviewDFX::HiSysEvent::EventType::FAULT, "PKG_NAME", "InitLightClient", "ERROR_CODE", MISC_NATIVE_GET_SERVICE_ERR); + HiviewDFX::HiSysEvent::EventType::FAULT, "PKG_NAME", "InitLightClient", "ERROR_CODE", + MISC_NATIVE_GET_SERVICE_ERR); MISC_HILOGE("Get service failed"); return MISC_NATIVE_GET_SERVICE_ERR; } diff --git a/interfaces/native/light/test/unittest/light_agent_test.cpp b/interfaces/native/light/test/unittest/light_agent_test.cpp index bf528a28b89ae68e1a09e6861f02e0bfadddfb03..37492a01929b727dd99d3e3c15328c6770a00398 100755 --- a/interfaces/native/light/test/unittest/light_agent_test.cpp +++ b/interfaces/native/light/test/unittest/light_agent_test.cpp @@ -37,10 +37,10 @@ public: void TearDown() {} }; -LightInfo *lightInfo_ = nullptr; -int32_t lightId_ = -1; -int32_t invalidLightId_ = -1; -int32_t lightType_ = -1; +LightInfo *g_lightInfo = nullptr; +int32_t g_lightId = -1; +int32_t g_invalidLightId = -1; +int32_t g_lightType = -1; /** * @tc.name: StartLightTest_001 @@ -52,12 +52,12 @@ HWTEST_F(LightAgentTest, StartLightTest_001, TestSize.Level1) { CALL_LOG_ENTER; int32_t count = -1; - int32_t ret = GetLightList(&lightInfo_, count); + int32_t ret = GetLightList(&g_lightInfo, count); for (int32_t i = 0; i < count; ++i) { MISC_HILOGI("lightId: %{public}d, lightName: %{public}s, lightNumber: %{public}d, lightType: %{public}d", - lightInfo_[i].lightId, lightInfo_[i].lightName, lightInfo_[i].lightNumber, lightInfo_[i].lightType); - lightId_ = lightInfo_[i].lightId; - lightType_ = lightInfo_[i].lightType; + g_lightInfo[i].lightId, g_lightInfo[i].lightName, g_lightInfo[i].lightNumber, g_lightInfo[i].lightType); + g_lightId = g_lightInfo[i].lightId; + g_lightType = g_lightInfo[i].lightType; } ASSERT_EQ(ret, 0); } @@ -119,15 +119,15 @@ HWTEST_F(LightAgentTest, StartLightTest_003, TestSize.Level1) int32_t powerLightId = 1; TurnOff(powerLightId); LightColor color; - bool ret = GetLightColor(color, lightType_); - if (!ret) { - ASSERT_EQ(ret, -1); + bool flag = GetLightColor(color, g_lightType); + if (!flag) { + ASSERT_FALSE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; animation.onTime = 50; animation.offTime = 50; - int32_t ret = TurnOn(lightId_, color, animation); + int32_t ret = TurnOn(g_lightId, color, animation); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); ASSERT_EQ(ret, 0); } @@ -143,15 +143,15 @@ HWTEST_F(LightAgentTest, StartLightTest_004, TestSize.Level1) { CALL_LOG_ENTER; LightColor color; - bool ret = GetLightColor(color, lightType_); - if (!ret) { - ASSERT_EQ(ret, -1); + bool flag = GetLightColor(color, g_lightType); + if (!flag) { + ASSERT_FALSE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_BUTT; animation.onTime = 50; animation.offTime = 50; - int32_t ret = TurnOn(lightId_, color, animation); + int32_t ret = TurnOn(g_lightId, color, animation); ASSERT_EQ(ret, -1); } } @@ -166,15 +166,15 @@ HWTEST_F(LightAgentTest, StartLightTest_005, TestSize.Level1) { CALL_LOG_ENTER; LightColor color; - bool ret = GetLightColor(color, lightType_); - if (!ret) { - ASSERT_EQ(ret, -1); + bool flag = GetLightColor(color, g_lightType); + if (!flag) { + ASSERT_FALSE(flag); } else { LightAnimation animation; animation.mode = -1; animation.onTime = 50; animation.offTime = 50; - int32_t ret = TurnOn(lightId_, color, animation); + int32_t ret = TurnOn(g_lightId, color, animation); ASSERT_EQ(ret, -1); } } @@ -189,15 +189,15 @@ HWTEST_F(LightAgentTest, StartLightTest_006, TestSize.Level1) { CALL_LOG_ENTER; LightColor color; - bool ret = GetLightColor(color, lightType_); - if (!ret) { - ASSERT_EQ(ret, -1); + bool flag = GetLightColor(color, g_lightType); + if (!flag) { + ASSERT_FALSE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; animation.onTime = -1; animation.offTime = 50; - int32_t ret = TurnOn(lightId_, color, animation); + int32_t ret = TurnOn(g_lightId, color, animation); ASSERT_EQ(ret, -1); } } @@ -212,15 +212,15 @@ HWTEST_F(LightAgentTest, StartLightTest_007, TestSize.Level1) { CALL_LOG_ENTER; LightColor color; - bool ret = GetLightColor(color, lightType_); - if (!ret) { - ASSERT_EQ(ret, -1); + bool flag = GetLightColor(color, g_lightType); + if (!flag) { + ASSERT_FALSE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; animation.onTime = 50; animation.offTime = -1; - int32_t ret = TurnOn(lightId_, color, animation); + int32_t ret = TurnOn(g_lightId, color, animation); ASSERT_EQ(ret, -1); } } @@ -235,15 +235,15 @@ HWTEST_F(LightAgentTest, StartLightTest_008, TestSize.Level1) { CALL_LOG_ENTER; LightColor color; - bool ret = GetLightColor(color, lightType_); - if (!ret) { - ASSERT_EQ(ret, -1); + bool flag = GetLightColor(color, g_lightType); + if (!flag) { + ASSERT_FALSE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; animation.onTime = 2; animation.offTime = 2; - int32_t ret = TurnOn(lightId_, color, animation); + int32_t ret = TurnOn(g_lightId, color, animation); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); ASSERT_EQ(ret, 0); } @@ -259,15 +259,15 @@ HWTEST_F(LightAgentTest, StartLightTest_009, TestSize.Level1) { CALL_LOG_ENTER; LightColor color; - bool ret = GetLightColor(color, lightType_); - if (!ret) { - ASSERT_EQ(ret, -1); + bool flag = GetLightColor(color, g_lightType); + if (!flag) { + ASSERT_FALSE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; animation.onTime = 2; animation.offTime = 2; - int32_t ret = TurnOn(invalidLightId_, color, animation); + int32_t ret = TurnOn(g_invalidLightId, color, animation); ASSERT_EQ(ret, -1); } } @@ -281,7 +281,7 @@ HWTEST_F(LightAgentTest, StartLightTest_009, TestSize.Level1) HWTEST_F(LightAgentTest, StartLightTest_010, TestSize.Level1) { CALL_LOG_ENTER; - int32_t ret = TurnOff(lightId_); + int32_t ret = TurnOff(g_lightId); ASSERT_EQ(ret, 0); } @@ -294,7 +294,7 @@ HWTEST_F(LightAgentTest, StartLightTest_010, TestSize.Level1) HWTEST_F(LightAgentTest, StartLightTest_011, TestSize.Level1) { CALL_LOG_ENTER; - int32_t ret = TurnOff(invalidLightId_); + int32_t ret = TurnOff(g_invalidLightId); ASSERT_EQ(ret, -1); } } // namespace Sensors diff --git a/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp b/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp index 3bbd1821fb024f466b90cef8c4e820b949d86d7b..aea5b9a7128261c4ef7bcd26690c049f02d5e835 100755 --- a/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp +++ b/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp @@ -23,15 +23,18 @@ namespace OHOS { namespace Sensors { namespace { -std::map> TRANSIENT_VIBRATION_INFOS = { +const std::map> TRANSIENT_VIBRATION_INFOS = { {0x28, {0x4d, 0x4d, 0x0b}}, {0x2c, {0x2a, 0x64, 0x07}}, {0x30, {0x44, 0x52, 0x16}}, {0x3c, {0x45, 0x34, 0x0a}}, {0x40, {0x2e, 0x43, 0x0a}}, {0x48, {0x51, 0x52, 0x0a}}, {0x4c, {0x3a, 0x0c, 0x0f}}, {0x50, {0x64, 0x20, 0x14}}, {0x54, {0x55, 0x34, 0x1c}}, {0x5c, {0x32, 0x0c, 0x13}}, {0x60, {0x12, 0x07, 0x0a}} -}; // {Id, {intensity, frequency, duration}} +}; constexpr int32_t INTENSITY_MAX = 100; constexpr int32_t TRANSIENT_GRADE_NUM = 4; constexpr int32_t CONTINUOUS_GRADE_NUM = 8; +constexpr int32_t CONTINUOUS_GRADE_MASK = 100; +constexpr float ROUND_OFFSET = 0.5; +constexpr float TRANSIENT_GRADE_GAIN = 0.25; constexpr float CONTINUOUS_GRADE_SCALE = 100. / 8; constexpr float INTENSITY_WEIGHT = 0.5; constexpr float FREQUENCY_WEIGHT = 0.5; @@ -78,22 +81,22 @@ void CustomVibrationMatcher::ProcessContinuousEvent(const VibrateEvent &event, i if (event.intensity == INTENSITY_MAX) { grade = CONTINUOUS_GRADE_NUM - 1; } else { - grade = round(event.intensity / CONTINUOUS_GRADE_SCALE + 0.5) - 1; + grade = round(event.intensity / CONTINUOUS_GRADE_SCALE + ROUND_OFFSET) - 1; } if ((!compositeEffects.empty()) && (event.startTime == preStartTime + preDuration)) { PrimitiveEffect& prePrimitiveEffect = compositeEffects.back().primitiveEffect; int32_t preEffectId = prePrimitiveEffect.effectId; - int32_t preGrade = preEffectId % 100; + int32_t preGrade = preEffectId % CONTINUOUS_GRADE_MASK; int32_t mergeDuration = preDuration + event.duration; if (preEffectId > EFFECT_ID_BOUNDARY && preGrade == grade && mergeDuration < DURATION_MAX) { - prePrimitiveEffect.effectId = mergeDuration * 100 + grade; + prePrimitiveEffect.effectId = mergeDuration * CONTINUOUS_GRADE_MASK + grade; preDuration = mergeDuration; return; } } PrimitiveEffect primitiveEffect; primitiveEffect.delay = event.startTime - preStartTime; - primitiveEffect.effectId = event.duration * 100 + grade; + primitiveEffect.effectId = event.duration * CONTINUOUS_GRADE_MASK + grade; CompositeEffect compositeEffect; compositeEffect.primitiveEffect = primitiveEffect; compositeEffects.push_back(compositeEffect); @@ -111,7 +114,7 @@ void CustomVibrationMatcher::ProcessTransientEvent(const VibrateEvent &event, in const std::vector &info = transientInfo.second; float frequencyDistance = std::abs(event.frequency - info[1]); for (int32_t j = 0; j < TRANSIENT_GRADE_NUM; ++j) { - float intensityDistance = std::abs(event.intensity - info[0] * (1 - j * 0.25)); + float intensityDistance = std::abs(event.intensity - info[0] * (1 - j * TRANSIENT_GRADE_GAIN)); float weightSum = INTENSITY_WEIGHT * intensityDistance + FREQUENCY_WEIGHT * frequencyDistance; if (weightSum < minWeightSum) { minWeightSum = weightSum;