From 7e043bb27f4c2f5440d4f4931297081c9cd1967c Mon Sep 17 00:00:00 2001
From: Hauke Petersen <hauke.petersen@fu-berlin.de>
Date: Wed, 5 Nov 2014 19:53:30 +0100
Subject: [PATCH] sys/shell: added commands for iot-lab_M3 sensors

---
 examples/default/Makefile           |  5 ++
 sys/shell/commands/Makefile         |  9 ++++
 sys/shell/commands/sc_isl29020.c    | 71 +++++++++++++++++++++++++
 sys/shell/commands/sc_l3g4200d.c    | 73 ++++++++++++++++++++++++++
 sys/shell/commands/sc_lps331ap.c    | 81 +++++++++++++++++++++++++++++
 sys/shell/commands/shell_commands.c | 27 ++++++++++
 6 files changed, 266 insertions(+)
 create mode 100644 sys/shell/commands/sc_isl29020.c
 create mode 100644 sys/shell/commands/sc_l3g4200d.c
 create mode 100644 sys/shell/commands/sc_lps331ap.c

diff --git a/examples/default/Makefile b/examples/default/Makefile
index fa481bfd49..599984c906 100644
--- a/examples/default/Makefile
+++ b/examples/default/Makefile
@@ -55,5 +55,10 @@ ifneq (,$(filter native,$(BOARD)))
 	USEMODULE += config
 	USEMODULE += random
 endif
+ifneq (,$(filter iot-lab_M3,$(BOARD)))
+	USEMODULE += isl29020
+	USEMODULE += lps331ap
+	USEMODULE += l3g4200d
+endif
 
 include $(RIOTBASE)/Makefile.include
diff --git a/sys/shell/commands/Makefile b/sys/shell/commands/Makefile
index 65cc917318..b78a6a7e34 100644
--- a/sys/shell/commands/Makefile
+++ b/sys/shell/commands/Makefile
@@ -43,5 +43,14 @@ endif
 ifeq ($(CPU),x86)
 	SRC += sc_x86_lspci.c
 endif
+ifneq (,$(filter isl29020,$(USEMODULE)))
+	SRC += sc_isl29020.c
+endif
+ifneq (,$(filter lps331ap,$(USEMODULE)))
+	SRC += sc_lps331ap.c
+endif
+ifneq (,$(filter l3g4200d,$(USEMODULE)))
+	SRC += sc_l3g4200d.c
+endif
 
 include $(RIOTBASE)/Makefile.base
