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.
Fork of daplink-validation by
main.cpp
- Committer:
- c1728p9
- Date:
- 2015-09-11
- Revision:
- 1:db2a55107c7e
- Parent:
- 0:c4a3bb148a79
- Child:
- 2:204ef796ee06
File content as of revision 1:db2a55107c7e:
#include "mbed.h"
#include <stdio.h>
Serial pc(USBTX, USBRX);
int main()
{
uint32_t baud;
uint32_t count;
uint32_t index;
uint32_t val;
uint8_t str[64];
count = 0;
index = 0;
pc.baud(115200);
pc.printf("{init}");
while(1) {
while (1) {
val = pc.getc();
// Check for overflow. Leave space for
// a null terminating character
if (index >= sizeof(str) - 1) {
index = 0;
}
// Check for start of frame
if ('{' == val) {
index = 0;
}
// Check for end of frame
str[index] = val;
index++;
// Check for end of frame
if ('}' == val && index > 0) {
str[index] = 0;
count = sscanf((char*)str, "{baud:%i}", &baud);
}
// Echo back character
pc.putc(val);
// Set baud if there is a valid command
if (count == 1) {
wait(0.01f);
pc.baud(baud);
wait(0.01f);
pc.printf("{change}");
count = 0;
}
}
}
}
