Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:ac40171bed6b
diff -r 000000000000 -r ac40171bed6b main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed May 27 22:47:33 2015 +0000
@@ -0,0 +1,64 @@
+#include "mbed.h"
+#include "Commands.h"
+
+#define COMMAND_MAX_SIZE 30
+
+char command[COMMAND_MAX_SIZE];
+int cmdIndex;
+int commandReady;
+
+CommandList commands;
+Serial pc(USBTX, USBRX);
+
+// This function is called when a character goes into the RX buffer.
+void rxCallback() {
+ char c;
+ c = pc.getc();
+
+ if(c != '\n')
+ {
+ command[cmdIndex++] = c;
+ command[cmdIndex] = 0;
+ }
+
+ if(cmdIndex == COMMAND_MAX_SIZE || c == '\r')
+ {
+ command[cmdIndex-1] = 0;
+ commandReady = 1;
+ cmdIndex = 0;
+ }
+}
+
+void parseServo(CommandArgs cmdArgs)
+{
+ if(cmdArgs.paramCount != 3)
+ printf("command %s: wrong parameters count\r\n", cmdArgs.params[0]);
+
+ printf("servo: %s %s\r\n",cmdArgs.params[1], cmdArgs.params[2]);
+}
+
+void parseUnknown(CommandArgs cmdArgs)
+{
+ printf("Unknown command '%s'\r\n", cmdArgs.params[0]);
+}
+
+int main()
+{
+ cmdIndex = 0;
+ commandReady = 0;
+
+ commands.add("unknown",parseUnknown);
+ commands.add("servo",parseServo);
+
+ pc.printf("Enter Command:\r\n");
+ pc.attach(&rxCallback, Serial::RxIrq);
+
+ while(1)
+ {
+ if(commandReady)
+ {
+ commands.parseCommand(command);
+ commandReady = 0;
+ }
+ }
+}