Skip to content

Commit

Permalink
Merge branch 'develop' into feature/remove-arduinojson
Browse files Browse the repository at this point in the history
* develop:
  Conform EStopManager to code style (#109)
  More code cleanup (#107)
  • Loading branch information
hhvrc committed Nov 7, 2023
2 parents bd034b9 + 468f387 commit 5957569
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 26 deletions.
5 changes: 2 additions & 3 deletions include/EStopManager.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#pragma once

#include <Arduino.h>
#include <cstdint>

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
Expand All @@ -14,5 +13,5 @@ namespace OpenShock::EStopManager {
void Init();
EStopStatus Update();
bool IsEStopped();
unsigned long WhenEStopped();
std::int64_t WhenEStopped();
} // namespace OpenShock::EStopManager
3 changes: 2 additions & 1 deletion include/GatewayClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

#include <string>
#include <unordered_map>
#include <cstdint>

namespace OpenShock {
class GatewayClient {
public:
GatewayClient(const std::string& authToken);
~GatewayClient();

enum class State {
enum class State : std::uint8_t {
Disconnected,
Disconnecting,
Connecting,
Expand Down
4 changes: 3 additions & 1 deletion include/WebSocketMessageType.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#pragma once

#include <cstdint>

namespace OpenShock {
enum class WebSocketMessageType {
enum class WebSocketMessageType : std::uint8_t {
Error,
Disconnected,
Connected,
Expand Down
10 changes: 5 additions & 5 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,37 @@ 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 =
-DOPENSHOCK_LED_GPIO=15

; 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
-DOPENSHOCK_TX_PIN=15

; 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 =
Expand Down
3 changes: 2 additions & 1 deletion src/CaptivePortalInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "GatewayConnectionManager.h"
#include "Logging.h"
#include "serialization/WSLocal.h"

#include "wifi/WiFiManager.h"

#include "serialization/_fbs/DeviceToLocalMessage_generated.h"
Expand Down Expand Up @@ -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;
}
}
19 changes: 11 additions & 8 deletions src/EStopManager.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#include "Arduino.h"
#include <EStopManager.h>
#include "EStopManager.h"

#include "Time.h"
#include "Logging.h"
#include "VisualStateManager.h"

#include <Arduino.h>

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;
Expand All @@ -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;
Expand All @@ -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:
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/event_handlers/websocket/gateway/_InvalidMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Logging.h"


const char* const TAG = "ServerMessageHandlers";

using namespace OpenShock::MessageHandlers::Server;
Expand All @@ -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());
}
2 changes: 1 addition & 1 deletion src/radio/RFTransmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/radio/rmt/MainEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "radio/rmt/PetTrainerEncoder.h"
#include "radio/rmt/XlcEncoder.h"


#include <unordered_map>

const char* const TAG = "RmtMainEncoder";
Expand All @@ -17,7 +18,7 @@ std::vector<rmt_data_t> 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 {};
}
}
Expand All @@ -36,7 +37,7 @@ std::shared_ptr<std::vector<rmt_data_t>> Rmt::GetZeroSequence(ShockerModelType m
sequence = std::make_shared<std::vector<rmt_data_t>>(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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/wifi/WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
#include "wifi/WiFiNetwork.h"
#include "wifi/WiFiScanManager.h"

#include <nonstd/span.hpp>

#include <WiFi.h>

#include <esp_wifi_types.h>

#include <vector>

#include <nonstd/span.hpp>
#include <cstdint>

const char* const TAG = "WiFiManager";

Expand Down

0 comments on commit 5957569

Please sign in to comment.