mirror of
https://github.com/Genaker/LoraSA.git
synced 2026-07-04 08:51:18 +02:00
Factor out detection + display loop
Refactor code that does not depend on y. Essentially, the following logic: Recall that some loops are folds, some are maps. Maps look at only elements with one index. The important property of maps is that map(f . g) = map(f) . map(g) - parts of the loop body can be split into separate loops. Another property of maps is that if map(f) does not depend on the output of map(g), then map(f) . map(g) = map(g) . map(f) - the loops can be reordered.
This commit is contained in:
+63
-4
@@ -6,17 +6,17 @@
|
||||
#include <cstring>
|
||||
#include <stdlib.h>
|
||||
|
||||
float Scan::getRSSI() { return 0.1; }
|
||||
|
||||
uint16_t Scan::rssiMethod(uint16_t *result)
|
||||
uint16_t Scan::rssiMethod(size_t samples, uint16_t *result, size_t res_size)
|
||||
{
|
||||
float scale((float)res_size / (HI_RSSI_THRESHOLD - LO_RSSI_THRESHOLD + 0.1));
|
||||
|
||||
memset(result, 0, res_size * sizeof(uint16_t));
|
||||
int result_index = 0;
|
||||
|
||||
//
|
||||
uint16_t max_signal = 65535;
|
||||
// N of samples
|
||||
for (int r = 0; r < SAMPLES_RSSI; r++)
|
||||
for (int r = 0; r < samples; r++)
|
||||
{
|
||||
float rssi = getRSSI();
|
||||
if (rssi < -65535)
|
||||
@@ -66,4 +66,63 @@ uint16_t Scan::rssiMethod(uint16_t *result)
|
||||
return max_signal;
|
||||
}
|
||||
|
||||
size_t Scan::detect(uint16_t *result, bool *filtered_result, size_t result_size,
|
||||
int samples)
|
||||
{
|
||||
size_t max_rssi_x = 999;
|
||||
|
||||
for (int y = 0; y < result_size; y++)
|
||||
{
|
||||
|
||||
LOG("%i:%i,", y, result[y]);
|
||||
#if !defined(FILTER_SPECTRUM_RESULTS) || FILTER_SPECTRUM_RESULTS == false
|
||||
if (result[y] && result[y] != 0)
|
||||
{
|
||||
filtered_result[y] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
filtered_result[y] = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// if samples low ~1 filter removes all values
|
||||
#if FILTER_SPECTRUM_RESULTS
|
||||
|
||||
filtered_result[y] = 0;
|
||||
// Filter Elements without neighbors
|
||||
// if RSSI method actual value is -xxx dB
|
||||
if (result[y] > 0 && samples > 1)
|
||||
{
|
||||
// do not process 'first' and 'last' row to avoid out of index
|
||||
// access.
|
||||
if ((y > 0) && (y < (result_size - 2)))
|
||||
{
|
||||
if (((result[y + 1] != 0) && (result[y + 2] != 0)) ||
|
||||
(result[y - 1] != 0))
|
||||
{
|
||||
filtered_result[y] = 1;
|
||||
// Fill empty pixel
|
||||
result[y + 1] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG("Filtered::%i,", y);
|
||||
}
|
||||
}
|
||||
} // not filtering if samples == 1 because it will be filtered
|
||||
else if (result[y] > 0 && samples == 1)
|
||||
{
|
||||
filtered_result[y] = 1;
|
||||
}
|
||||
#endif
|
||||
if (filtered_result[y] && max_rssi_x > y)
|
||||
{
|
||||
max_rssi_x = y;
|
||||
}
|
||||
}
|
||||
|
||||
return max_rssi_x;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user