You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by gi...@git.apache.org on 2017/08/30 18:06:40 UTC
[GitHub] mkiiskila commented on a change in pull request #505: [WIP, DO NOT MERGE] MYNEWT-828 SensorAPI: Sensor OIC notifications/triggers
mkiiskila commented on a change in pull request #505: [WIP, DO NOT MERGE] MYNEWT-828 SensorAPI: Sensor OIC notifications/triggers
URL: https://github.com/apache/mynewt-core/pull/505#discussion_r136143728
##########
File path: hw/sensor/src/sensor.c
##########
@@ -680,11 +784,777 @@ sensor_up_timestamp(struct sensor *sensor)
}
+static int
+sensor_tx_trigger(struct sensor *sensor, uint8_t transport, void *data,
+ sensor_type_t type)
+{
+ int rc;
+
+ rc = 0;
+#if MYNEWT_VAL(SENSOR_OIC)
+ if (transport == SENSOR_TRANSPORT_OIC) {
+ rc |= sensor_oic_tx_trigger(sensor, data, type);
+ }
+#endif
+
+ return rc;
+}
+
+/**
+ * Get the type traits for a sensor
+ *
+ * @param name of the sensor
+ * @param Ptr to sensor types trait struct
+ * @param type of sensor
+ *
+ * @return NULL on failure, sensor struct on success
+ */
+struct sensor *
+sensor_get_type_traits_byname(char *devname, struct sensor_type_traits **stt,
+ sensor_type_t type)
+{
+ struct sensor *sensor;
+
+ sensor = sensor_mgr_find_next_bydevname(devname, NULL);
+ if (!sensor) {
+ goto err;
+ }
+
+ *stt = sensor_get_type_traits_bytype(type, sensor);
+
+err:
+ return sensor;
+}
+
+/**
+ * Set the thresholds along with comparison algo for a sensor
+ *
+ * @param name of the sensor
+ * @param Ptr to sensor threshold
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+sensor_set_thresh(char *devname, struct sensor_type_traits *stt)
+{
+ struct sensor_type_traits *stt_tmp;
+ struct sensor *sensor;
+ int rc;
+
+ sensor = sensor_get_type_traits_byname(devname, &stt_tmp,
+ stt->stt_sensor_type);
+ if (!sensor) {
+ rc = SYS_EINVAL;
+ goto err;
+ }
+
+ if (!stt_tmp && stt) {
+ sensor_lock(sensor);
+ SLIST_INSERT_HEAD(&sensor->s_type_traits_list, stt, stt_next);
+ stt_tmp = stt;
+ sensor_unlock(sensor);
+ } else if (stt_tmp) {
+ sensor_lock(sensor);
+ stt_tmp->stt_low_thresh = stt->stt_low_thresh;
+ stt_tmp->stt_high_thresh = stt->stt_high_thresh;
+ stt_tmp->stt_algo = stt->stt_algo;
+ sensor_unlock(sensor);
+ } else {
+ rc = SYS_EINVAL;
+ goto err;
+ }
+
+ if (sensor->s_funcs->sd_set_trigger_thresh) {
+ rc = sensor->s_funcs->sd_set_trigger_thresh(sensor, stt_tmp->stt_sensor_type,
+ stt_tmp);
+ if (rc) {
+ goto err;
+ }
+ }
+
+ return 0;
+err:
+ return rc;
+}
+
+static int
+sensor_window_cmp(sensor_type_t type, sensor_data_t *low_thresh,
+ sensor_data_t *high_thresh, void *data)
+{
+ uint8_t tx_trigger;
+ sensor_data_t dataptr;
+
+ tx_trigger = 0;
+
+ switch(type) {
+ case SENSOR_TYPE_ROTATION_VECTOR:
+ dataptr.sqd = data;
+ tx_trigger |= dataptr.sqd->sqd_x_is_valid ?
+ high_thresh->sqd->sqd_x_is_valid ?
+ (dataptr.sqd->sqd_x < high_thresh->sqd->sqd_x) : 1 &&
+ low_thresh->sqd->sqd_x_is_valid ?
+ (dataptr.sqd->sqd_x > low_thresh->sqd->sqd_x) : 1 ?
+ (low_thresh->sqd->sqd_x_is_valid |
+ high_thresh->sqd->sqd_x_is_valid):0:0;
Review comment:
These are too complicated to evaluate for correctness. I suggest you simplify these statements.
Also, there's two large functions here which do almost the same thing. If you had a routine like:
sensor_value_cmp_lt(sensor_type_t type, sensor_data_t *a, sensor_data_t *b);
and then call it from these 2 routines.
BTW, what is the difference of algo_window and algo_watermark?
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services