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.
Dependencies: libmDot-dev-mbed5-deprecated ISL29011
Fork of mdot-examples by
Diff: peer_to_peer_example.cpp
- Revision:
- 6:3b41238872a8
- Parent:
- 5:c9ab5062cfc3
- Child:
- 7:5f2b3d1a9b0b
--- a/peer_to_peer_example.cpp Fri Dec 01 20:22:20 2017 +0000
+++ b/peer_to_peer_example.cpp Fri Dec 01 21:03:18 2017 +0000
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <iostream>
#include <string.h>
#include <mbed.h>
#include "dot_util.h"
@@ -84,6 +85,7 @@
char * DS7505sRead(int hex);
unsigned char * twosComplementConversion(unsigned char *value);
+void flushSerialBuffer(void);
//---------------------End of prototype functions-----------------------------//
void printMenu(){
@@ -271,6 +273,7 @@
*/
////////////////////////////////////////////////////////////////////////////////
printMenu();
+ flushSerialBuffer();
pc.printf("\n\rChoose what you want to do: \n\r");
char userInput = pc.getc();
@@ -371,17 +374,26 @@
}
break;
case 57: // 9
- int input;
+ int intRegister;
+ char input[2];
char passRegister[1];
+ int intData;
char passData[1];
- pc.scanf("What register do you want(2 digit hex form)? \n\r"
- "Ex: Register 0x01 enter 1"
- "%d", &input);
- itoa(input, passRegister, 16); // Convert number(input), into hexadecimal(16), and save in char buffer(passVariable)
+ pc.printf("What register do you want(2 digit hex form)? \n\r"
+ "Ex: Register 0x01 enter 01\n\r");
+ pc.gets(input,1);
+ intRegister = atoi(input);
+ itoa(intRegister, passRegister, 16); // Convert number(input), into hexadecimal(16), and save in char buffer(passVariable)
+ passRegister[0] = atoi(passRegister);
pc.printf("0x%x register\n\r", passRegister[0]);
- pc.scanf("What is the hex representation of your data? %d \n\r", input);
- itoa(input, passData, 16);
+
+ pc.printf("What is the hex representation of your data?\n\r");
+ pc.gets(input,1);
+ intData = atoi(input); // Convert input to integer
+ itoa(intRegister, passData, 16); //Convert number(input), into hexadecimal(16), and save in char buffer(passVariable)
+ passData[0] = atoi(passData);
pc.printf("0x%x is your data\n\r", passData[0]);
+ break;
default:
printMenu();
break;
@@ -820,3 +832,7 @@
// ---------------- End of writing cycle --------------------------//
}
////////////////////////////////////////////////////////////////////////////////
+
+// Used to clear serial buffer in beginning
+////////////////////////////////////////////////////////////////////////////////
+void flushSerialBuffer(void) { char char1 = 0; while (pc.readable()) { char1 = pc.getc(); } return; }
\ No newline at end of file
