Hi:
This code is to interface with a VMusic2 mp3 module from vinculum. I may ask for more help at some point, but for now my challenge is related purely to C programming.
The code below works to allow me to enter a character from the keyboard into Tera Term.
It then processes that character according to one of three options (for now)
Each option outputs a specific command to the VMusic2 as indicated in the comments.
In main() I have a getc() which is reading back the response from the VMusic2 and it displays 1 character at a time on a new line for each character according to the \n\r that I know I have in the code.
What I like about the code is that I don't have to worry about how long the message is as the "while VMusic.readable() stays active until all the characters are read.
I think it would be better to use gets() to grab all the characters into a string in one shot instead of looping through each character individually.
I would appreciate some guidance on changing the getc() to gets() as when I tried to read the content into a string I had several compiler errors about the kinds of data types and not being able to mix them in several lines of code in that "sendcommand" module.
I would like to use the "best practices", but I'm stuck at the moment. If someone can point to a good book that would help me understand the different types and what goes with what, I would really appreciate it.
Thanks
Tim
http://www.vinculum.com/documents/datasheets/DS_VMUSIC2.pdf
#include "mbed.h"
DigitalOut led1(LED1); // used in main() as indicator
DigitalOut led2(LED2); // not yet used
DigitalOut led3(LED3); // not yet used
DigitalOut led4(LED4); // not yet used
Serial pc (USBTX,USBRX); // define serial connection to PC via mbed USB
Serial VMusic (p9, p10); // define serial connection to VMusic2 module
DigitalOut cts(p8); // set up output to hold clear to send low
int value; // variable to hold characters returned from VMusic2
int command = 0x00; // just a declaration
//
int sendcommand(char command) // this will process the key entered and trigger sending command
{ // to VMusic2
if (command == 'D') // first letter for "D"ir
{
VMusic.printf("dir \r"); // sends directory command to VMusic2
}
else if (command == 'A') // last letter from IPA input set to "A"scii
{
VMusic.printf("IPA \r"); // sends "input set to Ascii" to VMusic2
pc.printf("Setting mode to ASCII input.\n\r "); // prints status message on screen
}
else if (command == 'H') // last letter from IPH input set to "H"ex
{
VMusic.printf("IPH \r"); // sends "input set to Hex" to VMusic2
pc.printf("Setting mode to HEX input. \n\r"); // prints status message on screen
}
else
{
pc.printf("Unsupported Command \n\r"); // handles key entry not in above specific list
}
return command; // makes the compiler happy although I am not using it
}
int main() {
pc.printf("Starting VMusic2: \n\r"); // just a message to the screen
while(1) {
led1 = 1; // just indicating that I am in while1 loop
cts = 0; // VMusic2 uses hardware handshaking so this sets CTS
command == ' '; // empty the variable for holding key entered
pc.scanf( "%c", &command ); // sets input to Tera Term to read keyboard
pc.printf("Character Entered: %X\n\r", command); // prints HEX of key entered
sendcommand(command); // calls the module to act on key entered
wait(.1); // arbitrary to give command some time
while (VMusic.readable()) // watches for content in serial input buffer
{
value = VMusic.getc(); // copies serial input buffer to variable
pc.printf("\rCharacter : %c\n\r",value); // sends captured data to screen
}
wait(0.2); // arbitrary left over from original default main()
led1 = 0; // indicate end of main() commands
wait(0.2); // arbitrary eft over from original default main()
}
}
Hi:
This code is to interface with a VMusic2 mp3 module from vinculum. I may ask for more help at some point, but for now my challenge is related purely to C programming.
The code below works to allow me to enter a character from the keyboard into Tera Term.
It then processes that character according to one of three options (for now)
Each option outputs a specific command to the VMusic2 as indicated in the comments.
In main() I have a getc() which is reading back the response from the VMusic2 and it displays 1 character at a time on a new line for each character according to the \n\r that I know I have in the code.
What I like about the code is that I don't have to worry about how long the message is as the "while VMusic.readable() stays active until all the characters are read.
I think it would be better to use gets() to grab all the characters into a string in one shot instead of looping through each character individually.
I would appreciate some guidance on changing the getc() to gets() as when I tried to read the content into a string I had several compiler errors about the kinds of data types and not being able to mix them in several lines of code in that "sendcommand" module.
I would like to use the "best practices", but I'm stuck at the moment. If someone can point to a good book that would help me understand the different types and what goes with what, I would really appreciate it.
Thanks
Tim
http://www.vinculum.com/documents/datasheets/DS_VMUSIC2.pdf