/* SmokyCoders Virtual Motion Robot — serial bridge example Baud: 115200 | Line-delimited JSON (see schema smokycoders.vmr.cmd/v1) Wire: USB serial only for this sketch (parse + print). Map joints.* to servos when you are ready. Respect estop + dryRun. */ String lineBuf; void setup() { Serial.begin(115200); while (!Serial) { ; } Serial.println(F("{\"ok\":true,\"role\":\"vmr-bridge\",\"schema\":\"smokycoders.vmr.cmd/v1\"}")); } void loop() { while (Serial.available()) { char c = (char)Serial.read(); if (c == '\n') { handleLine(lineBuf); lineBuf = ""; } else if (c != '\r') { if (lineBuf.length() < 2048) lineBuf += c; } } } void handleLine(const String& line) { if (line.length() < 8) return; // Minimal parsing without ArduinoJson — look for safety flags first bool estop = line.indexOf("\"estop\":true") >= 0; bool dry = line.indexOf("\"dryRun\":true") >= 0; if (estop) { Serial.println(F("{\"ack\":\"estop\",\"servos\":\"hold-zero\"}")); return; } if (dry) { Serial.println(F("{\"ack\":\"dry-run\",\"servos\":\"idle\"}")); return; } // Live path: parse angles with a proper JSON lib in production builds. Serial.print(F("{\"ack\":\"live\",\"bytes\":")); Serial.print(line.length()); Serial.println(F("}")); }