blob: 2edd0caf2ec076b5dcad6ae52390c62df6d53410 [file] [log] [blame]
Nathan Kulczakd7cdab22024-10-09 07:58:14 +00001/*
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
19namespace android {
20namespace idlcli {
21
22class CommandVibrator;
23
24namespace vibrator {
25
26using aidl::FrequencyAccelerationMapEntry;
27
28class CommandGetFrequencyToOutputAccelerationMap : public Command {
29 std::string getDescription() const override {
30 return "Retrieves vibrator frequency to output acceleration map.";
31 }
32
33 std::string getUsageSummary() const override { return ""; }
34
35 UsageDetails getUsageDetails() const override {
36 UsageDetails details{};
37 return details;
38 }
39
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
48 Status doMain(Args&& /*args*/) override {
49 std::string statusStr;
50 std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap;
51 Status ret;
52
53 if (auto hal = getHal<aidl::IVibrator>()) {
54 auto status = hal->call(&aidl::IVibrator::getFrequencyToOutputAccelerationMap,
55 &frequencyToOutputAccelerationMap);
56 statusStr = status.getDescription();
57 ret = (status.isOk() ? OK : ERROR);
58 } else {
59 return UNAVAILABLE;
60 }
61
62 std::cout << "Status: " << statusStr << std::endl;
63 std::cout << "Frequency to Output Amplitude Map: " << std::endl;
64 for (auto& entry : frequencyToOutputAccelerationMap) {
65 std::cout << entry.frequencyHz << " " << entry.maxOutputAccelerationGs << std::endl;
66 }
67
68 return ret;
69 }
70};
71
72static const auto Command =
73 CommandRegistry<CommandVibrator>::Register<CommandGetFrequencyToOutputAccelerationMap>(
74 "getFrequencyToOutputAccelerationMap");
75
76} // namespace vibrator
77} // namespace idlcli
78} // namespace android