Pierre-Hugues Husson | cafcef5 | 2018-09-28 20:15:45 +0200 | [diff] [blame] | 1 | #include <iostream> |
| 2 | #include <android/hardware/light/2.0/ILight.h> |
| 3 | #include <android/hardware/light/2.0/types.h> |
| 4 | |
| 5 | using ::android::hardware::light::V2_0::ILight; |
| 6 | using ::android::sp; |
| 7 | |
| 8 | int main(int argc, char **argv) { |
| 9 | auto svc = ILight::getService(); |
| 10 | svc->getSupportedTypes([](auto types) { |
| 11 | for(const auto& type: types) { |
| 12 | std::cout << "Got type " << toString(type) << std::endl; |
| 13 | } |
| 14 | }); |
| 15 | if(argc <= 1) return 0; |
| 16 | if(argc != 3 && argc != 6) return 1; |
| 17 | |
| 18 | std::string typeArg(argv[1]); |
| 19 | android::hardware::light::V2_0::Type type; |
| 20 | if(typeArg == "BACKLIGHT") |
| 21 | type = android::hardware::light::V2_0::Type::BACKLIGHT; |
| 22 | if(typeArg == "KEYBOARD") |
| 23 | type = android::hardware::light::V2_0::Type::KEYBOARD; |
| 24 | if(typeArg == "BUTTONS") |
| 25 | type = android::hardware::light::V2_0::Type::BUTTONS; |
| 26 | if(typeArg == "BATTERY") |
| 27 | type = android::hardware::light::V2_0::Type::BATTERY; |
| 28 | if(typeArg == "NOTIFICATIONS") |
| 29 | type = android::hardware::light::V2_0::Type::NOTIFICATIONS; |
| 30 | if(typeArg == "ATTENTION") |
| 31 | type = android::hardware::light::V2_0::Type::ATTENTION; |
| 32 | if(typeArg == "BLUETOOTH") |
| 33 | type = android::hardware::light::V2_0::Type::BLUETOOTH; |
| 34 | if(typeArg == "WIFI") |
| 35 | type = android::hardware::light::V2_0::Type::WIFI; |
| 36 | std::cout << "Set request type " << toString(type) << std::endl; |
| 37 | |
| 38 | android::hardware::light::V2_0::LightState state; |
| 39 | state.color = (uint32_t)strtoll(argv[2], NULL, 16); |
| 40 | state.flashMode = android::hardware::light::V2_0::Flash::NONE; |
| 41 | state.brightnessMode = android::hardware::light::V2_0::Brightness::USER; |
| 42 | |
| 43 | if(argc == 6) { |
| 44 | std::string flashArg(argv[3]); |
| 45 | if(flashArg == "NONE") |
| 46 | state.flashMode = android::hardware::light::V2_0::Flash::NONE; |
| 47 | if(flashArg == "TIMED") |
| 48 | state.flashMode = android::hardware::light::V2_0::Flash::TIMED; |
| 49 | if(flashArg == "HARDWARE") |
| 50 | state.flashMode = android::hardware::light::V2_0::Flash::HARDWARE; |
| 51 | |
| 52 | state.flashOnMs = atoi(argv[4]); |
| 53 | state.flashOffMs = atoi(argv[5]); |
| 54 | } |
| 55 | std::cout << "Set flash type to " << toString(state.flashMode) << std::endl; |
| 56 | |
| 57 | auto ret = svc->setLight(type, state); |
| 58 | std::cout << "Set light returned " << toString(ret) << std::endl; |
| 59 | } |