-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revise encoders to use shared buffer and handle terminator encoding s…
…eperately
- Loading branch information
Showing
14 changed files
with
177 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
#pragma once | ||
|
||
#include "RmtSequence.h" | ||
#include "ShockerCommandType.h" | ||
|
||
#include <esp32-hal-rmt.h> | ||
|
||
#include <cstdint> | ||
#include <vector> | ||
|
||
namespace OpenShock::Rmt::CaiXianlinEncoder { | ||
std::vector<rmt_data_t> GetSequence(uint16_t transmitterId, uint8_t channelId, OpenShock::ShockerCommandType type, uint8_t intensity); | ||
RmtSequence GetSequence(uint16_t shockerId, uint8_t channelId, OpenShock::ShockerCommandType type, uint8_t intensity); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
#pragma once | ||
|
||
#include "RmtSequence.h" | ||
#include "ShockerCommandType.h" | ||
#include "ShockerModelType.h" | ||
|
||
#include <esp32-hal-rmt.h> | ||
|
||
#include <cstdint> | ||
#include <memory> | ||
#include <vector> | ||
|
||
namespace OpenShock::Rmt { | ||
std::vector<rmt_data_t> GetSequence(ShockerModelType model, uint16_t shockerId, OpenShock::ShockerCommandType type, uint8_t intensity); | ||
inline std::vector<rmt_data_t> GetZeroSequence(ShockerModelType model, uint16_t shockerId) { | ||
return GetSequence(model, shockerId, ShockerCommandType::Vibrate, 0); | ||
} | ||
} | ||
RmtSequence GetSequence(ShockerModelType model, uint16_t shockerId, OpenShock::ShockerCommandType type, uint8_t intensity); | ||
} // namespace OpenShock::Rmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
#pragma once | ||
|
||
#include "RmtSequence.h" | ||
#include "ShockerCommandType.h" | ||
|
||
#include <esp32-hal-rmt.h> | ||
|
||
#include <cstdint> | ||
#include <vector> | ||
|
||
namespace OpenShock::Rmt::Petrainer998DREncoder { | ||
std::vector<rmt_data_t> GetSequence(uint16_t shockerId, OpenShock::ShockerCommandType type, uint8_t intensity); | ||
RmtSequence GetSequence(uint16_t shockerId, OpenShock::ShockerCommandType type, uint8_t intensity); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
#pragma once | ||
|
||
#include "RmtSequence.h" | ||
#include "ShockerCommandType.h" | ||
|
||
#include <esp32-hal-rmt.h> | ||
|
||
#include <cstdint> | ||
#include <vector> | ||
|
||
namespace OpenShock::Rmt::PetrainerEncoder { | ||
std::vector<rmt_data_t> GetSequence(uint16_t shockerId, OpenShock::ShockerCommandType type, uint8_t intensity); | ||
RmtSequence GetSequence(uint16_t shockerId, OpenShock::ShockerCommandType type, uint8_t intensity); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#pragma once | ||
|
||
#include "Common.h" | ||
|
||
#include <esp32-hal-rmt.h> | ||
|
||
#include <cstdint> | ||
|
||
namespace OpenShock::Rmt { | ||
class RmtSequence { | ||
DISABLE_COPY(RmtSequence); | ||
|
||
public: | ||
RmtSequence() | ||
: m_data(nullptr) | ||
, m_size(0) | ||
{ | ||
} | ||
RmtSequence(size_t size) | ||
: m_data(reinterpret_cast<rmt_data_t*>(malloc(size * 2 * sizeof(rmt_data_t)))) | ||
, m_size(size) | ||
{ | ||
} | ||
RmtSequence(RmtSequence&& other) noexcept | ||
: m_data(other.m_data) | ||
, m_size(other.m_size) | ||
{ | ||
other.m_data = nullptr; | ||
other.m_size = 0; | ||
} | ||
~RmtSequence() { free(m_data); } | ||
|
||
constexpr bool is_valid() const noexcept { return m_data != nullptr && m_size != 0; } | ||
|
||
constexpr rmt_data_t* payload() noexcept { return m_data; } | ||
constexpr rmt_data_t* terminator() noexcept { return m_data + m_size; } | ||
constexpr size_t size() const noexcept { return m_size; } | ||
|
||
RmtSequence& operator=(RmtSequence&& other) | ||
{ | ||
if (this == &other) return *this; | ||
|
||
free(m_data); | ||
|
||
m_data = other.m_data; | ||
m_size = other.m_size; | ||
|
||
other.m_data = nullptr; | ||
other.m_size = 0; | ||
|
||
return *this; | ||
} | ||
|
||
private: | ||
rmt_data_t* m_data; | ||
size_t m_size; | ||
}; | ||
} // namespace OpenShock::Rmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
#pragma once | ||
|
||
#include "RmtSequence.h" | ||
#include "ShockerCommandType.h" | ||
|
||
#include <esp32-hal-rmt.h> | ||
|
||
#include <cstdint> | ||
#include <vector> | ||
|
||
namespace OpenShock::Rmt::T330Encoder { | ||
std::vector<rmt_data_t> GetSequence(uint16_t transmitterId, OpenShock::ShockerCommandType type, uint8_t intensity); | ||
RmtSequence GetSequence(uint16_t shockerId, OpenShock::ShockerCommandType type, uint8_t intensity); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.