1 /* 2 * Copyright (C) 2024 The Android Open Source Project * 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 #include "utils.h" 17 #include "vibrator.h" 18 19 namespace android { 20 namespace idlcli { 21 22 class CommandVibrator; 23 24 namespace vibrator { 25 26 using aidl::FrequencyAccelerationMapEntry; 27 28 class CommandGetFrequencyToOutputAccelerationMap : public Command { getDescription() const29 std::string getDescription() const override { 30 return "Retrieves vibrator frequency to output acceleration map."; 31 } 32 getUsageSummary() const33 std::string getUsageSummary() const override { return ""; } 34 getUsageDetails() const35 UsageDetails getUsageDetails() const override { 36 UsageDetails details{}; 37 return details; 38 } 39 doArgs(Args & args)40 Status doArgs(Args& args) override { 41 if (!args.empty()) { 42 std::cerr << "Unexpected Arguments!" << std::endl; 43 return USAGE; 44 } 45 return OK; 46 } 47 doMain(Args &&)48 Status doMain(Args&& /*args*/) override { 49 auto hal = getHal(); 50 51 if (!hal) { 52 return UNAVAILABLE; 53 } 54 55 std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap; 56 auto status = hal->getFrequencyToOutputAccelerationMap(&frequencyToOutputAccelerationMap); 57 58 std::cout << "Status: " << status.getDescription() << std::endl; 59 std::cout << "Frequency to Output Amplitude Map: " << std::endl; 60 for (auto& entry : frequencyToOutputAccelerationMap) { 61 std::cout << entry.frequencyHz << " " << entry.maxOutputAccelerationGs << std::endl; 62 } 63 64 return status.isOk() ? OK : ERROR; 65 } 66 }; 67 68 static const auto Command = 69 CommandRegistry<CommandVibrator>::Register<CommandGetFrequencyToOutputAccelerationMap>( 70 "getFrequencyToOutputAccelerationMap"); 71 72 } // namespace vibrator 73 } // namespace idlcli 74 } // namespace android 75