Loading cmds/idlcli/Android.bp +6 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ cc_library { "vibrator/CommandAlwaysOnEnable.cpp", "vibrator/CommandCompose.cpp", "vibrator/CommandComposePwle.cpp", "vibrator/CommandGetFrequencyToOutputAccelerationMap.cpp", "vibrator/CommandGetBandwidthAmplitudeMap.cpp", "vibrator/CommandGetCapabilities.cpp", "vibrator/CommandGetCompositionDelayMax.cpp", Loading @@ -72,6 +73,11 @@ cc_library { "vibrator/CommandSetExternalControl.cpp", "vibrator/CommandSupportsAmplitudeControl.cpp", "vibrator/CommandSupportsExternalControl.cpp", "vibrator/CommandGetPwleV2PrimitiveDurationMaxMillis.cpp", "vibrator/CommandGetPwleV2CompositionSizeMax.cpp", "vibrator/CommandGetPwleV2PrimitiveDurationMinMillis.cpp", "vibrator/CommandComposePwleV2.cpp", "vibrator/CommandPerformVendorEffect.cpp", ], visibility: [":__subpackages__"], } Loading cmds/idlcli/vibrator/CommandComposePwleV2.cpp 0 → 100644 +146 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdlib.h> #include <charconv> #include "utils.h" #include "vibrator.h" namespace android { namespace idlcli { class CommandVibrator; namespace vibrator { using aidl::CompositePwleV2; using aidl::PwleV2Primitive; class CommandComposePwleV2 : public Command { std::string getDescription() const override { return "Compose normalized PWLE vibration."; } std::string getUsageSummary() const override { return "[options] <time> <frequency> <amplitude> ..."; } UsageDetails getUsageDetails() const override { UsageDetails details{ {"-b", {"Block for duration of vibration."}}, {"<time>", {"Segment duration in milliseconds"}}, {"<frequency>", {"Target frequency in Hz"}}, {"<amplitude>", {"Target amplitude in [0.0, 1.0]"}}, {"...", {"May repeat multiple times."}}, }; return details; } Status doArgs(Args& args) override { while (args.get<std::string>().value_or("").find("-") == 0) { auto opt = *args.pop<std::string>(); if (opt == "--") { break; } else if (opt == "-b") { mBlocking = true; } else { std::cerr << "Invalid Option '" << opt << "'!" << std::endl; return USAGE; } } if (args.empty()) { std::cerr << "Missing arguments! Please see usage" << std::endl; return USAGE; } while (!args.empty()) { PwleV2Primitive segment; if (auto timeMs = args.pop<decltype(segment.timeMillis)>(); timeMs && *timeMs >= 0 && *timeMs <= 0x7ffff) { segment.timeMillis = *timeMs; std::cout << "Time: " << segment.timeMillis << std::endl; } else { std::cerr << "Missing or Invalid Time!" << std::endl; return USAGE; } if (auto frequencyHz = args.pop<decltype(segment.frequencyHz)>(); frequencyHz && *frequencyHz >= 30 && *frequencyHz <= 300) { segment.frequencyHz = *frequencyHz; std::cout << "Frequency: " << segment.frequencyHz << std::endl; } else { std::cerr << "Missing or Invalid Frequency!" << std::endl; return USAGE; } if (auto amplitude = args.pop<decltype(segment.amplitude)>(); amplitude && *amplitude >= 0 && *amplitude <= 1.0) { segment.amplitude = *amplitude; std::cout << "Amplitude: " << segment.amplitude << std::endl; } else { std::cerr << "Missing or Invalid Amplitude!" << std::endl; return USAGE; } mCompositePwle.pwlePrimitives.emplace_back(std::move(segment)); } if (!args.empty()) { std::cerr << "Unexpected Arguments!" << std::endl; return USAGE; } return OK; } Status doMain(Args&& /*args*/) override { auto hal = getHal<aidl::IVibrator>(); if (!hal) { return UNAVAILABLE; } ABinderProcess_setThreadPoolMaxThreadCount(1); ABinderProcess_startThreadPool(); std::shared_ptr<VibratorCallback> callback; if (mBlocking) { callback = ndk::SharedRefBase::make<VibratorCallback>(); } auto status = hal->call(&aidl::IVibrator::composePwleV2, mCompositePwle, callback); if (status.isOk() && callback) { callback->waitForComplete(); } std::cout << "Status: " << status.getDescription() << std::endl; return status.isOk() ? OK : ERROR; } bool mBlocking; CompositePwleV2 mCompositePwle; }; static const auto Command = CommandRegistry<CommandVibrator>::Register<CommandComposePwleV2>("composePwleV2"); } // namespace vibrator } // namespace idlcli } // namespace android cmds/idlcli/vibrator/CommandGetFrequencyToOutputAccelerationMap.cpp 0 → 100644 +78 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "utils.h" #include "vibrator.h" namespace android { namespace idlcli { class CommandVibrator; namespace vibrator { using aidl::FrequencyAccelerationMapEntry; class CommandGetFrequencyToOutputAccelerationMap : public Command { std::string getDescription() const override { return "Retrieves vibrator frequency to output acceleration map."; } std::string getUsageSummary() const override { return ""; } UsageDetails getUsageDetails() const override { UsageDetails details{}; return details; } Status doArgs(Args& args) override { if (!args.empty()) { std::cerr << "Unexpected Arguments!" << std::endl; return USAGE; } return OK; } Status doMain(Args&& /*args*/) override { std::string statusStr; std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap; Status ret; if (auto hal = getHal<aidl::IVibrator>()) { auto status = hal->call(&aidl::IVibrator::getFrequencyToOutputAccelerationMap, &frequencyToOutputAccelerationMap); statusStr = status.getDescription(); ret = (status.isOk() ? OK : ERROR); } else { return UNAVAILABLE; } std::cout << "Status: " << statusStr << std::endl; std::cout << "Frequency to Output Amplitude Map: " << std::endl; for (auto& entry : frequencyToOutputAccelerationMap) { std::cout << entry.frequencyHz << " " << entry.maxOutputAccelerationGs << std::endl; } return ret; } }; static const auto Command = CommandRegistry<CommandVibrator>::Register<CommandGetFrequencyToOutputAccelerationMap>( "getFrequencyToOutputAccelerationMap"); } // namespace vibrator } // namespace idlcli } // namespace android cmds/idlcli/vibrator/CommandGetPwleV2CompositionSizeMax.cpp 0 → 100644 +72 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "utils.h" #include "vibrator.h" namespace android { namespace idlcli { class CommandVibrator; namespace vibrator { class CommandGetPwleV2CompositionSizeMax : public Command { std::string getDescription() const override { return "Retrieves vibrator PwleV2 max composition size."; } std::string getUsageSummary() const override { return ""; } UsageDetails getUsageDetails() const override { UsageDetails details{}; return details; } Status doArgs(Args& args) override { if (!args.empty()) { std::cerr << "Unexpected Arguments!" << std::endl; return USAGE; } return OK; } Status doMain(Args&& /*args*/) override { std::string statusStr; int32_t maxSize; Status ret; if (auto hal = getHal<aidl::IVibrator>()) { auto status = hal->call(&aidl::IVibrator::getPwleV2CompositionSizeMax, &maxSize); statusStr = status.getDescription(); ret = status.isOk() ? OK : ERROR; } else { return UNAVAILABLE; } std::cout << "Status: " << statusStr << std::endl; std::cout << "Max Size: " << maxSize << std::endl; return ret; } }; static const auto Command = CommandRegistry<CommandVibrator>::Register<CommandGetPwleV2CompositionSizeMax>( "getPwleV2CompositionSizeMax"); } // namespace vibrator } // namespace idlcli } // namespace android cmds/idlcli/vibrator/CommandGetPwleV2PrimitiveDurationMaxMillis.cpp 0 → 100644 +73 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "utils.h" #include "vibrator.h" namespace android { namespace idlcli { class CommandVibrator; namespace vibrator { class CommandGetPwleV2PrimitiveDurationMaxMillis : public Command { std::string getDescription() const override { return "Retrieves vibrator PwleV2 max primitive duration in milliseconds."; } std::string getUsageSummary() const override { return ""; } UsageDetails getUsageDetails() const override { UsageDetails details{}; return details; } Status doArgs(Args& args) override { if (!args.empty()) { std::cerr << "Unexpected Arguments!" << std::endl; return USAGE; } return OK; } Status doMain(Args&& /*args*/) override { std::string statusStr; int32_t maxDurationMs; Status ret; if (auto hal = getHal<aidl::IVibrator>()) { auto status = hal->call(&aidl::IVibrator::getPwleV2PrimitiveDurationMaxMillis, &maxDurationMs); statusStr = status.getDescription(); ret = status.isOk() ? OK : ERROR; } else { return UNAVAILABLE; } std::cout << "Status: " << statusStr << std::endl; std::cout << "Primitive duration max: " << maxDurationMs << " ms" << std::endl; return ret; } }; static const auto Command = CommandRegistry<CommandVibrator>::Register<CommandGetPwleV2PrimitiveDurationMaxMillis>( "getPwleV2PrimitiveDurationMaxMillis"); } // namespace vibrator } // namespace idlcli } // namespace android Loading
cmds/idlcli/Android.bp +6 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ cc_library { "vibrator/CommandAlwaysOnEnable.cpp", "vibrator/CommandCompose.cpp", "vibrator/CommandComposePwle.cpp", "vibrator/CommandGetFrequencyToOutputAccelerationMap.cpp", "vibrator/CommandGetBandwidthAmplitudeMap.cpp", "vibrator/CommandGetCapabilities.cpp", "vibrator/CommandGetCompositionDelayMax.cpp", Loading @@ -72,6 +73,11 @@ cc_library { "vibrator/CommandSetExternalControl.cpp", "vibrator/CommandSupportsAmplitudeControl.cpp", "vibrator/CommandSupportsExternalControl.cpp", "vibrator/CommandGetPwleV2PrimitiveDurationMaxMillis.cpp", "vibrator/CommandGetPwleV2CompositionSizeMax.cpp", "vibrator/CommandGetPwleV2PrimitiveDurationMinMillis.cpp", "vibrator/CommandComposePwleV2.cpp", "vibrator/CommandPerformVendorEffect.cpp", ], visibility: [":__subpackages__"], } Loading
cmds/idlcli/vibrator/CommandComposePwleV2.cpp 0 → 100644 +146 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdlib.h> #include <charconv> #include "utils.h" #include "vibrator.h" namespace android { namespace idlcli { class CommandVibrator; namespace vibrator { using aidl::CompositePwleV2; using aidl::PwleV2Primitive; class CommandComposePwleV2 : public Command { std::string getDescription() const override { return "Compose normalized PWLE vibration."; } std::string getUsageSummary() const override { return "[options] <time> <frequency> <amplitude> ..."; } UsageDetails getUsageDetails() const override { UsageDetails details{ {"-b", {"Block for duration of vibration."}}, {"<time>", {"Segment duration in milliseconds"}}, {"<frequency>", {"Target frequency in Hz"}}, {"<amplitude>", {"Target amplitude in [0.0, 1.0]"}}, {"...", {"May repeat multiple times."}}, }; return details; } Status doArgs(Args& args) override { while (args.get<std::string>().value_or("").find("-") == 0) { auto opt = *args.pop<std::string>(); if (opt == "--") { break; } else if (opt == "-b") { mBlocking = true; } else { std::cerr << "Invalid Option '" << opt << "'!" << std::endl; return USAGE; } } if (args.empty()) { std::cerr << "Missing arguments! Please see usage" << std::endl; return USAGE; } while (!args.empty()) { PwleV2Primitive segment; if (auto timeMs = args.pop<decltype(segment.timeMillis)>(); timeMs && *timeMs >= 0 && *timeMs <= 0x7ffff) { segment.timeMillis = *timeMs; std::cout << "Time: " << segment.timeMillis << std::endl; } else { std::cerr << "Missing or Invalid Time!" << std::endl; return USAGE; } if (auto frequencyHz = args.pop<decltype(segment.frequencyHz)>(); frequencyHz && *frequencyHz >= 30 && *frequencyHz <= 300) { segment.frequencyHz = *frequencyHz; std::cout << "Frequency: " << segment.frequencyHz << std::endl; } else { std::cerr << "Missing or Invalid Frequency!" << std::endl; return USAGE; } if (auto amplitude = args.pop<decltype(segment.amplitude)>(); amplitude && *amplitude >= 0 && *amplitude <= 1.0) { segment.amplitude = *amplitude; std::cout << "Amplitude: " << segment.amplitude << std::endl; } else { std::cerr << "Missing or Invalid Amplitude!" << std::endl; return USAGE; } mCompositePwle.pwlePrimitives.emplace_back(std::move(segment)); } if (!args.empty()) { std::cerr << "Unexpected Arguments!" << std::endl; return USAGE; } return OK; } Status doMain(Args&& /*args*/) override { auto hal = getHal<aidl::IVibrator>(); if (!hal) { return UNAVAILABLE; } ABinderProcess_setThreadPoolMaxThreadCount(1); ABinderProcess_startThreadPool(); std::shared_ptr<VibratorCallback> callback; if (mBlocking) { callback = ndk::SharedRefBase::make<VibratorCallback>(); } auto status = hal->call(&aidl::IVibrator::composePwleV2, mCompositePwle, callback); if (status.isOk() && callback) { callback->waitForComplete(); } std::cout << "Status: " << status.getDescription() << std::endl; return status.isOk() ? OK : ERROR; } bool mBlocking; CompositePwleV2 mCompositePwle; }; static const auto Command = CommandRegistry<CommandVibrator>::Register<CommandComposePwleV2>("composePwleV2"); } // namespace vibrator } // namespace idlcli } // namespace android
cmds/idlcli/vibrator/CommandGetFrequencyToOutputAccelerationMap.cpp 0 → 100644 +78 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "utils.h" #include "vibrator.h" namespace android { namespace idlcli { class CommandVibrator; namespace vibrator { using aidl::FrequencyAccelerationMapEntry; class CommandGetFrequencyToOutputAccelerationMap : public Command { std::string getDescription() const override { return "Retrieves vibrator frequency to output acceleration map."; } std::string getUsageSummary() const override { return ""; } UsageDetails getUsageDetails() const override { UsageDetails details{}; return details; } Status doArgs(Args& args) override { if (!args.empty()) { std::cerr << "Unexpected Arguments!" << std::endl; return USAGE; } return OK; } Status doMain(Args&& /*args*/) override { std::string statusStr; std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap; Status ret; if (auto hal = getHal<aidl::IVibrator>()) { auto status = hal->call(&aidl::IVibrator::getFrequencyToOutputAccelerationMap, &frequencyToOutputAccelerationMap); statusStr = status.getDescription(); ret = (status.isOk() ? OK : ERROR); } else { return UNAVAILABLE; } std::cout << "Status: " << statusStr << std::endl; std::cout << "Frequency to Output Amplitude Map: " << std::endl; for (auto& entry : frequencyToOutputAccelerationMap) { std::cout << entry.frequencyHz << " " << entry.maxOutputAccelerationGs << std::endl; } return ret; } }; static const auto Command = CommandRegistry<CommandVibrator>::Register<CommandGetFrequencyToOutputAccelerationMap>( "getFrequencyToOutputAccelerationMap"); } // namespace vibrator } // namespace idlcli } // namespace android
cmds/idlcli/vibrator/CommandGetPwleV2CompositionSizeMax.cpp 0 → 100644 +72 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "utils.h" #include "vibrator.h" namespace android { namespace idlcli { class CommandVibrator; namespace vibrator { class CommandGetPwleV2CompositionSizeMax : public Command { std::string getDescription() const override { return "Retrieves vibrator PwleV2 max composition size."; } std::string getUsageSummary() const override { return ""; } UsageDetails getUsageDetails() const override { UsageDetails details{}; return details; } Status doArgs(Args& args) override { if (!args.empty()) { std::cerr << "Unexpected Arguments!" << std::endl; return USAGE; } return OK; } Status doMain(Args&& /*args*/) override { std::string statusStr; int32_t maxSize; Status ret; if (auto hal = getHal<aidl::IVibrator>()) { auto status = hal->call(&aidl::IVibrator::getPwleV2CompositionSizeMax, &maxSize); statusStr = status.getDescription(); ret = status.isOk() ? OK : ERROR; } else { return UNAVAILABLE; } std::cout << "Status: " << statusStr << std::endl; std::cout << "Max Size: " << maxSize << std::endl; return ret; } }; static const auto Command = CommandRegistry<CommandVibrator>::Register<CommandGetPwleV2CompositionSizeMax>( "getPwleV2CompositionSizeMax"); } // namespace vibrator } // namespace idlcli } // namespace android
cmds/idlcli/vibrator/CommandGetPwleV2PrimitiveDurationMaxMillis.cpp 0 → 100644 +73 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "utils.h" #include "vibrator.h" namespace android { namespace idlcli { class CommandVibrator; namespace vibrator { class CommandGetPwleV2PrimitiveDurationMaxMillis : public Command { std::string getDescription() const override { return "Retrieves vibrator PwleV2 max primitive duration in milliseconds."; } std::string getUsageSummary() const override { return ""; } UsageDetails getUsageDetails() const override { UsageDetails details{}; return details; } Status doArgs(Args& args) override { if (!args.empty()) { std::cerr << "Unexpected Arguments!" << std::endl; return USAGE; } return OK; } Status doMain(Args&& /*args*/) override { std::string statusStr; int32_t maxDurationMs; Status ret; if (auto hal = getHal<aidl::IVibrator>()) { auto status = hal->call(&aidl::IVibrator::getPwleV2PrimitiveDurationMaxMillis, &maxDurationMs); statusStr = status.getDescription(); ret = status.isOk() ? OK : ERROR; } else { return UNAVAILABLE; } std::cout << "Status: " << statusStr << std::endl; std::cout << "Primitive duration max: " << maxDurationMs << " ms" << std::endl; return ret; } }; static const auto Command = CommandRegistry<CommandVibrator>::Register<CommandGetPwleV2PrimitiveDurationMaxMillis>( "getPwleV2PrimitiveDurationMaxMillis"); } // namespace vibrator } // namespace idlcli } // namespace android