String SensorDs1307::get(void) {
  String message = "\"" + instruction_code_ + "\":{" + id_ + ",";
  tmElements_t tm;
  if (read(tm)) {
    // Day
    if (tm.Day < 10) {
      message += "0";
    }
    message += tm.Day;
    message += "/";

    // Month
    if (tm.Month < 10) {
      message += "0";
    }
    message += tm.Month;
    message += "/";

    // Year
    message += tmYearToCalendar(tm.Year);
    message += " ";

    // Hour
    if (tm.Hour < 10) {
      message += "0";
    }
    message += tm.Hour;
    message += ":";

    // Minute
    if (tm.Minute < 10) {
      message += "0";
    }
    message += tm.Minute;
    message += ":";

    // Seconds
    if (tm.Second < 10) {
      message += "0";
    }
    message += tm.Second;
    message += "},";
  } 
  else {
    if (chipPresent()) {
        message += "0.0},\"ERR\":{2,\"ds1307\"},";
//      message += "Error: The time is not set on the DS1307 Time Sensor.\n";
//      message += "Likely Cause: The battery became dislodged or died.\n";
//      message += "Possible Fix: Run the set time function.";
    } 
    else {
        message += "0.0},\"ERR\":{3,\"ds1307\"},";
//      message += "Error: Unable to read the time from the DS1307 Time Sensor.\n";
//      message += "Likely Cause: Improper wiring or chip is dead.\n";
//      message += "Possible Fix: Check the circuitry.";
    }
  }
  return message; 
}
Exemple #2
0
void ab1815_print_timeElement(struct tmElements_t *time)
{
	printf("%i/%02i/%02i %02i:%02i:%02i",
	tmYearToCalendar(time->Year),
	time->Month,
	time->Day,
	time->Hour,
	time->Minute,
	time->Second
	);	
}
void PCF85xx::write(tmElementsWithMillis &tm) {
	uint64_t eeprom_time = this->load();

	uint16_t year_off = (int) tmYearToCalendar(tm.Year)
			- (int) year(eeprom_time / 1000);
	if ((!eeprom_time) == 0 || year_off >= 3 || year_off < 0) { //unset eeprom or bad offsets
		eeprom_time = makeTimeMilli(tm);
		this->save(eeprom_time);
		year_off = 0;
	}
	TIME time;

	time.hours.is24hr = time.hours.am = 0;
	time.hours.hour_t = tm.Hour / 10;
	time.hours.hour_u = tm.Hour % 10;

	time.day_year.day_t = tm.Day / 10;
	time.day_year.day_u = tm.Day % 10;

	time.day_year.year_off = year_off;

	time.wday_month.month_t = tm.Month / 10;
	time.wday_month.month_u = tm.Month % 10;
	time.wday_month.dow = tm.Wday;

	time.minutes.ten = tm.Minute / 10;
	time.minutes.unit = tm.Minute % 10;

	time.seconds.ten = tm.Second / 10;
	time.seconds.unit = tm.Second % 10;

	time.hundredths.ten = (tm.Milliseconds / 10) / 10;
	time.hundredths.unit = (tm.Milliseconds / 10) % 10;

	this->wire.beginTransmission(this->WRITE_ADDR);
	this->wire.write(this->HUNDRETH_SEC_REG); //Starting address
	uint8_t * data = (uint8_t*) &time;
	for (uint8_t i = 0; i < sizeof(time); i++) {
		this->wire.write(data[i]);
	}
	this->wire.endTransmission();
}
void Devices::displayDate(tmElements_t* time, Stream* displayOn)
{
    displayOn->print(tmYearToCalendar(time->Year), DEC);
    flash_print(displayOn, WQM_Strings::SLASH);
    LEADING_ZERO(displayOn, time->Month);
    displayOn->print(time->Month, DEC);
    flash_print(displayOn, WQM_Strings::SLASH);
    LEADING_ZERO(displayOn, time->Day);
    displayOn->print(time->Day, DEC);
    flash_print(displayOn, WQM_Strings::SPACE);
    LEADING_ZERO(displayOn, time->Hour);
    displayOn->print(time->Hour, DEC);
    flash_print(displayOn, WQM_Strings::COLON);
    LEADING_ZERO(displayOn, time->Minute);
    displayOn->print(time->Minute, DEC);
    flash_print(displayOn, WQM_Strings::COLON);
    LEADING_ZERO(displayOn, time->Second);
    displayOn->print(time->Second, DEC);
    displayOn->println();
}
Exemple #5
0
// 0x00
enum ab1815_status ab1815_set_time(struct ab1815_t *clock, struct tmElements_t *time)
{
	size_t length = (AB1815_REG_ALARM_HUNDREDTHS - AB1815_REG_TIME_HUNDREDTHS);
	uint8_t buffer[length];
	enum ab1815_status result = ab1815_status_ERROR;
			
	memset(buffer, 0, length);
	buffer[0] = bin2bcd(time->Hundredth);
	buffer[1] = bin2bcd(0x7F & time->Second);
	buffer[2] = bin2bcd(0x7F & time->Minute);
	buffer[3] = bin2bcd(0x3F & time->Hour);
	buffer[4] = bin2bcd(0x3F & time->Day);
	buffer[5] = bin2bcd(0x1F & time->Month);
	buffer[6] = bin2bcd(tmYearToCalendar(time->Year) - 2000);
	buffer[7] = bin2bcd(0x07 & time->Wday);
		
	if(ab1815_write(clock, AB1815_REG_TIME_HUNDREDTHS, buffer, length) == ab1815_status_OK)
	{
		result = ab1815_status_OK;	
	}
	return result;						
};
int year(time_t t) { // the year for the given time
  refreshCache(t);
  return tmYearToCalendar(tm.Year);
}