diff options
author | Ralph Nathan <ralphnathan@google.com> | 2015-12-03 14:26:06 -0800 |
---|---|---|
committer | Ralph Nathan <ralphnathan@google.com> | 2015-12-03 14:26:06 -0800 |
commit | 485f161d875f1d7f7b3e87591c3f797410577990 (patch) | |
tree | cfd65e5811f334d9a768b798632daccf40a32790 | |
parent | 9a13a5ea03f17f73f556f3ed13c9469e60aa9c46 (diff) | |
download | common-485f161d875f1d7f7b3e87591c3f797410577990.tar.gz |
Move lights example from device/generic/brillo.
Centralize all the example code for Brillo by moving the lights
example from device/generic/brillo.
BUG=25927954
TEST=lights-hal-example-app builds for dragonboard.
Change-Id: I9e6bb54b8c6955775a9846123a4535b8e645da0e
-rw-r--r-- | lights_example/example-app/Android.mk | 28 | ||||
-rw-r--r-- | lights_example/example-app/README | 8 | ||||
-rw-r--r-- | lights_example/example-app/hal-example-app.cpp | 71 |
3 files changed, 107 insertions, 0 deletions
diff --git a/lights_example/example-app/Android.mk b/lights_example/example-app/Android.mk new file mode 100644 index 0000000..2f7feec --- /dev/null +++ b/lights_example/example-app/Android.mk @@ -0,0 +1,28 @@ +# +# Copyright (C) 2015 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := lights-hal-example-app +LOCAL_MODULE_TAGS := optional +LOCAL_SRC_FILES := hal-example-app.cpp +LOCAL_SHARED_LIBRARIES := \ + libc \ + libhardware \ + +include $(BUILD_EXECUTABLE) diff --git a/lights_example/example-app/README b/lights_example/example-app/README new file mode 100644 index 0000000..a8fc128 --- /dev/null +++ b/lights_example/example-app/README @@ -0,0 +1,8 @@ +This folder contains example code for writing native apps that use Brillo LED +lights. + +Example files: + hal-example-app.cpp: + An example app that uses the lights HAL (defined in + hardware/libhardware/include/lights.h) directly. The app turns on the LED + light used for notifications, and turns it off 3 seconds later. diff --git a/lights_example/example-app/hal-example-app.cpp b/lights_example/example-app/hal-example-app.cpp new file mode 100644 index 0000000..ea5faf4 --- /dev/null +++ b/lights_example/example-app/hal-example-app.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <err.h> +#include <stdio.h> +#include <unistd.h> + +#include <hardware/hardware.h> +#include <hardware/lights.h> + +int main() { + const hw_module_t* module = nullptr; + struct light_device_t* light_device = nullptr; + + int ret = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, &module); + if (ret || !module) { + err(1, "Failed to load %s module", LIGHTS_HARDWARE_MODULE_ID); + } + + ret = module->methods->open( + module, LIGHT_ID_NOTIFICATIONS, + reinterpret_cast<struct hw_device_t**>(&light_device)); + if (ret || !light_device) { + err(1, "Failed to open light device for %s", LIGHT_ID_NOTIFICATIONS); + } + + struct light_state_t state = { + color: 1, + flashMode: LIGHT_FLASH_NONE, + flashOnMS: 0, + flashOffMS: 0, + brightnessMode: 0, + }; + struct light_state_t state_flash = { + color: 1, + flashMode: LIGHT_FLASH_TIMED, + flashOnMS: 50, + flashOffMS: 50, + brightnessMode: 0, + }; + + // On for three seconds. + light_device->set_light(light_device, &state); + sleep(3); + + // Flash for three seconds. + light_device->set_light(light_device, &state_flash); + sleep(3); + + // Off. + state.color = 0; + light_device->set_light(light_device, &state); + + light_device->common.close( + reinterpret_cast<struct hw_device_t*>(light_device)); + + return 0; +} |