var assignment

Hi All,

I'm having a small problem that's driving me nuts!!!

I'm getting a value back from the advanced iPod controller, that works no problem, now I want to assign this value to a string (so i can do something with it)....

This is what it looks like.

void iPodNameHandler(const char *name){ mySerial.print(F("iPod Name: ")); mySerial.println(name); }

What I want is

String iPodName;

void iPodNameHandler(const char *devicename){ mySerial.print(F("iPod Name: ")); mySerial.println(devicename); iPodName = devicename; }

So that later on I can then use iPodName to build a text string or do something with it like

if (iPodName == " " { mySerial.print(F("No iPod Found: ")); } else { mySerial.print(F("iPod Found: ")); }

Any tips and sorry i'm not a programmer.

john

What I want is

So, what is the problem?

The problem is that.

void iPodNameHandler(const char *devicename){
mySerial.print(F("iPod Name: ")); mySerial.println(devicename); <-------- this works and displays the name
iPodName = devicename; <-------- this does not work and never displays the name, its always blank
}

Same goes for the track name

void titleHandler(const char *Title){
mySerial.print(F("Title: ")); mySerial.println(Title); <-------- this works and displys the track name
iPodTrackSongName = Title; <-------- this does not work and never displays the name, its always blank
}

the Var values for iPodName and iPodTrackSongName never have anything in them.

         iPodName = devicename;                                      <-------- this does not work and never displays the name, its always blank

There is nothing in that code that displays anything.

http://snippets-r-us.com is down the road a ways. Maybe they can help you with the snippets.

Sorry mate, you’ve lost me!! are you saying that I’ve not given enough info for the problem to be seen??

I’m using the AdvancedRemote include

#include <AdvancedRemote.h>

//ipod vars
String iPodName;
//
String iPodPlaylistNumber;
String iPodPlaylistName;
String iPodPlaylistTrackNumber;

And when I use the built in ipod handlers (below)

void titleHandler(const char *Title){
iPodTrackSongName = Title;
mySerial.print(F("Title: ")); mySerial.println(Title); //Serial.println(“Asking for artist”);
advancedRemote.getArtist(chosenSongIndexIntoPlaylist);
// wait for artist handler to get called
}

void artistHandler(const char *Artist){
iPodTrackArtistName = temp;
mySerial.print(F("Artist: ")); mySerial.println(Artist); //Serial.println(“Asking for album”);
advancedRemote.getAlbum(chosenSongIndexIntoPlaylist);
// wait for album handler to get called
}

void albumHandler(const char *Album){
iPodTrackAlbumName = Album;
mySerial.print(F("Album: ")); mySerial.println(Album);
//Serial.println(“Turning on polling (which also seems to make it start playing”); /// turned off temp
advancedRemote.setPollingMode(AdvancedRemote::POLLING_START);

}

void iPodNameHandler(const char *devicename){
iPodName = devicename;
mySerial.print(F("iPod Name: ")); mySerial.println(iPodName);
}

non of the Var that I want filled get filled, they stay blank.

I can oly assume the the const char *name is a pointer to some sort of array on the ipod, and this isn’t getting saved in the var as it maybe the wrong type of return data (to be saved in a string var)??

Like I said I’m not a programmer and this is an attempt to get an ipod interface working.

Sorry mate, you've lost me!! are you saying that I've not given enough info for the problem to be seen??

Yes. You need to post code that compiles. You need to post ALL of it. You need to post it correctly. There is a sticky thread at the top of this forum that explains how.

    iPodTrackSongName = Title;

iPodTrackSongName is not defined.

void artistHandler(const char *Artist){
   iPodTrackArtistName = temp;

When the input is Artist, why are you assigning temp to iPodTrackArtistName?

non of the Var that I want filled get filled, they stay blank.

Well, it doesn't really matter, since you never seem to actually use the values.

I can oly assume the the const char *name is a pointer to some sort of array on the ipod

No. The pointer is to data on the Arduino. The pointer may be getting set to NULL, and the handler may get called again when that happens, but we can't see all of your code or any of your serial output, so we can only guess what the problem is. I'm not into guessing games, so you need to post all of your code. And links to the libraries and hardware used to connect the iPod to the Arduino.

I can't post all the code as its split over 13 tabs.

I get what you are saying though, I'll have to see if I can work it out.

Thanks for the help so far.

I don't know if this is the case or not, but it would be my next try.

I don't know that you can count on that pointer remaining valid. The pointer is coming from that callback function but you don't know if the data being pointed to is left there after that function exits or not. So storing that pointer in another variable you may be keeping the pointer just fine but the data may be gone before you try to use it.

I think I would work under the assumption that the data being pointed to is going to disappear. I would use strcpy to copy the iPod name or whatever into another (global) char array and then keep my pointer pointed to that instead. So instead of just capturing the pointer, go ahead and copy the whole string. That way you know for certain when you come back for it that it will still be there.

I can't post all the code as its split over 13 tabs.

The number of tabs is irrelevant. All that means is that there are 13 or more individual files, which you CAN zip up and attach to your post.

That is what you will need to do if you want help.