diff --git a/sys/shell/commands/sc_isl29020.c b/sys/shell/commands/sc_isl29020.c
new file mode 100644
index 0000000000..2d76294e10
--- /dev/null
+++ b/sys/shell/commands/sc_isl29020.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2014 Freie Universität Berlin
+ *
+ * This file is subject to the terms and conditions of the GNU Lesser
+ * General Public License v2.1. See the file LICENSE in the top level
+ * directory for more details.
+ */
+
+/**
+ * @ingroup shell_commands
+ * @{
+ *
+ * @file
+ * @brief       Provides shell commands to poll the ISL29020 sensor
+ *
+ * @author      Hauke Petersen <hauke.petersen@fu-berlin.de>
+ *
+ * @}
+ */
+
+#include <stdio.h>
+
+#include "board.h"
+#include "isl29020.h"
+
+#ifdef MODULE_ISL29020
+
+#define MODE        ISL29020_MODE_AMBIENT
+#define RANGE       ISL29020_RANGE_16K
+
+static isl29020_t isl29020_dev;
+
+void _get_isl29020_init_handler(int argc, char **argv)
+{
+    (void)argc;
+    (void)argv;
+
+    int res;
+
+    res = isl29020_init(&isl29020_dev, ISL29020_I2C, ISL29020_ADDR, RANGE, MODE);
+
+    if (res) {
+        puts("Error initializing ISL29020 sensor.");
+    }
+    else {
+        puts("Initialized ISL29020 sensor with default values");
+    }
+}
+
+void _get_isl29020_read_handler(int argc, char **argv)
+{
+    (void)argc;
+    (void)argv;
+
+    int val;
+
+    if (!isl29020_dev.address) {
+        puts("Error: please call `isl29020_init` first!");
+    }
+
+    val = isl29020_read(&isl29020_dev);
+    if (val < 0) {
+        puts("Error reading brightness value from ISL29020.");
+        return;
+    }
+    else {
+        printf("ISL29020: brightness %i LUX\n", val);
+    }
+}
+
+#endif /* MODULE_ISL29020 */
diff --git a/sys/shell/commands/sc_l3g4200d.c b/sys/shell/commands/sc_l3g4200d.c
new file mode 100644
index 0000000000..4ed360ead9
--- /dev/null
+++ b/sys/shell/commands/sc_l3g4200d.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2014 Freie Universität Berlin
+ *
+ * This file is subject to the terms and conditions of the GNU Lesser
+ * General Public License v2.1. See the file LICENSE in the top level
+ * directory for more details.
+ */
+
+/**
+ * @ingroup shell_commands
+ * @{
+ *
+ * @file
+ * @brief       Provides shell commands to poll the L3G4200D sensor
+ *
+ * @author      Hauke Petersen <hauke.petersen@fu-berlin.de>
+ *
+ * @}
+ */
+
+#include <stdio.h>
+
+#include "board.h"
+#include "l3g4200d.h"
+
+#ifdef MODULE_L3G4200D
+
+#define MODE        L3G4200D_MODE_100_25
+#define SCALE       L3G4200D_SCALE_500DPS
+
+static l3g4200d_t l3g4200d_dev;
+
+void _get_l3g4200d_init_handler(int argc, char **argv)
+{
+    (void)argc;
+    (void)argv;
+    int res;
+
+    res = l3g4200d_init(&l3g4200d_dev, L3G4200D_I2C, L3G4200D_ADDR,
+                        L3G4200D_INT, L3G4200D_DRDY,
+                        MODE, SCALE);
+
+    if (res) {
+        puts("Error initializing L3G4200D sensor.");
+    }
+    else {
+        puts("Initialized L3G4200D sensor with default values");
+    }
+}
+
+void _get_l3g4200d_read_handler(int argc, char **argv)
+{
+    (void)argc;
+    (void)argv;
+    int res;
+    l3g4200d_data_t data;
+
+    if (!l3g4200d_dev.addr) {
+        puts("Error: please call `l3g4200d_init` first!");
+    }
+
+    res = l3g4200d_read(&l3g4200d_dev, &data);
+    if (res < 0) {
+        puts("Error reading gyro values from L3G4200D.");
+        return;
+    }
+    else {
+        printf("L3G4200D: gyro values: roll(x): %6i   pitch(y): %6i   yaw(z): %6i\n",
+               data.acc_x, data.acc_y, data.acc_z);
+    }
+}
+
+#endif /* MODULE_L3G4200D */
diff --git a/sys/shell/commands/sc_lps331ap.c b/sys/shell/commands/sc_lps331ap.c
new file mode 100644
index 0000000000..e76bf4f393
--- /dev/null
+++ b/sys/shell/commands/sc_lps331ap.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2014 Freie Universität Berlin
+ *
+ * This file is subject to the terms and conditions of the GNU Lesser
+ * General Public License v2.1. See the file LICENSE in the top level
+ * directory for more details.
+ */
+
+/**
+ * @ingroup shell_commands
+ * @{
+ *
+ * @file
+ * @brief       Provides shell commands to poll the LPS331AP sensor
+ *
+ * @author      Hauke Petersen <hauke.petersen@fu-berlin.de>
+ *
+ * @}
+ */
+
+#include <stdio.h>
+
+#include "board.h"
+#include "lps331ap.h"
+
+#ifdef MODULE_LPS331AP
+
+#define RATE        LPS331AP_RATE_7HZ
+
+static lps331ap_t lps331ap_dev;
+
+void _get_lps331ap_init_handler(int argc, char **argv)
+{
+    (void)argc;
+    (void)argv;
+    int res;
+
+    res = lps331ap_init(&lps331ap_dev, LPS331AP_I2C, LPS331AP_ADDR, RATE);
+
+    if (res) {
+        puts("Error initializing LPS331AP sensor.");
+    }
+    else {
+        puts("Initialized LPS331AP sensor with default values");
+    }
+}
+
+void _get_lps331ap_read_handler(int argc, char **argv)
+{
+    (void)argc;
+    (void)argv;
+    int temp;
+    int pres;
+
+    if (!lps331ap_dev.address) {
+        puts("Error: please call `lps331ap_init` first!");
+    }
+
+    temp = lps331ap_read_temp(&lps331ap_dev);
+    pres = lps331ap_read_pres(&lps331ap_dev);
+
+    if (temp < 0) {
+        puts("Error reading temperature value from LPS331AP.");
+        return;
+    }
+    else {
+        int temp_abs = temp / 1000;
+        temp -= (temp_abs * 1000);
+        printf("LPS331AP: temperature:  %i.%03i °C\n", temp_abs, temp);
+    }
+
+    if (pres < 0) {
+        puts("Error reading pressure value from LPS331AP.");
+        return;
+    }
+    else {
+        printf("LPS331AP: pressure: %i mBar\n", pres);
+    }
+}
+
+#endif /* MODULE_LPS331AP */
diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c
index 7ac872d185..d018114663 100644
--- a/sys/shell/commands/shell_commands.c
+++ b/sys/shell/commands/shell_commands.c
@@ -49,6 +49,21 @@ extern void _get_weather_handler(int argc, char **argv);
 extern void _set_offset_handler(int argc, char **argv);
 #endif
 
