Просмотр исходного кода

Fixed positions reading using an iterator like method

tags/v1.2.0
Bertrand Lemasle 7 лет назад
Родитель
Сommit
72ad27ca7b
3 измененных файлов: 14 добавлений и 18 удалений
  1. +4
    -8
      GpsTracker/Debug.cpp
  2. +9
    -9
      GpsTracker/Positions.cpp
  3. +1
    -1
      GpsTracker/Positions.h

+ 4
- 8
GpsTracker/Debug.cpp Просмотреть файл

@@ -175,16 +175,12 @@ namespace debug {
char buffer[128];
hardware::i2c::eepromPowerOn();

//Serial.print('[');
for (int i = 0; i < 8; i++) {
hardware::i2c::eeprom.read(128 * i, buffer, 128);
for (int i = 0; i < 128; i++) {
//if (buffer[i] == 0) Serial.print(' ');
//else
Serial.print(buffer[i], HEX);
Serial.print(buffer[i], HEX);
}
}
//Serial.println(']');
Serial.println();
hardware::i2c::eepromPowerOff();
Log.notice("Done\n");
@@ -194,10 +190,10 @@ namespace debug {
uint16_t currentEntryIndex = config::value.firstEntry;
PositionEntry currentEntry;

while(positions::moveNext(currentEntryIndex)) {
positions::get(currentEntryIndex, currentEntry);
do {
if (!positions::get(currentEntryIndex, currentEntry)) break;
details::displayPosition(currentEntry);
}
} while (positions::moveNext(currentEntryIndex));
}

void getAndDisplayEepromLastPosition() {


+ 9
- 9
GpsTracker/Positions.cpp Просмотреть файл

@@ -41,21 +41,20 @@ namespace positions {
if (firstEntryIndex > _maxEntryIndex) firstEntryIndex = 0;

entryAddress = getEntryAddress(lastEntryIndex);
bool success = hardware::i2c::eeprom.writeBlock(entryAddress, entry);
if (success) {
VERBOSE_FORMAT("appendLast", "Written to EEPROM @ %X : [%d%% @ %dmV] [%d, %s]", entryAddress, battery.level, battery.voltage, gpsStatus, entry.position);
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);
config::value.firstEntry = firstEntryIndex;
config::value.lastEntry = lastEntryIndex;
config::write();
}
config::value.firstEntry = firstEntryIndex;
config::value.lastEntry = lastEntryIndex;
config::write();

storage::powerOff();
}

void get(uint16_t index, PositionEntry &entry) {
bool get(uint16_t index, PositionEntry &entry) {
uint16_t entryAddress = getEntryAddress(index);
if (entryAddress == -1) return;
if (entryAddress == -1) return false;

VERBOSE_FORMAT("get", "Reading entry n°%d @ %X", index, entryAddress);

@@ -64,6 +63,7 @@ namespace positions {
storage::powerOff();

VERBOSE_FORMAT("get", "Read from EEPROM @ %X : [%d%% @ %dmV] [%d, %s]", entryAddress, entry.battery.level, entry.battery.voltage, entry.status, entry.position);
return true;
}

bool moveNext(uint16_t &index) {


+ 1
- 1
GpsTracker/Positions.h Просмотреть файл

@@ -13,7 +13,7 @@ struct PositionEntry {
namespace positions {
void appendLast(const SIM808ChargingStatus battery, const SIM808_GPS_STATUS gpsStatus);

void get(uint16_t index, PositionEntry &entry);
bool get(uint16_t index, PositionEntry &entry);
bool moveNext(uint16_t &index);

bool needsToSend();


Загрузка…
Отмена
Сохранить