From 51a7e03717f11d1866d6cef392cd54a659a291f0 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Thu, 24 Aug 2023 08:40:20 +0800 Subject: [PATCH 1/5] add waterSpillLevel, waterSpillSpotCount for overall sensor data uplink --- mlx90640/mlx90640_lcd_display.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mlx90640/mlx90640_lcd_display.c b/mlx90640/mlx90640_lcd_display.c index 38479f3..0a96582 100644 --- a/mlx90640/mlx90640_lcd_display.c +++ b/mlx90640/mlx90640_lcd_display.c @@ -20,13 +20,14 @@ paramsMLX90640 mlx90640; static uint16_t eeMLX90640[832]; int status; volatile uint8_t draw_legend_once=0, normalPeopleTemp=32, blackOutTag=0, waterTempThreshold=8, normalWaterTemp=25, detectCycle=0, v_water_cnt=0,h_water_cnt=0; + // start with some initial colors float minTemp = 1.0f; float maxTemp = 60.0f; float centerTemp=0.0f; float averageTemp=0.0f; -volatile uint16_t waterSpillCount=0; - +volatile uint16_t waterSpillLevel=0, waterSpillSpotCount=0; +static uint16_t lastWaterSpillSpotCount=0; char tempBuffer[128]; // variables for interpolated colors uint8_t red, green, blue; @@ -179,7 +180,7 @@ static void drawMeasurement(void ) { BSP_LCD_SetFont(&Font16); memset(tempBuffer,0,sizeof(tempBuffer)); - sprintf(tempBuffer,(char *)"%2d", (uint8_t)max(v_water_cnt, h_water_cnt)); + sprintf(tempBuffer,(char *)"%2d", waterSpillSpotCount); BSP_LCD_DisplayStringAt(ST7789V_LCD_PIXEL_WIDTH-60, 15,(uint8_t *)tempBuffer,LEFT_MODE,LCD_COLOR_YELLOW); //APP_LOG(TS_OFF, VLEVEL_L, "%s\r\n",tempBuffer); @@ -236,6 +237,7 @@ static void drawPicture(void) } h_water_cnt = h_1 + h_2; + waterSpillSpotCount = max(v_water_cnt, h_water_cnt); } // Read pixel data from MLX90640. @@ -272,7 +274,7 @@ void blackOutFilter(void) } // ignore edge of FOV - waterSpillCount =0; + waterSpillLevel =0; for (y=2; y<22; y++) { for (x=2; x<30; x++) @@ -299,7 +301,7 @@ void blackOutFilter(void) if (blackOutTag == 0) { zoneMask[y*32+x] ++; - waterSpillCount ++; + waterSpillLevel ++; } } } @@ -316,6 +318,7 @@ void blackOutFilter(void) } void mlx90640_display_process(void) { + readTempValues(); setTempScale(); blackOutFilter(); @@ -336,7 +339,10 @@ void mlx90640_display_process(void) // BSP_LCD_DisplayOff(); } - //APP_LOG(TS_OFF, VLEVEL_L, "Water Spill Detected Level = %d of 600 \r\n", waterSpillCount); + if (waterSpillSpotCount != lastWaterSpillSpotCount) { + APP_LOG(TS_OFF, VLEVEL_L, "Water Spill Spot Detected Count = %2d Level = %d of 600 \r\n", waterSpillSpotCount,waterSpillLevel); + lastWaterSpillSpotCount = waterSpillSpotCount; + } } void mlx90640_display_init(void){ From d9bd3566fb86e559690e4434ed1cc799a46fc884 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Thu, 24 Aug 2023 11:45:23 +0800 Subject: [PATCH 2/5] refine waterSpillLevel show logic --- mlx90640/mlx90640_lcd_display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlx90640/mlx90640_lcd_display.c b/mlx90640/mlx90640_lcd_display.c index 0a96582..bd75144 100644 --- a/mlx90640/mlx90640_lcd_display.c +++ b/mlx90640/mlx90640_lcd_display.c @@ -339,7 +339,7 @@ void mlx90640_display_process(void) // BSP_LCD_DisplayOff(); } - if (waterSpillSpotCount != lastWaterSpillSpotCount) { + if ((waterSpillSpotCount != lastWaterSpillSpotCount)&&(waterSpillSpotCount != 0)) { APP_LOG(TS_OFF, VLEVEL_L, "Water Spill Spot Detected Count = %2d Level = %d of 600 \r\n", waterSpillSpotCount,waterSpillLevel); lastWaterSpillSpotCount = waterSpillSpotCount; } From 25c2638ac447665c008cab9e480c92e41e7f1673 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Thu, 24 Aug 2023 13:16:36 +0800 Subject: [PATCH 3/5] add calibrateWaterTemp for reference later --- mlx90640/mlx90640_lcd_display.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/mlx90640/mlx90640_lcd_display.c b/mlx90640/mlx90640_lcd_display.c index bd75144..56838f4 100644 --- a/mlx90640/mlx90640_lcd_display.c +++ b/mlx90640/mlx90640_lcd_display.c @@ -24,7 +24,7 @@ volatile uint8_t draw_legend_once=0, normalPeopleTemp=32, blackOutTag=0, waterTe // start with some initial colors float minTemp = 1.0f; float maxTemp = 60.0f; -float centerTemp=0.0f; +volatile float centerTemp=0.0f, calibrationWaterTemp=0.0f; float averageTemp=0.0f; volatile uint16_t waterSpillLevel=0, waterSpillSpotCount=0; static uint16_t lastWaterSpillSpotCount=0; @@ -39,7 +39,7 @@ 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}; - +void setCalibrationWaterTemp(void); void blackOutFilter(void); static uint16_t TempToColor(float val); static void setTempScale(void); @@ -48,6 +48,7 @@ static void drawLegend(void); static void drawMeasurement(void); static void drawPicture(void); static void readTempValues(void); + extern LCD_DrawPropTypeDef DrawProp; static uint16_t TempToColor(float val) { @@ -89,8 +90,20 @@ static uint16_t TempToColor(float val) // use the displays color mapping function to get 5-6-5 color palette (R=5 bits, G=6 bits, B-5 bits) return BSP_LCD_GetColor565(red, green, blue); } +void setCalibrationWaterTemp(void) +{ + char tempbuf[128]=""; + readTempValues(); + setTempScale(); + calibrationWaterTemp = centerTemp; + memset(tempbuf,0x0,sizeof(tempbuf)); + sprintf(tempbuf,(char *)"Calibration Water Temp =%2.2f \r\n", calibrationWaterTemp); + APP_LOG(TS_OFF,VLEVEL_L,"%s\r\n",tempbuf); + +} static void setTempScale(void) { + char tempbuf[250]=""; minTemp = 255; maxTemp = 0; averageTemp =0.0; @@ -103,6 +116,12 @@ static void setTempScale(void) { } averageTemp /= 768; + centerTemp = (tempValues[383 - 16] + tempValues[383 - 15] + tempValues[384 + 15] + tempValues[384 + 16]) / 4; + + memset(tempbuf,0x0,sizeof(tempbuf)); + sprintf(tempbuf,(char *)"AVG Temp=%2.2f CenterTemp=%2.2f normalWaterTemp=%2.2f CalibratedWaterTemp=%2.2f\r\n", (float)averageTemp, (float)centerTemp, (float)normalWaterTemp, (float)calibrationWaterTemp); + APP_LOG(TS_OFF,VLEVEL_L,"%s\r\n",tempbuf); + if (maxTemp > normalPeopleTemp) { blackOutTag = 1; @@ -182,7 +201,6 @@ static void drawMeasurement(void ) { memset(tempBuffer,0,sizeof(tempBuffer)); sprintf(tempBuffer,(char *)"%2d", waterSpillSpotCount); BSP_LCD_DisplayStringAt(ST7789V_LCD_PIXEL_WIDTH-60, 15,(uint8_t *)tempBuffer,LEFT_MODE,LCD_COLOR_YELLOW); - //APP_LOG(TS_OFF, VLEVEL_L, "%s\r\n",tempBuffer); } @@ -295,8 +313,11 @@ void blackOutFilter(void) //simple edge finding --end + if (calibrationWaterTemp > 0.0f) { // we have calibrated water temp process done) - if ((temp1 + (float)(waterTempThreshold / 10.0)) < max(averageTemp, normalWaterTemp)) + normalWaterTemp = calibrationWaterTemp; + } + if ((temp1 + (float)(waterTempThreshold / 10.0)) < min(averageTemp, normalWaterTemp)) { if (blackOutTag == 0) { From a9542a3d0104d920b6b7b072528d7c394b962c4c Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Thu, 24 Aug 2023 13:19:30 +0800 Subject: [PATCH 4/5] refine output value format --- mlx90640/mlx90640_lcd_display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlx90640/mlx90640_lcd_display.c b/mlx90640/mlx90640_lcd_display.c index 56838f4..9b93e50 100644 --- a/mlx90640/mlx90640_lcd_display.c +++ b/mlx90640/mlx90640_lcd_display.c @@ -119,7 +119,7 @@ static void setTempScale(void) { centerTemp = (tempValues[383 - 16] + tempValues[383 - 15] + tempValues[384 + 15] + tempValues[384 + 16]) / 4; memset(tempbuf,0x0,sizeof(tempbuf)); - sprintf(tempbuf,(char *)"AVG Temp=%2.2f CenterTemp=%2.2f normalWaterTemp=%2.2f CalibratedWaterTemp=%2.2f\r\n", (float)averageTemp, (float)centerTemp, (float)normalWaterTemp, (float)calibrationWaterTemp); + sprintf(tempbuf,(char *)"Temp AVG=%2.2fC Center=%2.2fC normalWater=%2.2fC CalibratedWater=%2.2fC\r\n", (float)averageTemp, (float)centerTemp, (float)normalWaterTemp, (float)calibrationWaterTemp); APP_LOG(TS_OFF,VLEVEL_L,"%s\r\n",tempbuf); if (maxTemp > normalPeopleTemp) From 5e99684106096ccf79c571db54b302efc6a01d1a Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Thu, 24 Aug 2023 13:31:43 +0800 Subject: [PATCH 5/5] recover back emissivity to 0.95f --- mlx90640/mlx90640_lcd_display.c | 2 +- mlx90640/mlx90640_user.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mlx90640/mlx90640_lcd_display.c b/mlx90640/mlx90640_lcd_display.c index 9b93e50..f209acc 100644 --- a/mlx90640/mlx90640_lcd_display.c +++ b/mlx90640/mlx90640_lcd_display.c @@ -303,7 +303,7 @@ void blackOutFilter(void) //simple edge finding --begin //if (((fabs(temp1 - temph1)> 0.3)) && (fabs(temp1 - tempv1)> 0.3)) - if (((temp1 - temph1)> 0.2) && ((temp1 - tempv1)> 0.2)) + if (((temp1 - temph1)> 0.3) && ((temp1 - tempv1)> 0.3)) //if (((temp1 > temph1)) && ((temp1 > tempv1))) { // vertical find and horizontal find edgeMask[x+y*32]++; diff --git a/mlx90640/mlx90640_user.c b/mlx90640/mlx90640_user.c index 29b82bb..af31e6c 100644 --- a/mlx90640/mlx90640_user.c +++ b/mlx90640/mlx90640_user.c @@ -2,7 +2,7 @@ #include "mlx90640_user.h" #include "sys_app.h" uint16_t frame[834]; -float emissivity=0.15f; //0.95f +float emissivity=0.95f; //0.95f uint8_t mlx90640_init(uint8_t refresh_rate,paramsMLX90640 *mlx90640) { int status;