blob: bb7f9f284afd00118560f6b02b9ebadf45b26959 [file] [log] [blame]
Harpreet \"Eli\" Sanghaeb8505c2020-04-10 12:40:23 +09001/*
2 * Copyright (C) 2020 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::Effect;
27using aidl::EffectStrength;
28
29class CommandAlwaysOnEnable : public Command {
30 std::string getDescription() const override {
31 return "Arm always-on haptic source with an effect.";
32 }
33
34 std::string getUsageSummary() const override { return "<id> <effect> <strength>"; }
35
36 UsageDetails getUsageDetails() const override {
37 UsageDetails details{
38 {"<id>", {"Source ID (device-specific)."}},
39 {"<effect>", {"Effect ID."}},
40 {"<strength>", {"0-2."}},
41 };
42 return details;
43 }
44
45 Status doArgs(Args &args) override {
46 if (auto id = args.pop<decltype(mId)>()) {
47 mId = *id;
48 std::cout << "Source ID: " << mId << std::endl;
49 } else {
50 std::cerr << "Missing or Invalid Source ID!" << std::endl;
51 return USAGE;
52 }
53 if (auto effect = args.pop<decltype(mEffect)>()) {
54 mEffect = *effect;
55 std::cout << "Effect: " << toString(mEffect) << std::endl;
56 } else {
57 std::cerr << "Missing or Invalid Effect!" << std::endl;
58 return USAGE;
59 }
60 if (auto strength = args.pop<decltype(mStrength)>()) {
61 mStrength = *strength;
62 std::cout << "Strength: " << toString(mStrength) << std::endl;
63 } else {
64 std::cerr << "Missing or Invalid Strength!" << std::endl;
65 return USAGE;
66 }
67 if (!args.empty()) {
68 std::cerr << "Unexpected Arguments!" << std::endl;
69 return USAGE;
70 }
71 return OK;
72 }
73
74 Status doMain(Args && /*args*/) override {
75 std::string statusStr;
76 Status ret;
77
78 if (auto hal = getHal<aidl::IVibrator>()) {
79 auto status = hal->call(&aidl::IVibrator::alwaysOnEnable, mId, mEffect, mStrength);
80
81 statusStr = status.getDescription();
82 ret = status.isOk() ? OK : ERROR;
83 } else {
84 return UNAVAILABLE;
85 }
86
87 std::cout << "Status: " << statusStr << std::endl;
88
89 return ret;
90 }
91
92 int32_t mId;
93 Effect mEffect;
94 EffectStrength mStrength;
95};
96
97static const auto Command =
98 CommandRegistry<CommandVibrator>::Register<CommandAlwaysOnEnable>("alwaysOnEnable");
99
100} // namespace vibrator
101} // namespace idlcli
102} // namespace android