summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Beare <bruce.j.beare@intel.com>2016-01-21 19:27:16 -0800
committerBruce Beare <bruce.j.beare@intel.com>2016-01-27 13:01:35 -0800
commitb5ef2166532e4436fefb8256cc088bac2dc4df82 (patch)
tree8281f163768e18f33b0ffb8b066a594f4923cb9d
parentdb39788be42272576056e36b1335be947c3b9d06 (diff)
downloadintel-b5ef2166532e4436fefb8256cc088bac2dc4df82.tar.gz
mraa based ledflasher application
BUG=none Signed-off-by: Bruce Beare <bruce.j.beare@intel.com> Change-Id: I0c14b4ad8c1d5afb401f63f94073bad8e5f24480
-rw-r--r--peripheral/examples/mraa/gpio_output/Android.mk14
-rw-r--r--peripheral/examples/mraa/gpio_output/ledflasher_mraa.cpp57
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;
+}