refine sort and find focusing areas logic
This commit is contained in:
parent
4d1ce540dd
commit
db309c84f7
|
@ -250,14 +250,14 @@ typedef struct
|
|||
float minTemp; /* 0-120 C */
|
||||
float centerTemp; /* 0-120 C */
|
||||
float averageTempInner; /* 0-120 C */
|
||||
uint8_t spot_cnt; /* 0-20 max of v_water_cnt h_water_cnt */
|
||||
uint8_t spillage_level; /* 0-99%, out of 768 dots */
|
||||
uint8_t v_water_cnt;
|
||||
uint8_t h_water_cnt;
|
||||
uint16_t spot_cnt; /* 0-20 max of v_water_cnt h_water_cnt */
|
||||
uint16_t spillage_level; /* 0-99%, out of 768 dots */
|
||||
uint16_t v_water_cnt;
|
||||
uint16_t h_water_cnt;
|
||||
|
||||
//uint8_t waterSpillMatrix[32][24]; /* temp matrix or mark */
|
||||
uint8_t upMask[80]; /* 0-80 origin value, 100-110, upload values */
|
||||
uint8_t order[80]; /* x, y of water in 10*8 matrix */
|
||||
uint16_t upMask[80]; /* 0-80 origin value, 100-110, upload values */
|
||||
uint16_t order[80]; /* x, y of water in 10*8 matrix */
|
||||
uint16_t battery_mV; /*mV, 1000mv-5000mv, regular 3300mV - 3600mV --4200mV */
|
||||
|
||||
uint8_t on_off_event; /* 1: liquid sensed, 0: no liquid sensed */
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
#define FPS8HZ 0x04
|
||||
#define FPS16HZ 0x05
|
||||
#define FPS32HZ 0x06
|
||||
|
||||
#define DetectCycleCount 8
|
||||
#define MLX90640_ADDR 0x33
|
||||
#define RefreshRate FPS_HALF_HZ //FPS1HZ //was FPS2HZ
|
||||
#define RefreshRate FPS4HZ //FPS1HZ //was FPS2HZ
|
||||
#define EMMISIVITY 0.96f //water Emisivity=0.96, human body == 0.92f
|
||||
#define TA_SHIFT 8 //Default shift for MLX90640 in open air
|
||||
|
||||
|
@ -33,7 +33,7 @@ volatile uint8_t waterTempThreshold=15; //15/10= 1.5 C
|
|||
|
||||
volatile uint8_t normalWaterTemp=25; // 25 C
|
||||
|
||||
volatile uint8_t detectCycle=0, v_water_cnt=0,h_water_cnt=0, spot_cnt=0;
|
||||
volatile uint16_t detectCycle=0, v_water_cnt=0,h_water_cnt=0, spot_cnt=0;
|
||||
// start with some initial colors
|
||||
volatile float minTemp = -20.0f;
|
||||
volatile float maxTemp = 120.0f;
|
||||
|
@ -54,7 +54,7 @@ int x, y, i, j;
|
|||
#define ROW 24
|
||||
#define COL 32
|
||||
static float tempValues[COL*ROW];
|
||||
volatile uint8_t zoneMask[ROW*COL]={0x0}, edgeMask[ROW*COL]={0x0}, upMask[ROW/3][COL/3]={0x0}, order[(ROW/3)*(COL/3)]={0x0};
|
||||
volatile uint16_t zoneMask[ROW*COL]={0x0}, edgeMask[ROW*COL]={0x0}, upMask[ROW/3][COL/3]={0x0}, order[(ROW/3)*(COL/3)]={0x0};
|
||||
volatile STS_M1A_SensorDataTypeDef m1a_data;
|
||||
void blackOutFilter(void);
|
||||
static uint16_t TempToColor(float val);
|
||||
|
@ -63,8 +63,10 @@ static void setAbcd(void);
|
|||
static void drawLegend(void);
|
||||
static void drawMeasurement(void);
|
||||
static void drawPicture(void);
|
||||
static void findFocusArea(void);
|
||||
static void readTempValues(void);
|
||||
static void bubbleSort(uint8_t arr[], uint8_t len, uint8_t order[]);
|
||||
static void sortFocusAreas(void);
|
||||
static void bubbleSort(uint16_t arr[], uint16_t len, uint16_t order[]);
|
||||
|
||||
extern LCD_DrawPropTypeDef DrawProp;
|
||||
/*
|
||||
|
@ -227,6 +229,60 @@ static void drawMeasurement(void ) {
|
|||
|
||||
}
|
||||
|
||||
|
||||
static void findFocusArea(void)
|
||||
{
|
||||
uint16_t h_cnt[COL]={0},v_cnt[ROW]={0}; //for horizon and vertical _water spill count
|
||||
// start from 2, ignore edge of FOV
|
||||
for (y=1; y<ROW-1; y++)
|
||||
{
|
||||
for (x=1; x<COL-1; x++) // Start from 2, ignore edge of FOV
|
||||
{
|
||||
|
||||
if (zoneMask[y*COL+x] > 3) {
|
||||
// APP_LOG(TS_OFF,VLEVEL_L,"\r\n X=%d Y=%d Count=%d\r\n",x,y,zoneMask[y*32+x]);
|
||||
//upMask[(x/3)*(y/3)] ++;
|
||||
upMask[(uint8_t)(y/3)][(uint8_t)(x/3)] ++; //translate to 11*8 matrix for upload
|
||||
|
||||
h_cnt[x] =1;
|
||||
v_cnt[y] =1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// simple count of water spill point cloud
|
||||
v_water_cnt=0;
|
||||
h_water_cnt=0;
|
||||
uint8_t v_1=0, v_2=0,h_1=0,h_2=0;
|
||||
|
||||
for (y=1; y<ROW/2; y++) {
|
||||
if ((1 == v_cnt[y]) && (0 == v_cnt[y-1])) {
|
||||
v_1++;
|
||||
}
|
||||
}
|
||||
for (y=12; y<ROW; y++) {
|
||||
if ((1 == v_cnt[y]) && (0 == v_cnt[y-1])) {
|
||||
v_2++;
|
||||
}
|
||||
}
|
||||
v_water_cnt= v_1 + v_2;
|
||||
|
||||
for (x=1; x<COL/2; x++) {
|
||||
if ((1 == h_cnt[x]) && (0 == h_cnt[x-1])) {
|
||||
h_1 ++;
|
||||
}
|
||||
}
|
||||
for (x=16; x<COL; x++) {
|
||||
if ((1 == h_cnt[x]) && (0 == h_cnt[x-1])) {
|
||||
h_2 ++;
|
||||
}
|
||||
}
|
||||
h_water_cnt = h_1 + h_2;
|
||||
|
||||
spot_cnt += max(h_water_cnt, v_water_cnt);
|
||||
// APP_LOG(TS_OFF, VLEVEL_L, " H cnt = %2u V cnt =%2u Spot Cnt=%2u \r\n", h_water_cnt, v_water_cnt, spot_cnt);
|
||||
|
||||
}
|
||||
|
||||
static void drawPicture(void)
|
||||
{
|
||||
uint8_t h_cnt[COL]={0},v_cnt[ROW]={0}; //for horizon and vertical _water spill count
|
||||
|
@ -373,9 +429,59 @@ void blackOutFilter(void)
|
|||
|
||||
detectCycle ++;
|
||||
|
||||
} while (detectCycle <30);
|
||||
} while (detectCycle <DetectCycleCount);
|
||||
|
||||
waterSpillCount /=DetectCycleCount;
|
||||
|
||||
}
|
||||
|
||||
static void sortFocusAreas(void)
|
||||
{
|
||||
float temp1=0.0, temph1=0.0, tempv1=0.0;
|
||||
|
||||
if (maxTemp > humanTempThreshold)
|
||||
{
|
||||
blackOutTag =1;
|
||||
} else
|
||||
{
|
||||
blackOutTag =0;
|
||||
}
|
||||
// ignore edge of FOV
|
||||
waterSpillCount =0;
|
||||
|
||||
for (y=1; y<ROW; y++)
|
||||
{
|
||||
for (x=1; x<COL; x++)
|
||||
{
|
||||
temp1 = (float)tempValues[(x) + (y*COL)];
|
||||
|
||||
#if 0
|
||||
temph1 = (float)tempValues[(x) + (y-1)*COL];
|
||||
tempv1 = (float)tempValues[(x) + (y+1)*COL];
|
||||
//simple edge finding --begin
|
||||
//if (((fabs(temp1 - temph1)> 0.3)) && (fabs(temp1 - tempv1)> 0.3))
|
||||
if ((fabs(temp1 - temph1)> 0.2) && (fabs(temp1 - tempv1)> 0.2))
|
||||
//if (((temp1 > temph1)) && ((temp1 > tempv1)))
|
||||
{ // vertical find and horizontal find
|
||||
edgeMask[x+y*COL]++;
|
||||
} else {
|
||||
//edgeMask[x+y*COL] = 0;
|
||||
}
|
||||
//simple edge finding --end
|
||||
#endif
|
||||
|
||||
if ((temp1 + (float)(waterTempThreshold / 10.0)) < averageTemp ) // was max(averageTemp, normalWaterTemp))
|
||||
{
|
||||
if (blackOutTag == 0) {
|
||||
zoneMask[y*COL+x] ++;
|
||||
//upMask[(uint8_t)(x/3)*(uint8_t)(y/3)] ++; //translate to 11*8 matrix for upload
|
||||
upMask[(uint8_t)(y/3)][(uint8_t)(x/3)] ++; //translate to 11*8 matrix for upload
|
||||
waterSpillCount ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
waterSpillCount /=30;
|
||||
|
||||
}
|
||||
|
||||
|
@ -384,7 +490,7 @@ void STS_M1A_SENSOR_Read(STS_M1A_SensorDataTypeDef *m1a_data)
|
|||
{
|
||||
|
||||
m1a_data->waterSpillCount = blackOutTag==0?waterSpillCount:0;
|
||||
m1a_data->spillage_level = (uint8_t)(waterSpillCount*99/560.0); //((ROW-2)*(COL-2))); // (24-4) * (32 -4) minus edge dots
|
||||
m1a_data->spillage_level = (uint8_t)((m1a_data->waterSpillCount)*99/560.0); //((ROW-2)*(COL-2))); // (24-4) * (32 -4) minus edge dots
|
||||
m1a_data->averageTemp = averageTemp;
|
||||
m1a_data->averageTempInner = averageTempInner;
|
||||
m1a_data->centerTemp = centerTemp;
|
||||
|
@ -418,7 +524,7 @@ void STS_M1A_SENSOR_Read(STS_M1A_SensorDataTypeDef *m1a_data)
|
|||
memset(tempBuffer,0x0,sizeof(tempBuffer));
|
||||
|
||||
sprintf(tempBuffer,(char *)"\r\n## Blackout=%u ######\n##Read Sensor Spot CNT=%4d (areas) \r\n## V_cnt=%2d (lane) H_cnt=%2d (lane) \r\n## Spillage Level =%02.2f%% \r\n## averageTempInner=%02.2f C averageTemp=%02.2f C centerTemp=%.2f C MinTemp=%02.2f C maxTemp=%02.2f C \r\n ######## Gap_Average= %02.2f Gap_Inner = %02.2f \r\n",
|
||||
(uint8_t)blackOutTag, (uint8_t)m1a_data->waterSpillCount, (uint8_t)v_water_cnt, (uint8_t)h_water_cnt, (float)(m1a_data->spillage_level), (float)averageTempInner, (float)averageTemp, (float)centerTemp, (float)minTemp, (float)maxTemp, (float)(averageTemp - minTemp),(float)(averageTempInner - minTemp));
|
||||
(uint8_t)blackOutTag, (int)m1a_data->waterSpillCount, (int)v_water_cnt, (int)h_water_cnt, (float)(m1a_data->spillage_level), (float)averageTempInner, (float)averageTemp, (float)centerTemp, (float)minTemp, (float)maxTemp, (float)(averageTemp - minTemp),(float)(averageTempInner - minTemp));
|
||||
APP_LOG(TS_OFF, VLEVEL_H,(char *)tempBuffer);
|
||||
|
||||
|
||||
|
@ -426,8 +532,8 @@ void STS_M1A_SENSOR_Read(STS_M1A_SensorDataTypeDef *m1a_data)
|
|||
{
|
||||
for (uint8_t i=0; i< 4; i++) {
|
||||
memset(tempBuffer,0x0,sizeof(tempBuffer));
|
||||
sprintf(tempBuffer, (char *) " Top {%2u} : order =%2u X=%2u : Y=%2u \r\n", (uint8_t)i, (uint8_t)(order[i]),
|
||||
(uint8_t)(order[i]%(10)), (uint8_t)(order[i]/10));
|
||||
sprintf(tempBuffer, (char *) " Top {%2u} : order =%2u X=%2u : Y=%2u \r\n", (uint8_t)i, (int)(order[i]),
|
||||
(int)(order[i]%(10)), (int)(order[i]/10));
|
||||
APP_LOG(TS_OFF, VLEVEL_H,(char *)tempBuffer);
|
||||
}
|
||||
}
|
||||
|
@ -441,28 +547,25 @@ void mlx90640_display_process(void)
|
|||
memset((void *)edgeMask, 0, sizeof(edgeMask));
|
||||
memset((void *)upMask, 0, sizeof(upMask));
|
||||
|
||||
detectCycle = 0;
|
||||
uint16_t spillcountTemp =0, spot_cntTemp=0;
|
||||
|
||||
do {
|
||||
//APP_LOG(TS_OFF, VLEVEL_H, "Detection Cycle = %u \r\n", detectCycle);
|
||||
readTempValues();
|
||||
setTempScale();
|
||||
blackOutFilter();
|
||||
drawPicture();
|
||||
sortFocusAreas();
|
||||
findFocusArea();
|
||||
|
||||
#if 0
|
||||
if (blackOutTag == 0)
|
||||
{
|
||||
//BSP_LCD_DisplayOn();
|
||||
// LCD_BL_ON();
|
||||
spillcountTemp +=waterSpillCount;
|
||||
spot_cntTemp += spot_cnt;
|
||||
|
||||
} while (detectCycle++ < DetectCycleCount);
|
||||
|
||||
waterSpillCount = spillcountTemp/DetectCycleCount;
|
||||
spot_cnt /= DetectCycleCount ; //max(v_water_cnt, h_water_cnt);
|
||||
|
||||
if (detectCycle !=0)
|
||||
{
|
||||
drawPicture();
|
||||
drawMeasurement();
|
||||
}
|
||||
} else {
|
||||
|
||||
//LCD_BL_OFF();
|
||||
//BSP_LCD_DisplayOff();
|
||||
}
|
||||
#endif
|
||||
if (blackOutTag == 0)
|
||||
{
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "Water Spill Detected Level = %u of 600 \r\n", waterSpillCount);
|
||||
|
@ -509,9 +612,9 @@ void STS_SENSOR_Thermal_Graph_Test_Process(float *self_test_result, uint8_t coun
|
|||
}
|
||||
|
||||
|
||||
static void bubbleSort(uint8_t arr[], uint8_t len, uint8_t order[])
|
||||
static void bubbleSort(uint16_t arr[], uint16_t len, uint16_t order[])
|
||||
{
|
||||
uint8_t i, j, temp, t1;
|
||||
uint16_t i, j, temp, t1;
|
||||
for (j=0; j < len ; j++) {
|
||||
order[j] = j;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue