|
| 1 | +#include "radio/rmt/T330Encoder.h" |
| 2 | + |
| 3 | +#include "radio/rmt/internal/Shared.h" |
| 4 | + |
| 5 | +const rmt_data_t kRmtPreamble = {960, 1, 790, 0}; |
| 6 | +const rmt_data_t kRmtOne = {220, 1, 980, 0}; |
| 7 | +const rmt_data_t kRmtZero = {220, 1, 580, 0}; |
| 8 | +const rmt_data_t kRmtPostamble = {220, 1, 135, 0}; |
| 9 | + |
| 10 | +using namespace OpenShock; |
| 11 | + |
| 12 | +std::vector<rmt_data_t> Rmt::T330Encoder::GetSequence(uint16_t transmitterId, ShockerCommandType type, uint8_t intensity) |
| 13 | +{ |
| 14 | + // Intensity must be between 0 and 100 |
| 15 | + intensity = std::min(intensity, static_cast<uint8_t>(100)); |
| 16 | + |
| 17 | + uint8_t typeVal = 0; |
| 18 | + switch (type) { |
| 19 | + case ShockerCommandType::Shock: |
| 20 | + typeVal = 0b01100001; |
| 21 | + break; |
| 22 | + case ShockerCommandType::Vibrate: |
| 23 | + typeVal = 0b01110010; |
| 24 | + break; |
| 25 | + case ShockerCommandType::Sound: |
| 26 | + typeVal = 0b10000100; |
| 27 | + intensity = 0; // The remote always sends 0, I don't know what happens if you send something else. |
| 28 | + break; |
| 29 | + default: |
| 30 | + return {}; // Invalid type |
| 31 | + } |
| 32 | + |
| 33 | + uint8_t channelId = 0; // CH1 is 0b0000 and CH2 is 0b1110 on my remote but other values probably work. |
| 34 | + |
| 35 | + // Payload layout: [channelId:4][typeU:4][transmitterId:16][intensity:8][typeL:4][channelId:4] |
| 36 | + uint64_t data = (static_cast<uint64_t>(channelId & 0xF) << 36) | (static_cast<uint64_t>(typeVal & 0xF0) << 28) | (static_cast<uint64_t>(transmitterId) << 16) | (static_cast<uint64_t>(intensity) << 8) | (static_cast<uint64_t>(typeVal & 0xF) << 4) | static_cast<uint64_t>(channelId & 0xF); |
| 37 | + |
| 38 | + // Shift the data left by 1 bit to append a zero |
| 39 | + data <<= 1; |
| 40 | + |
| 41 | + std::vector<rmt_data_t> pulses; |
| 42 | + pulses.reserve(43); |
| 43 | + |
| 44 | + // Generate the sequence |
| 45 | + pulses.push_back(kRmtPreamble); |
| 46 | + Internal::EncodeBits<41>(pulses, data, kRmtOne, kRmtZero); |
| 47 | + pulses.push_back(kRmtPostamble); |
| 48 | + |
| 49 | + return pulses; |
| 50 | +} |
0 commit comments