KEK/ESP32/comm_arduino.cpp
2024-05-19 21:20:02 +02:00

53 lines
745 B
C++

// (C) 2024 by Folkert van Heusden
// Released under MIT license
#include "gen.h"
#if defined(ESP32)
#include <driver/uart.h>
#include "comm_arduino.h"
#include "utils.h"
comm_arduino::comm_arduino(Stream *const s, const std::string & name): s(s), name(name)
{
}
comm_arduino::~comm_arduino()
{
}
bool comm_arduino::begin()
{
return true;
}
std::string comm_arduino::get_identifier() const
{
return name;
}
bool comm_arduino::is_connected()
{
return true;
}
bool comm_arduino::has_data()
{
return s->available();
}
uint8_t comm_arduino::get_byte()
{
while(!has_data())
vTaskDelay(5 / portTICK_PERIOD_MS);
return s->read();
}
void comm_arduino::send_data(const uint8_t *const in, const size_t n)
{
s->write(in, n);
}
#endif