summaryrefslogtreecommitdiff
path: root/n/es-2006/src/sniff_rvb.c
diff options
context:
space:
mode:
Diffstat (limited to 'n/es-2006/src/sniff_rvb.c')
-rw-r--r--n/es-2006/src/sniff_rvb.c92
1 files changed, 62 insertions, 30 deletions
diff --git a/n/es-2006/src/sniff_rvb.c b/n/es-2006/src/sniff_rvb.c
index c819efe..5941316 100644
--- a/n/es-2006/src/sniff_rvb.c
+++ b/n/es-2006/src/sniff_rvb.c
@@ -25,6 +25,7 @@
#include "sniff_rvb.h"
#include "io.h"
+#include "string.h"
#include "common.h"
#include "modules/proto/proto.h"
#include "modules/utils/byte.h"
@@ -34,7 +35,10 @@
/** Reference color. */
uint16_t sniff_rvb_reference_color[RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
/** Threshold table data. */
-int16_t sniff_rvb_threshold_table[RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
+uint16_t sniff_rvb_threshold[2][RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
+/** Used to build threshold */
+// XXX only bool needed, use bit operation if we need to use less space
+uint8_t sniff_rvb_sign[2][RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
/** Ratio min max */
uint16_t sniff_rvb_reference_color_min[RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
uint16_t sniff_rvb_reference_color_max[RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX];
@@ -53,22 +57,22 @@ sniff_rvb_try_reference (uint8_t sensor_num, uint16_t
ref[RVB_MAX_SENSOR][RVB_SNIFF_MAX_INDEX])
{
uint8_t compt;
- //
-
/* If sensor is valid */
if (sensor_rvb_values[sensor_num][0] != 0)
{
/* For each color add this value by averrage */
for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
- {
- if (ref[sensor_num][compt] == 0)
+ if (ref[sensor_num][compt] == 0)
+ {
ref[sensor_num][compt] =
sensor_rvb_values[sensor_num][compt];
+ }
else
+ {
ref[sensor_num][compt] =
- (sensor_rvb_values[sensor_num][compt] / 2
- + ref[sensor_num][compt] / 2);
- }
+ (sensor_rvb_values[sensor_num][compt] / 2
+ + ref[sensor_num][compt] / 2);
+ }
return !0;
}
return 0;
@@ -77,20 +81,19 @@ sniff_rvb_try_reference (uint8_t sensor_num, uint16_t
/* Test blue or red */
uint8_t
-sniff_rvb_analysis_color_other (uint8_t sensor, uint8_t color)
+sniff_rvb_analysis_color_other (uint8_t sensor, uint8_t color,
+ uint16_t threshold[RVB_SNIFF_MAX_INDEX],
+ uint8_t sign[RVB_SNIFF_MAX_INDEX])
{
uint8_t compt;
uint8_t what_is_it = color;
- for (compt = 0; compt < 4; compt++)
+ for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
{
- // XXX will be in cache table after
- uint16_t threshold = sniff_rvb_reference_color[sensor][compt]
- + sniff_rvb_threshold_table[color][compt];
// if relative threshold is positive, current value must be greater
// than the threshold
- if (sniff_rvb_threshold_table[color][compt] > 0)
+ if (sign[compt] > 0)
{
- if (sensor_rvb_values[sensor][compt] > threshold)
+ if (sensor_rvb_values[sensor][compt] > threshold[compt])
{
continue;
}
@@ -98,7 +101,7 @@ sniff_rvb_analysis_color_other (uint8_t sensor, uint8_t color)
// if negative, must be lower
else
{
- if (sensor_rvb_values[sensor][compt] < threshold)
+ if (sensor_rvb_values[sensor][compt] < threshold[compt])
{
continue;
}
@@ -130,18 +133,18 @@ sniff_rvb_analysis_color (uint8_t sensor, uint8_t mode)
if ((what_is_it == RVB_SNIFF_GREEN) || (mode == RVB_SNIFF_ONLY_GREEN))
goto sniff_rvb_set_ref_color_end;
-// XXX pb if reference too high and sum with threshold overflow
-// same pb with the cache table creation
-// XXX create cache table for blue and red
-
/* test for blue */
- if (sniff_rvb_analysis_color_other (sensor, RVB_SNIFF_BLUE) == RVB_SNIFF_BLUE)
+ if (sniff_rvb_analysis_color_other (sensor, RVB_SNIFF_BLUE,
+ sniff_rvb_threshold[RVB_THRESHOLD_BLUE][sensor],
+ sniff_rvb_sign[RVB_THRESHOLD_BLUE][sensor]) == RVB_SNIFF_BLUE)
{
what_is_it = RVB_SNIFF_BLUE;
goto sniff_rvb_set_ref_color_end;
}
/* test for red */
- if (sniff_rvb_analysis_color_other (sensor, RVB_SNIFF_RED) == RVB_SNIFF_RED)
+ if (sniff_rvb_analysis_color_other (sensor, RVB_SNIFF_RED,
+ sniff_rvb_threshold[RVB_THRESHOLD_RED][sensor],
+ sniff_rvb_sign[RVB_THRESHOLD_RED][sensor]) == RVB_SNIFF_RED)
{
what_is_it = RVB_SNIFF_RED;
goto sniff_rvb_set_ref_color_end;
@@ -179,10 +182,39 @@ sniff_rvb_set_ref_color_green (uint8_t sensor)
}
/* sub function of sniff_rvb_set_ref_color */
+/* XXX call only after the reference color initialization has been done */
void
-sniff_rvb_set_ref_color_other (uint8_t sensor)
+sniff_rvb_set_ref_color_other (uint8_t sensor, uint8_t color)
{
-
+ uint8_t compt;
+ uint16_t *threshold;
+ uint8_t *sign;
+ if (color == RVB_SNIFF_BLUE)
+ {
+ threshold = sniff_rvb_threshold[RVB_THRESHOLD_BLUE][sensor];
+ sign = sniff_rvb_sign[RVB_THRESHOLD_BLUE][sensor];
+ }
+ else
+ {
+ threshold = sniff_rvb_threshold[RVB_THRESHOLD_RED][sensor];
+ sign = sniff_rvb_sign[RVB_THRESHOLD_RED][sensor];
+ }
+ /* get sensor values */
+ /* test if valid */
+ if (sensor_rvb_values[sensor][0] != 0)
+ for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
+ {
+ /* compute threshold */
+ int16_t tmp = (sensor_rvb_values[sensor][compt]
+ - sniff_rvb_reference_color[sensor][compt]) / 2;
+ // XXX use ratio instead of 2
+ threshold[compt] = tmp + sniff_rvb_reference_color[sensor][compt];
+ /* store sign for faster processing later */
+ if (tmp > 0)
+ sign[compt] = RVB_THRESHOLD_POSITIVE;
+ else
+ sign[compt] = RVB_THRESHOLD_NEGATIVE;
+ }
}
/** Set the current color seen by some sensors as the reference color
@@ -197,7 +229,7 @@ sniff_rvb_set_ref_color (uint8_t sensor, uint8_t color)
break;
case RVB_SNIFF_RED:
case RVB_SNIFF_BLUE:
- sniff_rvb_set_ref_color_other (sensor);
+ sniff_rvb_set_ref_color_other (sensor, color);
break;
}
}
@@ -213,10 +245,10 @@ sniff_rvb_set_threshold (uint8_t color, int16_t red_ts, int16_t blue_ts,
case RVB_SNIFF_RED:
case RVB_SNIFF_BLUE:
case RVB_SNIFF_GREEN:
- sniff_rvb_threshold_table[color][0] = red_ts;
- sniff_rvb_threshold_table[color][1] = blue_ts;
- sniff_rvb_threshold_table[color][2] = clear_ts;
- sniff_rvb_threshold_table[color][3] = green_ts;
- break;
+// sniff_rvb_thresholdtable[color][0] = red_ts;
+// sniff_rvb_thresholdtable[color][1] = blue_ts;
+// sniff_rvb_thresholdtable[color][2] = clear_ts;
+// sniff_rvb_thresholdtable[color][3] = green_ts;
+ break;
}
}