Permalink
Browse files

Switch from using HardwareSerial to the more generic Stream as the cl…

…ass the library uses to communicate with the iPod.

Stream doesn't have a begin() method, so iPodSerial::setup() is removed.

Call begin() on your serial port in the setup() method of your sketch instead of calling setup() on the SimpleRemote or AdvancedRemote instance.
  • Loading branch information...
1 parent 0e6f322 commit 9b6d7e2a44489cbae899b944f50a036ec1f004cf David Findlay committed Jul 8, 2012
@@ -90,16 +90,14 @@ void setup()
//advancedRemote.setDebugPrint(Serial);
// use Serial3 (Mega-only) to talk to the iPod
+ Serial3.begin(iPodSerial::IPOD_SERIAL_RATE);
advancedRemote.setSerial(Serial3);
// register callback functions for the things we're going to read
advancedRemote.setFeedbackHandler(feedbackHandler);
advancedRemote.setItemCountHandler(itemCountHandler);
advancedRemote.setItemNameHandler(itemNameHandler);
- // let the library set itself up, now we've done our configuration of it
- advancedRemote.setup();
-
// start disabled, i.e. in good old Simple Remote mode
advancedRemote.disable();
}
@@ -392,8 +392,7 @@ void setup()
ar.setDebugPrint(clientPrint);
*/
- // let the library set itself up, now we've done our configuration of it
- ar.setup();
+ Serial.begin(iPodSerial::IPOD_SERIAL_RATE);
// start in simple remote mode
ar.disable();
@@ -171,6 +171,7 @@ void setup()
//advancedRemote.setDebugPrint(Serial);
// use Serial3 (Mega-only) to talk to the iPod
+ Serial3.begin(iPodSerial::IPOD_SERIAL_RATE);
advancedRemote.setSerial(Serial3);
// register callback functions for the things we're going to read
@@ -181,9 +182,6 @@ void setup()
advancedRemote.setPollingHandler(pollingHandler);
advancedRemote.setCurrentPlaylistSongCountHandler(currentPlaylistSongCountHandler);
- // let the library set itself up, now we've done our configuration of it
- advancedRemote.setup();
-
// start in simple remote mode
advancedRemote.disable();
}
@@ -175,8 +175,7 @@ void setup()
Ethernet.begin(MAC_ADDRESS, IP_ADDRESS);
server.begin();
- // let the library set itself up, now we've done our configuration of it
- sr.setup();
+ Serial.begin(iPodSerial::IPOD_SERIAL_RATE);
}
void loop()
@@ -51,7 +51,7 @@ void setup()
{
nunchuck_setpowerpins();
nunchuck_init();
- sr.setup();
+ Serial.begin(iPodSerial::IPOD_SERIAL_RATE);
}
void loop()
@@ -20,7 +20,7 @@ void setup()
// enable pull-up
digitalWrite(BUTTON_PIN, HIGH);
- simpleRemote.setup();
+ Serial.begin(iPodSerial::IPOD_SERIAL_RATE);
}
void loop()
@@ -48,7 +48,7 @@ iPodSerial::iPodSerial()
{
}
-void iPodSerial::setSerial(HardwareSerial &newiPodSerial)
+void iPodSerial::setSerial(Stream &newiPodSerial)
{
pSerial = &newiPodSerial;
}
@@ -71,11 +71,6 @@ void iPodSerial::setLogPrint(Print &newPrint)
}
#endif
-void iPodSerial::setup()
-{
- pSerial->begin(IPOD_SERIAL_RATE);
-}
-
bool iPodSerial::validChecksum(byte actual)
{
int expected = dataSize;
View
@@ -42,6 +42,9 @@
class iPodSerial
{
+public: // attributes
+ static const int IPOD_SERIAL_RATE = 19200;
+
public:
iPodSerial();
@@ -68,7 +71,7 @@ class iPodSerial
* Sets the serial port that the library will use to communicate with the iPod.
* This defaults to "Serial", i.e. the normal serial port.
*/
- void setSerial(HardwareSerial &newiPodSerial);
+ void setSerial(Stream &newiPodSerial);
#if defined(IPOD_SERIAL_DEBUG)
/**
@@ -145,8 +148,6 @@ class iPodSerial
static const byte HEADER1 = 0xFF;
static const byte HEADER2 = 0x55;
- static const int IPOD_SERIAL_RATE = 19200;
-
enum ReceiveState
{
WAITING_FOR_HEADER1 = 0,
@@ -159,7 +160,7 @@ class iPodSerial
byte *pData;
byte checksum;
- HardwareSerial *pSerial;
+ Stream *pSerial;
private: // methods
void sendHeader();

0 comments on commit 9b6d7e2

Please sign in to comment.