예제 #1
0
//initialize
void GoldieClock::begin(void)
{
    Adafruit_NeoPixel::begin();

    //get the time zone index from eeprom and ensure that it's valid
    tzIndex = eeprom_read_byte( &ee_tzIndex );
    if ( tzIndex >= sizeof(tzNames) / sizeof(tzNames[0]) )
    {
        tzIndex = 0;                            //not valid, set to UTC
        eeprom_write_byte( &ee_tzIndex, tzIndex);
    }
    tz = timezones[tzIndex];                    //set the tz

    time_t utc = getUTC();                      //synchronize with RTC
    while ( utc == getUTC() );                  //wait for increment to the next second
    utc = RTC.get();
    setUTC(utc);                                //set our time from the RTC
    Serial << F("\nTime set from RTC:\n");
    printDateTime(utc);
    Serial << F("UTC") << endl;
    time_t local = (*tz).toLocal(utc, &tcr);
    printDateTime(local);
    Serial << tcr -> abbrev << endl;

//    rainbowCycle(2, 2);                         //power-up eye candy
    clear();                                    //turn all the NeoPixels off at power up
    show();
}
예제 #2
0
				std::string strGPGGA()const{
					// 失敗することが多いので、エラー処理を加えて無視するようにする
					try{
						std::string tmp;
						tmp = boost::format("$GPGGA,").str();
						hmLib::date UTCD;
						UTCD.from_time(getUTC());
						tmp += (boost::format("%02d%02d%02d.%03d,") % UTCD.Hour%UTCD.Min%UTCD.Sec%UTCD.mSec).str();
						int d = (int)abs(getPos().y);
						int m = (int)abs(getPos().y*60.) - d * 60;
						int n = (int)abs(getPos().y*600000.) - d * 600000 - m * 10000;
						tmp += (boost::format("%02d%02d.%04d,%c,") % d%m%n % (getPos().y > 0 ? 'N' : 'S')).str();
						d = (int)abs(getPos().x);
						m = (int)abs(getPos().x*60.) - d * 60;
						n = (int)abs(getPos().x*600000.) - d * 600000 - m * 10000;
						tmp += (boost::format("%03d%02d.%04d,%c,") % d%m%n % (getPos().x > 0 ? 'E' : 'W')).str();
						tmp += (boost::format("%d,%02d,%02d.%d,") % (int)getFail() % 3 % 1 % 0).str();
						d = (int)getHeight();
						m = (int)(getHeight()*10.) - d * 10;
						tmp += (boost::format("%05d,%d,M,") % d%m).str();
						tmp += (boost::format("%04d.%d,M,%03d.%d,0000*") % 0 % 0 % 0 % 0).str();
						char csum = 0;
						for(int i = 1; i < (int)tmp.size() - 1; i++)csum ^= tmp[i];
						tmp.push_back(csum);
						tmp.push_back(0x0d);
						tmp.push_back(0x0a);
						return tmp;
					}
					catch(const std::exception& ex){
						std::string tmp = ex.what();
						return tmp;
					}
				}
