Ver Fonte

set RESULT_INACTIVE if there are no peaks in a time period

Xℹ Ruoyao há 4 anos atrás
pai
commit
29bf875917
3 ficheiros alterados com 10 adições e 4 exclusões
  1. 1 0
      demo/main.c
  2. 6 1
      jump_rope_count_device.c
  3. 3 3
      jump_rope_count_device.h

+ 1 - 0
demo/main.c

@@ -23,6 +23,7 @@ int main()
 	cfg.cy_window = fs * 1;
 	cfg.cy_crit = 250;
 	cfg.cy_suppress_time = fs * 1;
+	cfg.wait_time = fs * 1;
 
 	if (jump_rope_count_device_init(&dev, &cfg) != 0)
 		abort();

+ 6 - 1
jump_rope_count_device.c

@@ -63,6 +63,7 @@ int jump_rope_count_device_init(struct jump_rope_count_device *dev,
 	dev->cy_window = cfg->cy_window;
 	dev->cy_crit = cfg->cy_crit;
 	dev->cy_suppress_time = cfg->cy_suppress_time;
+	dev->wait_time = cfg->wait_time;
 
 	dev->cy_suppress = 0;
 
@@ -133,11 +134,15 @@ int process_packet(struct jump_rope_count_device *dev,
 	    schmidt_get(&dev->trig_gz) == 0 &&
 	    dev->cy_suppress == 0)
 	{
+		dev->remain_time = dev->wait_time;
 		*result = RESULT_TRIGGERED;
 		goto out;
 	}
 
-	*result = RESULT_NONE;
+	if (dev->remain_time)
+		dev->remain_time--;
+
+	*result = (dev->remain_time > 0 ? RESULT_NONE : RESULT_INACTIVE);
 out:
 	if (dev->cy_suppress > 0)
 		dev->cy_suppress--;

+ 3 - 3
jump_rope_count_device.h

@@ -8,7 +8,7 @@
 struct jump_rope_count_config
 {
 	float lg, hg, la, ha, lgz, hgz, a_g_window;
-	int cy_window, cy_crit, cy_suppress_time;
+	int cy_window, cy_crit, cy_suppress_time, wait_time;
 };
 
 struct jump_rope_count_device
@@ -16,8 +16,8 @@ struct jump_rope_count_device
 	struct schmidt trig_g, trig_a, trig_gz;
 	struct ringbuf rbuf_g, rbuf_a;
 	struct monotonic_queue mq_min_cy, mq_max_cy;
-	int cy_window, cy_crit, cy_suppress_time;
-	int cy_suppress;
+	int cy_window, cy_crit, cy_suppress_time, wait_time;
+	int cy_suppress, remain_time;
 };
 
 struct sensor_packet