WIP: keep local changes before merging remote

This commit is contained in:
Filipriec
2025-11-13 14:42:47 +01:00
parent 915c573b27
commit 3c11e1dff8
9 changed files with 320 additions and 47 deletions

57
cvicenie_5/Uart.cpp Normal file
View File

@@ -0,0 +1,57 @@
#include "Uart.h"
// Constructor
Uart::Uart(PinName tx, PinName rx, int baud = 9600)
: serial(tx, rx, baud)
{
received = false;
received_character = ' ';
// Set desired properties
serial.baud(baud);
serial.format(
/* bits */ 8,
/* parity */ SerialBase::None,
/* stop bit */ 1
);
serial.attach(callback(this, &Uart::rxInterrupt), SerialBase::RxIrq);
};
void Uart::rxInterrupt()
{
char c;
serial.read(&c, 1);
received_character = c;
received = true;
};
// Destructor
Uart::~Uart()
{
};
bool Uart::isCharReceived()
{
if(received)
{
received = false;
return true;
}
else
return false;
};
char Uart::getReceivedChar()
{
return received_character;
};
void Uart::writeChar(char c)
{
serial.write(&c, 1);
};
UnbufferedSerial* Uart::getSerial()
{
return &serial;
};