bool DS1374RTC::readAlarm(tmElements_t &tm) { uint8_t sec; timeDate_t timeDate; Wire.beginTransmission(DS1374_CTRL_ID); #if ARDUINO >= 100 Wire.write((uint8_t)0x04); // Set to alarm register #else Wire.send(0x04); // Set to alarm register #endif if (Wire.endTransmission() != 0) { exists = false; return false; } exists = true; // request the 4 TOD Counts Wire.requestFrom(DS1374_CTRL_ID, 3);// TODO replace magic number here if (Wire.available() < 3) return false; #if ARDUINO >= 100 timeDate.bytes[0] = Wire.read(); timeDate.bytes[1] = Wire.read(); timeDate.bytes[2] = Wire.read(); #else timeDate.bytes[0] = Wire.receive(); timeDate.bytes[1] = Wire.receive(); timeDate.bytes[2] = Wire.receive(); #endif breakTime(timeDate.time, tm); //if (sec & 0x80) return false; // clock is halted TODO - look at an equivalent here return true; }
// FLRDDE626>APRS,qAS,EGHL:/074548h5111.32N/00102.04W'086/007/A=000607 id0ADDE626 -019fpm +0.0rot 5.5dB 3e -4.3kHz void WiFi_forward_to_cloud() { tmElements_t tm; char str_lat[8]; char str_lon[8]; breakTime(fo.timestamp, tm); dtostrf_workaround(take_minutes(fo.latitude), 5, 2, str_lat); dtostrf_workaround(take_minutes(fo.longtitude), 5, 2, str_lon); //Serial.print(fo.latitude); Serial.print(" "); Serial.println(fo.longtitude); snprintf(UDPpacketBuffer, sizeof(UDPpacketBuffer), \ "FLR%X>APRS,qAS,%s:/%02d%02d%02dh%02d%s%s/%03d%s%s/A=%05u TS:%d RAW:%s", \ fo.addr, STATION_ID, tm.Hour, tm.Minute, tm.Second, \ abs(take_degrees(fo.latitude)), str_lat, (fo.latitude < 0 ? "S" : "N"), \ abs(take_degrees(fo.longtitude)), str_lon, (fo.longtitude < 0 ? "W" : "E"), \ fo.altitude, fo.timestamp, fo.raw.c_str() ); #ifdef SERIAL_VERBOSE Serial.println(UDPpacketBuffer); #endif client.println(UDPpacketBuffer); }
/* * setTime */ bool DS1339::setTime(time_t t) { byte buffer[7]; tmElements_t tm; breakTime(t, tm); buffer[0] = dec2bcd(tm.Second); buffer[1] = dec2bcd(tm.Minute); buffer[2] = dec2bcd(tm.Hour); buffer[3] = dec2bcd(tm.Wday); buffer[4] = dec2bcd(tm.Day); buffer[5] = dec2bcd(tm.Month); buffer[6] = dec2bcd(tmYearToY2k(tm.Year)); buffer[0] |= DS1339_CLOCKHALT; // stop the clock if(writeBytes(buffer, 0, 7) !=7) { return false; } if(isRunning()) { buffer[0] &= DS1339_SEC_MASK; if(writeBytes(buffer, 0, 7) != 7) { return false; } } return true; }
void refreshCache( time_t t){ if( t != cacheTime) { breakTime(t, tm); cacheTime = t; } }
void MCP7940RTC::setAlarm0(time_t t) { tmElements_t tm; breakTime(t, tm); Wire.beginTransmission(MCP7940_CTRL_ID); #if ARDUINO >= 100 Wire.write((uint8_t)0x0a); Wire.write((uint8_t)dec2bcd(tm.Second) & 0x7f); // Seconds Wire.write((uint8_t)dec2bcd(tm.Minute) & 0x7f); // Minutes Wire.write((uint8_t)dec2bcd(tm.Hour) & 0x3f); // Hour Wire.write((uint8_t)(dec2bcd(tm.Wday) | 0x70) & 0x97);// wDay, trigger on minutes matching Wire.write((uint8_t)dec2bcd(tm.Day) & 0x3f); // Day Wire.write((uint8_t)dec2bcd(tm.Month) & 0x1f); // Hour #else Wire.send(0x0a); Wire.send(dec2bcd(tm.Second & 0x7f)); // Seconds Wire.send(dec2bcd(tm.Minute & 0x7f)); // Minutes Wire.send(dec2bcd(tm.Hour & 0x3f)); // Hour Wire.send((dec2bcd(tm.Wday) | 0x70) & 0xf7); // wDay Wire.send(dec2bcd(tm.Day) & 0x3f); // Day Wire.send(dec2bcd(tm.Month) & 0x1f); // Hour #endif Wire.endTransmission(); // enable alarm 0 Wire.beginTransmission(MCP7940_CTRL_ID); #if ARDUINO >= 100 Wire.write((uint8_t)0x07); Wire.write((uint8_t)0x10); #else Wire.send(0x07); Wire.send(0x10); #endif Wire.endTransmission(); }
// -------------------------------------------------------- // Set the RTC to the given time_t value. // Returns the bus status (zero if successful). uint8_t DS1302RTC::set(time_t t) { tmElements_t tm; breakTime(t, tm); return ( write(tm) ); }
void godob::printdate(void) { char ch; // Warning! if(timeStatus() != timeSet) { LCD->setCursor(0, 1); LCD->print(F("RTC ERROR: SYNC!")); } else{ tmElements_t tm; breakTime(now(), tm); // Display abbreviated Day-of-Week in the lower left corner LCD->setCursor(0, 1); if(!Connected){ ch = '_'; } else if(reqPending){ ch = '+'; } else{ ch = '*'; } LCD->write(ch); LCD->write(' '); LCD->print(dayShortStr(tm.Wday)); LCD->print(" "); print2digits(tm.Day); LCD->print("/"); print2digits(tm.Month); LCD->print("/"); LCD->print(tm.Year+1970); } }
/*----------------------------------------------------------------------* * Set the RTC to the given time_t value. * * Returns the I2C status (zero if successful). * *----------------------------------------------------------------------*/ byte DS3232RTC::set(time_t t) { tmElements_t tm; breakTime(t, tm); return ( write(tm) ); }
bool DS1307RTC::set(time_t t) { tmElements_t tm; breakTime(t, tm); tm.Second |= 0x80; // stop the clock write(tm); tm.Second &= 0x7f; // start the clock write(tm); }
bool Alarm::isTriggered(time_t currentTime) { if (isEnabled()) { tmElements_t hms_alarm; tmElements_t hms_time; breakTime(_alarmTime, hms_alarm); breakTime(currentTime, hms_time); if (hms_alarm.Minute == hms_time.Minute && hms_alarm.Hour == hms_time.Hour) { return true; } } return false; }
void DS1307RTC::set(time_t t) { tmElements_t tm; breakTime(t, tm); //tm.Second |= 0x80; // stop the clock ray: removed this step //write(tm); //tm.Second &= 0x7f; // start the clock ray: moved to write function write(tm); }
// Funtion: Set current time bool SensorDs1307::setData(time_t t) { tmElements_t tm; breakTime(t, tm); tm.Second |= 0x80; // stop the clock write(tm); tm.Second &= 0x7f; // start the clock write(tm); }
char *convert_date(char *twitter_date, int utc_offset) { // Twitter date format: Sat, 12 Jan 2012 23:34:45 +0000 // 0123456789012345678901234567890 // 0 1 2 3 // Format in other parts of API: Sat Jan 12 23:34:45 +0000 2012 // Apparently not in search API, however. // Extract year. unsigned int year = strtol(twitter_date + 12, NULL, 10); // Extract abbreviated name of month. char *month_name = (char *) calloc(3 + 1, sizeof(char)); memcpy(month_name, twitter_date + 8, 3 * sizeof(char)); // Calculate month's number. uint8_t month = 0; while (strcmp(month_name, month_names[month]) != 0 && month < 11) { ++month; } ++month; // Put date within interval 1-12 instead of 0-11. free(month_name); // Convert to time structure. TimeElements utc_date; utc_date.Year = year - 1970; // Offset from 1970 as required by TimeElements. utc_date.Month = month; utc_date.Day = strtol(twitter_date + 5, NULL, 10); // Extract day. utc_date.Hour = strtol(twitter_date + 17, NULL, 10); // Extract hour. utc_date.Minute = strtol(twitter_date + 20, NULL, 10); // Extract minute. utc_date.Second = 0; // Convert to timestamp and apply UTC offset. time_t utc_time = makeTime(utc_date); time_t other_time = utc_time + utc_offset; // Convert back into time structure. TimeElements other_date; breakTime(other_time, other_date); // Length of minimal format string: // "- d/m hh:mm" // 12345678901 uint8_t result_length = 11; // Consider days and months with two digits. if (other_date.Day >= 10) { ++result_length; } if (other_date.Month >= 10) { ++result_length; } // Create the final string. char *result = (char *) calloc(result_length + 1, sizeof(char)); sprintf(result, DATE_FORMAT, other_date.Day, other_date.Month, other_date.Hour, other_date.Minute); return result; }
void godob::printtime(void) { tmElements_t tm; breakTime(now(), tm); LCD->setCursor(1, 0); print2digits(tm.Hour); LCD->print(":"); print2digits(tm.Minute); LCD->print(":"); print2digits(tm.Second); LCD->print(" GMT+2"); }
bool DS1307RTC::set(time_t t) { #ifdef __STM32F1__ DS1307RTC_INIT_WIRE(); #endif tmElements_t tm; breakTime(t, tm); tm.Second |= 0x80; // stop the clock write(tm); tm.Second &= 0x7f; // start the clock write(tm); }
bool DS1374RTC::setTime(time_t t) { tmElements_t tm; // TODO - don't need a break time here could setup another write routine // that uses the time_t value breakTime(t, tm); // tm.Second |= 0x80; // stop the clock setTime(tm); // tm.Second &= 0x7f; // start the clock // write(tm); }
void setRtcAlarm(byte hour, byte minute) { // copy time_t object, modify some fields, // inherit month, day, dayOfWeek and Year. time_t justNow = now(); tmElements_t alarmSetting; breakTime(justNow, alarmSetting); alarmSetting.Hour = hour; alarmSetting.Minute = minute; alarmSetting.Second = 0; wkAlarm.setAlarmTime(makeTime(alarmSetting)); printAlarmStatus(); }
Alarm::Alarm() { // fill in structure with current time time_t n = now(); tmElements_t alarmSetting; breakTime(n, alarmSetting); // set alarm value to 00:00:00 (HH:MM:SS). alarmSetting.Hour = 0; alarmSetting.Minute = 0; alarmSetting.Second = 0; setAlarmTime(makeTime(alarmSetting)); disableAlarm(); }
/** * Update RTC with new DCFTime */ void RTCDCF77::startStopDCF() { // Determine if to turn on the DCF77 receiver time_t currentTime = get(); TimeElements _timeElements; breakTime(currentTime, _timeElements); if ( ((long)(currentTime - status.previousRefTime) > minInterval) && // if last update longer ago than minInterval .. (_timeElements.Hour > 22) && (_timeElements.Hour < 4) // and during evening/night ( better reception) .. ) { if (!DCFC->isRunning()) { DCFC->Start(); } // Start DCF77 clock (if not running) } else { if (DCFC->isRunning()) { DCFC->Stop(); } // Else, stop DCF77 clock (if running) } }
// Aquire data from the RTC chip in BCD format // Returns true if successful bool DS1374RTC::readTime(tmElements_t &tm) { uint8_t value; timeDate_t timeDate; Wire.beginTransmission(DS1374_CTRL_ID); #if ARDUINO >= 100 Wire.write((uint8_t)0x00); #else Wire.send(0x00); #endif if (Wire.endTransmission() != 0) { exists = false; return false; } exists = true; // request the 4 TOD Counts Wire.requestFrom(DS1374_CTRL_ID, 9);// TODO replace magic number here if (Wire.available() < 9) return false; #if ARDUINO >= 100 timeDate.bytes[0] = Wire.read(); timeDate.bytes[1] = Wire.read(); timeDate.bytes[2] = Wire.read(); timeDate.bytes[3] = Wire.read(); value = Wire.read(); // Alarm registers value = Wire.read(); value = Wire.read(); value = Wire.read(); // Control value = Wire.read(); // Status #else timeDate.bytes[0] = Wire.receive(); timeDate.bytes[1] = Wire.receive(); timeDate.bytes[2] = Wire.receive(); timeDate.bytes[3] = Wire.receive(); value = Wire.receive(); // Alarm registers value = Wire.receive(); value = Wire.receive(); value = Wire.receive(); // Control value = Wire.receive(); // Status #endif breakTime(timeDate.time, tm); if (value & 0x80) return false; // clock is halted TODO return true; }
void MCP7940RTC::set(time_t t) { tmElements_t tm; breakTime(t, tm); tm.Second &= 0x7f; // stop the oscillator and write the data write(tm); uint8_t s = (tm.Second | 0x80); // assert oscillator start bit // Start the oscillator Wire.beginTransmission(MCP7940_CTRL_ID); #if ARDUINO >= 100 Wire.write((uint8_t)0x00); Wire.write((dec2bcd(tm.Second) | 0x80)); // Seconds #else Wire.send(0x00); Wire.send(s); #endif Wire.endTransmission(); }
int Controller::calculateProgress() { int progress = 0; // return variable time_t current = now(); // save current time tmElements_t elements; // create start time for comparsion breakTime(current, elements); // break time into elements elements.Second = 0; // set set start time elements.Hour = (int)*_times; elements.Minute = (int)*(_times+1); time_t start = makeTime(elements); // convert back to timestamp if (current > start) // if the cycle has started today { elements.Hour = (unsigned int)*(_times+2); // reuse elements to create stop time timestamp elements.Minute = (unsigned int)*(_times+3); time_t stop = makeTime(elements); // make the timestamp if (current < stop) { progress = (current-start)*100/(stop-start); // calculate progress } else { progress = 100; } } else { //breakTime(nextMidnight(current), elements); // lets make an elements object holding next day's date elements.Hour = (unsigned int)*(_times+4); // set the rewind time elements.Minute = (unsigned int)*(_times+5); time_t rewind = makeTime(elements); // make the timestamp if (current < rewind) { progress = 100; } } return progress; }
SetTimeHelper::SetTimeHelper() { for (int i = 0; i < 12; i ++) { monthNames[i] = (char *)monthNamesList[i]; } breakTime(now(), currentTime); retrieveCompileTime(); }
void setRTCTime(time_t t) { tmElements_t tm; breakTime(t, &tm); rtc.setTime_s(tm.Hour, tm.Minute, tm.Second); }
/** * Read the current time */ void App::getTime() { time_t local = timezone.toLocal( now() ); isDst = timezone.locIsDST(local); breakTime(local, time); }
void Devices::displayDate(time_t time, Stream* displayOn) { tmElements_t _t; breakTime(time, _t); displayDate(&_t, displayOn); }
void SetTimeMenu::configureTime() { Serial.println(F("Entering configureTime()...")); nextMode(); tmElements_t tm; #if TEENSYDUINO breakTime(now(), tm); #else if (!RTC.read(tm)) { app->debug(0, "Can't ¨read current time", true); delay(3000); return; } #endif switch (app->mode) { case SetTime::Hour: blinkColor(ColorNames::red); app->debug(0, "====== Setup =======", true); instructions(); what = (char *) "Hours"; h = tm.Hour; if (h == 0) { h = 24; } selectNumber(&h, 1, 24); if (app->mode == SetTime::Default) break; /* no break */ case SetTime::Minute: blinkColor(ColorNames::yellow); what = (char *) "Minutes"; m = tm.Minute; selectNumber(&m, 0, 59); if (app->mode == SetTime::Default) break; /* no break */ case SetTime::Save: blinkColor(ColorNames::red); if (h == 24) { h = 0; } tm.Hour = h; tm.Minute = m; tm.Second = 0; sprintf(buffer, "New Time: %2d:%02d", h, m); Serial.print("Setting Time to: "); Serial.println(buffer); #if DEBUG app->debug(0, "Saving New Time...", true); app->debug(1, buffer, false); app->debug(3, "Success! :)", false); #endif app->helper.setTimeTo(tm, 0); nextMode(); /* no break */ case SetTime::Last: app->mode = SetTime::Default; /* no break */ case SetTime::Default: return; }; }
void PCF85xx::set(time_t t) { tmElements_t tm; breakTime(t, tm); this->write(tm); }
void setup() { Serial.begin(SERIAL_SPEED); randomSeed(analogRead(1)); #ifdef DEBUG Serial.println("start test..."); Serial.print(F(" CE=")); Serial.print(PIN_CE); Serial.print(F(" CSN=")); Serial.print(PIN_CSN); Serial.print(F(" MISO=")); Serial.print(MISO); Serial.print(F(" MOSI=")); Serial.print(MOSI); Serial.print(F(" SCK=")); Serial.println(SCK); #endif #ifdef RTC_ENABLE rtc.init(90); uint32_t tmp = rtc.read(); setTime(tmp); Serial.print(millis()); Serial.print(F(": time is: ")); Serial.print(tmp); Serial.print(F(" = ")); tmElements_t tmElems; breakTime(tmp, tmElems); Serial.print((uint16_t) 1970 + tmElems.Year); Serial.print(F("/")); Serial.print(tmElems.Month); Serial.print(F("/")); Serial.print(tmElems.Day); Serial.print(F(" ")); Serial.print(tmElems.Hour); Serial.print(F(":")); Serial.print(tmElems.Minute); Serial.print(F(":")); Serial.println(tmElems.Second); #endif //enable watchdog wdt_enable(WDTO_8S); //get address config getAddress(); ram.init(RAM_MGR_SS_PIN, RAM_MGR_ADDRESS_WIDTH, RAM_MGR_RAM_LEN); #ifdef WEBSERVER_ENABLE webServerWrapper.init(); #endif #ifdef SDCARD_ENABLE sdcard.initSD(); discoveryManager.init(); nodeInfo.init(); #endif dispatcher.init(); hwInterface.init(); //init network l3.init(address_local); l2.init(&l3, PIN_CE, PIN_CSN, address_local); l3.setLayer2(&l2); dht11.init(A2, 20); #ifdef __AVR_ATmega2560__ rcsw.init(14, 21); #else rcsw.init(A6, 21); #endif bmp180.init(80); motion.init(A3, 50); light.init(A7, 60); //mytone.init(A8, 70); #ifdef RTC_ENABLE hwInterface.registerDriver((HardwareDriver*) &rtc); #endif hwInterface.registerDriver((HardwareDriver*) &dht11); hwInterface.registerDriver((HardwareDriver*) &rcsw); hwInterface.registerDriver((HardwareDriver*) &motion); hwInterface.registerDriver((HardwareDriver*) &light); hwInterface.registerDriver((HardwareDriver*) &bmp180); //hwInterface.registerDriver((HardwareDriver*) &mytone); dispatcher.init(&l3, &hwInterface); #ifdef SDCARD_LOGGER_ENABLE dispatcher.getResponseHandler()->registerListenerByPacketType(0, HARDWARE_COMMAND_RES, 0, &sdlistener); #endif #ifdef TIMER_ENABLE timer.init(); #endif /*/test rcsw //HardwareCommandResult cmd; //memset(&cmd, 0, sizeof(cmd)); //cmd.setHardwareType(HWType_rcswitch); //cmd.setAddress(rcsw.getAddress()); //cmd.setUint8ListNum(2); //cmd.getUint8List()[0] = 3; //cmd.getUint8List()[1] = 0; //hwInterface.executeCommand(&cmd); ///*/ /* SDcard::SD_nodeDiscoveryInfoTableEntry_t infos[2]; infos[0].hardwareAddress = 0xAA; infos[0].hardwareType = 0xBB; infos[0].rtcTimestamp = 0xCC; infos[1].hardwareAddress = 0xDD; infos[1].hardwareType = 0xEE; infos[1].rtcTimestamp = 0xFF; sdcard.saveDiscoveryInfos(1, infos, 2); SDcard::SD_nodeDiscoveryInfoTableEntry_t discovery[SD_DISCOVERY_NUM_INFOS_PER_NODE]; sdcard.getDiscoveryInfosForNode(1, discovery, SD_DISCOVERY_NUM_INFOS_PER_NODE); Serial.print(discovery[0].hardwareAddress); Serial.print(F(" ")); Serial.print(discovery[0].hardwareType); Serial.print(F(" ")); Serial.println(discovery[0].rtcTimestamp); Serial.print(discovery[1].hardwareAddress); Serial.print(F(" ")); Serial.print(discovery[1].hardwareType); Serial.print(F(" ")); Serial.println(discovery[1].rtcTimestamp); Serial.flush(); */ /* #ifdef SDCARD_ENABLE char buf[17]; memset(buf, 0, sizeof(buf)); Serial.print(millis()); Serial.print(F(": nodeinfo")); if(sdcard.getNodeInfo(l3.localAddress, (uint8_t*) buf, sizeof(buf))) { buf[16] = '\0'; Serial.print(F("=\"")); Serial.print(buf); Serial.println(F("\"")); } else { Serial.println(F(" not available")); } dispatcher.getResponseHandler()->registerListenerByPacketType(0, HARDWARE_COMMAND_RES, 0, &sdlistener); packet_application_numbered_cmd_t appPacket; memset(&appPacket, 0, sizeof(appPacket)); appPacket.packetType = HARDWARE_COMMAND_RES; command_t* hwcmd = (command_t*) appPacket.payload; hwcmd->address = 10; hwcmd->type = HWType_rtc; hwcmd->numUint8 = 4; uint32_t now = rtc.read(); hwcmd->uint8list[0] = now >> 24; hwcmd->uint8list[1] = (now >> 16) & 0xff; hwcmd->uint8list[2] = (now >> 8) & 0xff; hwcmd->uint8list[3] = now & 0xff; dispatcher.handleNumbered(13, HARDWARE_COMMAND_RES, 123, &appPacket); //sdlistener.doCallback(&appPacket, 17, 1234); #endif */ /* //mySimpleTimer = SimpleTimer::instance(); //Serial.println("### testHardwareCommand: Tone ###"); //Serial.flush(); //testHardwareCommandTone(); // // //Serial.println("### testHardwareCommand: Light ###"); //Serial.flush(); //testHardwareCommand(0, HWType_light, true); //testHardwareCommand(0, HWType_light, true); //testHardwareCommand(0, HWType_light, true); // //Serial.println("### testHardwareCommand: Temperature ###"); //Serial.flush(); //testHardwareCommand(0, HWType_temprature, true); // //Serial.println("### testHardwareCommand: Motion ###"); //Serial.flush(); //testHardwareCommand(0, HWType_motion, true); // //Serial.println("### testHardwareCommandRead ###"); //Serial.flush(); //testHardwareCommandRead(); // //Serial.println("### testDiscovery ###"); //Serial.flush(); //testDiscovery(); // //Serial.println("### testSubscriptionSet ###"); //Serial.flush(); //testSubscriptionSet(); // //Serial.println("### testSubscriptionInfo ###"); //Serial.flush(); //testSubscriptionInfo(); // //Serial.println("### testSubscriptionExecution ###"); //Serial.flush(); //testSubscriptionExecution(); // //Serial.println("### testSubscriptionPolling ###"); //Serial.flush(); //testSubscriptionPolling(); // //Serial.println("### testSubscriptionPolling Light ###"); //Serial.flush(); //testSubscriptionPollingLight(); // ////turn off LED //pinMode(LED_BUILTIN, LOW);*/ }
void Settings::setBreakTimeMin(int min) { m_settings->setValue(BREAKTIMEMIN_NAME, QVariant(min)); emit breakTimeChanged(breakTime()); }