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: SLCD mbed-rtos mbed
Fork of Serial_parser_v2 by
Diff: Serial_parser_v1.cpp
- Revision:
- 5:76c73467ef1a
- Parent:
- 4:31207d384db0
diff -r 31207d384db0 -r 76c73467ef1a Serial_parser_v1.cpp
--- a/Serial_parser_v1.cpp Mon Mar 23 16:37:23 2015 +0000
+++ b/Serial_parser_v1.cpp Wed Mar 25 15:51:37 2015 +0000
@@ -56,7 +56,7 @@
int isNote(char theNote){ //check for valid onte
- int noteListLen = sizeof(ALLNOTES);
+ int noteListLen = strlen(ALLNOTES);
int pos = NONOTE;
int i;
for (i=0; i<noteListLen; i++){
@@ -69,7 +69,7 @@
}
int isOctave(char theOct){ //check for valid onte
- int noteListLen = sizeof(VALIDOCTAVES);
+ int noteListLen = strlen(VALIDOCTAVES);
int pos = NOOCTAVE;
int i;
for (i=0; i<noteListLen; i++){
@@ -81,6 +81,34 @@
return (pos);
}
+int isValidData (char * commandChars){
+ #define NOTEPOS 0 // index of note and octive tokens
+ #define OCTPOS 1
+
+ int diatonicArrayIndex = 0; // this is the length into the diatonic scale array
+
+ int noteListLen = strlen(ALLNOTES);
+ int posNote = NONOTE;
+ for (int i=0; i<noteListLen; i++){
+ if (ALLNOTES[i] == commandChars[NOTEPOS]){
+ posNote = i;
+ break;
+ }
+ }
+
+ int octListLen = strlen(VALIDOCTAVES);
+ int posOct = NOOCTAVE;
+ for (int j=0; j<octListLen; j++){
+ if (VALIDOCTAVES[j] == commandChars[OCTPOS]){
+ posOct = j;
+ break;
+ }
+ }
+
+ diatonicArrayIndex = posNote + (OCTAVELLEN * posOct);
+ return diatonicArrayIndex;
+}
+
/* one way to do the parsing **************
void parseCommand (char * commandChars){
int charPos = 0;
@@ -108,19 +136,8 @@
**************** */
// calculating the valid command
void parseCommand (char * commandChars){
-#define NOTEPOS 0 // index of note and octive tokens
-#define OCTPOS 1
- int noteIndex;
- int octaveIndex;
- int diatonicArrayIndex = 0; // this is the length into the diatonic scale array
- bool validCommand = false;
-
- noteIndex = isNote(commandChars[NOTEPOS]);
- octaveIndex = isOctave(commandChars[OCTPOS]);
- validCommand = ((noteIndex != NONOTE)&&(octaveIndex != NOOCTAVE)); // test for good command string
-#ifdef PRINTDBUG
- if (validCommand) {
- diatonicArrayIndex = noteIndex + (OCTAVELLEN * octaveIndex);
+ int diatonicArrayIndex = isValidData(commandChars); // this is the length into the diatonic scale array
+ if (diatonicArrayIndex < 14 ) {
pc.printf("%s - IsNote - %4.2f OK\n\r", rxString, diatonicScale[diatonicArrayIndex]);
sprintf(rxString,"%4.1f", diatonicScale[diatonicArrayIndex]); // show frequency on LCD
} else {
@@ -130,6 +147,7 @@
#endif
return;
}
+
void LCDMessNoDwell(char *lMess){
slcd.Home();
slcd.clear();
