• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 class CommandGetBandwidthAmplitudeMap : public Command {
getDescription() const27     std::string getDescription() const override {
28         return "Retrieves vibrator bandwidth amplitude map.";
29     }
30 
getUsageSummary() const31     std::string getUsageSummary() const override { return ""; }
32 
getUsageDetails() const33     UsageDetails getUsageDetails() const override {
34         UsageDetails details{};
35         return details;
36     }
37 
doArgs(Args & args)38     Status doArgs(Args &args) override {
39         if (!args.empty()) {
40             std::cerr << "Unexpected Arguments!" << std::endl;
41             return USAGE;
42         }
43         return OK;
44     }
45 
doMain(Args &&)46     Status doMain(Args && /*args*/) override {
47         auto hal = getHal();
48 
49         if (!hal) {
50             return UNAVAILABLE;
51         }
52 
53         std::vector<float> bandwidthAmplitude;
54         float frequencyMinimumHz;
55         float frequencyResolutionHz;
56 
57         auto status = hal->getBandwidthAmplitudeMap(&bandwidthAmplitude);
58 
59         if (!status.isOk()) {
60             std::cout << "Status: " << status.getDescription() << std::endl;
61             return ERROR;
62         }
63 
64         status = hal->getFrequencyMinimum(&frequencyMinimumHz);
65 
66         if (!status.isOk()) {
67             std::cout << "Status: " << status.getDescription() << std::endl;
68             return ERROR;
69         }
70 
71         status = hal->getFrequencyResolution(&frequencyResolutionHz);
72 
73         if (!status.isOk()) {
74             std::cout << "Status: " << status.getDescription() << std::endl;
75             return ERROR;
76         }
77 
78         std::cout << "Status: " << status.getDescription() << std::endl;
79         std::cout << "Bandwidth Amplitude Map: " << std::endl;
80         float frequency = frequencyMinimumHz;
81         for (auto &e : bandwidthAmplitude) {
82             std::cout << frequency << ":" << e << std::endl;
83             frequency += frequencyResolutionHz;
84         }
85 
86         return OK;
87     }
88 };
89 
90 static const auto Command =
91     CommandRegistry<CommandVibrator>::Register<CommandGetBandwidthAmplitudeMap>(
92         "getBandwidthAmplitudeMap");
93 
94 }  // namespace vibrator
95 }  // namespace idlcli
96 }  // namespace android
97