Skip to content

Commit

Permalink
More Petrainer998DR protocol improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Nov 21, 2024
1 parent 9bf87bd commit 92559fc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/Checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace OpenShock::Checksum {
* Make sure the uint8 only has its high bits (0x0F) set before using this function
*/
constexpr uint8_t ReverseInverseNibble(uint8_t b) {
return ~ReverseNibble(b);
return (0x084C2A6E195D3B7F >> (b * 4)) & 0xF; // Trust me bro
}
} // namespace OpenShock::Checksum

Expand Down
4 changes: 2 additions & 2 deletions src/radio/rmt/Petrainer998DREncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ std::vector<rmt_data_t> Rmt::Petrainer998DREncoder::GetSequence(uint16_t shocker
return {}; // Invalid type
}

uint8_t typeVal = 0b0001 << typeShift;
uint8_t typeVal = 1 << typeShift;
uint8_t typeInvert = Checksum::ReverseInverseNibble(typeVal);

// TODO: Channel argument?
Expand All @@ -43,7 +43,7 @@ std::vector<rmt_data_t> Rmt::Petrainer998DREncoder::GetSequence(uint16_t shocker

// Payload layout: [channel:4][typeVal:4][shockerID:16][intensity:8][typeInvert:4][channelInvert:4] (40 bits)
uint64_t data
= (static_cast<uint64_t>(channel & 0b1111) << 36 | static_cast<uint64_t>(typeVal & 0b1111) << 32 | static_cast<uint64_t>(shockerId & 0x1FFFF) << 15 | static_cast<uint64_t>(intensity & 0x7F) << 8 | static_cast<uint64_t>(typeInvert & 0b1111) << 4 | static_cast<uint64_t>(channelInvert & 0b1111));
= (static_cast<uint64_t>(channel & 0xF) << 36 | static_cast<uint64_t>(typeVal & 0xF) << 32 | static_cast<uint64_t>(shockerId & 0x1FFFF) << 15 | static_cast<uint64_t>(intensity & 0x7F) << 8 | static_cast<uint64_t>(typeInvert & 0xF) << 4 | static_cast<uint64_t>(channelInvert & 0xF));

std::vector<rmt_data_t> pulses;
pulses.reserve(42);
Expand Down

0 comments on commit 92559fc

Please sign in to comment.