Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetNetIf NTPClient_NetServices TextLCD mbed
Revision 1:7974d199ed39, committed 2011-03-28
- Comitter:
- soramimi
- Date:
- Mon Mar 28 21:49:06 2011 +0000
- Parent:
- 0:7e901efc73e7
- Commit message:
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Mar 25 16:54:13 2011 +0000
+++ b/main.cpp Mon Mar 28 21:49:06 2011 +0000
@@ -13,36 +13,36 @@
unsigned long convert_gregorian_to_julian(int year, int month, int day)
{
- if (month < 3) {
- month += 9;
- year--;
- } else {
- month -= 3;
- }
- year += 4800;
- int c = year / 100;
- return c * 146097 / 4 + (year - c * 100) * 1461 / 4 + (153 * month + 2) / 5 + day - 32045;
+ if (month < 3) {
+ month += 9;
+ year--;
+ } else {
+ month -= 3;
+ }
+ year += 4800;
+ int c = year / 100;
+ return c * 146097 / 4 + (year - c * 100) * 1461 / 4 + (153 * month + 2) / 5 + day - 32045;
}
void convert_julian_to_gregorian(unsigned long j, int *year, int *month, int *day)
{
- int y, m, d;
- y = (j * 4 + 128179) / 146097;
- d = (j * 4 - y * 146097 + 128179) / 4 * 4 + 3;
- j = d / 1461;
- d = (d - j * 1461) / 4 * 5 + 2;
- m = d / 153;
- d = (d - m * 153) / 5 + 1;
- y = (y - 48) * 100 + j;
- if (m < 10) {
- m += 3;
- } else {
- m -= 9;
- y++;
- }
- *year = y;
- *month = m;
- *day = d;
+ int y, m, d;
+ y = (j * 4 + 128179) / 146097;
+ d = (j * 4 - y * 146097 + 128179) / 4 * 4 + 3;
+ j = d / 1461;
+ d = (d - j * 1461) / 4 * 5 + 2;
+ m = d / 153;
+ d = (d - m * 153) / 5 + 1;
+ y = (y - 48) * 100 + j;
+ if (m < 10) {
+ m += 3;
+ } else {
+ m -= 9;
+ y++;
+ }
+ *year = y;
+ *month = m;
+ *day = d;
}
void display(int year, int month, int day, int hour, int minute, int second)
@@ -57,7 +57,7 @@
eth.setup();
Host server(IpAddr(), 123, "ntp.jst.mfeed.ad.jp");
-
+
bool adjust = true;
double last = 0;
@@ -66,8 +66,10 @@
if (adjust) {
ntp.setTime(server);
adjust = false;
+ } else {
+ wait(0.1);
}
-
+
time_t t = time(0);
double s = t + 2440588.0 * 24 * 60 * 60; // chronological julian second
@@ -86,12 +88,10 @@
display(year, month, day, hour, minute, second);
- if (hour == 4 && minute == 0 && second == 0) {
+ if (minute == 59 && second == 30) {
adjust = true;
}
}
-
- wait(0.1);
}
return 0;