Trying to get a good architecture to work with this

This commit is contained in:
2025-10-29 22:04:50 +00:00
parent 43056411dd
commit 041fbcd724
+31 -12
View File
@@ -76,39 +76,58 @@ void setup() {
uint64_t lastDataRead = 0; uint64_t lastDataRead = 0;
typedef uint8_t PacketType;
const uint8_t IdentificationPacket = 0;
struct __attribute__((packed)) FlarePacket { // eventually try this out with __attrubute__((packed))
struct FlarePacket {
char StartMarker;
PacketType PktType;
char deviceName[32]; char deviceName[32];
char EndMarker;
}; };
void initFlarePacket(FlarePacket* packet) {
packet->StartMarker = 0x02; // Start of text
packet->EndMarker = 0x03; // End of text
}
bool gotAck = false; bool gotAck = false;
void sendHello() { void sendHello() {
FlarePacket flare; FlarePacket flare;
strcpy(flare.deviceName, "ESLabs CDashDisplay"); initFlarePacket(&flare);
const char devName[] = "ESLabs CDashDisplay";
flare.PktType = IdentificationPacket;
strncpy(flare.deviceName, devName, strlen(devName));
Serial.write((uint8_t*)&flare, sizeof(flare)); Serial.write((uint8_t*)&flare, sizeof(flare));
Serial.flush();
} }
#define CMD_HELLO 1
#define CMD_IDENTIFY 2 typedef uint8_t Command;
#define CMD_ACK 3 const Command CmdRequestID = 0;
const Command CmdAckID = 1;
uint64_t lastSent = 0; uint64_t lastSent = 0;
void loop(void) { void loop(void) {
uint64_t cur = millis(); uint64_t cur = millis();
if (!gotAck && (cur - lastSent) >= 1000) { // if (!gotAck && (cur - lastSent) >= 1000) {
// Send the packet again // // Send the packet again
sendHello(); // sendHello();
lastSent = cur; // lastSent = cur;
} // }
if (Serial.available() >= 1) { if (Serial.available() >= 1) {
uint8_t cmd = Serial.read(); uint8_t cmd = Serial.read();
if (cmd == CMD_IDENTIFY) { if (cmd == CmdRequestID) {
Serial2.println("Got identification request!"); Serial2.println("Got identification request!");
gearText.Update("Connecting");
sendHello(); sendHello();
} else if (cmd == CMD_ACK) { } else if (cmd == CmdAckID) {
Serial2.println("Got ack!"); Serial2.println("Got ack!");
gearText.Update("Connected");
gotAck = true;; gotAck = true;;
} }
} }