Go Down

Topic: Advanced remote (iPod) Title not consistent (Read 492 times) previous topic - next topic

potzli

Hi,

I trying the advanced remote library.

But get some strange thing.

The artist is good but Title is not correct. The next Title is already displayed
Why ???

Thanks

Code: [Select]
#include <AdvancedRemote.h>
#include <Bounce.h>


const byte BUTTON_PIN = 3;
const byte BUTTON_NEXTPL = 4;
const byte BUTTON_PAUSE = 5;
const byte BUTTON_PLAY = 6;

const unsigned long DEBOUNCE_MS = 50;
void printTime(const unsigned long ms);


Bounce button_next(BUTTON_PIN, DEBOUNCE_MS);
Bounce button_nextpl(BUTTON_NEXTPL, DEBOUNCE_MS);
Bounce button_pause(BUTTON_PAUSE, DEBOUNCE_MS);
Bounce button_play(BUTTON_PLAY, DEBOUNCE_MS);

AdvancedRemote advancedRemote;

unsigned long playlistCount = 0;
unsigned long trackCount = 0;
unsigned long totalSong = 0;
uint8_t activePl;
uint8_t playMode;

void feedbackHandler(AdvancedRemote::Feedback feedback, byte cmd)
{
  Serial.print("got feedback of 0x");
  Serial.print(feedback, HEX);
  Serial.print(" for cmd 0x");
  Serial.println(cmd, HEX);

  if (feedback != AdvancedRemote::FEEDBACK_SUCCESS)
  {
    Serial.println("Giving up as feedback wasn't SUCCESS");
    return;
  }
}

void itemNameHandler(unsigned long offset, const char *name)
{
  Serial.print("Playlist ");
  Serial.print(offset, DEC);
  Serial.print(" is named '");
  Serial.print(name);
  Serial.println("'");
}

void itemCountHandler(unsigned long count)
{
  Serial.print("Playlist Count: ");
  Serial.println(count);

  playlistCount = count;
}

void titleHandler(const char *name)
{
  Serial.print("Title: ");
  Serial.println(name);
  advancedRemote.getArtist(trackCount);
}

void artistHandler(const char *name)
{
  Serial.print("Artist: ");
  Serial.println(name);
  Serial.print("Track no: ");
  Serial.print(trackCount);
  Serial.print("/ ");
  Serial.println(totalSong);
  advancedRemote.getAlbum(trackCount);
}

void albumHandler(const char *name)
{
  Serial.print("Album: ");
  Serial.println(name);
}

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

void shuffleModeHandler(AdvancedRemote::ShuffleMode shuffleMode)
{
  Serial.print("shuffle mode: ");
  switch (shuffleMode)
  {
    case AdvancedRemote::SHUFFLE_MODE_OFF:
      Serial.println("Off");
      break;

    case AdvancedRemote::SHUFFLE_MODE_SONGS:
      Serial.println("Songs");
      break;

    case AdvancedRemote::SHUFFLE_MODE_ALBUMS:
      Serial.println("Albums");
      break;
  }
}

void repeatModeHandler(AdvancedRemote::RepeatMode repeatMode)
{
  Serial.print("repeat mode: ");
  switch (repeatMode)
  {
    case AdvancedRemote::REPEAT_MODE_OFF:
      Serial.println("Off");
      break;

    case AdvancedRemote::REPEAT_MODE_ONE_SONG:
      Serial.println("One Song");
      break;

    case AdvancedRemote::REPEAT_MODE_ALL_SONGS:
      Serial.println("All songs");
      break;
  }
}

void timeAndStatusHandler(unsigned long trackLenMs, unsigned long elapsedTimeMs, AdvancedRemote::PlaybackStatus status)
{
  Serial.print("Status: ");
  Serial.print(status);
  Serial.println("    0: stop, 1: play, 2: pause");
  playMode = status;
  if (playMode == 1)
  {
    advancedRemote.setPollingMode(AdvancedRemote::POLLING_START); //return the track elapsed time every 500ms
  }
}

void playlistPositionHandler(unsigned long index)
{
  Serial.print("Playlist track position: ");
  Serial.println(index);
  trackCount = index;
}

void currentPlaylistSongCountHandler(unsigned long count)
{
  Serial.print("Playlist total songs count: ");
  Serial.println(count);
  totalSong = count;
}

void pollingHandler(AdvancedRemote::PollingCommand command, unsigned long playlistPositionOrElaspedTimeMs)
{
  Serial.print("Polling: ");
  Serial.println(command);
  switch (command)
  {

    case AdvancedRemote::POLLING_TRACK_CHANGE:
      advancedRemote.getPlaylistPosition();
      advancedRemote.getTitle(trackCount);
      break;

    case AdvancedRemote::POLLING_ELAPSED_TIME:
      printTime(playlistPositionOrElaspedTimeMs);
      break;

    default:
      printTime(playlistPositionOrElaspedTimeMs);
  }
}

