This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new a416ba5  sensors: Add current and voltage support
a416ba5 is described below

commit a416ba5f1544db321cfcfdf8a87d69eac088cf94
Author: J. Ipanienko <[email protected]>
AuthorDate: Mon Aug 17 12:46:54 2020 -0500

    sensors: Add current and voltage support
    
    current.h and voltage.h are used in INA219 and INA226 and there were not 
added yet.
    Sensors shell also has support for current and voltage.
---
 hw/sensor/include/sensor/current.h | 41 ++++++++++++++++++++++++++++++++++++++
 hw/sensor/include/sensor/sensor.h  |  4 ++++
 hw/sensor/include/sensor/voltage.h | 41 ++++++++++++++++++++++++++++++++++++++
 hw/sensor/src/sensor_shell.c       | 28 ++++++++++++++++++++++++++
 4 files changed, 114 insertions(+)

diff --git a/hw/sensor/include/sensor/current.h 
b/hw/sensor/include/sensor/current.h
new file mode 100644
index 0000000..d86db58
--- /dev/null
+++ b/hw/sensor/include/sensor/current.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2020 Jesus Ipanienko
+ *
+ * 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.
+ */
+
+#ifndef __SENSOR_CURRENT_H__
+#define __SENSOR_CURRENT_H__
+
+#include "os/mynewt.h"
+#include "sensor/sensor.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Data representing a singular read from a current sensor
+ * All values are in V
+ */
+struct sensor_current_data {
+    float scd_current;
+
+    /* Validity */
+    uint8_t scd_current_is_valid:1;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SENSOR_CURRENT_H__ */
diff --git a/hw/sensor/include/sensor/sensor.h 
b/hw/sensor/include/sensor/sensor.h
index 71a811e..05ccb85 100644
--- a/hw/sensor/include/sensor/sensor.h
+++ b/hw/sensor/include/sensor/sensor.h
@@ -84,6 +84,10 @@ typedef enum {
     SENSOR_TYPE_EULER                = (1 << 14),
     /* Color Sensor */
     SENSOR_TYPE_COLOR                = (1 << 15),
+    /* Voltage */
+    SENSOR_TYPE_VOLTAGE              = (1 << 16),
+    /* Current */
+    SENSOR_TYPE_CURRENT              = (1 << 17),
 
     /* Standard sensor types to be defined here */
 
diff --git a/hw/sensor/include/sensor/voltage.h 
b/hw/sensor/include/sensor/voltage.h
new file mode 100644
index 0000000..1c9e470
--- /dev/null
+++ b/hw/sensor/include/sensor/voltage.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2020 Jesus Ipanienko
+ *
+ * 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.
+ */
+
+#ifndef __SENSOR_VOLTAGE_H__
+#define __SENSOR_VOLTAGE_H__
+
+#include "os/mynewt.h"
+#include "sensor/sensor.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Data representing a singular read from a voltage sensor
+ * All values are in V
+ */
+struct sensor_voltage_data {
+    float svd_voltage;
+
+    /* Validity */
+    uint8_t svd_voltage_is_valid:1;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SENSOR_VOLTAGE_H__ */
diff --git a/hw/sensor/src/sensor_shell.c b/hw/sensor/src/sensor_shell.c
index 4c401af..0f7f063 100644
--- a/hw/sensor/src/sensor_shell.c
+++ b/hw/sensor/src/sensor_shell.c
@@ -37,6 +37,8 @@
 #include "sensor/pressure.h"
 #include "sensor/humidity.h"
 #include "sensor/gyro.h"
+#include "sensor/voltage.h"
+#include "sensor/current.h"
 #include "console/console.h"
 #include "shell/shell.h"
 #include "hal/hal_i2c.h"
@@ -178,6 +180,12 @@ sensor_cmd_display_type(char **argv)
             case SENSOR_TYPE_COLOR:
                 console_printf("    color: 0x%x\n", type);
                 break;
+            case SENSOR_TYPE_VOLTAGE:
+                console_printf("    voltage: 0x%x\n", type);
+                break;
+            case SENSOR_TYPE_CURRENT:
+                console_printf("    current: 0x%x\n", type);
+                break;
             case SENSOR_TYPE_USER_DEFINED_1:
                 console_printf("    user defined 1: 0x%x\n", type);
                 break;
@@ -255,6 +263,8 @@ sensor_shell_read_listener(struct sensor *sensor, void 
*arg, void *data,
     struct sensor_press_data *spd;
     struct sensor_humid_data *shd;
     struct sensor_gyro_data *sgd;
+    struct sensor_voltage_data *svd;
+    struct sensor_current_data *scud;
     char tmpstr[13];
 
     console_printf("ts: [ secs: %ld usecs: %d cputime: %u ]\n",
@@ -422,6 +432,24 @@ sensor_shell_read_listener(struct sensor *sensor, void 
*arg, void *data,
         console_printf("\n");
     }
 
+    if (type == SENSOR_TYPE_VOLTAGE) {
+        svd = (struct sensor_voltage_data *)data;
+        if (svd->svd_voltage_is_valid) {
+            console_printf("voltage = %sV",
+                           sensor_ftostr(svd->svd_voltage, tmpstr, 13));
+        }
+        console_printf("\n");
+    }
+
+    if (type == SENSOR_TYPE_CURRENT) {
+        scud = (struct sensor_current_data *)data;
+        if (scud->scd_current_is_valid) {
+            console_printf("current = %sA",
+                           sensor_ftostr(scud->scd_current, tmpstr, 13));
+        }
+        console_printf("\n");
+    }
+
     return (0);
 }
 

Reply via email to