In the freertos task, we add code to periodically obtain temperature and time, mainly to read the temperature value, date, time, and send a semaphore so that the model can receive the semaphore and display it.
/* USER CODE END Header_StartDefaultTask */ void StartDefaultTask ( void *argument)
{
/* USER CODE BEGIN defaultTask */ static int16_t data_raw_temperature; static uint8_t whoamI;
stmdev_ctx_t dev_ctx;
dev_ctx.write_reg = platform_write;
dev_ctx.read_reg = platform_read;
dev_ctx.hand le = &SENSOR_BUS;
/* Check device ID */ stts22h_dev_id_get (&dev_ctx, &whoamI); if (whoamI != STTS22H_ID) while (1)
{ osDelay (10);
}
/* Infinite loop */ stts22h_temp_data_rate_set (&dev_ctx, STTS22H_1Hz ); for (;;)
{
uint8_t flag; stts22h_temp_flag_data_ready_get (&dev_ctx, &flag); if (flag) {
/* Read temperature data */ memset (&data_raw_temperature, 0, sizeof (int16_t)); stts22h_temperature_raw_get (&dev_ctx, &data_raw_temperature);
temperature_degC = stts22h_from_lsb_to_cels ius (
data_raw_temperature); HAL_RTC_GetTime (&hrtc, &GetTime, RTC_FORMAT_BIN); HAL_RTC_GetDate (&hrtc, &GetData, RTC_FORMAT_BIN); osSemaphoreRelease (myBinarySemtempHandle); osDelay (1000);
}
}
/* USER CODE END defaultTask */
}
Add a virtual function in modelListener.hpp and implement it in model.cpp: virtual void NotifyTempValudChanged ( float value, RTC_TimeTypeDef GetTime, RTC_DateTypeDef GetData) {} void Model::tick ()
{ if ( osSemaphoreGetCount (myBinarySemtempHandle)>0)
{
modelListener->NotifyTempValudChanged(temperature_degC,
GetTime, GetData);
}
}
Construct the virtual function NotifyTempValudChanged in screen1Presenter.hpp and implement it in screen1Presenter.cpp: virtual void NotifyTempValudChanged ( float value, RTC_TimeTypeDef GetTime, RTC_DateTypeDef GetData); void Screen1Presenter::NotifyTempValudChanged ( float value,
RTC_TimeTypeDef GetTime, RTC_DateTypeDef GetData)
{
view. setTempValud (value, GetTime, GetData);
}
The Stm32U599J-DK development board has a built-in thermometer, and the stm32u599J comes standard with an RTC peripheral, which can achieve accurate output and configuration of date and time.
In this project, we mainly implemented the MPV design pattern to achieve separate development of the background and the interface.