diff --git a/cmds/Android.bp b/cmds/Android.bp new file mode 100644 index 0000000..7daf55e --- /dev/null +++ b/cmds/Android.bp @@ -0,0 +1,12 @@ +cc_binary { + name: "aguiledbeltctl", + system_ext_specific: true, + srcs: [ + "aguiledbeltctl.cpp", + ], + shared_libs: [ + "vendor.mediatek.hardware.aguiledbelt@1.0", + "libutils", + "libhidlbase", + ], +} diff --git a/cmds/aguiledbeltctl.cpp b/cmds/aguiledbeltctl.cpp new file mode 100644 index 0000000..9d8b031 --- /dev/null +++ b/cmds/aguiledbeltctl.cpp @@ -0,0 +1,62 @@ +// vim: expandtab tabstop=4 shiftwidth=4 +#include +#include + +#include +#include + +using namespace ::vendor::mediatek::hardware::aguiledbelt::V1_0; + +void print_usage() { + std::cerr << "Usage: aguiledbeltctl " << std::endl; + std::cerr << " aguiledbeltctl clear" << std::endl; + std::cerr << std::endl; + std::cerr << " should be a binary string where each bit (0 or 1) corresponds to the ON state of each physical light belt" << std::endl; +} + +int main(int argc, char **argv) { + auto service = IAguiLedBeltLight::getService(); + + if (argc <= 1) { + print_usage(); + return -1; + } + + std::string arg1(argv[1]); + + if (arg1 == "clear") { + service->setLedBeltAlwaysOnState(0, 0, 0, false); + return 0; + } + + uint32_t light_id = std::stoi(std::string(argv[1]), nullptr, 2); + + if (light_id > 31) { + std::cerr << "First argument should be a bit field with each bit corresponding to one physical light belt" << std::endl; + return 0; + } + + if (argc < 6) { + print_usage(); + return -1; + } + + uint32_t r = std::stoi(std::string(argv[2])); + uint32_t g = std::stoi(std::string(argv[3])); + uint32_t b = std::stoi(std::string(argv[4])); + + if (r > 255 || g > 255 || b > 255) { + std::cerr << "Color channels must be bewteen 0 and 255" << std::endl; + return -1; + } + + uint32_t brightness = std::stoi(std::string(argv[5])); + + if (brightness > 100) { + std::cerr << "Brightness must be between 0 and 100" << std::endl; + return -1; + } + + service->setLedBeltAlwaysOnState(light_id, (r << 16) + (g << 8) + b, brightness, false); + return 0; +} diff --git a/device.mk b/device.mk index f531520..75cfc33 100644 --- a/device.mk +++ b/device.mk @@ -78,3 +78,7 @@ ifeq (,$(filter eng,$(TARGET_BUILD_VARIANT))) PRODUCT_SYSTEM_EXT_PROPERTIES += \ ro.adb.secure=1 endif + +# Custom commands +PRODUCT_PACKAGES += \ + aguiledbeltctl