예제 #3
0
UBool
TimeArrayTimeZoneRule::getFinalStart(int32_t prevRawOffset,
                                     int32_t prevDSTSavings,
                                     UDate& result) const {
    if (fNumStartTimes <= 0 || fStartTimes == NULL) {
        return FALSE;
    }
    result = getUTC(fStartTimes[fNumStartTimes - 1], prevRawOffset, prevDSTSavings);
    return TRUE;
}
예제 #4
0
UBool
TimeArrayTimeZoneRule::getPreviousStart(UDate base,
                                        int32_t prevRawOffset,
                                        int32_t prevDSTSavings,
                                        UBool inclusive,
                                        UDate& result) const {
    int32_t i = fNumStartTimes - 1;
    for (; i >= 0; i--) {
        UDate time = getUTC(fStartTimes[i], prevRawOffset, prevDSTSavings);
        if (time < base || (inclusive && time == base)) {
            result = time;
            return TRUE;
        }
    }
    return FALSE;
}
예제 #5
0
wxString DashboardInstrument_Clock::GetDisplayTime( wxDateTime UTCtime )
{
    wxString result( _T( "---" ) );
    if ( UTCtime.IsValid() ) {
        if ( getUTC() ) {
            result = UTCtime.FormatISOTime().Append( _T( " UTC" ) );
            return result;
        }
        wxDateTime displayTime;
        if ( g_iUTCOffset != 0 ) {
            wxTimeSpan offset( 0, g_iUTCOffset * 30, 0 );
            displayTime = UTCtime.Add( offset );
        }
        else {
            displayTime = UTCtime.FromTimezone( wxDateTime::UTC );
        }
        result = displayTime.FormatISOTime().Append( _T( " LCL" ) );
    }
    return result;
}
예제 #6
0
//run the time setting state machine. must be called frequently while in set mode.
//returns true when setting is complete or has timed out.
bool GoldieClock::setClock(void)
{
    static setStates_t SET_STATE;
    static time_t utc, local;
    static uint8_t newTzIndex;
    static int y, mth, d, h, m, maxDays;
    static uint16_t pixel;
    static uint32_t rpt;
    bool retval = false;

    //see if user wants to cancel set mode or if set mode has timed out
    if ( SET_STATE != SET_INIT )
    {
        if ( btnSet.pressedFor(SET_LONGPRESS) )
        {
            SET_STATE = SET_INIT;
            displayClock( getUTC() );
            while ( btnSet.isPressed() ) btnSet.read();    //wait for user to release the button
            return true;
        }
        uint32_t ms = millis();
        if ( (ms - btnSet.lastChange() >= SET_TIMEOUT) && (ms - btnIncr.lastChange() >= SET_TIMEOUT) )
        {
            SET_STATE = SET_INIT;
            return true;
        }
    }

    switch ( SET_STATE )
    {
    case SET_INIT:
        SET_STATE = SET_TZ;
        rpt = REPEAT_FIRST;
        utc = getUTC();
        local = (*tz).toLocal(utc, &tcr);
        newTzIndex = tzIndex;
        displaySet( newTzIndex, WHITE );
        while ( btnSet.isPressed() ) btnSet.read();    //wait for user to release the button
        break;

    case SET_TZ:
        if ( btnSet.wasReleased() )                    //then move on to set year
        {
            SET_STATE = SET_YEAR;
            rpt = REPEAT_FIRST;
            if ( newTzIndex != tzIndex )
            {
                tzIndex = newTzIndex;
                tz = timezones[tzIndex];
                eeprom_write_byte( &ee_tzIndex, tzIndex);
                Serial << F("Time zone changed to ") << tzNames[tzIndex] << endl;
            }
            y = year(local);
            if ( y < 2015 || y > 2074 ) y = 2015;      //year must be in range 2015-2074
            pixel = y - 2000;                          //map to pixel
            if ( pixel > 60 ) pixel -= 60;
            displaySet( pixel, MAGENTA );
        }
        else if ( btnIncr.wasReleased() )
        {
            rpt = REPEAT_FIRST;
            if ( ++newTzIndex >= sizeof(tzNames) / sizeof(tzNames[0]) ) newTzIndex = 0;
            displaySet( newTzIndex, WHITE );
        }
        else if ( btnIncr.pressedFor(rpt) )
        {
            rpt += REPEAT_INCR;
            if ( ++newTzIndex >= sizeof(tzNames) / sizeof(tzNames[0]) ) newTzIndex = 0;
            displaySet( newTzIndex, WHITE );
        }
        break;

    case SET_YEAR:
        if ( btnSet.wasReleased() )
        {
            SET_STATE = SET_MON;
            rpt = REPEAT_FIRST;
            mth = month(local);
            displaySet( mth, CYAN );
        }
        else if ( btnIncr.wasReleased() )
        {
            rpt = REPEAT_FIRST;
            if ( ++pixel > LAST_PIXEL ) pixel = 0;
            displaySet( pixel, MAGENTA );
            y = pixel < 15 ? 2060 + pixel : 2000 + pixel;    //map pixel to year
        }
        else if ( btnIncr.pressedFor(rpt) )
        {
            rpt += REPEAT_INCR;
            if ( ++pixel > LAST_PIXEL ) pixel = 0;
            displaySet( pixel, MAGENTA );
            y = pixel < 15 ? 2060 + pixel : 2000 + pixel;    //map pixel to year
        }
        break;

    case SET_MON:
        if ( btnSet.wasReleased() )
        {
            SET_STATE = SET_DAY;
            rpt = REPEAT_FIRST;
            d = day(local);
            maxDays = monthDays[mth-1];                      //number of days in the month
            if (mth == 2 && isLeap(y)) ++maxDays;            //account for leap year
            if ( d > maxDays ) d = maxDays;
            displaySet( d, YELLOW );
        }
        else if ( btnIncr.wasReleased() )
        {
            rpt = REPEAT_FIRST;
            if ( ++mth > 12 ) mth = 1;                       //wrap from dec back to jan
            displaySet( mth, CYAN );
        }
        else if ( btnIncr.pressedFor(rpt) )
        {
            rpt += REPEAT_INCR;
            if ( ++mth > 12 ) mth = 1;
            displaySet( mth, CYAN );
        }
        break;

    case SET_DAY:
        if ( btnSet.wasReleased() )
        {
            SET_STATE = SET_HOUR;
            rpt = REPEAT_FIRST;
            h = hour(local);
            displaySet( h, RED );
        }
        else if ( btnIncr.wasReleased() )
        {
            rpt = REPEAT_FIRST;
            if ( ++d > maxDays ) d = 1;
            displaySet( d, YELLOW );
        }
        else if ( btnIncr.pressedFor(rpt) )
        {
            rpt += REPEAT_INCR;
            if ( ++d > maxDays ) d = 1;
            displaySet( d, YELLOW );
        }
        break;

    case SET_HOUR:
        if ( btnSet.wasReleased() )
        {
            SET_STATE = SET_MIN;
            rpt = REPEAT_FIRST;
            m = minute(local);
            displaySet( m, BLUE );
        }
        else if ( btnIncr.wasReleased() )
        {
            rpt = REPEAT_FIRST;
            if ( ++h > 23 ) h = 0;
            displaySet( h, RED );
        }
        else if ( btnIncr.pressedFor(rpt) )
        {
            rpt += REPEAT_INCR;
            if ( ++h > 23 ) h = 0;
            displaySet( h, RED );
        }
        break;

    case SET_MIN:
        if ( btnSet.wasReleased() )
        {
            SET_STATE = SET_INIT;
            rpt = REPEAT_FIRST;
            tmElements_t tm;
            tm.Year = CalendarYrToTm(y);
            tm.Month = mth;
            tm.Day = d;
            tm.Hour = h;
            tm.Minute = m;
            tm.Second = 0;
            local = makeTime(tm);
            utc = (*tz).toUTC(local);
            RTC.set(utc);
            setUTC(utc);
            Serial << F("\nTime set to:\n");
            printDateTime(utc);
            Serial << F("UTC") << endl;
            printDateTime(local);
            Serial << tcr -> abbrev << endl;
            retval = true;
        }
        else if ( btnIncr.wasReleased() )
        {
            rpt = REPEAT_FIRST;
            if ( ++m > 59 ) m = 0;
            displaySet( m, BLUE );
        }
        else if ( btnIncr.pressedFor(rpt) )
        {
            rpt += REPEAT_INCR;
            if ( ++m > 59 ) m = 0;
            displaySet( m, BLUE );
        }
        break;
    }
    return retval;
}