int main()
{
// some code
HAL_TIM_Base_Start(&htim3);
HAL_ADC_Start_DMA(&hadc1, &adcValue, DMABufferSize);
while(1)
{
// some code
}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim == &htim2)
{
Display4Digit7Seg_Show(&display, NextDigitPosition());
}
if(htim == &htim3)
{
HAL_ADC_Start_DMA(&hadc1, &adcValue, DMABufferSize);
}
}
static void MX_ADC1_Init(void)
{
/* USER CODE BEGIN ADC1_Init 0 */
/* USER CODE END ADC1_Init 0 */
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC1_Init 1 */
/* USER CODE END ADC1_Init 1 */
/** Common config
*/
hadc1.Instance = ADC1;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */
/* USER CODE END ADC1_Init 2 */
}
Timer::~Timer()
{
if(_isElapsed)
{
std::this_thread::sleep_for(1ms);
}
else
{
Reset();
}
}
using WidthProperty = Property<float>;
. И чтобы скопировать необходимо знать тип Property. Я еще придумал что можно сделать Map где в качестве ключа название типа (float, int, ...), а в качестве значения функция:template<typename T>
static IProperty* Copy(const IProperty& value)
{
return new Property<T>(value.Get<T>());
}
class IStringConvertable
{
public:
virtual ~IStringConvertable() = default;
virtual std::string Convert() const = 0;
virtual void ConvertBack(const std::string& data) = 0;
};
class ISerializer
{
public:
virtual ~ISerializer() = default;
virtual void Serialize(const std::filesystem::path& path,
const IStringConvertable& data) const = 0;
virtual void Deserialize(const std::filesystem::path& path,
IStringConvertable& data) const = 0;
};
class Serializer: public ISerializer
{
public:
void Serialize(const std::filesystem::path& path,
const IStringConvertable& data) const override;
void Deserialize(const std::filesystem::path& path,
IStringConvertable& data) const override;
template<typename T> requires std::derived_from<T, IStringConvertable>
T Deserialize(const std::filesystem::path& path) const
{
T data = {};
Deserialize(path, data);
return data;
}
};
void Serializer::Serialize(const std::filesystem::path& path,
const IStringConvertable& data) const
{
if(std::ofstream stream(path); stream.is_open())
{
stream << data.Convert();
}
}
void Serializer::Deserialize(const std::filesystem::path& path,
IStringConvertable& data) const
{
if(std::ifstream stream(path); stream.is_open())
{
std::string buffer;
stream >> buffer;
data.ConvertBack(buffer);
}
}
class IRangeSerializer
{
public:
virtual ~IRangeSerializer() = default;
virtual void Serialize(const std::filesystem::path& path,
const std::span<IStringConvertable*> range,
const std::string& delimetr) const = 0;
virtual void Deserialize(const std::filesystem::path& path,
std::span<IStringConvertable*> range,
const std::string& delimetr) const = 0;
};