void setup()
{
  pinMode(BUTTON_PIN, INPUT);
  digitalWrite(BUTTON_PIN, HIGH);
  pinMode(BUTTON_NEXTPL, INPUT);
  digitalWrite(BUTTON_NEXTPL, HIGH);
  pinMode(BUTTON_PLAY, INPUT);
  digitalWrite(BUTTON_PLAY, HIGH);
  pinMode(BUTTON_PAUSE, INPUT);
  digitalWrite(BUTTON_PAUSE, HIGH);

  Serial.begin(9600);

  Serial6.begin(iPodSerial::IPOD_SERIAL_RATE);
  advancedRemote.setSerial(Serial6);
  delay(1000);
  Serial.println("iPod test");

  advancedRemote.enable();

  advancedRemote.setRepeatMode(AdvancedRemote::REPEAT_MODE_ALL_SONGS);  //set repeat mode all songs

  //Without this line t doesn't stat in play !!!???
  advancedRemote.controlPlayback(AdvancedRemote::PLAYBACK_CONTROL_PLAY_PAUSE); //toggle play/pause
  advancedRemote.setiPodNameHandler(iPodNameHandler); //return ipod name
  advancedRemote.setTimeAndStatusHandler(timeAndStatusHandler);  //return time, stop, play or pause, start polling if play
  advancedRemote.setCurrentPlaylistSongCountHandler(currentPlaylistSongCountHandler); //return total song into current playlist
  advancedRemote.setItemCountHandler(itemCountHandler);  //return item count
  advancedRemote.setPlaylistPositionHandler(playlistPositionHandler); //return playlist track position
  advancedRemote.setPollingHandler(pollingHandler);//return polling
  advancedRemote.setTitleHandler(titleHandler); //return title
  advancedRemote.setArtistHandler(artistHandler); //return artist
  advancedRemote.setAlbumHandler(albumHandler); //return album
  advancedRemote.setItemNameHandler(itemNameHandler);  //return item name
  //advancedRemote.getItemNames(AdvancedRemote::ITEM_PLAYLIST, 0, 2);  //give name from 0 long 2
  advancedRemote.switchToMainLibraryPlaylist(); //go to main playlist
  //  advancedRemote.setShuffleModeHandler(shuffleModeHandler); //Not ok
  advancedRemote.setShuffleMode(AdvancedRemote::SHUFFLE_MODE_SONGS);
  //advancedRemote.setRepeatModeHandler(repeatModeHandler); //Not ok
  advancedRemote.switchToItem(AdvancedRemote::ITEM_PLAYLIST, 0);
  advancedRemote.executeSwitch(0x00);
  //  advancedRemote.jumpToSongInCurrentPlaylist(105); //jump to track number...


  advancedRemote.getiPodName(); //ask ipod name
  advancedRemote.getTimeAndStatusInfo();
  advancedRemote.getSongCountInCurrentPlaylist(); //ask total song into current playlist
  advancedRemote.getItemCount(AdvancedRemote::ITEM_PLAYLIST); //ask total playlist
  advancedRemote.getPlaylistPosition(); //ask for playlist track position
  advancedRemote.getShuffleMode(); //Not ok
  advancedRemote.getRepeatMode();
  advancedRemote.getTitle(trackCount);

  //start playing but no ok probably because we are out of advancedRemote.loop() ?
  //  if (playMode != 1)
  //  {
  //    Serial.print("PLAY");
  //    advancedRemote.controlPlayback(AdvancedRemote::PLAYBACK_CONTROL_PLAY_PAUSE);
  //    advancedRemote.getTimeAndStatusInfo();
  //  }
}

void loop()
{
  advancedRemote.loop();

  if (button_next.update() && (button_next.read() == LOW))
  {
    Serial.println("NEXT");
    advancedRemote.controlPlayback(AdvancedRemote::PLAYBACK_CONTROL_SKIP_FORWARD);
  }

  if (button_nextpl.update() && (button_nextpl.read() == LOW))
  {
    activePl++;
    Serial.print("NEXT PLAYLIST:");
    Serial.println(activePl);
    if (activePl >= playlistCount)
    {
      activePl = 0;
    }

    advancedRemote.switchToItem(AdvancedRemote::ITEM_PLAYLIST, activePl);
    advancedRemote.executeSwitch(0x00);
    advancedRemote.getItemNames(AdvancedRemote::ITEM_PLAYLIST, activePl, 1);  //give name from activePl, long 1
    advancedRemote.getSongCountInCurrentPlaylist();
    //  advancedRemote.getTitle(trackCount);
  }

  if (button_pause.update() && (button_pause.read() == LOW))
  {
    advancedRemote.getTimeAndStatusInfo();

    if (playMode == 1)
    {
      Serial.print("PAUSE");
      advancedRemote.controlPlayback(AdvancedRemote::PLAYBACK_CONTROL_PLAY_PAUSE);
      advancedRemote.getTimeAndStatusInfo();
    }
  }

  if (button_play.update() && (button_play.read() == LOW))
  {
    advancedRemote.getTimeAndStatusInfo();

    if (playMode != 1)
    {
      Serial.print("PLAY");
      advancedRemote.controlPlayback(AdvancedRemote::PLAYBACK_CONTROL_PLAY_PAUSE);
      advancedRemote.getTimeAndStatusInfo();
    }
  }
}






void printTime(const unsigned long ms)
{
  const unsigned long totalSecs = ms / 1000;
  const unsigned int mins = totalSecs / 60;
  const unsigned int partialSecs = totalSecs % 60;

  Serial.print(mins);
  Serial.print(":");
  Serial.println(partialSecs);
}


potzli

Does anybody see an error in my code ?

A the power on the title and artist are ok. But after a next track the tilte is correct but the title displayed is the next one !!!

Thanks !


Go Up