343 lines
9.5 KiB
C
343 lines
9.5 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file : main.c
|
|
* @brief : Main program body
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* Copyright (c) 2021 STMicroelectronics.
|
|
* All rights reserved.
|
|
*
|
|
* This software is licensed under terms that can be found in the LICENSE file
|
|
* in the root directory of this software component.
|
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "main.h"
|
|
#include "app_lorawan.h"
|
|
#include "gpio.h"
|
|
#include "adc.h"
|
|
#include "dma.h"
|
|
#include "i2c.h"
|
|
#include "spi.h"
|
|
#include "tim.h"
|
|
#include "sys_app.h"
|
|
/* Private includes ----------------------------------------------------------*/
|
|
/* USER CODE BEGIN Includes */
|
|
#if 0
|
|
#include "mlx90640_user.h"
|
|
#include "user.h"
|
|
#include "bmp.h"
|
|
#include "st7789.h"
|
|
#endif
|
|
#include "MLX90640_API.h"
|
|
#include "MLX90640_I2C_Driver.h"
|
|
#include "stm32_hx8347d_lcd.h"
|
|
#include "Fonts/fonts.h"
|
|
#include "mlx90640_lcd_display.h"
|
|
/* USER CODE END Includes */
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
/* USER CODE BEGIN PTD */
|
|
|
|
/* USER CODE END PTD */
|
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
/* USER CODE BEGIN PD */
|
|
/* USER CODE END PD */
|
|
|
|
/* Private macro -------------------------------------------------------------*/
|
|
/* USER CODE BEGIN PM */
|
|
|
|
/* USER CODE END PM */
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN PV */
|
|
|
|
/* USER CODE END PV */
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
void SystemClock_Config(void);
|
|
/* USER CODE BEGIN PFP */
|
|
#if 0
|
|
paramsMLX90640 mlx90640;
|
|
static float mlx90640To[768];
|
|
BMP_8 bmp8[768];
|
|
float max_temp;
|
|
float min_temp;
|
|
float center_temp;
|
|
#endif
|
|
/* USER CODE END PFP */
|
|
|
|
/* Private user code ---------------------------------------------------------*/
|
|
/* USER CODE BEGIN 0 */
|
|
#if 0
|
|
uint32_t voltage_adc[1];
|
|
float bat_voltage;
|
|
extern BMP_INFO bmpinfo;
|
|
void test();
|
|
ENCODER my_encoder;
|
|
uint8_t img_method_arr[4]={GCM_Pseudo2,GCM_Pseudo1,GCM_Metal2,GCM_Gray};
|
|
MENU my_menu={
|
|
{"GCM_Pseudo2 ","GCM_Pseudo1 ","GCM_Metal2 ","GCM_Gray "},
|
|
0,
|
|
{"Nearest ","Bilinear "},
|
|
1,
|
|
{"screenshot","saving ","success ","fail "},
|
|
0
|
|
};
|
|
uint8_t key1_press,key2_press,button_press=1;
|
|
//menu1 bin_size or resize
|
|
//menu2 color_method
|
|
//menu3 screenshot
|
|
uint8_t chose_menu_index=0;
|
|
char buf[200];
|
|
#endif
|
|
/* USER CODE END 0 */
|
|
|
|
/**
|
|
* @brief The application entry point.
|
|
* @retval int
|
|
*/
|
|
int main(void)
|
|
{
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* USER CODE END 1 */
|
|
|
|
/* MCU Configuration--------------------------------------------------------*/
|
|
|
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
HAL_Init();
|
|
|
|
/* USER CODE BEGIN Init */
|
|
|
|
/* USER CODE END Init */
|
|
|
|
/* Configure the system clock */
|
|
SystemClock_Config();
|
|
|
|
/* USER CODE BEGIN SysInit */
|
|
|
|
/* USER CODE END SysInit */
|
|
|
|
/* Initialize all configured peripherals */
|
|
|
|
MX_LoRaWAN_Init();
|
|
/* USER CODE BEGIN 2 */
|
|
//MX_ADC_Init();
|
|
MX_GPIO_Init();
|
|
MX_DMA_Init();
|
|
MX_SPI_Init();
|
|
|
|
|
|
MX_I2C_Init();
|
|
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_L, "START LCD init....\r\n");
|
|
|
|
BSP_LCD_Init();
|
|
BSP_LCD_DisplayOn();
|
|
//HAL_Delay(2000);
|
|
//BSP_LCD_DisplayOff();
|
|
BSP_LCD_Test();
|
|
|
|
MLX90640_I2CInit();
|
|
mlx90640_display_init();
|
|
|
|
#if 0
|
|
APP_LOG(TS_OFF, VLEVEL_L, "DISPLAY ON....\r\n");
|
|
BSP_LCD_DisplayOn();
|
|
BSP_LCD_Clear(LCD_COLOR_YELLOW);
|
|
APP_LOG(TS_OFF, VLEVEL_L, "WIDTH = %d, HEIGHT =%d \r\n", BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
|
|
BSP_LCD_DisplayStringAt(45,45,"SmarToilets",LEFT_MODE,LCD_COLOR_BLUE);
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_L, "WIDTH = %d, HEIGHT =%d \r\n", BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
|
|
BSP_LCD_DisplayStringAt(45,45,"SmarToilets",LEFT_MODE,LCD_COLOR_RED);
|
|
APP_LOG(TS_OFF, VLEVEL_L, "DISPLAY LOGO....\r\n");
|
|
BSP_LCD_DisplayStringAt(45,45,"SmarToilets",LEFT_MODE,LCD_COLOR_BLUE);
|
|
#endif
|
|
while (1)
|
|
{
|
|
/* USER CODE END WHILE */
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
//BSP_LCD_DisplayOff();
|
|
mlx90640_display_process();
|
|
}
|
|
//HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_1);
|
|
#if 0
|
|
ST7789_Init();
|
|
APP_LOG(TS_OFF,VLEVEL_L,"\r\n Set Black Light...on....");
|
|
ST7789_SetBackLight(1);
|
|
ST7789_Test();
|
|
|
|
ST7789_SetBackLight(1);
|
|
//bmp_header_init(&bmpinfo);
|
|
//HAL_TIM_Base_Start_IT(&htim4);
|
|
//HAL_TIM_Encoder_Start(&htim2,TIM_CHANNEL_ALL);
|
|
//HAL_ADC_Start_DMA(&hadc,voltage_adc,1);
|
|
|
|
mlx90640_init(FPS2HZ,&mlx90640);
|
|
my_menu.chose_color_method_index=0;
|
|
|
|
while (1)
|
|
{
|
|
/* USER CODE END WHILE */
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
|
|
APP_LOG(TS_OFF,VLEVEL_L,"\r\nGet Raw data \r\n");
|
|
|
|
mlx90640_get_temp_mat(&mlx90640,mlx90640To);
|
|
APP_LOG(TS_OFF,VLEVEL_L,"\r\nSet backlight 1 \r\n");
|
|
ST7789_SetBackLight(1);
|
|
|
|
chose_menu_index =0;
|
|
my_menu.chose_color_method_index = chose_menu_index;
|
|
my_menu.chose_color_method_index++;
|
|
APP_LOG(TS_OFF,VLEVEL_L,"\r\n Set Method %u \r\n", (uint8_t)(img_method_arr[my_menu.chose_color_method_index]));
|
|
mlx90640_get_temp_mat(&mlx90640,mlx90640To);
|
|
draw_spectrum(img_method_arr[my_menu.chose_color_method_index]);
|
|
HAL_Delay(2000);
|
|
|
|
my_menu.chose_color_method_index++;
|
|
APP_LOG(TS_OFF,VLEVEL_L,"\r\n Set Method %u \r\n", (uint8_t)(img_method_arr[my_menu.chose_color_method_index]));
|
|
draw_spectrum(img_method_arr[my_menu.chose_color_method_index]);
|
|
HAL_Delay(2000);
|
|
|
|
my_menu.chose_color_method_index++;
|
|
APP_LOG(TS_OFF,VLEVEL_L,"\r\n Set Method %u \r\n", (uint8_t)(img_method_arr[my_menu.chose_color_method_index]));
|
|
draw_spectrum(img_method_arr[my_menu.chose_color_method_index]);
|
|
HAL_Delay(2000);
|
|
|
|
my_menu.chose_color_method_index++;
|
|
APP_LOG(TS_OFF,VLEVEL_L,"\r\n Set Method %u \r\n", (uint8_t)(img_method_arr[my_menu.chose_color_method_index]));
|
|
draw_spectrum(img_method_arr[my_menu.chose_color_method_index]);
|
|
HAL_Delay(2000);
|
|
|
|
APP_LOG(TS_OFF,VLEVEL_L,"\r\n");
|
|
for (int i=0; i< 24; i++)
|
|
{
|
|
APP_LOG(TS_OFF,VLEVEL_L,"\r\n");
|
|
for (int j=0; j < 32; j++) {
|
|
sprintf(buf,"%.1f", (float)(mlx90640To[j*i]));
|
|
APP_LOG(TS_OFF,VLEVEL_L,"%s ", buf);
|
|
}
|
|
HAL_Delay(2);
|
|
}
|
|
|
|
while(temp_to_bmp8(bmp8,mlx90640To,768,&max_temp,&min_temp,1))
|
|
{//温度异常重新获取
|
|
mlx90640_get_temp_mat(&mlx90640,mlx90640To);
|
|
}
|
|
sprintf(buf,"\r\n\nMax=%.2f, Min=%.2f, Center=%.2f\n",(float)max_temp, (float)min_temp, (float)mlx90640To[768/2]);
|
|
APP_LOG(TS_OFF,VLEVEL_L,"%s\r\n", buf);
|
|
}
|
|
#endif
|
|
/* USER CODE END 2 */
|
|
|
|
/* Infinite loop */
|
|
/* USER CODE BEGIN WHILE */
|
|
while (1)
|
|
{
|
|
/* USER CODE END WHILE */
|
|
MX_LoRaWAN_Process();
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
}
|
|
/* USER CODE END 3 */
|
|
}
|
|
|
|
/**
|
|
* @brief System Clock Configuration
|
|
* @retval None
|
|
*/
|
|
void SystemClock_Config(void)
|
|
{
|
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
|
|
/** Configure LSE Drive Capability
|
|
*/
|
|
HAL_PWR_EnableBkUpAccess();
|
|
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
|
|
|
|
/** Configure the main internal regulator output voltage
|
|
*/
|
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
|
|
|
/** Initializes the CPU, AHB and APB buses clocks
|
|
*/
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;
|
|
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
|
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
|
|
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
|
|
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_11;
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
|
|
/** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers
|
|
*/
|
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK3|RCC_CLOCKTYPE_HCLK
|
|
|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
|
|
|RCC_CLOCKTYPE_PCLK2;
|
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
|
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
RCC_ClkInitStruct.AHBCLK3Divider = RCC_SYSCLK_DIV1;
|
|
|
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
}
|
|
|
|
/* USER CODE BEGIN 4 */
|
|
|
|
/* USER CODE END 4 */
|
|
|
|
/**
|
|
* @brief This function is executed in case of error occurrence.
|
|
* @retval None
|
|
*/
|
|
void Error_Handler(void)
|
|
{
|
|
/* USER CODE BEGIN Error_Handler_Debug */
|
|
/* User can add his own implementation to report the HAL error return state */
|
|
__disable_irq();
|
|
while (1)
|
|
{
|
|
}
|
|
/* USER CODE END Error_Handler_Debug */
|
|
}
|
|
|
|
#ifdef USE_FULL_ASSERT
|
|
/**
|
|
* @brief Reports the name of the source file and the source line number
|
|
* where the assert_param error has occurred.
|
|
* @param file: pointer to the source file name
|
|
* @param line: assert_param error line source number
|
|
* @retval None
|
|
*/
|
|
void assert_failed(uint8_t *file, uint32_t line)
|
|
{
|
|
/* USER CODE BEGIN 6 */
|
|
/* User can add his own implementation to report the file name and line number,
|
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
while (1)
|
|
{
|
|
}
|
|
/* USER CODE END 6 */
|
|
}
|
|
#endif /* USE_FULL_ASSERT */
|