//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(); }
DashboardInstrument_Clock::DashboardInstrument_Clock( wxWindow *parent, wxWindowID id, wxString title, int cap_flag, wxString format ) : DashboardInstrument_Single( parent, id, title, cap_flag, format ) { // if format contains the string "LCL" then display time in local TZ if ( format.Contains( _T( "LCL" ) ) ) setUTC( false ); else setUTC( true ); wxClientDC dc(this); int w, dw; dc.GetTextExtent(m_title, &w, &m_TitleHeight, 0, 0, g_pFontTitle); dc.GetTextExtent(_T("00:00:00 UTC"), &dw, &m_DataHeight, 0, 0, g_pFontData); SetMinSize( wxSize(wxMax(wxMax(MinWidth, w), dw), m_TitleHeight+m_DataHeight)); }
//------------------------------------------------------------------------------ // Process phase //------------------------------------------------------------------------------ void Navigation::process(const LCreal dt) { BaseClass::process(dt); // Update UTC double v = utc + dt; if (v >= Basic::Time::D2S) v = (v - Basic::Time::D2S); setUTC(v); // --- // Update our primary route // --- if (priRoute != 0) priRoute->tcFrame(dt); }
//------------------------------------------------------------------------------ // Process phase //------------------------------------------------------------------------------ void Navigation::process(const LCreal dt) { BaseClass::process(dt); // --- // Update our position, attitude and velocities // --- if (getOwnship() != 0) { velValid = updateSysVelocity(); posValid = updateSysPosition(); attValid = updateSysAttitude(); magVarValid = updateMagVar(); } else { posValid = false; attValid = false; velValid = false; magVarValid = false; } // Update UTC double v = utc + dt; if (v >= Basic::Time::D2S) v = (v - Basic::Time::D2S); setUTC(v); // --- // Update our primary route // --- if (priRoute != 0) priRoute->tcFrame(dt); // Update our bullseye if (bull != 0) bull->compute(this); // --- // Update our navigational steering data // --- updateNavSteering(); }
//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; }