This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push: new 3927b3323 examples/bmi160:bmi160 add urob mode example. 3927b3323 is described below commit 3927b33237e35238934633fe4f0415e3f04fdcfc Author: likun17 <liku...@xiaomi.com> AuthorDate: Fri Jun 14 15:32:13 2024 +0800 examples/bmi160:bmi160 add urob mode example. Signed-off-by: likun17 <liku...@xiaomi.com> --- examples/bmi160/CMakeLists.txt | 7 ++- examples/bmi160/Kconfig | 7 +++ examples/bmi160/Makefile | 4 ++ examples/bmi160/sixaxis_uorb_main.c | 91 +++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 1 deletion(-) diff --git a/examples/bmi160/CMakeLists.txt b/examples/bmi160/CMakeLists.txt index c8aec0b60..18e1d01f9 100644 --- a/examples/bmi160/CMakeLists.txt +++ b/examples/bmi160/CMakeLists.txt @@ -19,6 +19,11 @@ # ############################################################################## if(CONFIG_EXAMPLES_SIXAXIS) + if(CONFIG_EXAMPLES_SIXAXIS_UORB) + set(CSRC sixaxis_main.c) + else() + set(CSRC sixaxis_uorb_main.c) + endif() nuttx_add_application( NAME ${CONFIG_EXAMPLES_SIXAXIS_PROGNAME} @@ -27,5 +32,5 @@ if(CONFIG_EXAMPLES_SIXAXIS) STACKSIZE ${CONFIG_EXAMPLES_SIXAXIS_STACKSIZE} SRCS - sixaxis_main.c) + ${CSRC}) endif() diff --git a/examples/bmi160/Kconfig b/examples/bmi160/Kconfig index c84b3afda..a850a5887 100644 --- a/examples/bmi160/Kconfig +++ b/examples/bmi160/Kconfig @@ -11,6 +11,13 @@ config EXAMPLES_SIXAXIS if EXAMPLES_SIXAXIS +config EXAMPLES_SIXAXIS_UORB + bool "BMI160 sensor uorb example" + default n + ---help--- + Enables Work with the UORB or Character Device interface. + If not set, the Character Device is used by default. + config EXAMPLES_SIXAXIS_PROGNAME string "Program name" default "sixaxis" diff --git a/examples/bmi160/Makefile b/examples/bmi160/Makefile index 56d39eb19..80d98ae2f 100644 --- a/examples/bmi160/Makefile +++ b/examples/bmi160/Makefile @@ -28,6 +28,10 @@ STACKSIZE = $(CONFIG_EXAMPLES_SIXAXIS_STACKSIZE) # sixaxis Example +ifeq ($(CONFIG_EXAMPLES_SIXAXIS_UORB),) MAINSRC = sixaxis_main.c +else +MAINSRC = sixaxis_uorb_main.c +endif include $(APPDIR)/Application.mk diff --git a/examples/bmi160/sixaxis_uorb_main.c b/examples/bmi160/sixaxis_uorb_main.c new file mode 100644 index 000000000..b07249ba5 --- /dev/null +++ b/examples/bmi160/sixaxis_uorb_main.c @@ -0,0 +1,91 @@ +/**************************************************************************** + * apps/examples/bmi160/sixaxis_uorb_main.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <poll.h> +#include <errno.h> +#include <sensor/accel.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define ACC_TIMEOUT 1000 +#define READ_TIMES 100 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * sixaxis_main + ****************************************************************************/ + +int main(int argc, FAR char *argv[]) +{ + FAR const struct orb_metadata *meta; + struct sensor_accel accel_data; + struct pollfd fds; + int ret = OK; + int fd; + int i; + + meta = ORB_ID(sensor_accel_uncal); + fd = orb_subscribe_multi(meta, 0); + if (fd < 0) + { + printf("sensor accel subscribe error! return:%d\n", fd); + return fd; + } + + fds.fd = fd; + fds.events = POLLIN; + + for (i = 0; i < READ_TIMES; i++) + { + if (poll(&fds, 1, ACC_TIMEOUT) > 0) + { + if (fds.revents & POLLIN) + { + ret = orb_copy(meta, fd, &accel_data); +#ifdef CONFIG_DEBUG_UORB + if (ret == OK && meta->o_format != NULL) + { + orb_info(meta->o_format, meta->o_name, &accel_data); + } +#endif + } + } + else if (errno != EINTR) + { + printf("Waited for %d milliseconds without a message. " + "Giving up. err:%d", ACC_TIMEOUT, errno); + break; + } + } + + orb_unsubscribe(fd); + printf("sensor accel read examples exit.\n"); + + return ret; +}