diff --git a/GpsTracker/Core.cpp b/GpsTracker/Core.cpp index 185d65a..fb24d0b 100644 --- a/GpsTracker/Core.cpp +++ b/GpsTracker/Core.cpp @@ -20,7 +20,7 @@ namespace core { gps::getTime(time); rtc::setTime(time); - positions::appendLast(battery, gpsStatus); + positions::appendLast(battery, gpsStatus, rtc::getTemperature()); uint8_t velocity; gps::getVelocity(velocity); diff --git a/GpsTracker/Debug.cpp b/GpsTracker/Debug.cpp index 17e2481..79223fd 100644 --- a/GpsTracker/Debug.cpp +++ b/GpsTracker/Debug.cpp @@ -6,7 +6,7 @@ #define MENU_ENTRY(name, text) const char MENU_##name[] PROGMEM = text -const char FAKE_GPS_ENTRY[] PROGMEM = "1,1,20170924074842.000,49.454862,1.144537,71.900,67.99,172.6,1,,1.3,2.2,1.8,,11,7,,,37,,"; +const char FAKE_GPS_ENTRY[] PROGMEM = "1,1,20170924184842.000,49.454862,1.144537,71.900,67.99,172.6,1,,1.3,2.2,1.8,,11,7,,,37,,"; MENU_ENTRY(HEADER, "-- Debug Menu --"); MENU_ENTRY(SEPARATOR, "----"); @@ -107,7 +107,7 @@ namespace debug { namespace details { inline void displayPosition(PositionEntry entry) { - Log.notice(F("%d%%, %dmV, %d, %s\n"), entry.battery.level, entry.battery.voltage, entry.status, entry.position); + Log.notice(F("%d%%, %dmV, %f°C, %d, %s\n"), entry.battery.level, entry.battery.voltage, entry.temperature, entry.status, entry.position); } } @@ -223,7 +223,7 @@ namespace debug { SIM808ChargingStatus status = hardware::sim808::device.getChargingState(); hardware::sim808::powerOff(); - positions::appendLast(status, SIM808_GPS_STATUS::OFF); + positions::appendLast(status, SIM808_GPS_STATUS::OFF, rtc::getTemperature()); } void setRtcTime() { diff --git a/GpsTracker/Positions.cpp b/GpsTracker/Positions.cpp index dc37bc5..97b2289 100644 --- a/GpsTracker/Positions.cpp +++ b/GpsTracker/Positions.cpp @@ -19,11 +19,11 @@ namespace positions { return ENTRIES_ADDR + (ENTRY_RESERVED_SIZE * index); } - void appendLast(const SIM808ChargingStatus battery, const SIM808_GPS_STATUS gpsStatus) { + void appendLast(const SIM808ChargingStatus battery, const SIM808_GPS_STATUS gpsStatus, const float temperature) { VERBOSE("appendLast"); uint16_t entryAddress; - PositionEntry entry = { battery, gpsStatus }; + PositionEntry entry = { battery, temperature, gpsStatus }; strlcpy(entry.position, gps::lastPosition, POSITION_SIZE); hardware::i2c::powerOn(); @@ -36,8 +36,8 @@ namespace positions { entryAddress = getEntryAddress(config.lastEntry); hardware::i2c::eeprom.writeBlock(entryAddress, entry); - - VERBOSE_FORMAT("appendLast", "Written to EEPROM @ %X : [%d%% @ %dmV] [%d, %s]", entryAddress, battery.level, battery.voltage, gpsStatus, entry.position); + + VERBOSE_FORMAT("appendLast", "Written to EEPROM @ %X : [%d%% @ %dmV] [%f°C] [%d, %s]", entryAddress, entry.battery.level, entry.battery.voltage, entry.temperature, entry.status, entry.position); config::set(config); hardware::i2c::powerOff(); @@ -53,7 +53,7 @@ namespace positions { hardware::i2c::eeprom.readBlock(entryAddress, entry); hardware::i2c::powerOff(); - VERBOSE_FORMAT("get", "Read from EEPROM @ %X : [%d%% @ %dmV] [%d, %s]", entryAddress, entry.battery.level, entry.battery.voltage, entry.status, entry.position); + VERBOSE_FORMAT("get", "Read from EEPROM @ %X : [%d%% @ %dmV] [%f°C] [%d, %s]", entryAddress, entry.battery.level, entry.battery.voltage, entry.temperature, entry.status, entry.position); return true; } diff --git a/GpsTracker/Positions.h b/GpsTracker/Positions.h index f5c6bff..21b29eb 100644 --- a/GpsTracker/Positions.h +++ b/GpsTracker/Positions.h @@ -6,12 +6,13 @@ struct PositionEntry { SIM808ChargingStatus battery; //sizeof = 4 + float temperature; //sizeof = 4 SIM808_GPS_STATUS status; //sizeof = 1 char position[POSITION_SIZE]; //sizeof = 115 }; //sizeof = 119 namespace positions { - void appendLast(const SIM808ChargingStatus battery, const SIM808_GPS_STATUS gpsStatus); + void appendLast(const SIM808ChargingStatus battery, const SIM808_GPS_STATUS gpsStatus, const float temperature); bool get(uint16_t index, PositionEntry &entry); bool moveNext(uint16_t &index); diff --git a/GpsTracker/Rtc.cpp b/GpsTracker/Rtc.cpp index 4818804..f901232 100644 --- a/GpsTracker/Rtc.cpp +++ b/GpsTracker/Rtc.cpp @@ -43,6 +43,14 @@ namespace rtc { hardware::i2c::powerOff(); } + float getTemperature() { + hardware::i2c::powerOn(); + float temperature = RTC.readTempRegister(); + hardware::i2c::powerOff(); + + return temperature; + } + void getTime(tmElements_t &time) { hardware::i2c::powerOn(); RTC.readTime(); diff --git a/GpsTracker/Rtc.h b/GpsTracker/Rtc.h index c72dbc3..16caef2 100644 --- a/GpsTracker/Rtc.h +++ b/GpsTracker/Rtc.h @@ -6,6 +6,7 @@ namespace rtc { void setup(); + float getTemperature(); void getTime(tmElements_t &time); void setTime(tmElements_t &time);