+#ifdef MODULE_ISL29020
+extern void _get_isl29020_init_handler(int argc, char **argv);
+extern void _get_isl29020_read_handler(int argc, char **argv);
+#endif
+
+#ifdef MODULE_LPS331AP
+extern void _get_lps331ap_init_handler(int argc, char **argv);
+extern void _get_lps331ap_read_handler(int argc, char **argv);
+#endif
+
+#ifdef MODULE_L3G4200D
+extern void _get_l3g4200d_init_handler(int argc, char **argv);
+extern void _get_l3g4200d_read_handler(int argc, char **argv);
+#endif
+
 #ifdef MODULE_LTC4150
 extern void _get_current_handler(int argc, char **argv);
 extern void _reset_current_handler(int argc, char **argv);
@@ -145,6 +160,18 @@ const shell_command_t _shell_command_list[] = {
     {"weather", "Prints measured humidity and temperature.", _get_weather_handler},
     {"offset", "Set temperature offset.", _set_offset_handler},
 #endif
+#ifdef MODULE_ISL29020
+    {"isl29020_init", "Initializes the isl29020 sensor driver.", _get_isl29020_init_handler},
+    {"isl29020_read", "Prints data from the isl29020 sensor.", _get_isl29020_read_handler},
+#endif
+#ifdef MODULE_LPS331AP
+    {"lps331ap_init", "Initializes the lps331ap sensor driver.", _get_lps331ap_init_handler},
+    {"lps331ap_read", "Prints data from the lps331ap sensor.", _get_lps331ap_read_handler},
+#endif
+#ifdef MODULE_L3G4200D
+    {"l3g4200d_init", "Initializes the l3g4200d sensor driver.", _get_l3g4200d_init_handler},
+    {"l3g4200d_read", "Prints data from the l3g4200d sensor.", _get_l3g4200d_read_handler},
+#endif
 #ifdef MODULE_LTC4150
     {"cur", "Prints current and average power consumption.", _get_current_handler},
     {"rstcur", "Resets coulomb counter.", _reset_current_handler},
-- 
GitLab