Added magnetometer support
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/616f7525 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/616f7525 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/616f7525 Branch: refs/heads/develop Commit: 616f7525c853fd30b98fac7bc46b4ff89406bb69 Parents: 5ca8eb3 Author: microbuilder <[email protected]> Authored: Thu Dec 29 02:23:47 2016 +0100 Committer: microbuilder <[email protected]> Committed: Thu Dec 29 02:23:47 2016 +0100 ---------------------------------------------------------------------- hw/sensor/include/sensor/mag.h | 49 +++++++++++++++++++++++++++++++++++++ hw/sensor/src/sensor_shell.c | 16 ++++++++++++ 2 files changed, 65 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/616f7525/hw/sensor/include/sensor/mag.h ---------------------------------------------------------------------- diff --git a/hw/sensor/include/sensor/mag.h b/hw/sensor/include/sensor/mag.h new file mode 100644 index 0000000..8387568 --- /dev/null +++ b/hw/sensor/include/sensor/mag.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#ifndef __SENSOR_MAG_H__ +#define __SENSOR_MAG_H__ + +#include "os/os.h" +#include "os/os_dev.h" +#include "sensor/sensor.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Data representing a singular read from a magnetometer. + * All values are in uTesla + */ +struct sensor_mag_data { + float smd_x; + float smd_y; + float smd_z; +} __attribute__((packed)); + +/** + * Magnetometer data is unused for this field. + */ +#define SENSOR_MAG_DATA_UNUSED (-1) + +#ifdef __cplusplus +} +#endif + +#endif /* __SENSOR_MAG_H__ */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/616f7525/hw/sensor/src/sensor_shell.c ---------------------------------------------------------------------- diff --git a/hw/sensor/src/sensor_shell.c b/hw/sensor/src/sensor_shell.c index dfd926d..1cf9613 100644 --- a/hw/sensor/src/sensor_shell.c +++ b/hw/sensor/src/sensor_shell.c @@ -31,6 +31,7 @@ #include "sensor/sensor.h" #include "sensor/accel.h" +#include "sensor/mag.h" #include "console/console.h" #include "shell/shell.h" @@ -85,6 +86,7 @@ sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data) { struct sensor_shell_read_ctx *ctx; struct sensor_accel_data *sad; + struct sensor_mag_data *smd; ctx = (struct sensor_shell_read_ctx *) arg; @@ -104,6 +106,20 @@ sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data) console_printf("\n"); } + if (ctx->type == SENSOR_TYPE_MAGNETIC_FIELD) { + smd = (struct sensor_mag_data *) data; + if (smd->smd_x != SENSOR_MAG_DATA_UNUSED) { + console_printf("x = %i, ", (int)smd->smd_x); + } + if (smd->smd_y != SENSOR_MAG_DATA_UNUSED) { + console_printf("y = %i, ", (int)smd->smd_y); + } + if (smd->smd_z != SENSOR_MAG_DATA_UNUSED) { + console_printf("z = %i", (int)smd->smd_z); + } + console_printf("\n"); + } + return (0); }
