Loading files
66c1bda98This file is pinned to the selected release. Download the original to open it in your design tool.
#pragma once
#include "Device/InputDevice.hpp"
#include "Stream/ReadWritable.hpp"
namespace Espfc::Device::Input {
class InputIBUS : public InputDevice
{
public:
struct IBusData
{
uint8_t len;
uint8_t cmd;
uint16_t ch[14];
uint16_t checksum;
} __attribute__((__packed__));
InputIBUS();
int begin(Stream::ReadWritable* serial);
InputStatus update() override;
uint16_t get(uint8_t i) const override;
void get(uint16_t* data, size_t len) const override;
size_t getChannelCount() const override;
bool needAverage() const override;
void parse(IBusData& frame, int d);
private:
enum IbusState
{
IBUS_LENGTH,
IBUS_CMD,
IBUS_DATA,
IBUS_CRC_LO,
IBUS_CRC_HI,
};
void apply(IBusData& frame);
static constexpr size_t IBUS_FRAME_SIZE = sizeof(IBusData);
static constexpr uint8_t IBUS_COMMAND = 0x40;
static constexpr size_t CHANNELS = 14;
Stream::ReadWritable* _serial;
IbusState _state;
uint8_t _idx = 0;
bool _new_data;
IBusData _data;
uint16_t _channels[CHANNELS];
};
} // namespace Espfc::Device::Input