Com: Implement proper communications
Implement a set of functions to create messages following the protocols defined in the README for communication. Handle HID, which is used to communicate with the interactive application. Update README with details on the message structures.
This commit is contained in:
parent
8d80dd2604
commit
bedd1f4f95
5 changed files with 126 additions and 7 deletions
39
src/Com.cpp
Normal file
39
src/Com.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
//
|
||||
// Created by Teo-CD on 24/09/23.
|
||||
//
|
||||
|
||||
#include "Com.h"
|
||||
|
||||
namespace Com {
|
||||
byte buffer[64];
|
||||
/**
|
||||
* Will flush buffer through either HID or Serial depending on build
|
||||
* options.
|
||||
* HID is the expected production usage as the interactive software will
|
||||
* use it for auto-detection.
|
||||
*/
|
||||
inline void flushBuffer() {
|
||||
#ifdef USB_RAWHID
|
||||
usb_rawhid_send(buffer, 0);
|
||||
#else
|
||||
Serial.write((const char*)buffer);
|
||||
#endif
|
||||
/* Clear the buffer. */
|
||||
memset(buffer, 0, 64);
|
||||
}
|
||||
|
||||
void sendFigUpdate(int8_t event) {
|
||||
buffer[0] = '@';
|
||||
buffer[1] = event;
|
||||
flushBuffer();
|
||||
}
|
||||
|
||||
void sendComment(const char *message, ...) {
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
buffer[0] = '#';
|
||||
buffer[1] = vsnprintf((char *)(buffer + 2), 62, message, args);
|
||||
va_end(args);
|
||||
flushBuffer();
|
||||
}
|
||||
}
|
11
src/main.cpp
11
src/main.cpp
|
@ -3,6 +3,7 @@
|
|||
#include "Pinout.h"
|
||||
|
||||
#include "RFID.h"
|
||||
#include "Com.h"
|
||||
|
||||
__attribute__((noreturn)) int main() {
|
||||
pinMode(pin_DBG_LED_1, OUTPUT);
|
||||
|
@ -36,7 +37,7 @@ __attribute__((noreturn)) int main() {
|
|||
*/
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("# System is powered up, running set-up.");
|
||||
Com::sendComment("# System is powered up, running set-up.");
|
||||
|
||||
/* TODO: Setups once module structure is up. */
|
||||
RFID rfid;
|
||||
|
@ -45,11 +46,11 @@ __attribute__((noreturn)) int main() {
|
|||
|
||||
/* Main loop */
|
||||
while (true) {
|
||||
int8_t tagID;
|
||||
int8_t tagEvent;
|
||||
|
||||
tagID = rfid.checkTags();
|
||||
if (tagID) {
|
||||
Serial.printf("Check tag result : %d\n", tagID);
|
||||
tagEvent = rfid.checkTags();
|
||||
if (tagEvent) {
|
||||
Com::sendFigUpdate(tagEvent);
|
||||
}
|
||||
|
||||
delay(100);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue