refine output format

This commit is contained in:
Yunhorn 2023-12-19 16:41:29 +08:00
parent 474ace4b74
commit a1ea2a9ee7
1 changed files with 32 additions and 26 deletions

View File

@ -37,8 +37,10 @@ float intPoint, val, a, b, c, d, ii;
int x, y, i, j;
// array for the 32 x 24 measured tempValues
static float tempValues[32*24];
volatile uint8_t zoneMask[32*24]={0x0}, edgeMask[32*24]={0x0}, upMask[10*9]={0x0};
#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 STS_M1A_SensorDataTypeDef m1a_data;
void blackOutFilter(void);
static uint16_t TempToColor(float val);
@ -201,27 +203,29 @@ static void drawMeasurement(void ) {
static void drawPicture(void)
{
uint8_t h_cnt[32]={0},v_cnt[24]={0}; //for horizon and vertical _water spill count
uint8_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<23; y++)
for (y=1; y<ROW-1; y++)
{
#if 0
BSP_LCD_FillRect(0, y*11+16, ST7789V_LCD_PIXEL_WIDTH, 4, LCD_COLOR_BLACK);
#endif
for (x=1; x<31; x++) // Start from 2, ignore edge of FOV
for (x=1; x<COL-1; x++) // Start from 2, ignore edge of FOV
{
if (zoneMask[y*32+x] > 3) {
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]);
#if 0
BSP_LCD_FillRect(x*8, y*11+16, 4, 4, LCD_COLOR_GREEN);
#endif
upMask[(x/3)*(y/3)] ++;
//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;
} else if (edgeMask[y*32+x] > 3) {
} else if (edgeMask[y*COL+x] > 3) {
#if 0
BSP_LCD_FillRect(x*8, y*11+16, 2, 2, LCD_COLOR_GRAY);
#endif
@ -238,24 +242,24 @@ static void drawPicture(void)
h_water_cnt=0;
uint8_t v_1=0, v_2=0,h_1=0,h_2=0;
for (y=1; y<12; y++) {
for (y=1; y<ROW/2; y++) {
if ((1 == v_cnt[y]) && (0 == v_cnt[y-1])) {
v_1++;
}
}
for (y=12; y<23; y++) {
for (y=12; y<ROW-1; y++) {
if ((1 == v_cnt[y]) && (0 == v_cnt[y-1])) {
v_2++;
}
}
v_water_cnt= v_1 + v_2;
for (x=1; x<16; x++) {
for (x=1; x<COL/2; x++) {
if ((1 == h_cnt[x]) && (0 == h_cnt[x-1])) {
h_1 ++;
}
}
for (x=16; x<32; x++) {
for (x=16; x<COL; x++) {
if ((1 == h_cnt[x]) && (0 == h_cnt[x-1])) {
h_2 ++;
}
@ -302,22 +306,22 @@ void blackOutFilter(void)
*/
// ignore edge of FOV
waterSpillCount =0;
for (y=2; y<22; y++)
for (y=1; y<ROW-1; y++)
{
for (x=2; x<30; x++)
for (x=1; x<COL-1; x++)
{
temp1 = (float)tempValues[(x) + (y*32)];
temph1 = (float)tempValues[(x) + (y-1)*32];
tempv1 = (float)tempValues[(x) + (y+1)*32];
temp1 = (float)tempValues[(x) + (y*COL)];
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*32]++;
edgeMask[x+y*COL]++;
} else {
//edgeMask[x+y*32] = 0;
//edgeMask[x+y*COL] = 0;
}
//simple edge finding --end
@ -327,8 +331,9 @@ void blackOutFilter(void)
{
if (blackOutTag == 0) {
zoneMask[y*32+x] ++;
upMask[(x*y)/9] ++; //translate to 10*8 matrix for upload
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 ++;
}
}
@ -350,9 +355,9 @@ void blackOutFilter(void)
void STS_M1A_SENSOR_Read(STS_M1A_SensorDataTypeDef *m1a_data)
{
uint8_t order[80];
m1a_data->waterSpillCount = waterSpillCount;
m1a_data->spillage_level = (uint8_t)((int)waterSpillCount*99/560)&0xff; // (24-4) * (32 -4) minus edge dots
m1a_data->spillage_level = (uint8_t)((int)waterSpillCount*99/((ROW-2)*(COL-2)))&0xff; // (24-4) * (32 -4) minus edge dots
m1a_data->averageTemp = averageTemp;
m1a_data->centerTemp = centerTemp;
m1a_data->minTemp = minTemp;
@ -366,7 +371,7 @@ void STS_M1A_SENSOR_Read(STS_M1A_SensorDataTypeDef *m1a_data)
//memcpy((void *)m1a_data->waterSpillMatrix,(const void *) zoneMask,sizeof(zoneMask));
if (waterSpillCount != 0) {
bubbleSort((uint8_t*)upMask, 80, (uint8_t*)order);
bubbleSort((uint8_t*)upMask, (ROW/3)*(COL/3), (uint8_t*)order);
for (uint8_t i= waterSpillCount; i<80;i++) {
order[i] = 0;
}
@ -387,7 +392,8 @@ void STS_M1A_SENSOR_Read(STS_M1A_SensorDataTypeDef *m1a_data)
{
for (uint8_t i=0; i< 4; i++) {
memset(tempBuffer,0,sizeof(tempBuffer));
sprintf(tempBuffer, (char *) " Top {%1d} =order =%2u X=%2u : Y=%2u \r\n", i, order[i], (uint8_t)(order[i]/10), (uint8_t)(order[i]%10));
sprintf(tempBuffer, (char *) " Top {%1d} =order =%2u X=%2u : Y=%2u \r\n", i, order[i],
(uint8_t)(order[i]%(COL/3)), (uint8_t)(order[i]/(COL/3)));
APP_LOG(TS_OFF, VLEVEL_L,(char *)tempBuffer);
}
}
@ -419,7 +425,7 @@ void mlx90640_display_process(void)
//BSP_LCD_DisplayOff();
}
#endif
APP_LOG(TS_OFF, VLEVEL_L, "Water Spill Detected Level = %d of 600 \r\n", waterSpillCount);
APP_LOG(TS_OFF, VLEVEL_L, "Water Spill Detected Level = %d of 768 \r\n", waterSpillCount);
}
void mlx90640_display_init(void){