diff --git a/include/puara/descriptors/jab.h b/include/puara/descriptors/jab.h index 160a561..5564e35 100644 --- a/include/puara/descriptors/jab.h +++ b/include/puara/descriptors/jab.h @@ -27,7 +27,6 @@ class Jab Jab() noexcept : threshold(5) , tied_value(nullptr) - , minmax(10) { } @@ -39,17 +38,16 @@ class Jab explicit Jab(double* tied) : threshold(5) , tied_value(tied) - , minmax(10) { } explicit Jab(Coord1D* tied) : threshold(5) , tied_value(&(tied->x)) - , minmax(10) { } +#if 0 double update(double reading) { minmax.update(reading); @@ -73,6 +71,18 @@ class Jab } return value; } +#else + //TODO VB: check that this works + double update(double reading) + { + const auto [min, max]{minmax.update(reading)}; + + if(max - min > threshold) + value = (max < 0 && min < 0) ? min - max : max - min; + + return value; + } + #endif int update(Coord1D reading) { @@ -89,6 +99,7 @@ class Jab } else { + // should we assert here, it seems like an error to call update() without a tied_value? return 0; } } @@ -104,7 +115,9 @@ class Jab private: double* tied_value{}; double value = 0; - puara_gestures::utils::RollingMinMax minmax; + + /** Keep track of the min and max values over the last 10 times Jab::update() was called. */ + puara_gestures::utils::RollingMinMax minmax{}; }; /** diff --git a/include/puara/descriptors/touch.h b/include/puara/descriptors/touch.h index fbabafd..08861a3 100644 --- a/include/puara/descriptors/touch.h +++ b/include/puara/descriptors/touch.h @@ -18,8 +18,12 @@ class Touch float touchTop{}; // f, 0--1 float touchMiddle{}; // f, 0--1 float touchBottom{}; // f, 0--1 + + /** brush: direction and intensity of capsense brush motion in ~cm/s (distance between stripes = ~1.5cm) */ float brush{}; // f, 0--? (~cm/s) double multiBrush[maxNumBlobs]{}; // ffff, 0--? (~cm/s) + + /** rub: intensity of rub motion in ~cm/s (distance between stripes = ~1.5cm) */ float rub{}; // f, 0--? (~cm/s) double multiRub[maxNumBlobs]{}; // ffff, 0--? (~cm/s) @@ -46,39 +50,25 @@ class Touch * the size of the array */ void updateTouchArray(int* discrete_touch, int touchSize) - { // raw_touch - - // touchAll: get the "amount of touch" for the entire touch sensor - // normalized between 0 and 1 + { + //update the "amount of touch" for the entire touch sensor, as well as the top, middle and bottom parts. + //All normalized between 0 and 1. touchAll = touchAverage(discrete_touch, 0, touchSize); - - // touchTop: get the "amount of touch" for the top part of the capsense - // normalized between 0 and 1 touchTop = touchAverage(discrete_touch, 0, touchSizeEdge); - - // touchMiddle: get the "amount of touch" for the central part of the capsense - // normalized between 0 and 1 - touchMiddle - = touchAverage(discrete_touch, (0 + touchSizeEdge), (touchSize - touchSizeEdge)); - - // touchBottom: get the "amount of touch" for the botton part of the capsense - // normalized between 0 and 1 + touchMiddle = touchAverage(discrete_touch, (0 + touchSizeEdge), (touchSize - touchSizeEdge)); touchBottom = touchAverage(discrete_touch, (touchSize - touchSizeEdge), touchSize); - // 1D blob detection: used for brush + // 1D blob detection: used for brush const auto movement = blobDetector.detect1D(discrete_touch, touchSize); - // brush: direction and intensity of capsense brush motion - // rub: intensity of rub motion - // in ~cm/s (distance between stripes = ~1.5cm) for(int i = 0; i < movement.size(); ++i) { if(movement[i] == 0) { if(brushCounter[i] < 10) { - brushCounter[i]++; // wait some time before dropping the rub/brush values + brushCounter[i]++; } else if(multiBrush[i] < 0.001) { @@ -87,32 +77,16 @@ class Touch } else { - // multiBrush[i] = multiBrushIntegrator[i].integrate( - // movement * 0.15, multiBrush[i], 0.7, leakyBrushFreq, leakyBrushTimer); - - // multiRub[i] = multiRubIntegrator[i].integrate( - // (std::abs(movement * 0.15)), multiRub[i], 0.7, leakyRubFreq, - // leakyRubTimer); - // multiBrush[i] = multiBrushIntegrator[i].integrate(movement[i] * 0.15); multiRub[i] = multiRubIntegrator[i].integrate(std::abs(movement[i] * 0.15)); } } else if(std::abs(movement[i]) > 1) { - // multiBrush[i] = multiBrushIntegrator[i].integrate( - // 0, multiBrush[i], 0.6, leakyBrushFreq, leakyBrushTimer); - multiBrush[i] = multiBrushIntegrator[i].integrate(0); } else { - // multiBrush[i] = multiBrushIntegrator[i].integrate( - // movement * 0.15, multiBrush[i], 0.8, leakyBrushFreq, leakyBrushTimer); - // multiRub[i] = multiRubIntegrator[i].integrate( - // (std::abs(movement * 0.15)) * 0.15, multiRub[i], 0.99, leakyRubFreq, - // leakyRubTimer); - multiBrush[i] = multiBrushIntegrator[i].integrate(movement[i] * 0.15); multiRub[i] = multiRubIntegrator[i].integrate((std::abs(movement[i] * 0.15))); @@ -123,7 +97,7 @@ class Touch rub = utils::arrayAverageZero(multiRub, maxNumBlobs); } - float touchAverage(float* touchArrayStrips, int firstStrip, int lastStrip) + static float touchAverage(float* touchArrayStrips, int firstStrip, int lastStrip) { int sum = 0; for(int i = firstStrip; i < lastStrip - 1; ++i) @@ -132,7 +106,7 @@ class Touch return ((float)sum) / (lastStrip - firstStrip); } - float touchAverage(int* touchArrayStrips, int firstStrip, int lastStrip) + static float touchAverage(int* touchArrayStrips, int firstStrip, int lastStrip) { int sum = 0; for(int i = firstStrip; i < lastStrip; i++)