删除多个类和结构体的拷贝构造函数和赋值运算符,确保不可复制性
Some checks failed
Build and Upload Artifact / build and upload-artifact (push) Has been cancelled

This commit is contained in:
chauyin
2025-05-21 18:54:12 +08:00
parent 69155f3ce1
commit 75b681e389
10 changed files with 47 additions and 6 deletions

View File

@@ -10,7 +10,11 @@ public:
explicit CanMv(UART_HandleTypeDef* uart)
: serialPort(std::make_unique<SerialPort>(uart, kBaudRate, kLength, kTimeout)) {}
~CanMv() = default;
~CanMv() = default;
CanMv(const CanMv&) = delete;
CanMv& operator=(const CanMv&) = delete;
CanMv(CanMv&&) = delete;
CanMv& operator=(CanMv&&) = delete;
private:
static constexpr uint32_t kBaudRate = 115200;

View File

@@ -10,7 +10,11 @@ public:
explicit DfPlayer(UART_HandleTypeDef* uart)
: serialPort(std::make_unique<SerialPort>(uart, kBaudRate, kLength, kTimeout)) {}
~DfPlayer() = default;
~DfPlayer() = default;
DfPlayer(const DfPlayer&) = delete;
DfPlayer& operator=(const DfPlayer&) = delete;
DfPlayer(DfPlayer&&) = delete;
DfPlayer& operator=(DfPlayer&&) = delete;
void Play();
void Stop();

View File

@@ -32,7 +32,11 @@ public:
explicit Hc05(UART_HandleTypeDef* uart)
: serialPort(std::make_unique<SerialPort>(uart, kBaudRate, kLength, kTimeout)) {}
~Hc05() = default;
~Hc05() = default;
Hc05(const Hc05&) = delete;
Hc05& operator=(const Hc05&) = delete;
Hc05(Hc05&&) = delete;
Hc05& operator=(Hc05&&) = delete;
Response SendCommand() {
Response data;

View File

@@ -16,6 +16,11 @@ public:
explicit Key(GpioHelper::Gpio gpio, GPIO_PinState normalStatus) : gpio(gpio), normalStatus(normalStatus) {
GpioHelper::GpioInit(gpio, GPIO_MODE_INPUT, normalStatus ? GPIO_PULLUP : GPIO_PULLDOWN);
}
~Key() = default;
Key(const Key&) = delete;
Key& operator=(const Key&) = delete;
Key(Key&&) = delete;
Key& operator=(Key&&) = delete;
bool IsPressed() {
auto reading = gpio.Read();

View File

@@ -25,6 +25,10 @@ public:
}
~SerialPort() = default;
SerialPort(const SerialPort&) = delete;
SerialPort& operator=(const SerialPort&) = delete;
SerialPort(SerialPort&&) = delete;
SerialPort& operator=(SerialPort&&) = delete;
void SetBaudRate(uint32_t baudRate) {
HAL_UART_DeInit(handle);

View File

@@ -19,6 +19,12 @@ public:
captureFlag = GetCaptureFlag(channel);
}
~Ultrasonic() = default;
Ultrasonic(const Ultrasonic&) = delete;
Ultrasonic& operator=(const Ultrasonic&) = delete;
Ultrasonic(Ultrasonic&&) = delete;
Ultrasonic& operator=(Ultrasonic&&) = delete;
double GetDistance(uint32_t time = 1) {
double distance = 0;
for (uint32_t cnt = 0; cnt < time; ++cnt) {
@@ -46,6 +52,7 @@ private:
double MeasureEchoTime() {
timer->Instance->CNT = 0;
uint32_t data[2];
__HAL_TIM_CLEAR_FLAG(timer, captureFlag);
HAL_TIM_IC_Start(timer, channel);
try {
for (auto& value : data) {