From 9b2296b0bc4539d1cce1dab0eeaf9c4d57fced0f Mon Sep 17 00:00:00 2001 From: Kasper Date: Wed, 14 Apr 2021 19:07:31 +0300 Subject: [PATCH] Fix sequence number having the wrong value * I'm really not sure what it is, but for some reason with the ternary operator the sequence number was ending up wrong - it would end up being 1 twice in a row, at startup it would be 0 when it should have been 1 and other issues. This fixes that * Also made it atomic Commit amended for code style by Adam Honse --- .../CorsairHydroPlatinumController.cpp | 11 ++++++++++- .../CorsairHydroPlatinumController.h | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Controllers/CorsairHydroPlatinumController/CorsairHydroPlatinumController.cpp b/Controllers/CorsairHydroPlatinumController/CorsairHydroPlatinumController.cpp index 11f883be..3d2af818 100644 --- a/Controllers/CorsairHydroPlatinumController/CorsairHydroPlatinumController.cpp +++ b/Controllers/CorsairHydroPlatinumController/CorsairHydroPlatinumController.cpp @@ -216,7 +216,16 @@ void CorsairHydroPlatinumController::SendColors(std::vector colors, un unsigned int CorsairHydroPlatinumController::GetSequenceNumber() { - return ((sequence_number < 32) ? sequence_number++ : sequence_number = 1) << 3; + if(sequence_number < 31) + { + sequence_number++; + } + else + { + sequence_number = 1; + } + + return(sequence_number << 3); } uint8_t CorsairHydroPlatinumController::ComputePEC(const void * data, size_t size) diff --git a/Controllers/CorsairHydroPlatinumController/CorsairHydroPlatinumController.h b/Controllers/CorsairHydroPlatinumController/CorsairHydroPlatinumController.h index 514f6e96..e8f7be79 100644 --- a/Controllers/CorsairHydroPlatinumController/CorsairHydroPlatinumController.h +++ b/Controllers/CorsairHydroPlatinumController/CorsairHydroPlatinumController.h @@ -43,7 +43,7 @@ private: std::string location; std::string firmware_version; - unsigned int sequence_number; + std::atomic sequence_number; void SendMagic(const uint8_t* magic, unsigned int command); void SendColors(std::vector colors, unsigned int start, unsigned int end, unsigned int command);