diff --git a/include/EStopManager.h b/include/EStopManager.h index 6c5b575f..167a7f4c 100644 --- a/include/EStopManager.h +++ b/include/EStopManager.h @@ -1,10 +1,9 @@ #pragma once -#include #include namespace OpenShock::EStopManager { - enum class EStopStatus : uint8_t { + enum class EStopStatus : std::uint8_t { ALL_CLEAR, // The initial, idle state ESTOPPED_AND_HELD, // The EStop has been pressed and has not yet been released ESTOPPED, // Idle EStopped state @@ -14,5 +13,5 @@ namespace OpenShock::EStopManager { void Init(); EStopStatus Update(); bool IsEStopped(); - unsigned long WhenEStopped(); + std::int64_t WhenEStopped(); } // namespace OpenShock::EStopManager diff --git a/include/GatewayClient.h b/include/GatewayClient.h index a083052b..1b4e2002 100644 --- a/include/GatewayClient.h +++ b/include/GatewayClient.h @@ -4,6 +4,7 @@ #include #include +#include namespace OpenShock { class GatewayClient { @@ -11,7 +12,7 @@ namespace OpenShock { GatewayClient(const std::string& authToken); ~GatewayClient(); - enum class State { + enum class State : std::uint8_t { Disconnected, Disconnecting, Connecting, diff --git a/include/WebSocketMessageType.h b/include/WebSocketMessageType.h index 3efd9bc9..8b0ceb6b 100644 --- a/include/WebSocketMessageType.h +++ b/include/WebSocketMessageType.h @@ -1,7 +1,9 @@ #pragma once +#include + namespace OpenShock { - enum class WebSocketMessageType { + enum class WebSocketMessageType : std::uint8_t { Error, Disconnected, Connected, diff --git a/platformio.ini b/platformio.ini index b9ccb147..a47d11bb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -51,7 +51,7 @@ build_flags = ; https://docs.platformio.org/en/latest/boards/espressif32/lolin_s2_mini.html [env:Wemos-Lolin-S2-Mini] -board = Wemos-Lolin-S2-Mini # override +board = Wemos-Lolin-S2-Mini ; override custom_openshock.chip = ESP32-S2 custom_openshock.chip_variant = N4R2 build_flags = @@ -59,21 +59,21 @@ build_flags = ; https://docs.platformio.org/en/latest/boards/espressif32/lolin_s3.html [env:Wemos-Lolin-S3] -board = Wemos-Lolin-S3 # override +board = Wemos-Lolin-S3 ; override custom_openshock.chip = ESP32-S3 custom_openshock.chip_variant = N16R8 build_flags = -DOPENSHOCK_LED_WS2812B=38 [env:Pishock-2023] -board = Wemos-D1-Mini-ESP32 # override +board = Wemos-D1-Mini-ESP32 ; override custom_openshock.chip = ESP32-D0WD build_flags = -DOPENSHOCK_LED_GPIO=2 -DOPENSHOCK_TX_PIN=12 [env:Pishock-Lite-2021] -board = Wemos-D1-Mini-ESP32 # override +board = Wemos-D1-Mini-ESP32 ; override custom_openshock.chip = ESP32-D0WDQ6 build_flags = -DOPENSHOCK_LED_GPIO=2 @@ -81,7 +81,7 @@ build_flags = ; https://docs.platformio.org/en/latest//boards/espressif32/seeed_xiao_esp32s3.html [env:Seeed-Xiao-ESP32S3] -board = seeed_xiao_esp32s3 # builtin +board = seeed_xiao_esp32s3 ; builtin custom_openshock.chip = ESP32-S3 custom_openshock.chip_variant = N8R8 build_flags = diff --git a/src/CaptivePortalInstance.cpp b/src/CaptivePortalInstance.cpp index 7d53336f..87ce31bc 100644 --- a/src/CaptivePortalInstance.cpp +++ b/src/CaptivePortalInstance.cpp @@ -5,6 +5,7 @@ #include "GatewayConnectionManager.h" #include "Logging.h" #include "serialization/WSLocal.h" + #include "wifi/WiFiManager.h" #include "serialization/_fbs/DeviceToLocalMessage_generated.h" @@ -140,7 +141,7 @@ void CaptivePortalInstance::handleWebSocketEvent(std::uint8_t socketId, WebSocke break; default: m_socketDeFragger.clear(); - ESP_LOGE(TAG, "Unknown WebSocket event type: %d", type); + ESP_LOGE(TAG, "Unknown WebSocket event type: %u", type); break; } } diff --git a/src/EStopManager.cpp b/src/EStopManager.cpp index 35e21908..39da390e 100644 --- a/src/EStopManager.cpp +++ b/src/EStopManager.cpp @@ -1,16 +1,19 @@ -#include "Arduino.h" -#include +#include "EStopManager.h" +#include "Time.h" +#include "Logging.h" #include "VisualStateManager.h" +#include + const char* const TAG = "EStopManager"; using namespace OpenShock; static EStopManager::EStopStatus s_estopStatus = EStopManager::EStopStatus::ALL_CLEAR; -static unsigned long s_estopHoldToClearTime = 5000; -static unsigned long s_lastEStopButtonStateChange = 0; -static unsigned long s_estoppedAt = 0; +static std::uint32_t s_estopHoldToClearTime = 5000; +static std::int64_t s_lastEStopButtonStateChange = 0; +static std::int64_t s_estoppedAt = 0; static bool s_lastEStopButtonState = HIGH; static std::uint8_t s_estopPin; @@ -34,7 +37,7 @@ bool EStopManager::IsEStopped() { #endif } -unsigned long EStopManager::WhenEStopped() { +std::int64_t EStopManager::WhenEStopped() { #ifdef OPENSHOCK_ESTOP_PIN if (IsEStopped()) { return s_estoppedAt; @@ -50,7 +53,7 @@ EStopManager::EStopStatus EStopManager::Update() { #ifdef OPENSHOCK_ESTOP_PIN bool buttonState = digitalRead(s_estopPin); if (buttonState != s_lastEStopButtonState) { - s_lastEStopButtonStateChange = millis(); + s_lastEStopButtonStateChange = OpenShock::millis(); } switch (s_estopStatus) { case EStopManager::EStopStatus::ALL_CLEAR: @@ -69,7 +72,7 @@ EStopManager::EStopStatus EStopManager::Update() { break; case EStopManager::EStopStatus::ESTOPPED: // If the button is held again for the specified time after being released, clear the EStop - if (buttonState == LOW && s_lastEStopButtonState == LOW && s_lastEStopButtonStateChange + s_estopHoldToClearTime <= millis()) { + if (buttonState == LOW && s_lastEStopButtonState == LOW && s_lastEStopButtonStateChange + s_estopHoldToClearTime <= OpenShock::millis()) { s_estopStatus = EStopManager::EStopStatus::ESTOPPED_CLEARED; ESP_LOGI(TAG, "Clearing EStop on button release!"); OpenShock::VisualStateManager::SetEmergencyStop(false); diff --git a/src/event_handlers/websocket/gateway/ShockerCommandList.cpp b/src/event_handlers/websocket/gateway/ShockerCommandList.cpp index 9fddb54a..d1b9f6a2 100644 --- a/src/event_handlers/websocket/gateway/ShockerCommandList.cpp +++ b/src/event_handlers/websocket/gateway/ShockerCommandList.cpp @@ -23,7 +23,7 @@ void _Private::HandleShockerCommandList(const OpenShock::Serialization::ServerTo return; } - ESP_LOGV(TAG, "Received command list from API (%d commands)", commands->size()); + ESP_LOGV(TAG, "Received command list from API (%llu commands)", commands->size()); for (auto command : *commands) { std::uint16_t id = command->id(); diff --git a/src/event_handlers/websocket/gateway/_InvalidMessage.cpp b/src/event_handlers/websocket/gateway/_InvalidMessage.cpp index 76143ab6..68ef41b1 100644 --- a/src/event_handlers/websocket/gateway/_InvalidMessage.cpp +++ b/src/event_handlers/websocket/gateway/_InvalidMessage.cpp @@ -2,6 +2,7 @@ #include "Logging.h" + const char* const TAG = "ServerMessageHandlers"; using namespace OpenShock::MessageHandlers::Server; @@ -12,5 +13,5 @@ void _Private::HandleInvalidMessage(const OpenShock::Serialization::ServerToDevi return; } - ESP_LOGE(TAG, "Invalid message type: %d", root->payload_type()); + ESP_LOGE(TAG, "Invalid message type: %u", root->payload_type()); } diff --git a/src/radio/RFTransmitter.cpp b/src/radio/RFTransmitter.cpp index 6dbfbdae..720c7a7d 100644 --- a/src/radio/RFTransmitter.cpp +++ b/src/radio/RFTransmitter.cpp @@ -43,7 +43,7 @@ RFTransmitter::RFTransmitter(std::uint8_t gpioPin, int queueSize) : m_txPin(gpio } char name[32]; - snprintf(name, sizeof(name), "RFTransmitter-%d", m_txPin); + snprintf(name, sizeof(name), "RFTransmitter-%u", m_txPin); if (xTaskCreate(TransmitTask, name, 4096, this, 1, &m_taskHandle) != pdPASS) { ESP_LOGE(TAG, "[pin-%u] Failed to create task", m_txPin); diff --git a/src/radio/rmt/MainEncoder.cpp b/src/radio/rmt/MainEncoder.cpp index 60bf868e..59f93cc4 100644 --- a/src/radio/rmt/MainEncoder.cpp +++ b/src/radio/rmt/MainEncoder.cpp @@ -4,6 +4,7 @@ #include "radio/rmt/PetTrainerEncoder.h" #include "radio/rmt/XlcEncoder.h" + #include const char* const TAG = "RmtMainEncoder"; @@ -17,7 +18,7 @@ std::vector Rmt::GetSequence(ShockerModelType model, std::uint16_t s case ShockerModelType::CaiXianlin: return Rmt::XlcEncoder::GetSequence(shockerId, 0, type, intensity); default: - ESP_LOGE(TAG, "Unknown shocker model: %d", model); + ESP_LOGE(TAG, "Unknown shocker model: %u", model); return {}; } } @@ -36,7 +37,7 @@ std::shared_ptr> Rmt::GetZeroSequence(ShockerModelType m sequence = std::make_shared>(Rmt::XlcEncoder::GetSequence(shockerId, 0, ShockerCommandType::Vibrate, 0)); break; default: - ESP_LOGE(TAG, "Unknown shocker model: %d", model); + ESP_LOGE(TAG, "Unknown shocker model: %u", model); sequence = nullptr; break; } diff --git a/src/wifi/WiFiManager.cpp b/src/wifi/WiFiManager.cpp index 763de8f2..82566b8c 100644 --- a/src/wifi/WiFiManager.cpp +++ b/src/wifi/WiFiManager.cpp @@ -10,13 +10,14 @@ #include "wifi/WiFiNetwork.h" #include "wifi/WiFiScanManager.h" +#include + #include #include #include - -#include +#include const char* const TAG = "WiFiManager";