| Vince Leung | 1c0eaa9 | 2021-02-02 06:47:13 +0000 | [diff] [blame] | 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 CommandGetResonantFrequency : public Command { | 
 | 27 |     std::string getDescription() const override { | 
 | 28 |         return "Retrieves vibrator resonant frequency in Hz."; | 
 | 29 |     } | 
 | 30 |  | 
 | 31 |     std::string getUsageSummary() const override { return ""; } | 
 | 32 |  | 
 | 33 |     UsageDetails getUsageDetails() const override { | 
 | 34 |         UsageDetails details{}; | 
 | 35 |         return details; | 
 | 36 |     } | 
 | 37 |  | 
 | 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 |  | 
 | 46 |     Status doMain(Args && /*args*/) override { | 
 | 47 |         std::string statusStr; | 
 | 48 |         float resonantFrequencyHz; | 
 | 49 |         Status ret; | 
 | 50 |  | 
 | 51 |         if (auto hal = getHal<aidl::IVibrator>()) { | 
 | 52 |             auto status = hal->call(&aidl::IVibrator::getResonantFrequency, &resonantFrequencyHz); | 
 | 53 |             statusStr = status.getDescription(); | 
 | 54 |             ret = status.isOk() ? OK : ERROR; | 
 | 55 |         } else { | 
 | 56 |             return UNAVAILABLE; | 
 | 57 |         } | 
 | 58 |  | 
 | 59 |         std::cout << "Status: " << statusStr << std::endl; | 
 | 60 |         std::cout << "Resonant Frequency: " << resonantFrequencyHz << " Hz" << std::endl; | 
 | 61 |  | 
 | 62 |         return ret; | 
 | 63 |     } | 
 | 64 | }; | 
 | 65 |  | 
 | 66 | static const auto Command = CommandRegistry<CommandVibrator>::Register<CommandGetResonantFrequency>( | 
 | 67 |     "getResonantFrequency"); | 
 | 68 |  | 
 | 69 | }  // namespace vibrator | 
 | 70 | }  // namespace idlcli | 
 | 71 | }  // namespace android |