diff options
author | Bruce Beare <bruce.j.beare@intel.com> | 2016-02-03 00:08:54 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-02-03 00:08:54 +0000 |
commit | e499ad11c72eaef3367303155216f7d52e389af8 (patch) | |
tree | 826708774ea919516b8ba201ed217fba3d537de7 | |
parent | f37fef5dc4197e0ab4691890f92ac10f921d3c5e (diff) | |
parent | b5ef2166532e4436fefb8256cc088bac2dc4df82 (diff) | |
download | intel-e499ad11c72eaef3367303155216f7d52e389af8.tar.gz |
mraa based ledflasher application
am: b5ef216653
* commit 'b5ef2166532e4436fefb8256cc088bac2dc4df82':
mraa based ledflasher application
-rw-r--r-- | peripheral/examples/mraa/gpio_output/Android.mk | 14 | ||||
-rw-r--r-- | peripheral/examples/mraa/gpio_output/ledflasher_mraa.cpp | 57 |
2 files changed, 71 insertions, 0 deletions
diff --git a/peripheral/examples/mraa/gpio_output/Android.mk b/peripheral/examples/mraa/gpio_output/Android.mk index a8d50a5..3733403 100644 --- a/peripheral/examples/mraa/gpio_output/Android.mk +++ b/peripheral/examples/mraa/gpio_output/Android.mk @@ -26,3 +26,17 @@ LOCAL_MODULE := example-gpio-output-mraa LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := OutputGPIO.cpp include $(BUILD_EXECUTABLE) + + +# MRAA based ledflasher example application +include $(CLEAR_VARS) +LOCAL_CPPFLAGS:= -Wno-unused-parameter -fexceptions +LOCAL_CFLAGS += -DLOG_TAG=\"ledflasher-mraa\" -Wno-unused-parameter +LOCAL_SHARED_LIBRARIES := libcutils libupm libmraa + +LOCAL_MODULE := ledflasher-mraa +LOCAL_MODULE_TAGS := optional +LOCAL_SRC_FILES := ledflasher_mraa.cpp +include $(BUILD_EXECUTABLE) + + diff --git a/peripheral/examples/mraa/gpio_output/ledflasher_mraa.cpp b/peripheral/examples/mraa/gpio_output/ledflasher_mraa.cpp new file mode 100644 index 0000000..39005f6 --- /dev/null +++ b/peripheral/examples/mraa/gpio_output/ledflasher_mraa.cpp @@ -0,0 +1,57 @@ +/* + * 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. + */ + +/* + * This is an example to flash a number of LED lights in a pattern. + * Connect your LEDs to appropriate GPIOs (as many as you like) + * then modify gpio[] and m_gpio[] to specify the pins. + */ +#include <unistd.h> +#include <stdio.h> + +#include <mraa.h> + +int main(int argc, char* argv[]) { + const unsigned gpio[] = {0, 1, 2}; + const int gpio_count = sizeof(gpio)/sizeof(*gpio); + mraa_gpio_context m_gpio[] = {NULL, NULL, NULL}; + + mraa_init(); + for (int i = 0; i < gpio_count; i++) { + m_gpio[i] = mraa_gpio_init(gpio[i]); + if (!m_gpio[i]) { + fprintf(stderr, "Unable to initialize GPIO %d, invalid pin number?\n", + gpio[i]); + return 1; + } + mraa_gpio_dir(m_gpio[i], MRAA_GPIO_OUT); + } + + for (int iterations = 0; iterations < 3; iterations++) { + for (int i = 0; i < gpio_count; i++) { + mraa_gpio_write(m_gpio[i], 1); + sleep(1); + } + for (int i = gpio_count-1; i >= 0; i--) { + mraa_gpio_write(m_gpio[i], 0); + sleep(1); + } + } + + for (int i = 0; i < gpio_count; i++) + mraa_gpio_close(m_gpio[i]); + return 0; +} |