diff options
7 files changed, 521 insertions, 0 deletions
diff --git a/cmds/idlcli/Android.bp b/cmds/idlcli/Android.bp index 50c2cd8be2..36dcbca0a3 100644 --- a/cmds/idlcli/Android.bp +++ b/cmds/idlcli/Android.bp @@ -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", @@ -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__"], } diff --git a/cmds/idlcli/vibrator/CommandComposePwleV2.cpp b/cmds/idlcli/vibrator/CommandComposePwleV2.cpp new file mode 100644 index 0000000000..6d3cf84a2e --- /dev/null +++ b/cmds/idlcli/vibrator/CommandComposePwleV2.cpp @@ -0,0 +1,146 @@ +/* + * 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 diff --git a/cmds/idlcli/vibrator/CommandGetFrequencyToOutputAccelerationMap.cpp b/cmds/idlcli/vibrator/CommandGetFrequencyToOutputAccelerationMap.cpp new file mode 100644 index 0000000000..2edd0caf2e --- /dev/null +++ b/cmds/idlcli/vibrator/CommandGetFrequencyToOutputAccelerationMap.cpp @@ -0,0 +1,78 @@ +/* + * 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 diff --git a/cmds/idlcli/vibrator/CommandGetPwleV2CompositionSizeMax.cpp b/cmds/idlcli/vibrator/CommandGetPwleV2CompositionSizeMax.cpp new file mode 100644 index 0000000000..cca072c46f --- /dev/null +++ b/cmds/idlcli/vibrator/CommandGetPwleV2CompositionSizeMax.cpp @@ -0,0 +1,72 @@ +/* + * 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 diff --git a/cmds/idlcli/vibrator/CommandGetPwleV2PrimitiveDurationMaxMillis.cpp b/cmds/idlcli/vibrator/CommandGetPwleV2PrimitiveDurationMaxMillis.cpp new file mode 100644 index 0000000000..dbbfe1a6d4 --- /dev/null +++ b/cmds/idlcli/vibrator/CommandGetPwleV2PrimitiveDurationMaxMillis.cpp @@ -0,0 +1,73 @@ +/* + * 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 diff --git a/cmds/idlcli/vibrator/CommandGetPwleV2PrimitiveDurationMinMillis.cpp b/cmds/idlcli/vibrator/CommandGetPwleV2PrimitiveDurationMinMillis.cpp new file mode 100644 index 0000000000..09225c49c4 --- /dev/null +++ b/cmds/idlcli/vibrator/CommandGetPwleV2PrimitiveDurationMinMillis.cpp @@ -0,0 +1,73 @@ +/* + * 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 CommandGetPwleV2PrimitiveDurationMinMillis : public Command { + std::string getDescription() const override { + return "Retrieves vibrator PwleV2 minimum 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 minDurationMs; + Status ret; + + if (auto hal = getHal<aidl::IVibrator>()) { + auto status = hal->call(&aidl::IVibrator::getPwleV2PrimitiveDurationMinMillis, + &minDurationMs); + statusStr = status.getDescription(); + ret = status.isOk() ? OK : ERROR; + } else { + return UNAVAILABLE; + } + + std::cout << "Status: " << statusStr << std::endl; + std::cout << "Primitive duration min: " << minDurationMs << " ms" << std::endl; + + return ret; + } +}; + +static const auto Command = + CommandRegistry<CommandVibrator>::Register<CommandGetPwleV2PrimitiveDurationMinMillis>( + "getPwleV2PrimitiveDurationMinMillis"); + +} // namespace vibrator +} // namespace idlcli +} // namespace android diff --git a/cmds/idlcli/vibrator/CommandPerformVendorEffect.cpp b/cmds/idlcli/vibrator/CommandPerformVendorEffect.cpp new file mode 100644 index 0000000000..9c25bd2038 --- /dev/null +++ b/cmds/idlcli/vibrator/CommandPerformVendorEffect.cpp @@ -0,0 +1,73 @@ +/* + * 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 <thread> + +#include "utils.h" +#include "vibrator.h" + +using std::chrono::milliseconds; +using std::this_thread::sleep_for; + +namespace android { +namespace idlcli { + +class CommandVibrator; + +namespace vibrator { + +using aidl::VendorEffect; + +class CommandPerformVendorEffect : public Command { + std::string getDescription() const override { return "Perform vendor vibration effect."; } + + std::string getUsageSummary() const override { return "[options] <none>"; } + + UsageDetails getUsageDetails() const override { + UsageDetails details{ + {"-b", {"Block for duration of vibration."}}, + {"<none>", {"No valid input."}}, + }; + 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; + } + } + + return OK; + } + + Status doMain(Args&& /*args*/) override { return UNAVAILABLE; } + + bool mBlocking; + VendorEffect mEffect; +}; + +static const auto Command = CommandRegistry<CommandVibrator>::Register<CommandPerformVendorEffect>( + "performVendorEffect"); + +} // namespace vibrator +} // namespace idlcli +} // namespace android |