[gnoduino] examples: more recent g++ scope fixes



commit df04d15e50779f4bbd5e19835569511bc2617798
Author: Pascal de Bruijn <pmjdebruijn pcode nl>
Date:   Thu Aug 14 19:09:42 2014 +0200

    examples: more recent g++ scope fixes

 .../examples/UdpNtpClient/UdpNtpClient.ino         |   55 +++++++++-----------
 .../Firmata/examples/I2CFirmata/I2CFirmata.ino     |   32 ++++++------
 2 files changed, 41 insertions(+), 46 deletions(-)
---
diff --git a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino 
b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
index a476aac..bbb41b0 100644
--- a/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
+++ b/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
@@ -45,6 +45,30 @@ byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing pack
 // A UDP instance to let us send and receive packets over UDP
 EthernetUDP Udp;
 
+// send an NTP request to the time server at the given address
+unsigned long sendNTPpacket(IPAddress& address)
+{
+  // set all bytes in the buffer to 0
+  memset(packetBuffer, 0, NTP_PACKET_SIZE);
+  // Initialize values needed to form NTP request
+  // (see URL above for details on the packets)
+  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
+  packetBuffer[1] = 0;     // Stratum, or type of clock
+  packetBuffer[2] = 6;     // Polling Interval
+  packetBuffer[3] = 0xEC;  // Peer Clock Precision
+  // 8 bytes of zero for Root Delay & Root Dispersion
+  packetBuffer[12]  = 49;
+  packetBuffer[13]  = 0x4E;
+  packetBuffer[14]  = 49;
+  packetBuffer[15]  = 52;
+
+  // all NTP fields have been given values, now
+  // you can send a packet requesting a timestamp:
+  Udp.beginPacket(address, 123); //NTP requests are to port 123
+  Udp.write(packetBuffer,NTP_PACKET_SIZE);
+  Udp.endPacket();
+}
+
 void setup() 
 {
  // Open serial communications and wait for port to open:
@@ -112,38 +136,9 @@ void loop()
     Serial.println(epoch %60); // print the second
   }
   // wait ten seconds before asking for the time again
-  delay(10000); 
+  delay(10000);
 }
 
-// send an NTP request to the time server at the given address
-unsigned long sendNTPpacket(IPAddress& address)
-{
-  // set all bytes in the buffer to 0
-  memset(packetBuffer, 0, NTP_PACKET_SIZE);
-  // Initialize values needed to form NTP request
-  // (see URL above for details on the packets)
-  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
-  packetBuffer[1] = 0;     // Stratum, or type of clock
-  packetBuffer[2] = 6;     // Polling Interval
-  packetBuffer[3] = 0xEC;  // Peer Clock Precision
-  // 8 bytes of zero for Root Delay & Root Dispersion
-  packetBuffer[12]  = 49;
-  packetBuffer[13]  = 0x4E;
-  packetBuffer[14]  = 49;
-  packetBuffer[15]  = 52;
-
-  // all NTP fields have been given values, now
-  // you can send a packet requesting a timestamp:
-  Udp.beginPacket(address, 123); //NTP requests are to port 123
-  Udp.write(packetBuffer,NTP_PACKET_SIZE);
-  Udp.endPacket();
-}
-
-
-
-
-
-
 
 
 
diff --git a/libraries/Firmata/examples/I2CFirmata/I2CFirmata.ino 
b/libraries/Firmata/examples/I2CFirmata/I2CFirmata.ino
index 1da8963..7ed7b63 100644
--- a/libraries/Firmata/examples/I2CFirmata/I2CFirmata.ino
+++ b/libraries/Firmata/examples/I2CFirmata/I2CFirmata.ino
@@ -55,6 +55,22 @@ byte i2cRxData[32];
 boolean readingContinuously = false;
 byte queryIndex = 0;
 
+/* reference: BlinkM_funcs.h by Tod E. Kurt, ThingM, http://thingm.com/ */
+// Enables Pins A2 and A3 to be used as GND and Power
+// so that I2C devices can be plugged directly
+// into Arduino header (pins A2 - A5)
+static void enablePowerPins(byte pwrpin, byte gndpin)
+{
+  if(powerPinsEnabled == 0) {
+    DDRC |= _BV(pwrpin) | _BV(gndpin);
+    PORTC &=~ _BV(gndpin);
+    PORTC |=  _BV(pwrpin);
+    powerPinsEnabled = 1;
+    Firmata.sendString("Power pins enabled");
+    delay(100);
+  }
+}
+
 void readAndReportData(byte address, int theRegister, byte numBytes)
 {
   if (theRegister != REGISTER_NOT_SPECIFIED) {
@@ -180,22 +196,6 @@ void systemResetCallback()
   queryIndex = 0;
 }
 
-/* reference: BlinkM_funcs.h by Tod E. Kurt, ThingM, http://thingm.com/ */
-// Enables Pins A2 and A3 to be used as GND and Power
-// so that I2C devices can be plugged directly
-// into Arduino header (pins A2 - A5)
-static void enablePowerPins(byte pwrpin, byte gndpin)
-{
-  if(powerPinsEnabled == 0) {
-    DDRC |= _BV(pwrpin) | _BV(gndpin);
-    PORTC &=~ _BV(gndpin);
-    PORTC |=  _BV(pwrpin);
-    powerPinsEnabled = 1;
-    Firmata.sendString("Power pins enabled");
-    delay(100);
-  }
-}
-
 void setup()
 {
   Firmata.setFirmwareVersion(2, 0);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]