Added null command type
Set DeviceModes type to uint8_t Set APICommand type field uint8_t Added and implemented a seend-lock variable
This commit is contained in:
@ -1,13 +1,16 @@
|
||||
#define DATAGRAM_HDR 0xAA
|
||||
|
||||
// Comandos del cronómetro
|
||||
enum ChronoCommands
|
||||
enum ChronoCommands : uint8_t
|
||||
{
|
||||
Null = 0x00, // Comando nulo
|
||||
ForceStart = 0x01, // Forzar inicio
|
||||
ForceStop = 0x02, // Forzar detención
|
||||
ForceReset = 0x04 // Forcer reinicio del cronómetro
|
||||
};
|
||||
|
||||
// Modos de operación del dispositivo
|
||||
enum DeviceModes
|
||||
enum DeviceModes : uint8_t
|
||||
{
|
||||
CHRONO = 0x00 // Modo Cronómetro
|
||||
};
|
||||
@ -15,10 +18,9 @@ enum DeviceModes
|
||||
// Estructura para un comando de la API sin datos
|
||||
struct ChronoAPICommand
|
||||
{
|
||||
const static char type = 0xAA; // Cabecera de Comando
|
||||
uint8_t type; // Cabecera de Comando
|
||||
ChronoCommands command; // Comando solicitado
|
||||
};
|
||||
|
||||
// Unión genérica para serializar y des-serializar tipos
|
||||
template <typename T>
|
||||
union buffer
|
||||
@ -26,13 +28,16 @@ union buffer
|
||||
T data;
|
||||
uint8_t buffer[sizeof(T)];
|
||||
};
|
||||
|
||||
bool sendLock = false;
|
||||
// Función para enviar un buffer por I2C
|
||||
template <typename T>
|
||||
void SendBuffer(buffer<T> buffer)
|
||||
{
|
||||
while (sendLock)
|
||||
delay(1);
|
||||
sendLock = true;
|
||||
|
||||
Wire.flush();
|
||||
Wire.beginTransmission(0x26);
|
||||
Wire.write(buffer.buffer, sizeof(T));
|
||||
Wire.endTransmission();
|
||||
sendLock = false;
|
||||
}
|
||||
Reference in New Issue
Block a user