From 05e6d4b94fed35ecabe52bc37f12a0cb8d57f49d Mon Sep 17 00:00:00 2001 From: Pierre-Hugues Husson Date: Mon, 10 Jun 2019 23:54:23 +0200 Subject: [PATCH] Add oneplus-motor command --- cmds/Android.bp | 12 ++++++++++++ cmds/oneplus-motor.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 cmds/oneplus-motor.cpp diff --git a/cmds/Android.bp b/cmds/Android.bp index 952cbfb..333bca8 100644 --- a/cmds/Android.bp +++ b/cmds/Android.bp @@ -111,3 +111,15 @@ cc_binary { "libhidlbase", ], } + +cc_binary { + name: "oneplus-motor", + srcs: [ + "oneplus-motor.cpp", + ], + shared_libs: [ + "vendor.oneplus.hardware.motorcontrol@1.0", + "libutils", + "libhidlbase", + ], +} diff --git a/cmds/oneplus-motor.cpp b/cmds/oneplus-motor.cpp new file mode 100644 index 0000000..f1906c1 --- /dev/null +++ b/cmds/oneplus-motor.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +using ::vendor::oneplus::hardware::motorcontrol::V1_0::IOPMotorControl; +using ::android::sp; + +int main(int argc, char **argv) { + auto svc = IOPMotorControl::getService(); + if(svc == nullptr) { + std::cerr << "Failed getting IMotor" << std::endl; + return -1; + } + if(argc<2) { + std::cerr << "Usage: " << argv[0] << " " << std::endl; + return -1; + } + std::string cmd(argv[1]); + if(cmd == "read") { + int ret = svc->readMotorData(1, 16); + std::cout << "Read motor data 1/16 returned " << ret << std::endl; + return 0; + } else if(cmd == "down") { + int ret = svc->writeMotorData(1, 0, 1); + std::cout << "Down motor control data 1/0/1 returned " << ret << std::endl; + return 0; + } else if(cmd == "up") { + int ret = svc->writeMotorData(1, 1, 1); + std::cout << "Down motor control data 1/1/1 returned " << ret << std::endl; + return 0; + } +}