[ 
https://issues.apache.org/jira/browse/MYNEWT-881?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16365397#comment-16365397
 ] 

ASF GitHub Bot commented on MYNEWT-881:
---------------------------------------

rymanluk commented on a change in pull request #718: MYNEWT-881: SensorAPI: Add 
sensor_unset_thresh() API and LIS2DH12 set threshold cb fix
URL: https://github.com/apache/mynewt-core/pull/718#discussion_r168440930
 
 

 ##########
 File path: hw/drivers/sensors/lis2dh12/src/lis2dh12.c
 ##########
 @@ -1463,7 +1485,75 @@ lis2dh12_sensor_set_trigger_thresh(struct sensor 
*sensor,
         }
     }
 
+err:
+    return rc;
+}
+
+
+/**
+ * Set the trigger threshold values and enable interrupts
+ *
+ * @param ptr to sensor
+ * @param the Sensor type
+ * @param Sensor type traits
+ *
+ * @return 0 on success, non-zero on failure
+ */
+static int
+lis2dh12_sensor_set_trigger_thresh(struct sensor *sensor,
+                                   sensor_type_t type,
+                                   struct sensor_type_traits *stt)
+{
+    int rc;
+    uint8_t fs;
+    struct sensor_itf *itf;
+    sensor_data_t low_thresh;
+    sensor_data_t high_thresh;
+
+    itf = SENSOR_GET_ITF(sensor);
+
+    if (type != SENSOR_TYPE_ACCELEROMETER) {
+        rc = SYS_EINVAL;
+        goto err;
+    }
+
+    memcpy(&low_thresh, &stt->stt_low_thresh, sizeof(low_thresh));
+    memcpy(&high_thresh, &stt->stt_high_thresh, sizeof(high_thresh));
+
+    rc = lis2dh12_get_full_scale(itf, &fs);
+    if (rc) {
+        goto err;
+    }
+
+    if (fs == LIS2DH12_FS_2G) {
+        fs = 16;
+    } else if (fs == LIS2DH12_FS_4G) {
+        fs = 32;
+    } else if (fs == LIS2DH12_FS_8G) {
+        fs = 62;
+    } else if (fs == LIS2DH12_FS_16G) {
+        fs = 186;
+    } else {
+        rc = SYS_EINVAL;
+        goto err;
+    }
+
+    /* Set low threshold and enable interrupt */
+    rc = lis2dh12_set_low_thresh(itf, low_thresh, fs, stt);
+    if (rc) {
+        hal_gpio_irq_release(itf->si_low_pin);
+        goto err;
+    }
+
+    /* Set high threshold and enable interrupt */
+    rc = lis2dh12_set_high_thresh(itf, high_thresh, fs, stt);
+    if (rc) {
+        hal_gpio_irq_release(itf->si_high_pin);
 
 Review comment:
   Similar comment as above.  hal_gpio_irq_release(itf->si_high_pin); could be 
done in "err" label in of lis2dh12_set_high_thresh()

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> SensorAPI: Add sensor_unset_thresh() API and LIS2DH12 set threshold cb fix
> --------------------------------------------------------------------------
>
>                 Key: MYNEWT-881
>                 URL: https://issues.apache.org/jira/browse/MYNEWT-881
>             Project: Mynewt
>          Issue Type: Improvement
>      Security Level: Public(Viewable by anyone) 
>          Components: Drivers, Sensor Framework
>    Affects Versions: v1_3_0_rel
>         Environment: ruuvitag-revb2
>            Reporter: Vipul Rahane
>            Assignee: Vipul Rahane
>            Priority: Major
>              Labels: core
>             Fix For: v1_4_0_rel
>
>
> There are two issues for calling the lis2dh12_sensor_set_trigger_thresh() :
> 1. gpio irq was not being released before doing a re-initialization
>  2. srec was malloced and calling the function multiple times would have 
> malloced additional memory without freeing it.
> Solution:
>  1. Release the gpio irq
>  2. Remove the malloc and add a ptr for the sensor in each type trait so that 
> a sensor read could be performed in the irq handler.
> Also, sensor_unset_thresh() API was added to unset thresholds 
> triggers/interrupts.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to